Creating a bibliography with BibTeX

One of the nice features of writing a paper in LaTeX is BibTeX, which formats your bibliography automatically for you, enables you to change the format without much effort, and automatically makes sure your in-text citations are consistent with your bibliography. However, for this to work well, you need to make sure you enter your bibliography data consistently so that BibTeX then formats your entries consistently.

I will assume here that you've already followed my article on how to set up a LaTeX paper repository.

Creating a bib entry

In your sources.bib file in your paper repository, a typical bib entry looks something like this:

@inproceedings{vandePaper08,
    author = {Alice {van de Paper} and Bob Authorson and Carrie Writerman},
    title = {A paper on writing papers},
    year = {2008},
    booktitle = {Advances in Good Paper Writing Processes}}

Every bib entry will have this general form:

  • a @_____ entry type
  • an opening brace {
  • an identifier that you will use to cite the paper in your LaTeX. This is up to you (whatever helps you remember it); I usually do Lastname08 for a paper written by first author Firstname Lastname in 2008. If there are multiple of these, I append a letter: Lastname08a, Lastname08b, etc.
  • data fields of the form ____ = {____} separated by commas
  • a closing brace }

Guidelines

There are many types of entry aside from @inproceedings (see below), but the format of the bib entry will look like this regardless. In particular, here are some rules to follow that apply for all types of bibliography entry:

  • Forced Format: any time you want to force BibTeX to apply a particular formatting, wrap the text in braces {...}.
    • in the paper title title = {On Bayesian inference}, BibTeX may decide that it should be typeset as "On bayesian inference," which is not correct because Bayesian is a proper noun and needs to be capitalized. Therefore, you should include braces to force the format: title = {On {B}ayesian inference}.
    • a similar strategy can be used to include accents by surrounding by braces, e.g., Alice C{\^o}t{\'e} will typeset as Alice Côté
  • Author Names: names are full (not abbreviated), Firstname Lastname, separated by "and," no commas. Do not use Lastname, Firstname formatting; I have found this to be more error prone in the past, especially with complicated names. For lastnames with spaces, use braces, for example Firstname {Lastname III}.
    • never include "et al" in an entry; it's BibTeX's job to compress that for you
    • some journals only show you initials, e.g., "B. Authorson." You'll need to google for what B stands for before creating your bib entry.
  • Titles: are sentence format for everything except books, which are initial caps.
    • e.g. for a paper, article, or chapter in a collection: title = {On {B}ayesian procedures for inferring a {D}irichlet mixture of betas}
    • e.g. for a book: title = {Probability Theory: Examples and Counterexamples}

Citations

Since you included the natbib package after reading how to set up a LaTeX repo, you have two major options for citing references in your text: \citet (no parentheses) or \citep (parentheses). Use \citet when the citation is part of your sentence. For example, \citet{Authorson18} showed that X is true will typeset as something like

Authorson & Writerman (2018) showed that X is true.

When the citation is not part of the sentence, use \citep. For example, It is possible to show that X is true \citep{Authorson18} will typeset as

It is possible to show that X is true (Authorson & Writerman, 2018).

Three things to look out for when using citations:

  • Books: When citing a book, never cite the entire book; always cite a particular chapter, theorem, page range etc. You can do this with optional arguments to \citep, e.g., paper writing skills \citep[Ch.~3]{Authorson18} will typeset as

    paper writing skills (Ch.~3, Authorson & Writerman, 2018)

  • Citation spacing: Make sure to include a space before each \citep or \citet command. This makes sure citations are spaced properly. For example, paper writing skills\citep{Authorson18} will typeset as

    paper writing skills(Authorson & Writerman, 2018)

    while paper writing skills \citep{Authorson18} will be properly spaced:

    paper writing skills (Authorson & Writerman, 2018)

  • Numbered citations: If your bibliography format is numbers—and citations appear in your text like [4]—then \citep should be used. BibTeX will complain if you use \citet.

Compiling

In order to make sure your paper and bibliography are compiled properly, you will need to run the following five commands:

pdflatex main.tex
pdflatex main.tex
bibtex main
pdflatex main.tex
pdflatex main.tex

If your sources.bib file has errors, you will see them here after the bibtex main call. Note that warnings should be treated as errors; a warning is simply something that BibTeX can ignore and move past. But it usually means that your PDF file will have incorrectly formatted / broken citations. For example, the below "warning" implies that you tried to use \citep{ghahramani06} in the main text of your paper, but there is no bib entry with the ghahramani06 tag. In your paper, you will see a "??" where your citation should be.

This is BibTeX, Version 0.99d (TeX Live 2017/Debian)
The top-level auxiliary file: main.aux
A level-1 auxiliary file: superposition_algorithm.aux
The style file: unsrtnat.bst
Database file #1: sources.bib
Warning--I didn't find a database entry for "ghahramani06"
(There was 1 warning)

Note: some fancy LaTeX editors have a button to compile your document. Unfortunately, many of them do not report BibTeX warnings. Feel free to use this when you're working, but before you send a draft to your advisor, you should compile your document on the command line to catch and fix all the errors/warnings from pdflatex and bibtex.

Common bib entry types

Conference papers

For conference papers, use the @inproceedings entry type.

@inproceedings{vandePaper08,
    author = {Alice {van de Paper} and Bob Authorson and Carrie Writerman},
    title = {A paper on writing papers},
    year = {2008},
    booktitle = {Advances in Good Paper Writing Processes}}

Journal articles

For a standard journal article, use the @article type. Notes:

  • some journals don't use issue numbers, in which case you can omit number
  • note the double dash -- in page ranges
@article{vandePaper09,
    author = {Alice {van de Paper} and Bob Authorson},
    title = {A really long paper on writing papers},
    year = {2009},
    volume = {10},
    number = {3},
    pages = {1234--5678},
    journal = {The Annals of Paper Writing}}

arXiv articles

It is becoming increasingly common to cite unpublished arXiv articles. For these, I use the @article entry type, filling out only author/title/year and using the journal for a brief formatted link to the arXiv identifier. A lot of people would put something like arXiv e-print arXiv:0901.23456, but I don't like how much redundancy there is there; arXiv only hosts one type of media (articles), so there's no reason to be verbose about it.

@article{vandePaper09b,
    author = {Alice {van de Paper} and Bob Authorson},
    title = {A really long paper on writing papers},
    year = {2009},
    journal = {arXiv:0901.23456}}

Also note that sometimes when you first write your manuscript, a paper is only on arXiv; but then later on down the road it gets published. Before submitting your final version of your work to a conference or journal, search google for any arXiv citations to see if they've been published. Cite only the published version.

Books

For books, use the @book entry type. Note: when citing a book, never cite the entire thing. In your LaTeX code, you should always provide the optional argument to specify page ranges, chapters, a theorem number, etc. For example, you should never do \citep{vandePaper10}, but instead be more specific: \citep[Ch.~3]{vandePaper10}, or \citep[p.~773--779]{vandePaper10}.

@book{vandePaper10,
    author = {Alice {van de Paper}},
    title = {Writing Lots of Papers: A Book About It},
    year = {2009},
    edition = {$2^\text{nd}$},
    publisher = {Paper Writing Press}}

If it's a chapter in a collection, use the @incollection type. Since the citation won't be for an entire book, you don't necessarily need to include optional information in the \cite command.

@incollection{vandePaper10,
    author = {Alice {van de Paper}},
    title = {A Chapter on Writing Papers},
    editor = {Bob Authorson and Carrie Writerman},
    booktitle = {The Handbook of Paper Writing},
    publisher = {Paper Writing Press},
    year = {2009},
    pages = {266--290},
    chapter = {10}}

Other

For other things not listed above—which represent about 99% of cases I run into regularly—I consult google and see what other people have used. For example, this site provides a nice list of types that you might run into, e.g.,

  • @phdthesis: for Ph.D. theses
  • @techreport: for technical reports
  • @misc: for online resources, lecture notes, etc

Editing Checklist

Here is a checklist to go through before your paper draft is ready to show your advisor. Make sure you check both your sources.bib file and your rendered PDF paper for errors. Sometimes it's easier to spot an error in one or the other.

  • paper titles are all sentence format with first word capitalized, all others lower case except proper nouns, e.g. title = {On {B}ayesian stuff for reasons}.
  • book titles are all initial caps format, e.g. title = {{B}ayesian Statistics in the Real World}
  • all proper nouns are capitalized with {___} braces, e.g. the {B}ayesian above)
  • venues (journal/conf name), are all initial caps, e.g. journal = {The Annals of Papers and Whatnot}
  • author names are all Firstname Lastname format separated by and and no commas
  • for any arXiv papers, check google to see if they've been published; if so, update to the published article
  • make sure all special characters (e.g. ô) are properly typeset
  • make sure that all citations to a book include a specific part of the book (chapter, page range, theorem, etc)
  • make sure all citations have a space between them and preceding text
  • fix all bibtex warnings and errors. Compile your work on the command line to see all the errors and warnings.
  • do not include URLs in citations