Your support for our advertisers helps cover the cost of hosting, research, and maintenance of this document

Formatting Information — An introduction to typesetting with LATEX

### In this section…

This is one of the most powerful features of LATEX. As we mentioned when discussing Figures and Tables, you can label any point in a document with a name you make up, so that you can refer to it by that name from anywhere else in the document (or even from another document) and LATEX will always work out the right cross-reference number for you, no matter how much you edit the text or move it around.

As we well see later, a similar method is also used to cite documents for a bibliography or list of references, and there are packages to sort and format these in the correct style for different journals or publishers.

### 5.3.1 Cross-references

You label the place in your document you want to refer to by adding the command \label followed by a short name you make up, in curly braces: exactly as we did for labelling Figures and Tables in § 4.2.2.

\section{New Research}
\label{newstuff}


You can then refer to this place from anywhere in the same document with the command \ref followed by the name you used, eg

In section~\ref{newstuff} there is a list of recent
projects.


In section 13.5 there is a list of recent projects.

• Note the use of the unbreakable space (~) between the \ref and the word before it. This prints a space but prevents the line ever breaking at that point, should it fall close to the end of a line when being typeset.

• The \S command can be used if you want the section sign § instead of the word ‘section’ (there is also a \P command that produces the paragraph sign or pilcrow ).

Labels MUST be unique (that is, each value MUST occur only once as a label within a single document), but you can have as many references to them as you like. If you are familiar with HTML, this is the same concept as the internal linking mechanism using # labels (or IDs in XHTML or HTML5).

Labels in normal text

If the label is in normal text, as above, the reference will give the current chapter/section/subsection number (depending on the current document class).

Labels in Tables or Figures

If the label is inside a Table or Figure, the reference provides the Table number or Figure number prefixed by the chapter number (remember that in Tables and Figures the \label command MUST come after the \caption command).

The \ref command does not produce the word ‘Figure’ or ‘Table’ for you: you have to type it yourself, or use the varioref package which automates it.

Labels in lists

A label in an item in an enumerated list will provide the item number. In other lists its value is null or undefined.

Labels elsewhere

If there is no apparent countable structure at the point in the document where you put the label (in a bulleted list, for example), the reference will be null or undefined.

The command \pageref followed by any of your label values will provide the page number where the label occurred, instead of the reference number, regardless of the document structure. This makes it possible to refer to something by page number as well as by its \ref number, which is useful in very long documents like this one (varioref automates this too).

LATEX records the label values each time the document is processed, so the updated values will get used the next time the document is processed. You therefore need to process the document one extra time before final printing or viewing, if you have changed or added references, to make sure the values are correctly resolved. Most LATEX editors handle this automatically by typesetting the document twice when needed.

Unresolved references are printed as two question marks, and they also cause a warning message at the end of the log file. There’s never any harm in having \labels you don’t refer to, but using \ref when you don’t have a matching \label is an error, as is defining two labels with the same value.

### 5.3.2 Bibliographic references

The mechanism used for references to reading lists and bibliographies is very similar to that used for normal cross-references. Instead of using \ref you use \cite or one of the variants explained in § 5.3.2.3; and instead of \label, you attach a label value to each of the reference entries for the books, articles, reports, etc that you want to cite. You keep these reference entries in a bibliographic reference database that uses the BIBTEX data format (see § 5.3.2.2).

This does away with the time needed to maintain and format references each time you cite them, and dramatically improves accuracy. It means you only ever have to enter the bibliographic details of your references once, and you can then cite them in any document you write, and the ones you cite will get formatted automatically to the style you specify.

#### 5.3.2.1 Choosing between BIBTEX and biblatex

LATEX has two systems for doing this, BIBTEX (old) and biblatex (new): both of them use the same file format, called BIBTEX.

• the older BIBTEX system uses a separate file for each style format (eg Harvard, Oxford, IEEE, Vancouver, MLA, APA, etc), plus a sort-and-extract program also called bibtex, which creates the formatting for the references in LATEX. The drawbacks of BIBTEX are that a) it doesn’t handle accented and other non-Latin characters very easily and b) the style format files (.bst files) are written in its own rather strange and unique language, making them extremely difficult to modify.

• the newer biblatex system is a standard LATEX package with options for the different style formats. There is also a new program (biber) to replace bibtex for sorting and extracting the references from your BIBTEX file. The main advantages are that abiblatex works with UTF-8 characters, so accents and other writing systems are handled natively, especially with XƎLATEX and bbiblatex is written entirely in LATEX, providing a much more extensible data model, so updating or writing layout formats it is much easier than with BIBTEX.

Many basic formats are included as options within the biblatex package, but there are add-on subpackages to handle additional format-specific features, such as biblatex-apa, biblatex-chicago, etc (see the example in the first code listing in §5.3.2.4 ‘Setting up biblatex with biber’).

The biblatex package with the biber program is therefore recommended, as it is under active development. However, there are a few classes and packages which have not yet been rewritten and may still require BIBTEX style formats, and there are some less common style formats which are not available prepackaged for biblatex. However, the flexibility of the biblatex data model means altering or extending style formats to create your own is much easier than it is for BIBTEX, although this is not a task for the beginner.

### Cheatsheet

Clea F Rees has written an excellent cheatsheet with virtually everything on it that you need for quick reference to using biblatex. This is downloadable as the package biblatex-cheatsheet from CTAN.

#### 5.3.2.2 The BIBTEX file format

The format for BIBTEX files is used for both biber and bibtex programs, and is specified in the original BIBTEX documentation (look on your system for btxdoc.pdf). The biblatex package and its updated style formats provide more fields and more document types.

There is a required minimum set of fields for each of a dozen or so types of document: book, article (in a journal), article (in a collection), chapter (in a book), thesis, report, conference paper (in a Proceedings), etc, exactly as with all other reference management systems. These are all (entry types and entry fields) listed in detail in the biblatex documentation (Lehman, Kime, Boruvka & Wright, 2015, sections 2.1 & 2.2 p.6).

Each BIBTEX entry starts with an @ sign followed by the type of document, followed by the whole entry in a single set of curly braces. The first value is the unique key (label) that you make up, followed by a comma:

@book{fg,
...
}


Then comes each field (in any order), using the format:

keyword = {value},


There MUST be a comma after each line except the last.

@book{fg,
title        = {{An Innkeeper's Diary}},
author       = {John Fothergill},
edition      = {3rd},
publisher    = {Penguin},
year         = 1929,
}


Most TEX-sensitive editors have a BIBTEX mode which understands these entries and provides menus or templates for writing them. The rules are:

• Omit the comma after the last field in the entry (only — eg after {London} in the example)

• Some styles recapitalise the title when they format: to prevent this, enclose the title in double curly braces as in the example;

• Also use extra curly braces to enclose multi-word surnames, otherwise only the last will be used in the sort, and the others will be assumed to be forenames, for example the British explorer can be sorted under T with author = {Ranulph {Twisleton Wykeham Fiennes}}

• Multiple authors go in the one author field, separated by the word and (see example below)

• Values which are purely numeric (eg years) may omit the curly braces;

• Fields can occur in any order but the format must otherwise be strictly observed;

• Fields which are not used do not have to be included (so if your editor automatically inserts them as blank or prefixed by OPT [optional], you can safely delete them as unused lines)

Here’s another example, this time for a book on how to write mathematics — note the multiple authors separated by and.

@book{mathwrite,
author = 	 {Donald E Knuth and Tracey Larrabee and Paul M Roberts},
title = 	 {{Mathematical Writing}},
publisher = 	 {Mathematical Association of America},
address = 	 {Washington, DC},
series = 	 {MAA Notes 14},
isbn = 	 {0-88385-063-X},
year = 	 {1989}}


Every reference in your reference management software MUST have a unique key value (label or ID): you can make this up, just like you do with normal cross-references, but some bibliographic software automatically assigns a value, usually based on some abbreviation of the author and year. These keys are for your convenience in referencing: in normal circumstances your readers will not see them. You can see these labels in the right-hand-most column and at the bottom of the screenshot in Figure 5.1, and in the examples above. You use this label in your documents when you cite your works.

There are many built-in options to the biblatex package for adjusting the citation and reference formats, only a few of which are covered here. Read the package documentation for details: it is possible to construct your own style simply by adjusting the settings, with no programming required (unlike the older BIBTEX styles, which are written in a programming language used nowhere else).

Many users keep their BIBTEX files in the same directory as their document[s], but it is also possible to tell LATEX and BIBTEX that they are in a different directory. This is a directory specified by the $BIBINPUTS shell or environment variable. On Unix & GNU/Linux systems (including Apple Macintosh OS X), and in TEX Live for Windows, this is your TEX installation’s texmf/bibtex/bib directory — the same one that old-style BIBTEX .bst style files are kept in — but you should use your personal TEX directory and create a subdirectory of the same name in there for your own .bib files. MiKTEX also uses the same$BIBINPUTS variable, but it is not set on installation: you need to set it using the Windows Systems Settings (see for example https://www.computerhope.com/issues/ch000549.htm).

#### 5.3.2.3 Citation commands

The basic command is \cite, followed by the label of the entry in curly braces. You can cite several entries in one command: separate the labels with commas.

\cite{fg}
\cite{bull,davy,heller}


For documents with many citations, use the button or menu item in your bibliographic reference manager, which will insert the relevant command for you (you can see it activated for the TEXStudio editor in Figure 5.1).

How the citation appears is governed by the reference format (style) you specify in the options to the biblatex package (see § 5.3.2.4) or in a \bibliographystyle command if you are using BIBTEX (see § 5.3.2.5). There are three common formats used:

authoryear

There are two types of this format: one with the year in parentheses and one with the whole citation in parentheses.

The first type is used in phrases or sentences where the name of the author is part of the sentence, and the year is there to identify what is being cited; in biblatex this command is \textcite{fg}

...as has clearly been shown by Fothergill (1929).

The second type is used where the phrase or sentence is already complete, and the citation is being added in support: in biblatex this command is \parencite{fg}

...as we have already clearly shown (Fothergill, 1929).

numeric

This format is popular in some scientific disciplines and produces just a number in square brackets [42]. The references at the end of the document are numbered in sort order.

alphabetic

This format is also popular in some scientific disciplines and produces a three- or four-letter abbreviation of the author’s name and two digits of the year, all in square brackets [Fot29]. The references at the end of the document are labelled with the same format in sort order.

To direct your reader to a specific page or chapter, you can add a prefix and/or a suffix as optional arguments in square brackets before the label.

...as shown by \textcite[p.12]{mathwrite}.


The prefix gets printed at the start of the citation and the suffix gets printed at the end, but all still within the parentheses, if any. As they are both optional arguments, and as suffixes are far more common than prefixes, when only one optional argument is given, it is assumed to be the suffix.. The example here therefore produces .

If you are using bibtex, you can only specify a suffix, as the sole optional argument.

Footnoted citations are common in History and related disciplines, to the extent that scholars in these fields actually call their references ‘footnotes’, which is confusing. The command \footcite does these (see Table 5.1) but it is only relevant for author-year styles (in numeric style it just produces the number, which looks wrong).

There are many variant forms of these commands, either for specific styles like Harvard, IEEE, APA, MLA, etc; or for grammatical modifications like capitalising name prefixes, omitting the comma between name and year, or adding multiple notes; or for extracting specific fields from an entry (eg \titlecite). If you have requirements not met by the formats described here, you can find them in the documentation for the biblatex package.

### Table 5.1: Built-in citation style commands and formats (biblatex)

 Style Command Result authoryear \parencite{fg} (Fothergill, 1929) authoryear \textcite{fg} Fothergill (1929) authoryear \footcite{fg} ¹ numeric \cite{fg} [42] alphabetic \cite{fg} [Fot29] authoryear \cite{fg} Fothergill 1929

¹ Fothergill 1929.

If you are using BIBTEX, the commands you can use are not standardised except for \cite. Instead, they depend on which style format you use, for example the popular natbib package, which implements author-year citation for the natural sciences, uses \citet and \citep instead of \textcite and \parencite.

### Figure 5.1: JabRef displaying a file of references, ready to insert a citation of Fothergill’s book into a LATEX document being edited with TEXStudio

Your reference management software will have a display something like Figure 5.1 (details vary between systems, but they all do roughly the same job in roughly the same way), showing all your references with the data in the usual fields (title, author, date, etc).

Your BIBTEX file, saved or exported to a .bib file from your reference management software, looks like the examples in § 5.3.2.2.

If your software doesn’t save BIBTEX format direct, save it in RIS format, then open the .ris file in something like JabRef and save it as a .bib file from there.

#### 5.3.2.4 Setting up biblatex with biber

You set up your document with the following packages:

1. the babel package with appropriate languages, even if you are only using one language. The default language is American English, so there are commands to map this to other language variants (shown in the example for British English)

2. the csquotes package, which automates the use of quotation marks around titles or not, depending on the type of reference;

3. the biblatex package itself, specifying the biber program and the style of references you want, either numeric, alphabetic, or authoryear; or a publisher’s style (in this example I am using APA format); and any options for handling links like DOIs, URIs, and ISBNs;

4. finally, the name of your BIBTEX file[s] (see the sidebar ‘Bibliographic reference databases’) with one or more \addbibresource commands.

\usepackage[frenchb,german,british]{babel}
\usepackage{csquotes}
\usepackage[backend=biber,doi=true,isbn=true,
url=true,style=apa]{biblatex}
\DeclareLanguageMapping{british}{british-apa}


Finally, you need to add the \printbibliography command at the point in your document where you want the full list of references you have cited to be printed. See § 5.3.2.6 for details of how XƎLATEX produces the references.

### Versions of biber and biblatex

One important point to note is that biblatex and biber are step-versioned; that is, each version of the biblatex package only works with a specific version of the biber program. There is a table of these dependencies in the biblatex documentation PDF. If you update biblatex for some reason (perhaps to make use of a new feature), you MUST update your copy of biber to the correct version, and vice versa, otherwise you will not be able to produce a bibliography.

#### 5.3.2.5 Using BIBTEX

The BIBTEX method is deprecated, partly because it does not handle UTF-8 character-encoding correctly, and partly because its unusual internal programming language makes it hard to extend.

The principles underlying BIBTEX are identical to biblatex: you create and maintain your BIBTEX file of references in exactly the same way, and you use the \cite in the same way. But there is no basic package to load with options: instead, you specify the name of the style you want, using a \bibliographystyle command in your Preamble, plus any additional packages needed to help with the formatting. You then use the \bibliography command to give the name of your BIBTEX file (without the .bib extension) at the point you want the references to be printed.

\bibliographystyle{apsr}
\usepackage{natbib,har2nat}
...
\bibliography{myrefs}


In this example the American Political Science Review (APSR) Harvard-like reference style has been selected (common in the political and economic sciences), which normally means numerical citation, but the author wants the Natural Sciences (author-year) form of citation, which is provided by the natbib package, which in turn requires the har2nat package to handle Harvard-style formatting. The natbib package provides \citet for textual citation like Fothergill (1929), and \citep for parenthetic citation like (Fothergill, 1929).

There is an option on all the cite commands and variants to let you specify a suffix to the citation, so \citep[Foreword, p.13]{fg} produces (Fothergill, 1929, Foreword, p 13).

See § 5.3.2.6 for details of how PDFLATEX produces the references.

#### 5.3.2.6 Producing the references

Because of the record—extract—format process (the same as used for cross-references), you will get a warning message about ‘unresolved references’ the first time you process your document after adding a new citation for a previously uncited work and running biber or bibtex. The bibtex program produces a bold ?? where the unresolved reference will be; biber produces the entry label in bold instead. This will disappear once LATEX has been run again, which is why so many editors have a Build function to do the job for you.

Your LATEX editor’s or button or menu entry should therefore handle the business of running biber or bibtex for you. If not, here’s how to do it manually in a Command window:

For XƎLATEX with biber

Run XƎLATEX, then run biber to extract and sort the details from the BIBTEX file, and then run XƎLATEX again:

xelatex myreport
biber myreport
xelatex myreport

For PDFLATEX with bibtex

Run PDFLATEX, then run bibtex to extract and sort the details from the BIBTEX file, and then run PDFLATEX again twice (to resolve the references):

pdflatex myreport
bibtex myreport
pdflatex myreport
pdflatex myreport


In practice, authors tend to retypeset their documents from time to time during writing anyway, so they can keep an eye on the typographic progress of the document. Just clicking the or button after adding a new \cite command, and subsequent runs of LATEX will incrementally incorporate all references without you having to worry about it.

1. Be aware that in some disciplines where cross-references are not much used, the word ‘references’ may be used to mean ‘bibliographic references’.

2. This section is labelled normalxref, for example.

3. Thus I can refer here to the label at the start of this section as \ref{normalxref} and get the value ‘§ 5.3.1’.

4. In fact, the old bibtex program can be still be used instead of biber with biblatex, but this would be perverse.