Dear all,

In this exercise we will learn how to use \(\LaTeX\) to reference our citations and sections. Later on, we will also learn how to refer to Figures and Tables.

Let’s start.

Gerko


1 Referencing in Tex

There are three general (read: widely used) ways of referencing in Tex:

  1. The standard citation environment in Tex
  2. The natbib citation environment
  3. The biblatex citation environment

The difference between the implementations is in the level of customization. The standard citation environment is simple, but limited. natbib allows you to customize pretty much anything and biblatex provides an easier and more flexible interface and a better language localization that the other two options. The good thing is that the three implementations use the same sources; only the calls differ:

  • to cite a publication in tex, use \cite{} to produce a (Author, year) reference, and use \citeA{} to produce a Author (year) reference (at least in APA style).
  • in natbib, \citep{} produces the (Author, year) reference and \citet{} yields the Author (year) reference (when using APA style)
  • in biblatex, you are better off with this cheat sheet to explore the possibilities

So, why not use thestandard citation environment? First, the additional packages work with the hyperref package, which you should always use (see Exercise 1). Second, depending on the target journal for any research project, style conventions for referencing may differ. For example, in medicinal sciences the convention is to use numbered references (such as [1], [2] and [3-5]). In psychology, people adhere to the APA rules and references are adressed in so-called author-year style. natbib allows you to very quickly specify these styles, without any hassle. The standard citation environment does not fully allow for such implementations. Third, many journals use natbib themselves. So if you acquire the style files from the journal, you do not have to change all the \cite{}’s and \citeA{}’s. This is also the reason why I will focus primarily on natbib in this course: Even though biblatex is more flexible; it has not been adopted by our community yet. Plus, you can use natbib’s citation environment in biblatex.


2 BibTex

BibTeX is reference management software for formatting lists of references. Bluntly stolen from wikipedia:


Here’s how BibTeX works. It takes as input

  1. an .aux file produced by LaTeX on an earlier run;
  2. a .bst file (the style file), which specifies the general reference-list style and specifies how to format individual entries, and which is written by a style designer [..] in a special-purpose language [..], and
  3. .bib file(s) constituting a database of all reference-list entries the user might ever hope to use.

BibTeX chooses from the .bib file(s) only those entries specified by the .aux file (that is, those given by LaTeX’s \cite or \nocite commands), and creates as output a .bbl file containing these entries together with the formatting commands specified by the .bst file. LaTeX will use the .bbl file, perhaps edited by the user, to produce the reference list.


In other words; you have a global bibliography (library) - or a seperate bibliography for each project, if you wish - with all your references. This is your .bib file. When you run tex, an .aux file is produced. If you reference to something in your text, these citations will be recorded in the .aux file. bibtex will match the citations in your .aux file to those in the specified .bib file (and produce an error if you reference somthing that is not in your .bib file) to produce a .bbl file that specifically matches the bibliography style (e.g. numbers, APA style, sorted, alphabetized, etc.) that you have specified in tex. If you re-run your tex code now, the references will be printed in your pdf.

Have a look at the manuscript in the \Latex background folder in this week’s course page folder for an example of a natbib implementation. Especially take a look at the .bib and .bbl files. See e.g. here for a list of all possible citation elements you can refer to with bibtex.


2.1 Re-running tex after bibtex

This is important. In fact, it is so important (and a common error by students and experts) that I devote a seperate paragraph to it! bibtex and tex are NOT the same and their code has not by default run simultaneously –> you need the following order:

  1. compile (or set) your tex code
  2. compile your bibtex environment
  3. re-compile your tex code to include the stuff bibtex produced
  4. re-compile your tex code to process and print the tex vs bibtex implementation

Depending on the software you use to write in tex, you can automate this procedure to always include bibtex when compiling your tex code. I choose not too, but that is my personal preference (running redundant commands every time is just a waste of time and resources, even when it is fast). But ‘whatever floats your boat’.


3 Reference managers

There is a lot of specialized software to manage your bibliographies. Such software would allow you to import bibtex entries from search engines such as Google Scholar and assign your own reference key to each publication. You need a good reference manager if you work with bibtex. If you are on Windows/Linux, I would suggest JabRef. If you are on a Mac, the BibDesk reference manager that is included in the MacTex distribution would be perfect. These are suggestions. There are many more reference managers. Again; whatever floats your boat.

So let’s start the exercises.


4 Exercise

If you missed it earlier; here you can find a very useful natbib reference sheet. For all exercises, use the exercises.bib bibliography and the bib_template.tex file from the course page. Specify the references such that you obtain the desired output.


  1. Have a look at this biblatex page and this natbib page for even more detail on natbib and biblatex.
  2. See how in the bib_template.tex file the first line of Section 2 refers back to Section 1 through \ref{label}.
  3. Study the examples in the Latex background/Examples folder. Especially study the example Example4_natbib numbered.tex as it provides you with a way of enclosing your bibliography in your tex file. Some journals require this.

Create five documents:

  1. Produce a document named Ex2V0.pdf based on bib_template.tex with numbered references that are sorted alphabetically, but not compressed
  2. Produce a document named Ex2V1.pdf with numbered references that are sorted on order of appearance, but not compressed.
  3. Produce a document named Ex2V2.pdf with numbered references that are sorted on order of appearance and compressed.
  4. Produce a document named Ex2V3.pdf document in APA style. Make sure that reference URL’s are printed in the References Section.
  5. Produce a document named Ex2V4.pdf document in APA style, with references highlighted in black.

You may use biblatex or natbib interchangeably. Upload the documents to SurfDrive before the next lecture starts. I will post the code solutions after that lecture.


IF YOU RUN INTO PROBLEMS: ASK ME!

Do not spend too much time debugging your code; you can dedicate the rest of your career to that.


HTML5 Icon
source: http://slinky.me/gEd