Bibliography with BibTeX

How to manage references and automatically generate a perfectly formatted bibliography in LaTeX using BibTeX.

One of the most powerful features of LaTeX is its automatic bibliography generation. Instead of manually typing out references and struggling with alphabetical sorting or journal-specific formatting styles (like APA or IEEE), LaTeX does it all for you using BibTeX.

1. Create a .bib File

BibTeX stores your references in a separate plain-text database file, usually named references.bib.

Each reference in the file looks like a block of code:

@article{einstein1905,
  author = {Albert Einstein},
  title = {On the Electrodynamics of Moving Bodies},
  journal = {Annalen der Physik},
  volume = {322},
  number = {10},
  pages = {891--921},
  year = {1905}
}
 
@book{knuth1984,
  author = {Donald Knuth},
  title = {The TeXbook},
  publisher = {Addison-Wesley},
  year = {1984}
}

The first string (einstein1905) is the citation key. You use this key to reference the article in your main document.

Don't write .bib files manually

You should never type these out by hand! Use a reference manager like Zotero or Mendeley to export a .bib file, or simply click "Export Citation -> BibTeX" on Google Scholar to copy-paste the exact code block.

2. Cite the References in Your Text

In your main .tex file, use the \cite{} command whenever you want to insert a reference, passing the citation key as the argument.

The theory of relativity dramatically changed modern physics \cite{einstein1905}. 
Furthermore, the typesetting system we use today was invented in the 1980s \cite{knuth1984}.

3. Print the Bibliography

At the end of your document (where you want the references to appear), you must specify the visual style of the bibliography and point LaTeX to your .bib file.

% Set the formatting style (e.g., plain, ieee, apa)
\bibliographystyle{plain}
 
% Tell LaTeX the name of your .bib file (without the extension)
\bibliography{references}

The Compilation Cycle

When compiling locally, BibTeX requires a specific sequence of commands to link the citations properly. If you use a desktop editor, you must run:

  1. pdflatex main.tex (finds the \cite commands)
  2. bibtex main.aux (extracts the references from the .bib file)
  3. pdflatex main.tex (inserts the references into the text)
  4. pdflatex main.tex (fixes the page numbers)

With LetX, you don't have to worry about this. Our cloud compiler automatically detects BibTeX and runs the entire compilation cycle instantly in the background.