LaTeX Bibliography: How to Add References
There are three ways to get a reference list into a LaTeX document: type it by hand with thebibliography, generate it with BibTeX, or generate it with biblatex. For almost every real document you want one of the last two.
On this page
A LaTeX bibliography is the list of references at the end of your document, and the numbers or names in the text that point to it. You can type the list yourself, but usually you keep your references in a separate .bib file and let a program pick out the cited entries, sort them and format them in a citation style. That program is either BibTeX, the classic tool that has shipped with LaTeX since 1985, or biber, which works together with the biblatex package. Either way you write \cite{key} in the text and compile the document a few times. The sections below show a minimal working example for each method.
The three ways
thebibliography (by hand) |
BibTeX | biblatex + biber | |
|---|---|---|---|
| What you write | Every entry, fully formatted, in the document | A .bib file plus \bibliographystyle and \bibliography |
A .bib file plus \usepackage{biblatex}, \addbibresource and \printbibliography |
| How you compile | pdflatex twice |
pdflatex, bibtex, pdflatex, pdflatex |
pdflatex, biber, pdflatex, pdflatex |
| Styles | None: what you type is what you get | .bst files (plain, alpha, journal styles) |
Options in the preamble (style=numeric, authoryear, …) |
| Strengths | No extra files, no extra tools | Required by most journal and conference templates | Flexible, full Unicode, easy to customise |
| Limits | No sorting, no style switching, no reuse | Styles are hard to modify, limited Unicode | Not accepted by many publishers |
Which one to pick:
- BibTeX if your journal, conference or thesis template ships a
.bstfile or tells you to use\bibliographystyle. - biblatex for everything new where you are free to choose.
- By hand only for a handful of references in a one-off document.
Quick start with BibTeX
First, put your references in a file called references.bib next to your .tex file. Each entry has a type, a citation key and fields (see The BibTeX format and Entry types):
@book{lamport1994latex,
author = {Lamport, Leslie},
title = {{\LaTeX}: A Document Preparation System},
edition = {Second},
publisher = {Addison-Wesley},
address = {Reading, MA},
year = {1994},
isbn = {0-201-52983-1}
}
@book{knuth1984texbook,
author = {Knuth, Donald E.},
title = {The {\TeX}book},
publisher = {Addison-Wesley},
address = {Reading, MA},
year = {1984}
}
@manual{patashnik1988bibtexing,
author = {Patashnik, Oren},
title = {{BibTeXing}},
year = {1988},
month = feb,
note = {Documentation for general {BibTeX} users}
}
You rarely need to type entries yourself: paste a DOI into DOI to BibTeX or export them from Google Scholar or your reference manager.
Then cite the entries by key, choose a style and say where the list goes:
\documentclass{article}
\begin{document}
\LaTeX{} is described in~\cite{lamport1994latex}, \TeX{}
in~\cite{knuth1984texbook}, and BibTeX in~\cite{patashnik1988bibtexing}.
\bibliographystyle{plain}
\bibliography{references}
\end{document}
Note that \bibliography{references} takes the file name without the .bib extension. Compile with four commands (here for a file called main.tex):
pdflatex main
bibtex main
pdflatex main
pdflatex main
The first run records the cited keys in main.aux, bibtex writes the formatted list to main.bbl, the second run reads it in, and the third resolves the numbers in the text. latexmk does all of this for you:
latexmk -pdf main
The result is a section titled “References” with three numbered entries, sorted alphabetically by author, and [1], [2], [3] in the text. With the plain style, Knuth’s book comes out in the .bbl file as:
\bibitem{knuth1984texbook}
Donald~E. Knuth.
\newblock {\em The {\TeX}book}.
\newblock Addison-Wesley, Reading, MA, 1984.
which prints as “[1] Donald E. Knuth. The TeXbook. Addison-Wesley, Reading, MA, 1984.” For the full walkthrough see Using BibTeX; if bibtex is not found, see Install BibTeX.
Quick start with biblatex
The same references.bib works unchanged with biblatex. Load the package in the preamble, register the file (this time with the extension) and print the list:
\documentclass{article}
\usepackage[backend=biber,style=authoryear]{biblatex}
\addbibresource{references.bib}
\begin{document}
\LaTeX{} is described in~\cite{lamport1994latex}, \TeX{}
in~\cite{knuth1984texbook}, and BibTeX in~\cite{patashnik1988bibtexing}.
\printbibliography
\end{document}
Compile with biber instead of bibtex:
pdflatex main
biber main
pdflatex main
pdflatex main
or again simply latexmk -pdf main, which detects biblatex and runs biber itself. The style is chosen with the style= option rather than a .bst file. How the two systems differ, and when switching is worth it, is covered in BibTeX vs. biblatex.
Writing the bibliography by hand: thebibliography
Without any .bib file, you can write the list directly in the document:
\documentclass{article}
\begin{document}
\LaTeX{} is described in~\cite{lamport1994latex}.
\begin{thebibliography}{9}
\bibitem{lamport1994latex}
Leslie Lamport.
\emph{\LaTeX: A Document Preparation System}.
Addison-Wesley, Reading, MA, 2nd edition, 1994.
\bibitem{knuth1984texbook}
Donald E. Knuth.
\emph{The \TeX book}.
Addison-Wesley, Reading, MA, 1984.
\end{thebibliography}
\end{document}
Each \bibitem{key} starts an entry and \cite{key} refers to it as usual. The argument {9} is not a count: it is sample text whose width sets the indentation of the labels. Use {9} for up to nine entries and {99} for up to 99. Compile with pdflatex twice; no other tool is involved.
This is exactly what BibTeX generates into the .bbl file. Writing it yourself means LaTeX prints entries in the order you typed them, with the formatting you typed, every time. There is no sorting, no switching to another style, and no reuse across documents. That is fine for a short report with five references, and painful beyond that.
Citation commands and styles
The basic commands work with all three methods:
\cite{key}prints the label, for example[2].\cite[p.~12]{key}adds a page or other note:[2, p. 12].\cite{key1,key2}cites several entries at once.\nocite{key}adds an entry to the list without citing it in the text;\nocite{*}adds every entry in the.bibfile.
Whether you get numbers like [2] or author and year like “(Knuth 1984)” depends on the style. For author-year citations with BibTeX, load the natbib package and an author-year style such as plainnat; then \citep{key} gives “(Knuth, 1984)” and \citet{key} gives “Knuth (1984)”. In biblatex the equivalents are \parencite{key} and \textcite{key}.
BibTeX styles are .bst files: the standard ones come with every TeX distribution, and journals supply their own. biblatex styles are selected by name with style=. The Styles page shows what the common ones look like.
Where the bibliography goes and how it is titled
The list appears wherever you put \bibliography{...}, \printbibliography or the thebibliography environment, usually just before \end{document}.
The heading depends on the document class: article prints “References”, while book and report print “Bibliography” as a chapter. To change it, redefine \refname (article) or \bibname (book, report):
\renewcommand{\refname}{Sources}
If you use babel, it resets these names when the language is selected, so put the change into the caption hook instead, for example \addto\captionsenglish{\renewcommand{\refname}{Sources}}. With biblatex, pass the title directly: \printbibliography[title={Sources}].
The standard classes do not list the bibliography in the table of contents. Add \addcontentsline{toc}{section}{\refname} right before \bibliography{...} (use chapter and \bibname in a book), or, with biblatex, write \printbibliography[heading=bibintoc]. The tocbibind package does the same for all classes.
For a separate bibliography per chapter, biblatex offers refsection environments: wrap each chapter in one and put \printbibliography inside it, before \end{refsection}. With BibTeX, the chapterbib or bibunits packages do the job.
Common problems
The bibliography is empty, or the text shows “Citation undefined”. BibTeX (or biber) has not run, or LaTeX has not been rerun afterwards. Run the full four-step sequence, or use latexmk.
Question marks [?] instead of numbers. Same cause: the citation keys are not resolved yet. If they remain after a full run, the key in \cite does not match any key in the .bib file (keys are case-sensitive). Check the .blg log for “I didn’t find a database entry”.
“There were undefined references.” This LaTeX warning after the first run is normal. If it is still there after the last run, check the keys as above.
“I couldn’t open database file references.bib”. The file name in \bibliography{...} is wrong, the file is in another folder, or you wrote references.bib instead of references. With biblatex, \addbibresource needs the extension.
An entry in the .bib file is missing from the list. BibTeX only includes entries that you cite. Use \nocite{key} or \nocite{*}.
Capital letters are turned into lower case. Many styles lowercase titles. Protect words that must stay capitalised with braces: title = {A History of {NASA}}. See Special symbols.
Overleaf. Overleaf runs latexmk automatically, so you only need to upload the .bib file and recompile.
More questions are answered in the FAQ.