1 % \iffalse meta-comment
4 % The LaTeX3 Project and any individual authors listed elsewhere
7 % This file is part of the LaTeX base system.
8 % -------------------------------------------
10 % It may be distributed and/or modified under the
11 % conditions of the LaTeX Project Public License, either version 1.3c
12 % of this license or (at your option) any later version.
13 % The latest version of this license is in
14 % http://www.latex-project.org/lppl.txt
15 % and version 1.3c or later is part of all distributions of LaTeX
16 % version 2005/12/01 or later.
18 % This file has the LPPL maintenance status "maintained".
20 % The list of all files belonging to the LaTeX base distribution is
21 % given in the file `manifest.txt'. See also `legal.txt' for additional
24 % The list of derived (unpacked) files belonging to the distribution
25 % and covered by LPPL is defined by the unpacking scripts (with
26 % extension .ins) which are part of the distribution.
31 %%% From File: ltxref.dtx
35 \ProvidesFile{ltxref.dtx}
36 [2014/09/29 v1.1k LaTeX Kernel (Cross Referencing)]
38 \documentclass{ltxdoc}
39 \GetFileInfo{ltxref.dtx}
52 \MaintainedByLaTeXTeam{latex}
61 % \changes{v1.0c}{1994/03/29}
62 % {Create file ltcntlen from parts of ltmiscen and ltherest.}
63 % \changes{v1.1a}{1994/05/19}
64 % {Extract file ltxref from ltcntlen.}
65 % \changes{v1.1b}{1994/05/21}{Use new warning commands}
66 % \changes{v1.1c}{1994/05/25}{Modify documentation}
68 % \section{Cross Referencing}
69 % The user writes |\label|\marg{foo} to define the following
72 % |\ref|\marg{foo}: value of most recently incremented referencable
73 % counter. in the current environment. (Chapter, section,
74 % theorem and enumeration counters counters are
75 % referencable, footnote counters are not.)
77 % |\pageref|\marg{foo}: page number at which |\label{foo}| command
78 % appeared. where foo can be any string of characters not
79 % containing `|\|', `|{|' or `|}|'.
81 % Note: The scope of the |\label| command is delimited by environments,
83 % |\begin{theorem} \label{foo} ... \end{theorem} \label{bar}|\\
84 % defines |\ref{foo}| to be the theorem number and |\ref{bar}| to be
85 % the current section number.
87 % Note: |\label| does the right thing in terms of spacing -- i.e.,
88 % leaving a space on both sides of it is equivalent to leaving
89 % a space on either side.
94 % \subsection{Cross Referencing}
102 % This is implemented as follows. A referencable counter CNT is
103 % incremented by the command \refstepcounter{CNT} , which sets
104 % \@currentlabel == {CNT}{eval(\p@cnt\theCNT)}. The command
105 % \label{FOO} then writes the following on file \@auxout :
106 % \newlabel{FOO}{{eval(\@currentlabel)}{eval(\thepage)}}
110 % if \r@foo undefined
111 % then @refundefined := G T
113 % Warning: 'reference foo on page ... undefined'
114 % else \@car \eval(\r@FOO)\@nil
120 % if \r@foo undefined
121 % then @refundefined := G T
123 % Warning: 'reference foo on page ... undefined'
124 % else \@cdr \eval(\r@FOO)\@nil
130 % \begin{macro}{\G@refundefinedtrue}
131 % \changes{v1.1i}{1995/12/07}{Renamed (back) from \cs{G@refundefined}}
132 % \begin{macro}{\@refundefined}
133 % \changes{v1.1h}{1995/10/24}{Switch for refundefined replaced}
134 % This does not save on name-space (since \cs{G@refundefinedfalse}
135 % was never needed) but it does make the implementation of such
136 % one-way switches more consistent. The extra macro to make the
137 % change is used since this change appears several times.
139 % \textbf{Note} despite its name, |\G@refundefinedtrue| does
140 % \emph{not} correspond to an |\if| command, and there is no
141 % matching \ldots|false|. It would be more natural to call the
142 % command |\G@refundefined| (as inspection of the change log will
143 % reveal) but unfortunately such a change would break any package
144 % that had defined a |\ref|-like command that mimicked the
145 % definition of |\ref|, calling |\G@refundefinedtrue|. Inspection
146 % of the \TeX\ archives revealed several such packages, and so this
147 % command has been named \ldots|true| so that the definition of
148 % |\ref| need not be changed, and the packages will work without
151 % \newif\ifG@refundefined
152 % \def\G@refundefinedtrue{\global\let\ifG@refundefined\iftrue}
153 % \def\G@refundefinedfalse{\global\let\ifG@refundefined\iffalse}
154 \def\G@refundefinedtrue{%
155 \gdef\@refundefined{%
156 \@latex@warning@no@line{There were undefined references}}}
157 \let\@refundefined\relax
164 % \begin{macro}{\ref}
165 % \changes{LaTeX2e}{1993/12/11}{Macro reimplemented}
166 % \begin{macro}{\pageref}
167 % \changes{LaTeX2e}{1993/12/11}{Macro reimplemented}
168 % \begin{macro}{\@setref}
169 % \changes{LaTeX2e}{1993/12/11}{Macro added}
170 % \changes{v1.1h}{1995/10/24}{Switch for refundefined renamed}
171 % \changes{v1.1i}{1995/12/07}{Switch for refundefined restored}
172 % Referencing a |\label|.
173 % RmS 91/10/25: added a few extra |\reset@font|,
174 % as suggested by Bernd Raichle
176 % RmS 92/08/14: made |\ref| and |\pageref| robust
178 % RmS 93/09/08: Added setting of refundefined switch.
182 \protect\G@refundefinedtrue
183 \nfss@text{\reset@font\bfseries ??}%
184 \@latex@warning{Reference `#3' on page \thepage \space
187 \expandafter#2#1\null
189 \def\ref#1{\expandafter\@setref\csname r@#1\endcsname\@firstoftwo{#1}}
190 \def\pageref#1{\expandafter\@setref\csname r@#1\endcsname
198 % \begin{macro}{\newlabel}
199 % \changes{v1.1b}{1994/05/21}{Use new warning commands}
200 % \changes{v1.1e}{1995/04/24}{Make \cs{@onlypreamble} for /1388.}
201 % \changes{v1.1e}{1995/06/19}
202 % {Use \cs{@newl@bel} to share code with \cs{bibcite}}
203 % \changes{v1.1g}{1995/07/14}
204 % {Remove \cs{@onlypreamble} so still defined in new \cs{enddocument}}
205 % This command will be written to the \texttt{.aux} file to
206 % pass label information from one run to another.
207 % \begin{macro}{\@newl@bel}
208 % The internal form of |\newlabel| and |\bibcite|. Note that this
209 % macro does it's work inside a group. That way the local
210 % assignments it needs to do don't clutter the save stack. This
211 % prevents large documents with many labels to run out of save
213 % \changes{v1.1h}{1995/10/24}{Switch for multiplelabels replaced by
215 % \changes{v1.1k}{2001/02/16}{Added an extra grouplevel (PR3250), jlb}
217 \def\@newl@bel#1#2#3{{%
218 \@ifundefined{#1@#2}%
220 {\gdef \@multiplelabels {%
221 \@latex@warning@no@line{There were multiply-defined labels}}%
222 \@latex@warning@no@line{Label `#2' multiply defined}}%
223 \global\@namedef{#1@#2}{#3}}}
227 \def\newlabel{\@newl@bel r}
231 \@onlypreamble\@newl@bel
236 % \begin{macro}{\if@multiplelabels}
237 % \changes{v1.1h}{1995/10/24}{Macro removed}
238 % \begin{macro}{\@multiplelabels}
239 % \changes{v1.1h}{1995/10/24}{Switch for multiplelabels removed}
240 % This is redefined to produce a warning if at least one label is
241 % defined more than once. It is executed by the |\enddocument|
244 \let \@multiplelabels \relax
249 % \begin{macro}{\label}
250 % \changes{v1.1d}{1994/11/04}{(ASAJ)Added \cs{protected@write}}
251 % \begin{macro}{\refstepcounter}
252 % \changes{v1.1d}{1994/11/04}{(ASAJ)Added \cs{protected@edef}}
253 % The commands |\label| and |\refstepcounter| have been changed to
254 % allow |\protect|'ed commands to work properly. For example,
256 % \def\thechapter{\protect\foo{\arabic{chapter}.\roman{section}}}
258 % will cause a |\label{bar}| command to define |\ref{bar}| to expand
259 % to something like |\foo{4.d}|. Change made 20 Jul 88.
262 \def\label#1{\@bsphack
263 \protected@write\@auxout{}%
264 {\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
269 \def\refstepcounter#1{\stepcounter{#1}%
270 \protected@edef\@currentlabel
271 {\csname p@#1\endcsname\csname the#1\endcsname}%
278 % \begin{macro}{\@currentlabel}
279 % For |\label| commands that come before any environment
290 % \subsection{An extension of counter referencing}
293 % At the moment a reference to a counter |foo| will generate the
294 % equivalent of |\p@foo\thefoo| although not quite in this form. For
295 % some applications it would be nice of one could have |\thefoo| being
296 % an argument to |\p@foo| to be able to put material before and after
297 % the number generated by |\thefoo|. This can be easily achieved with
298 % a small change to one of the kernel commands as follows:
301 %\def\refstepcounter#1{\stepcounter{#1}%
302 % \protected@edef\@currentlabel
303 % {\csname p@#1\expandafter\endcsname\csname the#1\endcsname}%
307 % The trick is to ensure that |\csname the#1\endcsname| is turned into
308 % a single token before |\p@...| is expanded further. This way, if the
309 % |\p@...| command is a macro with one argument it will receive
310 % |\the...|. With the kernel code (i.e., without the |\expandafter|)
311 % it will instead pick up |\csname| which would be disastrous.
313 % Using |\expandafter| instead of braces delimiting the argument is
314 % better because, assuming that the |\p@...| command is not defined as
315 % a macro with one argument, the braces will stay and prohibit kerning
316 % that might otherwise happen between the glyphs generated by
317 % |\the...| and surrounding glyphs.
319 % We have refrained from making this change in the kernel code
320 % although for existing documents it would be 100\% backward
321 % compatible. The reason being that any class or package making use of
322 % this functionality would then horribly fail with older \LaTeX{}
325 % Instead we suggest that people who are interested in using this
326 % functionality in a document class or package add the redefinition to
327 % the class file. To ensure that this redefinition is properly applied
328 % they might want to test for the original definition first, e.g.
331 %\CheckCommand*\refstepcounter[1]{\stepcounter{#1}%
332 % \protected@edef\@currentlabel
333 % {\csname p@#1\endcsname\csname the#1\endcsname}%
335 %\renewcommand*\refstepcounter[1]{\stepcounter{#1}%
336 % \protected@edef\@currentlabel
337 % {\csname p@#1\expandafter\endcsname\csname the#1\endcsname}%