What a label actually stores
A cross-reference in LaTeX is not a pointer into your document; it is a line in a side file. When TeX reaches \label{eq:gauss} it does not look around for the thing you are standing next to. It reads one internal macro, \@currentlabel, and writes whatever that macro holds into the .aux file the run is producing, under a control-sequence name built from your key. Every later \ref is a lookup in the table assembled from those lines. Nothing about the surrounding text is consulted a second time, which is why a reference can be well-formed, print a number in the right format, and still name the wrong object.
\@currentlabel is written by \refstepcounter{<counter>}, and that is the only counter-stepping command that writes it. Plain \stepcounter moves the number and leaves the label alone; so does \addtocounter. The commands you depend on all call \refstepcounter internally --- \section, \caption, \item inside enumerate, \begin{equation}, \bibitem --- and the ones you build by hand usually do not. That single asymmetry is why a home-made \newenvironment{exercise} that steps its counter with \stepcounter makes \label{ex:one} resolve to the enclosing section.
Reading the file back is just as mechanical. Bare LaTeX writes two fields per label, the number and the page; with hyperref loaded the same line carries five, roughly \newlabel{eq:gauss}{{4.2}{17}{}{equation.4.2}{}}. \ref prints the first field, \pageref the second, \nameref the third, and the fourth is the PDF destination a click uses. This is why a reference can be half right: the number and the link come from different slots of one record, so a stale .aux, an unusual \p@<counter> prefix or a collided anchor name can move one without moving the other.
\text{stored} = \mathtt{currentlabel}\ \text{at that instant} \Longleftarrow \mathtt{refstepcounter}_{\text{most recent}}
main.aux and search for \newlabel. Each hit shows the key with its number, page and destination exactly as the next pass will see them.
Two passes, and the ?? you get on the first
The .aux is written by the run that is also reading it. At \begin{document} LaTeX inputs \jobname.aux from the previous run, turning every \newlabel line it finds into a definition; while it typesets the body it appends the new lines to that same file. On the first compile of a fresh document the table is therefore empty, every \ref expands to ??, and the log closes with LaTeX Warning: There were undefined references. The second compile reads what the first wrote. Nothing is broken; the ?? is the system telling you it asked for a key that does not exist yet.
Two details make the rule less trivial than it sounds. First, LaTeX does not rerun because you asked it to: it notices that a label it needed was missing, or that a stored value changed, and writes Rerun to get cross-references right. into the log. latexmk and most editors parse exactly that string, which is why one button press appears to solve a two-pass problem --- it is running the passes, not skipping them. Second, the table is keyed on \jobname. Compiling a chapter file directly, renaming the root document, or building into a directory that is not the one holding the .aux gives you an empty table again, with no diagnostic anyone reads.
Everything that throws away auxiliary files throws away the label table. A CI pipeline that runs the engine once per checkout, a repository that commits .tex but never .aux, a clean button pressed before the final build, and \includeonly narrowed to one chapter whose siblings were never built all produce the same result: correct prose, ?? in every pointer. When a collaborator reports ?? where you see numbers, ask what their build command is before you touch the source.
\mathtt{??} \xrightarrow{\;\text{pass 1: write .aux}\;} \{\,\mathtt{eq:gauss} \mapsto (4.2,\,17)\,\} \xrightarrow{\;\text{pass 2: read .aux}\;} (4.2)
.aux from somebody else's build resolves your references to their page numbers.% ============================================================
% The whole subject of this document is the reference machinery.
% Compile it TWICE: pass 1 writes the label table, pass 2 reads it.
% ============================================================
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[a4paper,margin=2.5cm]{geometry}
\usepackage{xcolor} % teal is not a base colour name
\usepackage[colorlinks=true,linkcolor=blue,citecolor=teal]{hyperref}
\usepackage{cleveref} % after hyperref, never before it
\begin{document}
\tableofcontents
\section{Gaussian integrals}\label{sec:gauss}
\begin{equation}
\label{eq:gauss}% anywhere after \begin{equation} is correct
\int_{-\infty}^{\infty} e^{-x^{2}}\,dx = \sqrt{\pi}
\end{equation}
One key, five macros, five different strings on the same line:
\ref{eq:gauss}, \eqref{eq:gauss}, \pageref{eq:gauss}, \autoref{eq:gauss}
and \cref{eq:gauss}.
% ref -> bare number eqref -> number in parentheses
% pageref -> the page autoref -> "Equation <n>"
% cref -> "equation (<n>)", lower case, and it is a link
\section{A float, and where its label goes}
\begin{figure}[htbp]
\centering
\rule{4cm}{2cm}
\caption{The error curve.}%
\label{fig:error}% MUST follow \caption: that is what steps figure
\end{figure}
As discussed in \cref{fig:error}. Move the \verb|\label| one line up and the
number it stores becomes the section's --- right format, no error, wrong
object. That is the whole reason the ordering rule exists.
\section{A list worth pointing at}
\begin{enumerate}
\item Set up the integral over the whole line. \label{itm:setup}
\item Square it and pass to polar coordinates. \label{itm:polar}
\end{enumerate}
Step \ref{itm:setup} is fine, because \verb|\item| steps \verb|enumi| through
\verb|\refstepcounter|. A \verb|\label| written on the
\verb|\begin{enumerate}| line, before the first \verb|\item|, would name the
section instead.
% main.aux, when you open it after pass 1, is an ordinary text file:
% \newlabel{eq:gauss}{{1}{1}{}{equation.1}{}}
% \newlabel{fig:error}{{1}{1}{}{figure.1}{}}
% \newlabel{itm:polar}{{2}{1}{}{Hei.2}{}} % Hei = hyperref's name for enumi
% Pass 2 is nothing but the second time those lines get read.
\end{document}
Where the label stands decides what it names
Because \label only reads \@currentlabel, its position is a statement about the command that came before it, not the one that follows. Inside equation the counter is stepped at \begin{equation}, so the label may stand anywhere in the body, and house style puts it first, where it cannot be separated from the display it belongs to. After \section{...}, not before it. Inside a numbered list, on the line after the \item whose number you want, since \item is what steps enumi.
Floats are where this bites, because there the counter is stepped by \caption. Writing \caption{...}\label{fig:x} is correct and \label{fig:x}\caption{...} is not --- the second records whatever was last stepped, usually the section. No error is produced. The number comes out in a plausible format, the entry in the list of figures looks reasonable, and the only symptom is that \cref{fig:x} says "section 2.1" in the middle of a sentence about a picture. A float you moved by hand at the last minute reproduces the same bug in a document that was correct the week before, which is why the ordering rule is worth memorising rather than looking up.
The same mechanism gives you a deliberate trick. What is stored is \p@<counter> followed by \the<counter>, so redefining the first macro adds a prefix that appears in references and nowhere else: with \renewcommand{\p@solution}{Solution~} the heading prints 3 while \ref{sol:quad} prints Solution 3. And \theH<counter>, the macro hyperref uses to build the anchor name, is the same idea applied to the link side --- which makes it the surgical fix when two objects legitimately print the same number.
\int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}
\label after the command that steps the counter you want.e^{i\pi} + 1 = 0
ref, eqref, pageref: which macro for which string
\ref typesets the stored number and nothing else. \eqref, from amsmath, performs the same lookup and wraps the result in parentheses in math style, which is the typographically correct way to name a display and the reason it exists. Typing (\ref{eq:x}) by hand looks the same and is not: the brackets are upright text symbols rather than maths, and if \p@equation ever carries a prefix, your parentheses end up outside it.
\pageref reads the page field instead of the number field, so it obeys whatever page numbering is active --- a reference to a label in roman front matter prints vii, not 7. \nameref reads the title field and gives you the heading text of the target; it has something to read only because hyperref (or nameref on its own) fills that field when the label is written, and without either you get ! Undefined control sequence at the first use.
Two more cover the everyday gaps. \ref*{key} prints the number with the link switched off, which is what you want when the noun and the punctuation are yours and only the digits should come from the machine. \autoref and \cref supply the word as well: \autoref capitalises it, \cref lower-cases it and \Cref capitalises it again, and cleveref additionally pluralises and collapses lists. Pick one and use it throughout, because a thesis that alternates between "fig. 3", "Figure 3" and "3" reads as if three people wrote it --- which is usually accurate.
\underbrace{4.2}_{\text{ref}}\quad \underbrace{(4.2)}_{\text{eqref}}\quad \underbrace{17}_{\text{pageref}}\quad \underbrace{\text{Equation }4.2}_{\text{autoref}}\quad \underbrace{\text{equation (4.2)}}_{\text{cref}}
\eqref. Mixing them in one sentence is the tell of a pasted-together document.Names, duplicates and silent redirection
The prefixes in eq:, fig:, sec:, tab: and enu: are decoration as far as TeX is concerned: a key is an opaque string. They earn their keep in three other places --- greppability, editor autocomplete, and the fact that a name carrying its own type cannot be attached to the wrong kind of object without looking wrong. The convention worth adding once a document has chapters is a per-unit prefix such as ch04:eq:wave, because a shared appendix compiled into two reports is where identical keys first appear.
When one key is used twice the run reports LaTeX Warning: Label `fig:setup' multiply defined., and then does something less obvious than the wording suggests. The whole record --- number, page, title and destination together --- is replaced by whichever write happens last, so the earlier object becomes unreachable through that name while every mention of it now carries the later object's number. Recent kernels also end the run with LaTeX Warning: There were multiply-defined labels., so you do not have to scroll a thousand lines to find out.
A second warning looks similar and means something different: Package hyperref Warning: Destination with the same identifier (name{figure.2.1}) has been already used, duplicate ignored. That is not a duplicate key at all --- two distinct labels produced the same anchor name because \theH<counter> collided, typically a counter that restarts without the anchor restarting with it, a theorem sharing a counter, or a repeated \phantomsection. The reference resolves, the text is right, and the click jumps to the earlier of the two objects.
Finding the first kind is cheap. Search the sources for \label{ and pipe the result through sort and a duplicate filter; the refcheck package reports undefined, duplicated and never-referenced labels during the build; and from inside the document \@ifundefined{r@<key>}{not yet}{ok} tests whether a key resolved, which turns a stale .aux into a visible word rather than two question marks. The refcount package exposes the same table more comfortably through \getrefnumber{key}.
\{\,\mathtt{fig:setup} \mapsto 1.4\,\} \;\cup\; \{\,\mathtt{fig:setup} \mapsto 2.7\,\} \longrightarrow \{\,\mathtt{fig:setup} \mapsto 2.7\,\}
.aux rather than the sources when you want the truth: \newlabel lines are what the next pass will actually read, duplicates included.\documentclass[12pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[margin=2.5cm]{geometry}
\usepackage[colorlinks=true]{hyperref}
\makeatletter
% (A) A label stores \p@<counter> followed by \the<counter>. Redefine the
% first half and a word appears in every reference while the printed
% heading itself stays bare.
\newcounter{solution}[chapter]
\renewcommand{\thesolution}{\arabic{solution}}
\renewcommand{\p@solution}{Solution~}
\newenvironment{solution}
{\par\medskip\noindent\refstepcounter{solution}% <- refstepcounter, not stepcounter
\textbf{\thesolution.}\ }
{\par\medskip}
% (B) hyperref builds the PDF destination name from \theH<counter>. Two
% objects whose \theH form collides produce
% Package hyperref Warning: Destination with the same identifier
% (name{figure.2.1}) has been already used, duplicate ignored.
% and the second one then has no anchor of its own to jump to.
\newcommand{\isresolved}[2]{%
\@ifundefined{r@#1}{#2}{resolved from the previous pass}}
\makeatother
\begin{document}
\chapter{Inequalities}\label{ch:one}
\begin{figure}[htbp]\centering
\rule{3cm}{1.6cm}
\caption{Two curves.}\label{fig:setup}
\end{figure}
The heading below prints a bare number while the reference to it does not,
because \verb|\p@solution| only enters the stored form: see \ref{sol:first}.
\begin{solution}\label{sol:first}
Square both sides and compare term by term.
\end{solution}
\chapter{Applications}\label{ch:two}
\begin{figure}[htbp]\centering
\rule{3cm}{1.6cm}
\caption{The same drawing, reused.}\label{fig:setup} % key used twice
\end{figure}
Reference to \ref{fig:setup}. The key was written twice, so the run warns
\emph{Label `fig:setup' multiply defined} and the \emph{later} line owns the
number, the page, the title and the destination together: the first figure is
now unreachable through that name.
\section{A collided anchor, not a collided key}
\setcounter{figure}{0} % deliberate: restart the counter inside chapter 2
\begin{figure}[htbp]\centering
\rule{3cm}{1.6cm}
\caption{Also numbered 2.1.}\label{fig:again}
\end{figure}
\ref{fig:again} resolves and is typeset, but its destination name is the one
figure 2.1 already registered, so clicking it jumps upward. Distinct labels,
distinct numbers in the text, one anchor shared -- and only a warning in the
log says so.
\section*{Asking from inside the document}
\isresolved{eq:nowhere}{NOT RESOLVED --- compile again}\\
\isresolved{fig:setup}{NOT RESOLVED --- compile again}
\end{document}
The word in front of the number, and the order that supplies it
LaTeX itself has no vocabulary. \ref prints digits, and the noun is either typed by you or supplied by a package. hyperref's \autoref looks it up in a control sequence named after the counter --- \<counter>autorefname --- so \figureautorefname is Figure and \sectionautorefname is Section. The built-in counters already have entries; a counter you created with \newcounter does not, and \autoref{ex:one} prints a bare number with no complaint. The fix is one line, \newcommand*{\exerciseautorefname}{Exercise}.
cleveref keeps its own table and a wider one: \crefname{exercise}{exercise}{exercises} for the lower-case form and \Crefname{exercise}{Exercise}{Exercises} for the capitalised one --- singular and plural, twice, because the two cases are separate lookups. It is also the only one of the pair that understands plurality and lists: \cref{sec:a,sec:b,sec:c} folds into "sections 1, 2 and 3" and \crefrange{sec:a}{sec:c} into "sections 1 to 3", where \autoref would give you two sentences of hand-typed conjunction. Its capitalise option is the polite default for prose that names headings in full.
The loading order is not etiquette, and the failure mode is why people distrust this paragraph. hyperref redefines \ref, \cite, \label and the sectioning commands as it loads, so it belongs at the bottom of the preamble; cleveref then wraps the versions hyperref produced, so it belongs below it, and nothing else is allowed under either. Load them the other way round and hyperref installs its own \ref over cleveref's wrapper: the numbers stay correct, the words disappear, the links stop working, and no error is issued. The canonical tail is hyperref then cleveref.
\{\,a,b,c\,\} \longmapsto \text{sections 1, 2 and 3} \qquad a \le k \le b \longmapsto \text{sections 1 to 3}
\autoref and \cref once per document: they capitalise differently and only one of them pluralises, so mixing them reads as three authors in a paragraph.References that cross a file, or a document
A multi-file project does not have one label table during the build, but it ends up with one. Each \included unit writes its own .aux, and the master file gathers them with \@input{ch04.aux} lines, so by the time the references are resolved the whole book shares a single key space. That is precisely what makes \includeonly{chapters/04-wave} usable: the excluded units are never read, yet their auxiliary files still are, so \cref{eq:projection} in your working chapter resolves --- to the numbers left by the last full build. Plausible, stale and unmarked is the most dangerous combination this cluster produces.
Across two documents the same idea is exposed on purpose by the xr family: \externaldocument{supplementary} reads supplementary.aux into the current table, and from then on a key defined over there resolves over here. It is read-only and unlinked --- the other document must have been compiled, and its .aux must be where this build can find it --- and the prefixed form, \externaldocument[supp:]{supplementary}, is what keeps two independent key spaces from colliding the moment both define fig:setup. For clickable jumps use xr-hyper instead, loaded before hyperref, because hyperref has to see it in order to route external destination names at all.
Three boundary cases are worth knowing before you meet them under a deadline. A \subfile child compiled on its own resolves nothing outside itself, since the siblings' auxiliary files were never pulled in --- a property of the layout, not a bug to chase. Two documents that reference each other need xr in both and converge only after two rounds of each build. And when the other document's numbering is genuinely unstable, write the pointer by hand: a hard-coded "see the supplementary material, equation (S4)" is more honest than a machine number that silently changes every time somebody else rebuilds.
% ============================================================
% main.tex -- labels gathered from included units and from a
% document that is not part of this build at all
% ============================================================
\documentclass[12pt,a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[margin=2.5cm]{geometry}
% Cross-document referencing. Use xr-hyper rather than xr as soon as hyperref
% is in the document, and load it BEFORE hyperref: hyperref notices it there
% and routes the external destination names through the other file, which is
% the difference between a resolving number and a clickable jump.
\usepackage{xr-hyper}
\usepackage[colorlinks=true]{hyperref}
\usepackage{cleveref}
% The prefixed form keeps the two key spaces apart, so both documents are free
% to define fig:setup. Write \externaldocument{supplementary} with no optional
% argument to import the foreign keys verbatim instead.
\externaldocument[supp:]{supplementary}
\begin{document}
\mainmatter
% chapters/04-wave.aux is written by that \include and pulled back into
% main.aux through an \@input line, so the whole book keeps ONE label table.
\include{chapters/01-basics}
\include{chapters/04-wave}
% \includeonly{chapters/04-wave} % a fast single-chapter build: the excluded
% files are never read (their counters do not
% advance) but their .aux files still are, so
% \ref into them prints the numbers from the
% last FULL build. Plausible and stale.
As \cref{eq:wave} shows --- and compare the notation in
\ref{supp:eq:derivation} of the separate supplementary document, whose
\texttt{.aux} must exist beside it for this to resolve at all.
\end{document}
% ============================================================
% supplementary.tex -- a normal document; its .aux is the interface
% ============================================================
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\begin{document}
\section{Derivation}
\begin{equation}\label{eq:derivation}
\lVert x\rVert_{2} = \Bigl(\sum_{i} x_{i}^{2}\Bigr)^{1/2}
\end{equation}
Nothing here knows it is being referenced from elsewhere: the exported table
is a side effect of compiling it.
\end{document}
Citations are the same machine, with one program more
The \cite{key} and \bibitem{key} pair is the label-ref contract with a different writer. \bibitem steps the list counter through \refstepcounter and emits a \newlabel line, which is why \ref{knuth1984} really does print the entry number of a bibliography item you never meant to label. The difference is upstream: the .aux also collects a \citation{key} line for every \cite, and those lines are what BibTeX reads --- together with the \bibdata and \bibstyle records in the same file --- to select entries from the .bib data and write the .bbl that a later LaTeX pass inputs.
That extra program is why the pass order stops being a matter of taste: latex, bibtex, latex, latex. Run bibtex before the first LaTeX pass and it answers I couldn't open file name "main.aux", because the file holding the citation list does not exist yet. Run only one LaTeX pass afterwards and every citation prints [?] under LaTeX Warning: Citation `knuth1984' undefined., because the .bbl arrived too late in the sequence to be read. latexmk and arara are not speeding this up; they are encoding the dependency so the passes happen in the right order.
biblatex moves the selection step from bibtex to biber and keeps the shape identical --- one pass to emit the request list, later passes to consume the result --- so nothing in this section changes when a venue asks for it. What does change is that an entry is keyed by its bibliographic data rather than by a \bibitem you wrote, and the printed number is a sort order rather than a counter. The debugging instinct stays the same, though: when a citation will not resolve, open the .aux first and check whether the key was ever asked for.
% Equation with a number and label:
\begin{equation}
\label{eq:gaussian}
\int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}
\end{equation}
% Inline reference (hyperref makes it a link):
Combining \eqref{eq:gaussian} with \eqref{eq:laplace} …
% Bibliography, minimal BibTeX workflow:
% 1. \cite{knuth1984} in the text
% 2. a .bib file with the entries
% 3. \bibliographystyle{plain} \bibliography{refs}
% 4. run latex → bibtex → latex → latex
Lesson cheat sheet
One key line of code from each section — jump to it or copy it straight from here.
\text{stored} = \mathtt{currentlabel}\ \text{at that instant} \Longleftarrow \mathtt{refstepcounter}_{\text{most recent}}
\documentclass[11pt,a4paper]{article}
\int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}
\underbrace{4.2}_{\text{ref}}\quad \underbrace{(4.2)}_{\text{eqref}}\quad \underbrace{17}_{\text{pageref}}\quad \underbrace{\text{Equation }4.2}_{\text{autoref}}\quad \underbrace{\text{equation (4.2)}}_{\text{cref}}
\documentclass[12pt,a4paper]{report}
\{\,a,b,c\,\} \longmapsto \text{sections 1, 2 and 3} \qquad a \le k \le b \longmapsto \text{sections 1 to 3}
Common mistakes
- Every pointer reads
??and the log ends withLaTeX Warning: There were undefined references.One pass on a changed document, or a.auxthat was deleted, was never written because a child file was compiled directly under another\jobname, or lives in a directory this build cannot see. Compile twice, or letlatexmkreact toRerun to get cross-references right.--- do not "fix" it by typing the numbers. LaTeX Warning: Label `fig:setup' multiply defined.The key appears twice, usually a copy-pasted figure block or one shared chapter compiled into two reports. The later write owns number, page, title and destination together, so the first object silently stops existing as a target. Namespace keys per unit, then search the sources for duplicate\label{strings;refcheckwill report them for you.\cref{fig:setup}prints "section 2.1" and the run reports nothing at all. The label stands before\caption, and\captionis the command that stepsfigure, so\@currentlabelstill held the section number when the label was written. The order inside a float is\caption{...}\label{fig:setup}, always.\autoref{ex:quad}prints "2.1" with no word in front, and cleveref does the same for a counter of yours. Nothing names a user counter: define\newcommand*{\exerciseautorefname}{Exercise}for hyperref, and\crefnameplus\Crefnamefor cleveref.\autorefwill also never say "Figures 1 and 2" --- that is cleveref's job.- References print the correct number and are not clickable, and the only clue is that
\crefhas started behaving like\ref.cleverefwas loaded beforehyperref, so hyperref patched\refafterwards and threw cleveref's wrapper away. Order: every other package, then hyperref, then cleveref --- withxr-hyper, if you use it, above hyperref. LaTeX Warning: Citation `knuth1984' undefined.plus a bibliography section that is empty although the run finished cleanly.bibtexran before the first LaTeX pass, so there were no\citationlines to read, or it ran and LaTeX was not run twice more. latex, bibtex, latex, latex; when the output looks unchanged, compare the timestamps of the.auxand the.bblinstead of re-reading your source.
Questions about this lesson
Why does my LaTeX document show ?? for cross-references the first time I compile?
\newlabel line into the .aux for every \label and reads a table left by an earlier pass --- which, for a new document, is empty, so every lookup misses and prints ??. Pass 2 reads the file pass 1 just wrote and the numbers appear. Compile twice, or let latexmk detect "Rerun to get cross-references right." and do it for you.What is the difference between \ref, \eqref, \pageref and \autoref in LaTeX?
\ref prints the stored number alone; \eqref (amsmath) wraps that number in math-style parentheses, which is the correct form for a display; \pageref prints the page the label was written on rather than its number; \autoref (hyperref) prints the number preceded by the word registered for that counter, such as "Equation 4.2", and is also a link. \nameref prints the title of the target instead of any number.How many times should I compile a LaTeX document with lots of cross-references?
Can I reference a label defined in another LaTeX document?
\externaldocument{supplementary} reads supplementary.aux into your label table, and keys defined over there then resolve here. It is read-only and not clickable, and the other document must have been compiled, with its .aux beside it. Use \externaldocument[supp:]{supplementary} to prefix the imported keys so the two documents can both define fig:setup. For clickable links to another PDF, load xr-hyper before hyperref instead of xr.Why does \autoref print only a number instead of "Exercise 2.1"?
\autoref builds its word by looking up \<counter>autorefname, and a counter you created with \newcounter has no such definition --- hyperref falls back to the bare number without warning. Add \newcommand*{\exerciseautorefname}{Exercise}. If you use cleveref instead, the equivalent is \crefname{exercise}{exercise}{exercises} plus \Crefname{exercise}{Exercise}{Exercises}, which also buys you plural forms and ranges that \autoref cannot produce.Does \label really have to come after \caption in a figure?
\label stores whatever \refstepcounter wrote into \@currentlabel most recently, and inside a float it is \caption that steps the figure counter. Put the label first and it stores the last section number instead: the run is clean, the number is correctly formatted, and the reference names the wrong object. Inside equation you have a choice, because the counter steps at \begin{equation}.How do I make a LaTeX reference print a number I chose, with no counter behind it?
\tag{3.7} inside the equation: the printed number becomes 3.7 and \eqref reproduces it. For anything else, set \@currentlabel by hand immediately before the label --- \makeatletter\def\@currentlabel{S4}\makeatother\label{eq:hand} makes \ref{eq:hand} print S4. Both are escapes from the numbering rather than part of it: the object is not counted, so it does not appear in a list of figures and hyperref has no real destination for it.Live playground: edit the LaTeX, see it render
The preview updates as you type — break it on purpose to see how errors look.
Keep reading
Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.