LaTeX by Example: References
Managing citations and bibliographies is a core strength of LaTeX. This example shows the basic `thebibliography` environment.
Code
\documentclass{article}
\begin{document}
As stated by Lamport \cite{lamport94}, LaTeX is a macro package for TeX.
Knuth \cite{knuth84} created the underlying TeX engine.
% The bibliography
\begin{thebibliography}{9}
\bibitem{lamport94}
Leslie Lamport,
\textit{\LaTeX: A Document Preparation System},
Addison Wesley, Massachusetts,
2nd Edition,
1994.
\bibitem{knuth84}
Donald E. Knuth,
\textit{The \TeX book},
Addison Wesley, Massachusetts,
1984.
\end{thebibliography}
\end{document}Explanation
LaTeX provides a built-in environment called thebibliography for managing references. Inside this environment, each reference is defined using \bibitem{key}, where "key" is a unique identifier you choose (e.g., "lamport94"). In the main text, you cite these works using \cite{key}.
When you compile the document, LaTeX replaces \cite{key} with a number (like [1]) and formats the list of references at the end of the document. The argument {9} in \begin{thebibliography}{9} tells LaTeX to reserve enough space for labels up to one digit wide. If you have more than 9 references, you would use {99}.
For larger projects, it is standard practice to use BibTeX or BibLaTeX. These tools allow you to store your references in a separate .bib database file. You then reference them in your LaTeX document, and the tool automatically extracts only the cited works and formats them according to a specific style (e.g., APA, IEEE) without you needing to format each entry manually.
Code Breakdown
\cite{lamport94} inserts the citation marker (e.g., [1]) in the text.\bibitem{lamport94} defines the bibliography entry associated with the key.
