Introduction to Citations in LaTeX
In academic and professional writing, citing your sources is essential. It gives credit to other authors, allows readers to verify your facts, and avoids plagiarism. While you could type out your bibliography manually, LaTeX provides a powerful automated system that handles formatting, numbering, and alphabetizing for you.
To manage citations effectively, we use a separate database file (a .bib file) to store bibliographic information and a package (usually biblatex) to format that information within our document. This "separation of content from style" allows you to change your entire citation format (e.g., from Numeric to APA) just by changing one line of code.
1. Creating the Bibliography Database (.bib)
The first step is creating a plain text file with the extension .bib. This file acts as a library of all the books, articles, and websites you might want to cite. Each entry follows a specific structure:
@book{hawking1988,
author = {Stephen Hawking},
title = {A Brief History of Time},
publisher = {Bantam Books},
year = {1988},
address = {London}
}
@article{einstein1905,
author = {Albert Einstein},
title = {Does the Inertia of a Body Depend Upon Its Energy Content?},
journal = {Annalen der Physik},
volume = {18},
pages = {639--641},
year = {1905}
}Key Components:
- Entry Type: (e.g.,
@book,@article) tells LaTeX what kind of source it is. - Citation Key: (e.g.,
hawking1988) is a unique nickname you create. You will use this key to reference the source in your document. - Fields: (e.g.,
author,title,year) contain the specific data for the entry.
Note: When writing names in the
authorfield, always use the formatSurname, FirstnameorFirstname Surname. If there are multiple authors, separate them with the wordand(e.g.,Smith, John and Doe, Jane).
2. Setting Up BibLaTeX
To use your .bib file in your LaTeX document, we recommend the biblatex package. It is the modern standard, offering more flexibility and easier customization than the older bibtex system.
In your .tex file's preamble, you need to load the package and point to your bibliography file:
\documentclass{article}
\usepackage[utf8]{inputenc}
% 1. Load the biblatex package
\usepackage[style=numeric, backend=biber]{biblatex}
% 2. Import your .bib file (ensure the filename matches exactly)
\addbibresource{references.bib}
\begin{document}
Hello! According to \cite{hawking1988}, the universe is vast.
% 3. Print the bibliography list
\printbibliography
\end{document}Understanding the Backend
In the example above, backend=biber is specified. Biber is the program that processes your citations. Most modern LaTeX editors (like Typevia or VS Code) handle this automatically, but it is important to know that "Biber" is the engine working behind the scenes.
3. Choosing Your Citation Style
Different academic disciplines require different citation styles. With biblatex, changing styles is as simple as updating the style option in your preamble.
Common Styles:
- Numeric (
style=numeric): Commonly used in science and engineering. Citations appear as numbers in brackets: [1]. - Alphabetic (
style=alphabetic): Similar to numeric, but uses a code based on the author's name and year: [Haw88]. - Author-Year (
style=authoryear): Common in social sciences. Citations appear as (Hawking, 1988). - APA/MLA/Chicago: Specialized styles often require specific packages (e.g.,
style=apa).
Example of switching to an author-year format:
\usepackage[style=authoryear, backend=biber]{biblatex}4. In-Text Citation Commands
Once your bibliography is set up, you need to cite your sources within the text. biblatex provides several commands to help your citations flow naturally with your prose.
| Command | Result (Numeric) | Result (Author-Year) |
|---|---|---|
\cite{key} | [1] | Hawking 1988 |
\parencite{key} | [1] | (Hawking, 1988) |
\textcite{key} | Hawking [1] | Hawking (1988) |
Adding Page Numbers
If you are quoting a specific page, you can add it as an optional argument in square brackets:
As stated by Einstein, energy and mass are related \parencite[p. 640]{einstein1905}.Citing Multiple Sources
You can cite multiple works at once by separating the keys with commas:
Foundational physics is complex \cite{hawking1988, einstein1905}.5. Best Practices and Common Pitfalls
Proper Casing in Titles
Many citation styles automatically convert titles to "sentence case" (only the first word capitalized). If you have a proper noun (like "Einstein" or "London") that must remain capitalized, wrap the letter or word in curly braces:
title = {Discovery of {X}-rays in {G}ermany},The "Four-Step" Compilation
If you are working on your own computer (not using an online tool like Typevia), you may notice your citations appearing as question marks [?] at first. This is because citations require a specific compilation sequence:
- pdflatex: Scans the document for
\citekeys. - biber: Looks up those keys in your
.bibfile. - pdflatex: Incorporates the data from Biber.
- pdflatex: Finalizes the cross-references and page numbers.
Only Printing Cited Works
By default, \printbibliography only shows the sources you actually cited in your text. If you want to include a source in your bibliography without explicitly citing it, use the \nocite{key} command. To print every single item in your .bib file, use \nocite{*}.
Common Mistake: Forgetting the
.bibextension in the\addbibresource{}command. Unlike the older\bibliography{}command,biblatexrequires the file extension.
- Correct:
\addbibresource{references.bib}- Incorrect:
\addbibresource{references}
Summary Example
Here is a complete, minimal example you can copy and try:
\documentclass{article}
\usepackage[style=authoryear]{biblatex}
% Creating a sample file on the fly for this example
\begin{filecontents}{my_refs.bib}
@article{sample2023,
author = {Writer, Anne},
title = {Learning LaTeX for Beginners},
journal = {Journal of Digital Education},
year = {2023}
}
\end{filecontents}
\addbibresource{my_refs.bib}
\begin{document}
According to \textcite{sample2023}, LaTeX makes citation management much easier.
Using the parenthetical style is also possible \parencite{sample2023}.
\printbibliography
\end{document}