Referencing

Overview:

  • Teaching: 25 min
  • Exercises: 0 min

Objectives

  • To insert inline citations and a bibliography to your $\LaTeX$ documents
  • To manage references and bibliography construction via BibTeX

Referencing in Scientific Documents

The references that you include in your scientific work are of central importantance; they can serve to provide background and introductory/ learning material for your subject area, as motivation for exploring the topic of your document itself, or support the results of your work either numerically or theoretically. Needless to say, it is important to include references in your work and to manage your sources carefully. We aren't going to go into the details of how to reference professionally (in the sense of writing a document) here, instead we are going to show you how you can use $\LaTeX$ to manage your external sources and include citations in your work.

Setup

If you haven't already got a $\LaTeX$ source file to hand that you don't mind editing for the purposes of this lesson, you can download our source code from the previous lesson here.

Out-of-the-box referencing

$\LaTeX$ supports embedding references in your source file and then creating a bibliography from those references. Standard bibliography commands in $\LaTeX$ have a similar syntax to that of lists and items.

\documentclass{article}

\begin{document}

This is an example of including bibliographies in your document. You can cite a paper by using the \textit{$\backslash$cite} command. \cite{knuthwebsite}

\bibliographystyle{unsrt}

\begin{thebibliography}{9}
\bibitem{latexcompanion} 
Michel Goossens, Frank Mittelbach, and Alexander Samarin. 
\textit{The \LaTeX\ Companion}. 
Addison-Wesley, Reading, Massachusetts, 1993.

\bibitem{einstein} 
Albert Einstein. 
\textit{Zur Elektrodynamik bewegter K{\"o}rper}. (German) 
[\textit{On the electrodynamics of moving bodies}]. 
Annalen der Physik, 322(10):891–921, 1905.

\bibitem{knuthwebsite} 
Knuth: Computers and Typesetting,
\\\texttt{http://www-cs-faculty.stanford.edu/\~{}uno/abcde.html}
\end{thebibliography}

\end{document}

The environment thebibliography produces a list of references. Depending on the \bibliographystyle, the format of the citation in the text and in the bibliography/ reference list will change. A popular style is unsrt which numbers references as they appear in the text displaying this in the citation as a parameter inside braces. A list of different bibliography styles can be found on Overleaf.

The 9 in \begin{thebibliography}{9} provides an upper bound to the number of references in the document. This should be "the greatest power of 10, -1" that you can safely estimate; so should be 9 if you expect less than 10 references, 99 if you expect more than 10 and less than 100, etc. Although if you're at the point when you have $>5$ references, chances are you want to be using an external bibliography as we recommend in this lesson!

To create a bibliography entry the command \bibitem is used. A parameter inside braces is set to label this entry and can later be used as identifier for this reference, similarly to the way we give labels to equations, figures, and sections. After the closing brace the information about the reference is entered; name of the author, book title, publisher, etc. In this example, we cite the website at the end of the sentence using the command \cite{knuthwebsite}, which will automatically insert a citation into the document at the point the \cite command is called.

Bibliography management with Bibtex

Whilst it is possible to create a bibliograhy within your document's source file, there are several inconveniences with doing this:

  • It’s up to you to accurately format each \bibitem based on the reference style you’re asked to use
  • If you need the reference list to be sorted by the last names of first authors, you have to sort the \bibitems yourself
  • If you have different documents that use the same references, you have to re-enter this information at the end of every one of them!

BibTeX is a helpful bibliography management tool which helps us overcome some of these problems. Rather than writing bibliography entries in the source file, we will keep them in a separate file and ask BibTeX to handle the creation of our bibliography. The first thing we need to do is create a bibliography file, which is a file containing text and having the extension .bib (like how our source file is contains text and has the extension .tex so it can be interpretted by $\LaTeX$).

The bibliography file

References are kept in a bibliography file whose extension is .bib, and this file consists of a list of records and fields. Each bibliography record holds relevant information for a single reference - a book, article, website, etc. The fields of a given record hold the information like author, title, published date, and the like.

First, let's create a bibliography file which includes some references for our main document.

NOTE: Like with the images you want to include in your document, you should save your .bib file to the same directory as your source .tex file. If you are familar with paths, you can ignore this advice and insert the path to the .bib file like we described with images.

MagicalThesisBib.bib is our bibliography and it looks like this:

@book{rowling2001fantastic,
  title={Fantastic Beasts and Where to Find Them},
  author={Rowling, J. K.},
  year={2001},
  publisher={Bloomsbury}
}

@book{lewis2001chronicles,
  title={The Chronicles of Narnia},
  author={Lewis, Clive Staples},
  year={2001},
  publisher={Harper Collins}
}

@book{tolkien2012lord,
  title={The Lord of the Rings: One Volume},
  author={Tolkien, John Ronald Reuel},
  year={2012},
  publisher={Houghton Mifflin Harcourt}
}

@article{graham2019anatomy,
    author = {Graham, William M.},
    title = {Anatomy of Magical Beasts},
    journal = {Magical Enquires of Muggles},
    volume = {134},
    number = {10},
    pages = {1--2572},
    year = {2019},
    DOI = {"http://dx.doi.org/some_relevant_numbers}
}

Our Bibliography

You can download our bibliography here, if you don't want to make your own. In general, most articles and journals that are available online will provide BibTeX citations in the correct syntax on the article/journal website. References for books can normally be found similarly, or by searching for the article, book, or website via a tool like Google Scholar which can generate the references in BibTeX format for you. However if you obtain the reference information from anywhere other than the offical source, you should cross-check the information in the fields before using it.

MagicalThesisBib.bib contains records in a special format. There are many different types of record you can include, but here we have only included the two most common:

  • @article{} : For journal articles or arXiv pre-prints.
  • @book{} : For textbooks.

Notice that records are started with the @ symbol and not a backslash as in the main .tex document. The @article{...} syntax itself tells BibTeX that this record is an article, and so can only contain fields corresponding to articles. Fields are set using their keywords, followed by an = and then putting the value of the field in curly braces { }. Fields are separated by commas (see the ends of the lines above) - line breaks are not necessary but they make everything look a lot nicer! The syntax

title = {Anatomy of Magical Beasts}

sets the value of the title field to "Anatomy of Magical Beasts", for example.

Each record has a list of required and optional fields. BibTeX will complain to you if you do not provide a value for a required field in a record, but will ignore any mising optional fields. When generating your bibliography, BibTeX will by default include as much information as you provide it, which might mean that some references print differently in the document (even if they are of the same record type) because optional information has been provided for one.

Putting the Bibliography in the Document

Once we have created a bibliography file, we need to link it to the source .tex file using the command \bibliography{bib_file}. Replace bib_file with the name of your bibliography, of course. If you are using a local editor, you might even get away with not including the .bib extension in the filename, but it's always safer to include it.

NOTE: If you didn't save the .bib file to the same directory as your .tex file, this is where you will need to include the path to the file too.

We also need to provide a \bibliographystyle so that BibTeX knows how to format our references for us - in this lesson we'll stick with the unsrt style. Below is a minimum working example:

\documentclass{article}

\begin{document}
There are several magical animals that are yet undiscovered \cite{rowling2001fantastic} that could provide huge boons to our everyday lifestyle and working environment.
Oliphaunts \cite{tolkien2012lord} have the potential to eliminate the need for heavy construction machinery and heavy-goods transport, and provide little to no air pollution as an additional benefit.
Indeed, we can even predict the resulting pattern in the concentration of carbon dioxide in the atmosphere ($c_{atm}$) on a timescale of years ($t$) after this switch:
\begin{equation} \label{eq:CO2Reduction}
    c_{atm} = c_{0} e^{-\sigma t},
\end{equation}
where $c_{0}$ is the current concentration of carbon dioxide in the atmosphere and $\sigma>0$ is the so-called ``Oliphaunt efficiency coefficient". \newline

Phoenixes, with their healing ability and ease of flight, could effectively act quickly to prevent disaster in environmental crises.
Indeed these remarkable healing properties were discussed in a recent work \cite{graham2019anatomy} which hypothesised how such an ability could have developed through the process of evolution.

\bibliographystyle{unsrt}
\bibliography{MagicalThesisBib.bib}

\end{document}

Important things to note are that we include the two bibliography commands inside the document environment, that is not in the preamble. When you render/ compile the .tex file you should notice a list of references inserted at the end of the document, and your cite commands should be replaced by the appropriate reference number that BibTeX has assigned to each record.

Compile with BibTeX

If you are using a local editor, you may need to render/compile your .tex file multiple times, first with $\LaTeX$, then BibTeX (or BibLaTeX), then $\LaTeX$ again.

Other useful features of using BibTeX to handle our sources include:

  • If we move references around in the file, the numbering will automatically adjust.
  • Records in our bibliography file that are not referenced in the .tex file are automatically omitted from the bibliography. This means that you can have (in theory) one master .bib file which you use for all your documents!
  • Changing the \bibliographystyle will automatically reformat the reference list, and the appearance of the inline citations (\cite commands).

Source Code

You can download our bibligraphy file here if you would like to use it yourself. Furthermore, we also provide this file which is a .tex file that contains working examples of BibTeX citations in action (using the aforementioned .bib file). This file also combines everything you have seen in the previous 3 lessons, so covers sections, figures, internal cross-referencing and referencing external sources via BibTeX.

Key points:

  • BibTex is a helpful bibliography management tool.
  • We provide all our references in an external .bib file.
  • We link our .tex file to the .bib file using the command \bibliography.
  • We can change the format of our citations and bibliography using the \bibliographystyle command.

End of Introductory Lesssons

This lesson concludes the introductory lessons for $\LaTeX$; having covered everything you need to begin writing professional documents using $\LaTeX$ and BibTeX. We also provide two futher lessons on some more advanced topics:

  • Macros : Making your own custom commands in $\LaTeX$, which can be useful when writing long documents, or several related documents.
  • Handling Multiple Files : When writing long documents (cough thesis cough) it is helpful to break down your source code into multiple files, then stitch them back together for organisational (and speed) purposes.

The "NEXT" button below will take you to the lesson on macros. Press "SCHEDULE" to return to the contents page for these lessons.