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).

CommandWhat it outputsTypical usage
\label{key}No output; labels the preceding objectImmediately 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 numberSee 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

\documentclass{ctexart}
\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.

PrefixObjectExample
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

\usepackage[colorlinks=true, linkcolor=blue,   % In-text citations: blue
            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

@article{alexnet2012,                          % Entry type: journal article
  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 typeCorresponding referenceKey fields
@articleJournal articleauthor、title、journal、year
@inproceedingsConference paperauthor、title、booktitle、year
@bookBookauthor/editor、title、publisher、year
@phdthesisPhD thesisauthor、title、school、year
@misc / @onlineWeb 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

\documentclass{ctexart}
\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}

BibTeX 生成的参考文献列表


Why Compile Four Times

After adding BibTeX, the full compilation becomes four steps, forming a pipeline among the files.

BibTeX 编译流水线:tex 到 aux 到 bbl 再到 pdf

StepCommandPurpose
1xelatex mainGenerates main.aux, recording which keys are cited in the text
2bibtex mainReads .aux and refs.bib, and generates the main.bbl bibliography
3xelatex mainTypesets the .bbl contents into the document
4xelatex mainCitation 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.

DimensionBibTeXbiblatex + biber
Release time1985Since 2009
Unicode / ChineseLimited supportNative UTF-8
Style customizationRequires writing .bst files; high barrier to entryLaTeX syntax, intuitive
Chinese national standardRequires configuration; somewhat cumbersomeDirectly supported by the biblatex-gb7714-2015 package
Usage recommendationUse for old templates or when required by journalsPreferred for new projects and Chinese papers

Example: Basic biblatex Usage

\usepackage[backend=biber, style=numeric]{biblatex}  % backend specifies biber
\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

RequirementCommand
Create a label\label{prefix:name} (immediately after the referenced object)
Reference number / page number / equation\ref、\pageref、\eqref
Hyperlinkshyperref (load it last)
Cite references\cite{key}; store references in a .bib database
Generate the bibliographyBibTeX:\bibliography;biblatex:\printbibliography
One-command compilationlatexmk -pdf main.tex
Other extensions