automatically appear at the citations, and a bibliography arranged in citation order is automatically generated at the end of the document—you didn't write a single line of formatting.
Two powerful automation tools for long documents: cross-referencing (sections, figures/tables, and equations referencing one another) and bibliography management (BibTeX).
Their common philosophy: numbering is always automatic; you only need to come up with a "label name."
Labels and References: \label and \ref
Cross-referencing in three steps: at the referenced location, create a label with \label{label}; at the referencing location, get the number with \ref{label} (or \pageref, \eqref).
| Command | What it outputs | Typical usage |
|---|---|---|
| \label{key} | No output; labels the preceding object | Immediately after \section, \caption, equation |
| \ref{key} | Number (e.g., 3, 1.2) | Section~\ref{sec:method} |
| \eqref{key} | Number in parentheses (e.g., (1)) | Eq.~\eqref{eq:loss} (for equations only) |
| \pageref{key} | Page number | See page~\pageref{sec:method} |
\label must immediately follow the referenced command and be written at the same environment level—"\section{Method}\label{sec:m}" is the correct form. If you put \label in the next paragraph, it will reference the wrong object. For equations, \label should be written inside the equation environment.
Example: Cross-referencing sections, equations, and figures
\usepackage{amsmath, graphicx}
\begin{document}
\section{Method}\label{sec:method}
This section introduces the model structure; the loss function is given in Eq.~\eqref{eq:loss},
The experimental analysis is given in Section~\ref{sec:result}.
\begin{equation}\label{eq:loss}
L = \sum_{i=1}^{n} \left( y_i - \hat{y}_i \right)^2
\end{equation}
\section{Experimental Results}\label{sec:result}
Method (Section~\ref{sec:method})'s loss is measured by Eq.~\eqref{eq:loss},
and the curve shape is shown in Figure~\ref{fig:sin}。
\begin{figure}[htbp]
\centering
\includegraphics[width=0.5\textwidth]{sin}
\caption{Sine curve}
\label{fig:sin}
\end{figure}
\end{document}
All references automatically get the correct numbers. From then on, no matter how many new sections or equations you insert, the numbers and references update automatically—the ultimate antidote to "manually fixing numbers until you go crazy" in Word.
For label naming, it is recommended to use "prefix:content." Common prefix conventions are as follows.
| Prefix | Object | Example |
|---|---|---|
| sec: | Section | \label{sec:method} |
| fig: | Graph | \label{fig:sin} |
| tab: | Table | \label{tab:result} |
| eq: | Equation | \label{eq:loss} |
| chap: | Chapter (report/book) | \label{chap:intro} |
Hyperlinks: The hyperref Package
After loading hyperref, all \ref, \cite, and \url commands automatically become clickable links, and a sidebar bookmark panel is generated in the PDF.
Example: Common hyperref Configurations
citecolor=blue, urlcolor=blue]{hyperref}
% colorlinks=true marks links with colors (the default red boxes are ugly)
% Three parameters control respectively: internal references / bibliography citations / URL colors
\url{https://www.example.com} % URL typesetting: automatic line breaking, clickable
hyperref should almost always be the last package loaded in the preamble—it can only transform the document correctly after all other packages are in place; loading it too early causes inexplicable conflicts.
Bibliography: BibTeX Workflow
The right way to handle references is not to hand-write a list at the end of the document, but rather: store the bibliographic information in a .bib database, cite it in the text with \cite, and let the BibTeX program automatically generate the formatted bibliography.
First, let's look at what the bibliography database looks like—each reference is an "entry."
Example: refs.bib Bibliography Database
author = {Krizhevsky, Alex and Sutskever, Ilya and Hinton, Geoffrey E.},
title = {ImageNet Classification with Deep Convolutional Neural Networks},
journal = {Communications of the ACM},
year = {2017},
volume = {60},
pages = {84--90}
}
@book{goodfellow2016, % Entry type: book
author = {Goodfellow, Ian and Bengio, Yoshua and Courville, Aaron},
title = {Deep Learning},
publisher = {MIT Press},
year = {2016}
}
The first item in the braces is thecitation key(e.g., alexnet2012); in the text, \cite{alexnet2012} uses it to find this reference. The key name is arbitrary, but it must be unique throughout the document.
| Entry type | Corresponding reference | Key fields |
|---|---|---|
| @article | Journal article | author、title、journal、year |
| @inproceedings | Conference paper | author、title、booktitle、year |
| @book | Book | author/editor、title、publisher、year |
| @phdthesis | PhD thesis | author、title、school、year |
| @misc / @online | Web pages, reports, etc. | title、url、note、year |
On the text side, there are only two commands, placed at the end of the document:
Example: Citing and Generating the Bibliography
\begin{document}
The breakthrough in deep learning originated with AlexNet~\cite{alexnet2012},
For a systematic textbook, see~\cite{goodfellow2016}。
\bibliographystyle{plain} % Bibliography style: plain numeric style
\bibliography{refs} % Bibliography database file (without the .bib extension)
\end{document}

Why Compile Four Times
After adding BibTeX, the full compilation becomes four steps, forming a pipeline among the files.
| Step | Command | Purpose |
|---|---|---|
| 1 | xelatex main | Generates main.aux, recording which keys are cited in the text |
| 2 | bibtex main | Reads .aux and refs.bib, and generates the main.bbl bibliography |
| 3 | xelatex main | Typesets the .bbl contents into the document |
| 4 | xelatex main | Citation numbers stabilize and display correctly |
The reason citations display as [?] lies in this pipeline: you didn't run bibtex, or you didn't compile twice more after running it. Overleaf automatically runs all the steps for you; locally, latexmk -pdf main.tex is recommended to do it all in one go.
BibLaTeX: A More Modern Choice
BibTeX is a veteran from 1985; its successor biblatex (paired with the biber program) is more worth learning about in Chinese-language scenarios.
| Dimension | BibTeX | biblatex + biber |
|---|---|---|
| Release time | 1985 | Since 2009 |
| Unicode / Chinese | Limited support | Native UTF-8 |
| Style customization | Requires writing .bst files; high barrier to entry | LaTeX syntax, intuitive |
| Chinese national standard | Requires configuration; somewhat cumbersome | Directly supported by the biblatex-gb7714-2015 package |
| Usage recommendation | Use for old templates or when required by journals | Preferred for new projects and Chinese papers |
Example: Basic biblatex Usage
\addbibresource{refs.bib} % Note: include the .bib extension
\begin{document}
The breakthrough in deep learning originated with AlexNet~\cite{alexnet2012}。
\printbibliography[title=References] % Print the bibliography at the end of the document
\end{document}
Change the command from bibtex to biber, and the rest of the compilation pipeline is exactly the same. When writing a Chinese graduation thesis, install the biblatex-gb7714-2015 package and switch the style to gb7714-2015 to meet the national standard bibliography format.
Summary
| Requirement | Command |
|---|---|
| Create a label | \label{prefix:name} (immediately after the referenced object) |
| Reference number / page number / equation | \ref、\pageref、\eqref |
| Hyperlinks | hyperref (load it last) |
| Cite references | \cite{key}; store references in a .bib database |
| Generate the bibliography | BibTeX:\bibliography;biblatex:\printbibliography |
| One-command compilation | latexmk -pdf main.tex |