3-4: Bibliographies

LaTeX is a little idiosyncratic and ungainly at first, but a few of its features are so convenient that they make it hard to go back to a traditional word processor. This lesson is about including citations and bibliographies in your paper, which is one of the best examples of such a feature.

.bib Files and BibTeX

LaTeX’s general approach with everything is to keep the data and formatting separate. In the case of bibliographies, the data will be stored in a separate .bib file, external to the main .tex file. (You can also build your bibliography manually, but we don’t recommend it.) Here is a very short example, so that we can have something concrete to explain.

\documentclass{article}
\begin{document}
Short is sweet~\cite{Wonka12}.
\bibliography{myrefs}
\bibliographystyle{abbrv}
\end{document}

Assume that the external file myrefs.bib contains exactly the following text (without \documentclass{}, \begin{document}, or anything else):

@book{Wonka12,
  title = {Small Desserts},
  author = {William Wonka},
  publisher = {Glucose, Fructose, \& Co.},
  year = {2012}
}
@book{Other12,
  title = {Not Cited},
  author = {Other Guy},
  publisher = {Invisible, Inc.},
  year = {2012}
}

Then compiling the LaTeX file will produce the following:

Notice that the bibliography file has automatically been formatted and numbered; even the author’s first name has been abbreviated. The bibliographic entry Other12 that was not cited does not appear; this is part of the design of BibTeX, which lets you keep one list of all of your references, and will only pull out the ones that each of your documents actually needs.

Behind the Scenes

There are extra steps involved in running BibTeX, the program separate from LaTeX which processes the .bib file. Most editors let you do these steps automatically:

  • In TeXworks, you have to ensure the typesetting method (the drop-down menu immediately to the right of the green “play” button) is set to pdfLaTeX+MakeIndex+BibTeX.
  • In WinEdt, the easiest way is for the typesetting method to be set to PDFTeXify.
  • For MacTeX, you need the .bib files in a special location, and you need to manually run the four commands below; read on.
  • In most online editors, this should be handled automatically for you.

Depending on what software you use, you might or might not really need to know about the following nitty-gritty; many modern LaTeX systems try to keep the details under the hood. But sometimes it can be helpful to know that bibliographies are completed in a four-phase process:

  • you run (pdf)LaTeX, which produces an .aux file (that is, you can use either LaTeX or pdfLaTeX)
  • you run a separate program BibTeX, which uses the .aux and .bib files to create a .bbl file in the right format, using only the references that are actually cited
  • you run (pdf)LaTeX twice again, which this time will pull in the .bbl information, assign them numbers, and print those numbers in the text where the citations appear.

Two additional technical notes: you only need to re-run BibTeX when you change the .bib file or what is cited; and if you happen to be using LaTeX with dvips and ps2pdf, you only need to run dvips and ps2pdf once at the very end.

Recipe for Building a Bibliography

Here are the essential elements to getting your bibliography in place.

  1. Create a .bib file with all of your references in it.
    • Each bibliography item is in the format @entrytype{label, field = {value}, field = {value}, ...}. You can also surround the values with “quotes” instead of braces. The label can be anything, but it’s probably helpful for you to be consistent.
      • Don’t use quotes or spaces in the label.
    • Only certain entry types are allowed. Each type only allows certain valid fields. We showed you the @book entry type before. Two others that are most often useful are @article and @misc:
      @article{BG93,
       title = {Donut Shops and Speed Traps: Evaluating Models of Supervision on Police Behavior},
       author = {Brehm, John and Gates, Scott},
       journal = {American Journal of Political Science},
       volume = {37},
       number = {2},
       pages = {555--581},
       year = {1993},
      }
      @misc{Tao07,
       title = {Quantum mechanics and {T}omb {R}aider},
       author = {Terry Tao},
       howpublished = {\url{http://terrytao.wordpress.com/quantum-mechanics-and-tomb-raider/}},
       year = {2007}
      }

      In {T}omb {R}aider, the extra {}s prevent conversion to lower-case; the \url{} will work if hyperref is included.

    • You can add a field note = {} to almost any entry type, to force extra information to appear.
    • Not all bibliographic styles use all of the valid fields.
    • Comments with % don’t work in .bib files; but you can leave data before or after the @itemtype{} if you don’t mind that it can generate warnings.
    • For further entry types (phdthesis@ etc), Wikipedia has a good summary of the valid types, their fields, and how to format author names.
  2. Use \bibliographystyle{some-style} and then \bibliography{bibfile-name-prefix} in your document, to generate the bibliography. Here is a link to a list of valid Bibtex bibliography styles in case you don’t like abbrv.
  3. Make sure the .bib file is in the right place with the name bibfile-name-prefix.bib; typically the right place is just the same folder as your .tex file. Like including graphics, you also can specify a different directory (relative to the LaTeX execution directory) such as c:/folder/myrefs.bib or ../myrefs.bib or subfolder/myrefs.bib.
  4. In addition to \cite{label}, you can use \cite{label1, label2} or \cite[specifier]{label}, for example the specifier might reference a particular numbered section, page, or theorem.
  5. Stylistically, instead of writing a space between a word and a citation like see \cite{Tao07}, you should write see~\cite{Tao07} because ~ is a non-breaking space and will prevent the word from ever appearing on the line after the word.
  6. In the event that you want to include an item in the bibliography without actually citing it, use \nocite{label}.

The instructions above will suffice for most purposes, but if you’re really interested in becoming a power user of bibliographies, look up the very new BibLaTeX package. To manage longer .bib files in a more structured way, you can use the free program JabRef. Most journals will offer an export/cite link that will auto-generate the bibtex entry for you, so you don’t necessarily need to type all entries manually. Finally, if you want to have textual citations like “as proven in Gauss (1799)” then you should check out the natbib package.

These are course notes for the University of Waterloo's course Math 600: Mathematical Software.
© 2012—. Written and developed by David Pritchard and Stephen Tosh. Contact (goes to the CEMC)