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}
60 % \changes{v1.0c}{1994/03/29}
61 % {Create file ltcntlen from parts of ltmiscen and ltherest.}
62 % \changes{v1.1a}{1994/05/19}
63 % {Extract file ltxref from ltcntlen.}
64 % \changes{v1.1b}{1994/05/21}{Use new warning commands}
65 % \changes{v1.1c}{1994/05/25}{Modify documentation}
67 % \section{Cross Referencing}
68 % The user writes |\label|\marg{foo} to define the following
71 % |\ref|\marg{foo}: value of most recently incremented referencable
72 % counter. in the current environment. (Chapter, section,
73 % theorem and enumeration counters counters are
74 % referencable, footnote counters are not.)
76 % |\pageref|\marg{foo}: page number at which |\label{foo}| command
77 % appeared. where foo can be any string of characters not
78 % containing `|\|', `|{|' or `|}|'.
80 % Note: The scope of the |\label| command is delimited by environments,
82 % |\begin{theorem} \label{foo} ... \end{theorem} \label{bar}|\\
83 % defines |\ref{foo}| to be the theorem number and |\ref{bar}| to be
84 % the current section number.
86 % Note: |\label| does the right thing in terms of spacing -- i.e.,
87 % leaving a space on both sides of it is equivalent to leaving
88 % a space on either side.
93 % \subsection{Cross Referencing}
101 % This is implemented as follows. A referencable counter CNT is
102 % incremented by the command \refstepcounter{CNT} , which sets
103 % \@currentlabel == {CNT}{eval(\p@cnt\theCNT)}. The command
104 % \label{FOO} then writes the following on file \@auxout :
105 % \newlabel{FOO}{{eval(\@currentlabel)}{eval(\thepage)}}
109 % if \r@foo undefined
110 % then @refundefined := G T
112 % Warning: 'reference foo on page ... undefined'
113 % else \@car \eval(\r@FOO)\@nil
119 % if \r@foo undefined
120 % then @refundefined := G T
122 % Warning: 'reference foo on page ... undefined'
123 % else \@cdr \eval(\r@FOO)\@nil
129 % \begin{macro}{\G@refundefinedtrue}
130 % \changes{v1.1i}{1995/12/07}{Renamed (back) from \cs{G@refundefined}}
131 % \begin{macro}{\@refundefined}
132 % \changes{v1.1h}{1995/10/24}{Switch for refundefined replaced}
133 % This does not save on name-space (since \cs{G@refundefinedfalse}
134 % was never needed) but it does make the implementation of such
135 % one-way switches more consistent. The extra macro to make the
136 % change is used since this change appears several times.
138 % \textbf{Note} despite its name, |\G@refundefinedtrue| does
139 % \emph{not} correspond to an |\if| command, and there is no
140 % matching \ldots|false|. It would be more natural to call the
141 % command |\G@refundefined| (as inspection of the change log will
142 % reveal) but unfortunately such a change would break any package
143 % that had defined a |\ref|-like command that mimicked the
144 % definition of |\ref|, calling |\G@refundefinedtrue|. Inspection
145 % of the \TeX\ archives revealed several such packages, and so this
146 % command has been named \ldots|true| so that the definition of
147 % |\ref| need not be changed, and the packages will work without
150 % \newif\ifG@refundefined
151 % \def\G@refundefinedtrue{\global\let\ifG@refundefined\iftrue}
152 % \def\G@refundefinedfalse{\global\let\ifG@refundefined\iffalse}
153 \def\G@refundefinedtrue{%
154 \gdef\@refundefined{%
155 \@latex@warning@no@line{There were undefined references}}}
156 \let\@refundefined\relax
163 % \begin{macro}{\ref}
164 % \changes{LaTeX2e}{1993/12/11}{Macro reimplemented}
165 % \begin{macro}{\pageref}
166 % \changes{LaTeX2e}{1993/12/11}{Macro reimplemented}
167 % \begin{macro}{\@setref}
168 % \changes{LaTeX2e}{1993/12/11}{Macro added}
169 % \changes{v1.1h}{1995/10/24}{Switch for refundefined renamed}
170 % \changes{v1.1i}{1995/12/07}{Switch for refundefined restored}
171 % Referencing a |\label|.
172 % RmS 91/10/25: added a few extra |\reset@font|,
173 % as suggested by Bernd Raichle
175 % RmS 92/08/14: made |\ref| and |\pageref| robust
177 % RmS 93/09/08: Added setting of refundefined switch.
181 \protect\G@refundefinedtrue
182 \nfss@text{\reset@font\bfseries ??}%
183 \@latex@warning{Reference `#3' on page \thepage \space
186 \expandafter#2#1\null
188 \def\ref#1{\expandafter\@setref\csname r@#1\endcsname\@firstoftwo{#1}}
189 \def\pageref#1{\expandafter\@setref\csname r@#1\endcsname
197 % \begin{macro}{\newlabel}
198 % \changes{v1.1b}{1994/05/21}{Use new warning commands}
199 % \changes{v1.1e}{1995/04/24}{Make \cs{@onlypreamble} for /1388.}
200 % \changes{v1.1e}{1995/06/19}
201 % {Use \cs{@newl@bel} to share code with \cs{bibcite}}
202 % \changes{v1.1g}{1995/07/14}
203 % {Remove \cs{@onlypreamble} so still defined in new \cs{enddocument}}
204 % This command will be written to the \texttt{.aux} file to
205 % pass label information from one run to another.
206 % \begin{macro}{\@newl@bel}
207 % The internal form of |\newlabel| and |\bibcite|. Note that this
208 % macro does it's work inside a group. That way the local
209 % assignments it needs to do don't clutter the save stack. This
210 % prevents large documents with many labels to run out of save
212 % \changes{v1.1h}{1995/10/24}{Switch for multiplelabels replaced by
214 % \changes{v1.1k}{2001/02/16}{Added an extra grouplevel (PR3250), jlb}
216 \def\@newl@bel#1#2#3{{%
217 \@ifundefined{#1@#2}%
219 {\gdef \@multiplelabels {%
220 \@latex@warning@no@line{There were multiply-defined labels}}%
221 \@latex@warning@no@line{Label `#2' multiply defined}}%
222 \global\@namedef{#1@#2}{#3}}}
226 \def\newlabel{\@newl@bel r}
230 \@onlypreamble\@newl@bel
235 % \begin{macro}{\if@multiplelabels}
236 % \changes{v1.1h}{1995/10/24}{Macro removed}
237 % \begin{macro}{\@multiplelabels}
238 % \changes{v1.1h}{1995/10/24}{Switch for multiplelabels removed}
239 % This is redefined to produce a warning if at least one label is
240 % defined more than once. It is executed by the |\enddocument|
243 \let \@multiplelabels \relax
248 % \begin{macro}{\label}
249 % \changes{v1.1d}{1994/11/04}{(ASAJ)Added \cs{protected@write}}
250 % \begin{macro}{\refstepcounter}
251 % \changes{v1.1d}{1994/11/04}{(ASAJ)Added \cs{protected@edef}}
252 % The commands |\label| and |\refstepcounter| have been changed to
253 % allow |\protect|'ed commands to work properly. For example,
255 % \def\thechapter{\protect\foo{\arabic{chapter}.\roman{section}}}
257 % will cause a |\label{bar}| command to define |\ref{bar}| to expand
258 % to something like |\foo{4.d}|. Change made 20 Jul 88.
261 \def\label#1{\@bsphack
262 \protected@write\@auxout{}%
263 {\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
268 \def\refstepcounter#1{\stepcounter{#1}%
269 \protected@edef\@currentlabel
270 {\csname p@#1\endcsname\csname the#1\endcsname}%
277 % \begin{macro}{\@currentlabel}
278 % For |\label| commands that come before any environment
289 % \subsection{An extension of counter referencing}
292 % At the moment a reference to a counter |foo| will generate the
293 % equivalent of |\p@foo\thefoo| although not quite in this form. For
294 % some applications it would be nice of one could have |\thefoo| being
295 % an argument to |\p@foo| to be able to put material before and after
296 % the number generated by |\thefoo|. This can be easily achieved with
297 % a small change to one of the kernel commands as follows:
300 %\def\refstepcounter#1{\stepcounter{#1}%
301 % \protected@edef\@currentlabel
302 % {\csname p@#1\expandafter\endcsname\csname the#1\endcsname}%
306 % The trick is to ensure that |\csname the#1\endcsname| is turned into
307 % a single token before |\p@...| is expanded further. This way, if the
308 % |\p@...| command is a macro with one argument it will receive
309 % |\the...|. With the kernel code (i.e., without the |\expandafter|)
310 % it will instead pick up |\csname| which would be disastrous.
312 % Using |\expandafter| instead of braces delimiting the argument is
313 % better because, assuming that the |\p@...| command is not defined as
314 % a macro with one argument, the braces will stay and prohibit kerning
315 % that might otherwise happen between the glyphs generated by
316 % |\the...| and surrounding glyphs.
318 % We have refrained from making this change in the kernel code
319 % although for existing documents it would be 100\% backward
320 % compatible. The reason being that any class or package making use of
321 % this functionality would then horribly fail with older \LaTeX{}
324 % Instead we suggest that people who are interested in using this
325 % functionality in a document class or package add the redefinition to
326 % the class file. To ensure that this redefinition is properly applied
327 % they might want to test for the original definition first, e.g.
330 %\CheckCommand*\refstepcounter[1]{\stepcounter{#1}%
331 % \protected@edef\@currentlabel
332 % {\csname p@#1\endcsname\csname the#1\endcsname}%
334 %\renewcommand*\refstepcounter[1]{\stepcounter{#1}%
335 % \protected@edef\@currentlabel
336 % {\csname p@#1\expandafter\endcsname\csname the#1\endcsname}%