# Bibliography with biblatex

> Bibliographies with biblatex and Biber: a minimal setup, citation commands, styles and options, what a compile does, and when to prefer biblatex to BibTeX.

A lesson in Learn LaTeX (Figures, tables, and references), from TeXeR: https://texer.org/learn/bibliography-with-biblatex

After this page you can produce citations and a reference list with biblatex and Biber, choose and adjust a style with package options, and decide whether biblatex or BibTeX suits your document.

## A minimal setup

biblatex reads the same `.bib` files as BibTeX, described in [Bibliography with BibTeX](https://texer.org/learn/bibliography-with-bibtex), but the commands around them differ. Load the package with a style, name the file in the preamble with `\addbibresource`, and print the list with `\printbibliography`.

```latex
\documentclass[varwidth=11cm,border=10pt]{standalone}
\usepackage[style=authoryear]{biblatex}
\begin{filecontents}{references.bib}
@article{knuth1984literate,
  author  = {Knuth, Donald E.},
  title   = {Literate Programming},
  journal = {The Computer Journal},
  volume  = {27},
  number  = {2},
  pages   = {97--111},
  year    = {1984},
}
@book{lamport1994latex,
  author    = {Lamport, Leslie},
  title     = {{LaTeX}: A Document Preparation System},
  edition   = {2},
  publisher = {Addison-Wesley},
  year      = {1994},
}
\end{filecontents}
\addbibresource{references.bib}
\begin{document}
\textcite{knuth1984literate} treats a program as an
essay. For the markup itself, see the
manual \parencite[8]{lamport1994latex}.

\printbibliography
\end{document}
```

The `filecontents` block only writes the `.bib` file so that the example is a single file. There is no `\bibliographystyle`: the style is an option of the package.

> **Warning: Give \addbibresource the full file name**
>
> Unlike `\bibliography`, `\addbibresource` needs the extension: `references.bib`, not `references`. It belongs in the preamble. Without the extension Biber reports `ERROR - Cannot find 'references'!` and the list stays empty.

## Citation commands

| Command | With a numeric style | With `authoryear` |
| --- | --- | --- |
| `\cite{key}` | [1] | Knuth 1984 |
| `\parencite{key}` | [1] | (Knuth 1984) |
| `\textcite{key}` | Knuth [1] | Knuth (1984) |
| `\footcite{key}` | In a footnote | In a footnote |
| `\autocite{key}` | As `\parencite` | As `\parencite` |
| `\citeauthor{key}`, `\citeyear{key}`, `\citetitle{key}` | One part of the entry | One part of the entry |

Every command takes two optional notes, one before the citation and one after it. A note that is a bare number is treated as a page and gets its "p." automatically.

```latex
\documentclass[varwidth=11cm,border=10pt]{standalone}
\usepackage[style=authoryear]{biblatex}
\begin{filecontents}{references.bib}
@book{knuth1984texbook,
  author    = {Knuth, Donald E.},
  title     = {The {TeX}book},
  publisher = {Addison-Wesley},
  year      = {1984},
}
\end{filecontents}
\addbibresource{references.bib}
\begin{document}
\cite{knuth1984texbook} \\
\parencite{knuth1984texbook} \\
\textcite{knuth1984texbook} \\
\parencite[see][12]{knuth1984texbook} \\
\citeauthor{knuth1984texbook} wrote
\citetitle{knuth1984texbook} in \citeyear{knuth1984texbook}.
\end{document}
```

`\autocite` follows the style, so it becomes a footnote under a `verbose` style. Use it if you may switch styles later.

## Styles and options

The standard styles are `numeric` (the default), `numeric-comp`, `alphabetic`, `authoryear`, `authortitle`, and `verbose`. Styles for APA, IEEE, Chicago, and other conventions are separate packages that must be installed with your TeX system. Behavior that BibTeX fixes inside a style file is an option here.

```latex
\usepackage[
  style=numeric-comp,   % [1-3] instead of [1, 2, 3]
  sorting=none,         % list in order of citation
  giveninits=true,      % D. E. Knuth
  maxbibnames=5,        % then "et al." in the list
  doi=false, isbn=false % hide these fields
]{biblatex}
```

biblatex also knows more kinds of sources and fields than BibTeX, such as `@online` with `url` and `urldate`, and it can print several lists, each filtered by type or keyword.

```latex
\documentclass[varwidth=11cm,border=10pt]{standalone}
\usepackage[sorting=none]{biblatex}
\begin{filecontents}{references.bib}
@online{ctan,
  author  = {{CTAN Team}},
  title   = {The Comprehensive {TeX} Archive Network},
  url     = {https://ctan.org},
  urldate = {2024-03-01},
}
@book{knuth1984texbook,
  author    = {Knuth, Donald E.},
  title     = {The {TeX}book},
  publisher = {Addison-Wesley},
  year      = {1984},
}
\end{filecontents}
\addbibresource{references.bib}
\begin{document}
Packages are distributed through CTAN \autocite{ctan}.
\textcite[chapter~3]{knuth1984texbook} explains how
\TeX{} reads what you type.

\printbibliography[type=book, title={Books}]
\printbibliography[type=online, title={Websites}]
\end{document}
```

## What a compile does

The sequence mirrors BibTeX's, with Biber in the middle: LaTeX writes the citations to a `.bcf` file, Biber reads it and the `.bib` file and writes a `.bbl` file, and LaTeX runs again to print the list and resolve the citations.

In TeXeR, a compile runs Biber whenever the document uses biblatex. Biber does not fetch remote bibliography files there, so upload the `.bib` file to the project. See [Compiling](https://texer.org/docs/compiling#bibliographies-indexes-and-glossaries). The DOI and arXiv lookup and the key completion described in [References and citations](https://texer.org/docs/references) work the same way, including after `\parencite{`, `\textcite{`, and `\autocite{`.

## biblatex or BibTeX

Choose BibTeX, usually with `natbib`, when:

- A journal or conference gives you a template with a `.bst` file. Many publishers accept only that.
- You work with co-authors or tools that expect `\bibliography`.

Choose biblatex when:

- You control the format yourself, as in a thesis, a report, or a book.
- You need footnote citations, author-title styles, or small changes to a style, which are options or short LaTeX commands instead of a new `.bst` file.
- Your sources include names or titles in other scripts. Biber sorts Unicode text correctly for each language.
- You want a list per chapter, or lists split by type.

If you move a `natbib` document to biblatex, the option `natbib=true` keeps `\citet` and `\citep` working.

## Common mistakes

- **`\bibliographystyle` left in the document.** TeX stops with `! Package biblatex Error: '\bibliographystyle' invalid for 'biblatex'.` Delete the line and set `style=` instead.
- **Loading `natbib` as well.** `! Package biblatex Error: Incompatible package 'natbib'.` Remove `\usepackage{natbib}` and use the `natbib=true` option.
- **Running BibTeX instead of Biber on your own computer.** The list is empty and the log says `Please (re)run Biber on the file`. Set your editor to use Biber, or load biblatex with `backend=bibtex` and accept fewer features.

## Next

- [Bibliography with BibTeX](https://texer.org/learn/bibliography-with-bibtex)
- [Footnotes and margin notes](https://texer.org/learn/footnotes-and-margin-notes)
- [Thesis structure](https://texer.org/learn/thesis-structure)
