Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

LaTeX Cross-referencing and Bibliography Management

LaTeX Cross-referencing and Bibliography Management

Two major automation tools for long documents: cross-referencing (sections, figures, tables, and formulas pointing to each other) and bibliography management (BibTeX).

Their shared philosophy: numbering is always automatic; you only assign a "label name".


Labels and References: \label and \ref

Cross-referencing in three steps: place \label{tag} at the referenced point, and retrieve the number at the citation with \ref{tag} (or \pageref, \eqref).

Command What It Outputs Typical Combination
\label{key} No output; labels the preceding object Right after \section, \caption, equation
\ref{key} Number (e.g., 3, 1.2) Section~\ref{sec:method}
\eqref{key} Parenthesized number (e.g., (1)) Equation~\eqref{eq:loss} (formula-specific)
\pageref{key} Page number where it appears See page~\pageref{sec:method}

\label must follow the referenced command immediately and be written at the same environment level - "\section{Method}\label{sec:m}" is the correct posture; if you write \label in the next paragraph, the reference will point to the wrong object. A formula's \label must be written inside the equation environment.

Example: Sections, Formulas, and Figures Referencing Each Other

\

documentclass

{

ctexart}
\usepackage{amsmath, graphicx}
\begin{document}

  \section{方法}\label{sec:method}       

This section introduces the model structure; the loss function is in equation~\eqref{eq:loss},
and the experimental analysis is 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{实验结果}\label{sec:result}       

The loss of the method (Section~\ref{sec:method}) is measured by equation~\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

}

Compilation result of cross-references among sections, equations, and figures

All references automatically obtained the correct numbers. No matter how many new sections or formulas you insert later, numbers and references update automatically - the ultimate cure for "manually changing numbers until you break down" in Word.

It is recommended to name labels "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: Formula \label{eq:loss}
chap: Chapter (report/book) \label{chap:intro}

Hyperlinks: The hyperref Package

After loading hyperref, all \ref, \cite, and \url automatically become clickable links and generate a sidebar bookmarks panel in the PDF.

Example: Common hyperref Configuration

\

usepackage

[

colorlinks=true, linkcolor=blue,  

% body citations: blue

            citecolor=blue, urlcolor=blue

]{

hyperref

}

% colorlinks=true marks links with color (the default red box is ugly)

% three parameters control: internal references / citation references / URL colors

\url

{

https://www.runoob.com

}

     

% URL typesetting: automatic line break, clickable

hyperref should almost always be the last package loaded in the preamble - it must wait for all other packages to be in place before correctly modifying the document; loading it early causes mysterious conflicts.


References: The BibTeX Workflow

The correct approach to references is not to handwrite a list at the end, but: store reference information in a .bib database, cite in the body with \cite, and let the BibTeX program auto-generate a formatted list.

First look at what a reference database looks like - each reference is an "entry".

Example: refs.bib Reference 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 braces is the citation key (e.g., alexnet2012); \cite{alexnet2012} in the body finds this reference through it; the key name is arbitrary but must be unique in 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 page, report, etc. title, url, note, year

The body side has only two commands, placed at the document end:

Example: Citing and Generating the Reference List

\

documentclass

{

ctexart}
\begin{document}
The breakthrough in deep learning came from AlexNet~\cite{alexnet2012},
and a systematic textbook is~\cite{goodfellow2016}.

  \bibliographystyle{plain

}

         

% bibliography style: plain numeric style

\bibliography

{

refs

}

               

% bibliography database file (without .bib extension)

\end

{

document

}

Bibliography list generated by BibTeX

Citations automatically appear as [1], [2], and a reference list ordered by citation is auto-generated at the end - you wrote not a single line of formatting.


Why Compile Four Times

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

BibTeX compilation pipeline: tex to aux to bbl to pdf

Step Command Purpose
1 xelatex main Generate main.aux, recording which keys the body cited
2 bibtex main Read .aux and refs.bib, generate the main.bbl reference list
3 xelatex main Typeset the .bbl content into the document
4 xelatex main Citation numbers are stable and displayed correctly

The reason a citation shows [?] is hidden in this pipeline: bibtex was not run, or it was run but not compiled twice more. Overleaf runs all steps automatically; locally, latexmk -pdf main.tex is recommended to do it in one go.


BibLaTeX: A More Modern Choice

BibTeX is the veteran from 1985; its successor biblatex (with the biber program) is more worth knowing in Chinese scenarios.

Dimension BibTeX biblatex + biber
Birth Year 1985 From 2009
Unicode / Chinese Limited support Native UTF-8
Style Customization Requires writing .bst files, high threshold LaTeX syntax, intuitive
Chinese National Standard Requires configuration, cumbersome The biblatex-gb7714-2015 package supports it directly
Usage Recommendation Use when old templates or journals require it New projects and Chinese papers first

Example: Basic biblatex Usage

\

usepackage

[

backend=biber, style=numeric

]{

biblatex

}

 

% backend specifies biber

\addbibresource

{

refs.bib

}

                         

% note the .bib extension

\begin

{

document}
The breakthrough in deep learning came from AlexNet~\cite{alexnet2012

}

.

\printbibliography

[

title=References

]

                 

% print the reference list at the document end

\end

{

document

}

Change the command from bibtex to biber; the rest of the compilation pipeline is identical. When writing a Chinese graduation thesis, install the biblatex-gb7714-2015 package and change the style to gb7714-2015 to meet the national standard bibliographic format.


Summary

Requirements Command
Tagging \label{prefix:name} (right after the referenced object)
Citation number / page / formula \ref, \pageref, \eqref
Hyperlinks hyperref (load last)
Citing references \cite{key}, references stored in .bib database
Generating the reference list BibTeX:\bibliography;biblatex:\printbibliography
One-command compilation latexmk -pdf main.tex