Debian Codegraph @

texmf-dist/source/latex-dev/base/ltxref.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 1993-2026
4 % The LaTeX Project and any individual authors listed elsewhere
5 % in this file.
6 %
7 % This file is part of the LaTeX base system.
8 % -------------------------------------------
9 %
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 % https://www.latex-project.org/lppl.txt
15 % and version 1.3c or later is part of all distributions of LaTeX
16 % version 2008 or later.
17 %
18 % This file has the LPPL maintenance status "maintained".
19 %
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
22 % information.
23 %
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.
27 %
28 % \fi
29 %
30 % \iffalse
31 %%% From File: ltxref.dtx
32 %
33 %<*driver>
34 % \fi
35 \ProvidesFile{ltxref.dtx}
36 [2026/01/07 v1.1w LaTeX Kernel (Cross Referencing)]
37 % \iffalse
38 \documentclass{ltxdoc}
39 \GetFileInfo{ltxref.dtx}
40 \title{\filename}
41 \date{\filedate}
42 \author{%
43 Johannes Braams\and
44 David Carlisle\and
45 Alan Jeffrey\and
46 Leslie Lamport\and
47 Frank Mittelbach\and
48 Chris Rowley\and
49 Rainer Sch\"opf}
50
51 \begin{document}
52 \MaintainedByLaTeXTeam{latex}
53 \maketitle
54 \DocInput{\filename}
55 \end{document}
56 %</driver>
57 % \fi
58 %
59 % \changes{v1.0c}{1994/03/29}
60 % {Create file ltcntlen from parts of ltmiscen and ltherest.}
61 % \changes{v1.1a}{1994/05/19}
62 % {Extract file ltxref from ltcntlen.}
63 % \changes{v1.1b}{1994/05/21}{Use new warning commands}
64 % \changes{v1.1c}{1994/05/25}{Modify documentation}
65 % \changes{v1.1p}{2022/04/12}{Add starred variants for the ref commands}
66 %
67 % \section{Cross Referencing}
68 % The user writes |\label|\marg{foo} to define the following
69 % cross-references:
70 %
71 % |\ref|*\marg{foo}: value of most recently incremented referenceable
72 % counter. in the current environment. (Chapter, section,
73 % theorem, footnote and enumeration counters and other counters
74 % stepped with \cs{refstepcounter} are
75 % referenceable.)
76 %
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 `|}|'.
80 %
81 % Note: The scope of the |\label| command is delimited by environments,
82 % so\\
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.
86 %
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.
90 %
91 % Note: the starred versions |\ref*| and |\pageref*| are provided
92 % to align with the use of \pkg{hyperref}. Without \pkg{hyperref} (or some
93 % other package using the starred form) the star is simply ignored.
94 %
95 % Note: starting with 2023-06-01 |\label| stores also the current value
96 % of |\@currentlabelname| which should typically contain a (sanitized) title.
97 % (A reference command |\nameref| is provided by the \pkg{nameref} package.)
98 % |\label| also stores |\@currentHref| which if set should refer to a target name
99 % for links. This value is set and used by \pkg{hyperref}. Unlike the other values
100 % |\@currentHref| should be set globally. A fifth value |\@kernel@reserved@label@data|
101 % is reserved for the kernel to allow future extensions of the cross-reference
102 % system.
103 %
104 %
105 % \MaybeStop{}
106 %
107 % \subsection{Cross Referencing}
108 %
109 % \begin{oldcomments}
110 % \begin{macrocode}
111 %<*2ekernel>
112 \message{x-ref,}
113 % \end{macrocode}
114 %
115 % This is implemented as follows. A referenceable counter CNT is
116 % incremented by the command \refstepcounter{CNT} , which sets
117 % \@currentlabel == {CNT}{eval(\p@cnt\theCNT)}. The command
118 % \label{FOO} then writes the following on file \@auxout :
119 % \newlabel{FOO}{{eval(\@currentlabel)}{eval(\thepage)}%
120 % {eval(\@currentlabelname)}{eval(\@currentHref)}{eval(\@kernel@reserved@label@data)}}
121 %
122 % \ref{FOO} ==
123 % BEGIN
124 % if \r@foo undefined
125 % then @refundefined := G T
126 % ??
127 % Warning: 'reference foo on page ... undefined'
128 % else \@car \eval(\r@FOO)\@nil
129 % fi
130 % END
131 %
132 % \pageref{foo} =
133 % BEGIN
134 % if \r@foo undefined
135 % then @refundefined := G T
136 % ??
137 % Warning: 'reference foo on page ... undefined'
138 % else \@cdr \eval(\r@FOO)\@nil
139 % fi
140 % END
141 %
142 % \end{oldcomments}
143 %
144 % \DescribeMacro\labelformat
145 % A reference via |\ref| produces by default the data associated with
146 % the corresponding |\label| command (typically a number); any
147 % additional formatting has to be provided by the user. If, for
148 % example, references to equations are always to be typeset as
149 % ``equation (\textit{number})'', one has to code
150 % ``\verb=equation (\ref{=\textit{key}\verb=})=''. With |\labelformat|
151 % there is a possibility to generate such
152 % frills automatically without resorting to low-level coding.
153 % The command takes two arguments: the first is
154 % the name of a counter and the second is its representation when
155 % referenced. This means that for a successful usage, one has to know
156 % the counter name being used for generating the label, though in
157 % practice this should not pose a problem. The current counter number
158 % is picked up as an argument.
159 % Here are two examples:
160 %\begin{verbatim}
161 % \labelformat{section}{section~#1}
162 % \labelformat{equation}{equation~(#1)}}
163 %\end{verbatim}
164 %
165 % \DescribeMacro\Ref
166 % A side effect of using |\labelformat| is that, depending on the
167 % defined formatting, it becomes impossible to use |\ref| at the
168 % beginning of a sentence (if its replacement text starts with a
169 % lowercase letter). To overcome this problem we
170 % introduce the command |\Ref| that behave like
171 % |\ref| except that it uppercases the first token
172 % of the generated string.
173 %
174
175 % To make |\Ref| work properly the very first token in the second
176 % argument of |\labelformat| has to be a simple \textsc{ascii} or
177 % UTF-8 letter, otherwise the capitalization will fail or worse, you
178 % will end up with some error messages. If you actually need something
179 % more complicated in this place (e.g., an accented letter not written
180 % as a UTF-8 character) you have to explicitly surround it with
181 % braces, to identify the part that needs to be capitalized. For
182 % example, for figure references in the Hungarian language you might
183 % want to write |\labelformat{figure}{{\'a}bra~\thefigure}| or use
184 % |\labelformat{figure}{ábra~\thefigure}| which avoids the brace
185 % problem.
186 %
187 %
188 % \begin{macro}{\G@refundefinedtrue}
189 % \changes{v1.1i}{1995/12/07}{Renamed (back) from \cs{G@refundefined}}
190 % \begin{macro}{\@refundefined}
191 % \changes{v1.1h}{1995/10/24}{Switch for refundefined replaced}
192 % This does not save on name-space (since \cs{G@refundefinedfalse}
193 % was never needed) but it does make the implementation of such
194 % one-way switches more consistent. The extra macro to make the
195 % change is used since this change appears several times.
196 %
197 % \textbf{Note} despite its name, |\G@refundefinedtrue| does
198 % \emph{not} correspond to an |\if| command, and there is no
199 % matching \ldots|false|. It would be more natural to call the
200 % command |\G@refundefined| (as inspection of the change log will
201 % reveal) but unfortunately such a change would break any package
202 % that had defined a |\ref|-like command that mimicked the
203 % definition of |\ref|, calling |\G@refundefinedtrue|. Inspection
204 % of the \TeX\ archives revealed several such packages, and so this
205 % command has been named \ldots|true| so that the definition of
206 % |\ref| need not be changed, and the packages will work without
207 % change.
208 % \begin{macrocode}
209 % \newif\ifG@refundefined
210 % \def\G@refundefinedtrue{\global\let\ifG@refundefined\iftrue}
211 % \def\G@refundefinedfalse{\global\let\ifG@refundefined\iffalse}
212 \def\G@refundefinedtrue{%
213 \gdef\@refundefined{%
214 \@latex@warning@no@line{There were undefined references}}}
215 \let\@refundefined\relax
216 % \end{macrocode}
217 % \end{macro}
218 % \end{macro}
219 %
220 % \begin{macrocode}
221 % \end{macrocode}
222 % \begin{macro}{\ref}
223 % \changes{LaTeX2e}{1993/12/11}{Macro reimplemented}
224 % \changes{LaTeX2e}{2022/04/12}{Macro reimplemented with a starred version}
225 % \begin{macro}{\pageref}
226 % \changes{LaTeX2e}{1993/12/11}{Macro reimplemented}
227 % \changes{LaTeX2e}{2022/04/12}{Macro reimplemented with a starred version}
228 % \begin{macro}{\@setref}
229 % \changes{LaTeX2e}{1993/12/11}{Macro added}
230 % \changes{v1.1h}{1995/10/24}{Switch for refundefined renamed}
231 % \changes{v1.1i}{1995/12/07}{Switch for refundefined restored}
232 % Referencing a |\label|.
233 % RmS 91/10/25: added a few extra |\reset@font|,
234 % as suggested by Bernd Raichle
235 %
236 % RmS 92/08/14: made |\ref| and |\pageref| robust
237 %
238 % RmS 93/09/08: Added setting of refundefined switch.
239 % \begin{macrocode}
240 %</2ekernel>
241 %<*2ekernel|latexrelease>
242 %<latexrelease>\IncludeInRelease{2023/06/01}%
243 %<latexrelease> {\@kernel@sref}{store five arguments}%
244 \def\@setref#1#2#3{%
245 \ifx#1\relax
246 \protect\G@refundefinedtrue
247 \nfss@text{\reset@font\bfseries ??}%
248 \@latex@warning{Reference `#3' on page \thepage \space
249 undefined}%
250 \else
251 \expandafter#2#1\@empty\@empty\@empty\null
252 \fi}
253 % \end{macrocode}
254 % \begin{macrocode}
255 \long\def\@firstoffive#1#2#3#4#5{#1}
256 \long\def\@secondoffive#1#2#3#4#5{#2}
257 \def\@kernel@sref#1{\expandafter\@setref\csname r@#1\endcsname\@firstoffive{#1}}
258 \def\@kernel@spageref#1{\expandafter\@setref\csname r@#1\endcsname
259 \@secondoffive{#1}}
260 %<latexrelease>\EndIncludeInRelease
261 %<latexrelease>\IncludeInRelease{2022/06/01}%
262 %<latexrelease> {\@kernel@sref}{store five arguments}%
263 %<latexrelease>\def\@setref#1#2#3{%
264 %<latexrelease> \ifx#1\relax
265 %<latexrelease> \protect\G@refundefinedtrue
266 %<latexrelease> \nfss@text{\reset@font\bfseries ??}%
267 %<latexrelease> \@latex@warning{Reference `#3' on page \thepage \space
268 %<latexrelease> undefined}%
269 %<latexrelease> \else
270 %<latexrelease> \expandafter#2#1\null
271 %<latexrelease> \fi}
272 %<latexrelease>\let\@firstoffive\undefined
273 %<latexrelease>\let\@secondoffive\undefined
274 %<latexrelease>\def\@kernel@sref#1{\expandafter\@setref\csname r@#1\endcsname\@firstoftwo{#1}}
275 %<latexrelease>\def\@kernel@spageref#1{\expandafter\@setref\csname r@#1\endcsname
276 %<latexrelease> \@secondoftwo{#1}}
277 %<latexrelease>\EndIncludeInRelease
278 %<latexrelease>\IncludeInRelease{0000/00/00}%
279 %<latexrelease> {\@kernel@sref}{store five arguments}%
280 %<latexrelease>\def\@setref#1#2#3{%
281 %<latexrelease> \ifx#1\relax
282 %<latexrelease> \protect\G@refundefinedtrue
283 %<latexrelease> \nfss@text{\reset@font\bfseries ??}%
284 %<latexrelease> \@latex@warning{Reference `#3' on page \thepage \space
285 %<latexrelease> undefined}%
286 %<latexrelease> \else
287 %<latexrelease> \expandafter#2#1\null
288 %<latexrelease> \fi}
289 %<latexrelease>\let\@firstoffive\undefined
290 %<latexrelease>\let\@secondoffive\undefined
291 %<latexrelease>\let\@kernel@sref\undefined
292 %<latexrelease>\let\@kernel@spageref\undefined
293 %<latexrelease>\EndIncludeInRelease
294 % \end{macrocode}
295 %
296 %
297 %
298 %
299 % \begin{macrocode}
300 %<latexrelease>\IncludeInRelease{2022/06/01}%
301 %<latexrelease> {\ref}{Add starred reference commands}%
302 % \end{macrocode}
303 % \begin{macrocode}
304 \let\@kernel@ref\@kernel@sref
305 \let\@kernel@pageref\@kernel@spageref
306 \NewDocumentCommand\ref{s}
307 {\IfBooleanTF{#1}{\@kernel@sref}{\@kernel@ref}}
308 \NewDocumentCommand\pageref{s}
309 {\IfBooleanTF{#1}{\@kernel@spageref}{\@kernel@pageref}}
310 % \end{macrocode}
311 % As the commands are now protected we also need expandable versions for use
312 % in \cs{ifthenelse}:
313 % \begin{macrocode}
314 \def\@kernel@pageref@exp#1{\csname cs_if_exist:cTF\endcsname
315 {r@#1}{\csname tl_item:cn\endcsname{r@#1}{2}}{0}}
316 \def\@kernel@ref@exp#1{\csname cs_if_exist:cTF\endcsname
317 {r@#1}{\csname tl_item:cn\endcsname{r@#1}{1}}{0}}
318 % \end{macrocode}
319 % \begin{macrocode}
320 %</2ekernel|latexrelease>
321 %<latexrelease>\EndIncludeInRelease
322 %<latexrelease>\IncludeInRelease{0000/00/00}%
323 %<latexrelease> {\ref}{Add starred reference commands}%
324 %<latexrelease>\def\ref#1{\expandafter\@setref\csname r@#1\endcsname\@firstoftwo{#1}}
325 %<latexrelease>\def\pageref#1{\expandafter\@setref\csname r@#1\endcsname
326 %<latexrelease> \@secondoftwo{#1}}
327 %<latexrelease>
328 %<latexrelease>\EndIncludeInRelease
329 %<*2ekernel>
330 % \end{macrocode}
331 % \end{macro}
332 % \end{macro}
333 % \end{macro}
334 %
335 %
336 % \begin{macro}{\newlabel}
337 % \changes{v1.1b}{1994/05/21}{Use new warning commands}
338 % \changes{v1.1e}{1995/04/24}{Make \cs{@onlypreamble} for /1388.}
339 % \changes{v1.1e}{1995/06/19}
340 % {Use \cs{@newl@bel} to share code with \cs{bibcite}}
341 % \changes{v1.1g}{1995/07/14}
342 % {Remove \cs{@onlypreamble} so still defined in new \cs{enddocument}}
343 % This command will be written to the \texttt{.aux} file to
344 % pass label information from one run to another.
345 % \begin{macro}{\@newl@bel}
346 % The internal form of |\newlabel| and |\bibcite|. Note that this
347 % macro does it's work inside a group. That way the local
348 % assignments it needs to do don't clutter the save stack. This
349 % prevents large documents with many labels to run out of save
350 % stack.
351 % \changes{v1.1h}{1995/10/24}{Switch for multiplelabels replaced by
352 % inline code}
353 % \changes{v1.1k}{2001/02/16}{Added an extra grouplevel (PR3250), jlb}
354 % \begin{macrocode}
355 \def\@newl@bel#1#2#3{{%
356 \@ifundefined{#1@#2}%
357 \relax
358 {\gdef \@multiplelabels {%
359 \@latex@warning@no@line{There were multiply-defined labels}}%
360 \@latex@warning@no@line{Label `#2' multiply defined}}%
361 \global\@namedef{#1@#2}{#3}}}
362 % \end{macrocode}
363 %
364 % \begin{macrocode}
365 \def\newlabel{\@newl@bel r}
366 % \end{macrocode}
367 %
368 % \begin{macrocode}
369 \@onlypreamble\@newl@bel
370 % \end{macrocode}
371 % \end{macro}
372 % \end{macro}
373 %
374 % \begin{macro}{\if@multiplelabels}
375 % \changes{v1.1h}{1995/10/24}{Macro removed}
376 % \begin{macro}{\@multiplelabels}
377 % \changes{v1.1h}{1995/10/24}{Switch for multiplelabels removed}
378 % This is redefined to produce a warning if at least one label is
379 % defined more than once. It is executed by the |\enddocument|
380 % command.
381 % \begin{macrocode}
382 \let \@multiplelabels \relax
383 % \end{macrocode}
384 % \end{macro}
385 % \end{macro}
386 %
387 % \begin{macro}{\label}
388 % \changes{v1.1d}{1994/11/04}{(ASAJ)Added \cs{protected@write}}
389 % \changes{v1.1d}{1994/11/04}{(ASAJ)Added \cs{protected@edef}}
390 % \changes{v1.1q}{2023/05/12}{(UFi)extended to store five arguments}
391 % \changes{v1.1q}{2023/05/12}{(UFi)added a hook with argument}
392 % \changes{v1.1v}{2025/11/10}{(UFi)Disable commands while writing to the aux, gh1841}
393 % The commands |\label| and |\refstepcounter| have been changed to
394 % allow |\protect|'ed commands to work properly. For example,
395 %\begin{verbatim}
396 % \def\thechapter{\protect\foo{\arabic{chapter}.\roman{section}}}
397 %\end{verbatim}
398 % will cause a |\label{bar}| command to define |\ref{bar}| to expand
399 % to something like |\foo{4.d}|. Change made 20 Jul 88.
400 %
401 % \begin{macrocode}
402 %</2ekernel>
403 %<*2ekernel|latexrelease>
404 %<latexrelease>\IncludeInRelease{2026/06/01}%
405 %<latexrelease> {\label}{disable commands while writing}%
406 \def\label#1{\@bsphack
407 \begingroup
408 \UseHookWithArguments{label}{1}{#1}%
409 \protected@write\@auxout{%
410 % \end{macrocode}
411 % \cs{@currentlabelname} can contain a \cs{label} command and this can loop (gh1841).
412 % We disable the commands that are also disabled when writing \cs{addtocontents}.
413 % \begin{macrocode}
414 \let\label\@gobble@om
415 \let\index\@gobble@som
416 \let\glossary\@gobble@om}%
417 {\string\newlabel{#1}{{\@currentlabel}{\thepage}%
418 {\@currentlabelname}{\@currentHref}{\@kernel@reserved@label@data}}}%
419 \endgroup
420 \@esphack}
421 %<latexrelease>\EndIncludeInRelease
422 %<latexrelease>\IncludeInRelease{2023/06/01}%
423 %<latexrelease> {\label}{store five label arguments}%
424 \providecommand\@currentlabelname{}
425 \providecommand\@currentHref{}
426 \providecommand\@kernel@reserved@label@data{}
427 \NewHookWithArguments{label}{1}
428 %<latexrelease>\def\label#1{\@bsphack
429 %<latexrelease> \begingroup
430 %<latexrelease> \UseHookWithArguments{label}{1}{#1}%
431 %<latexrelease> \protected@write\@auxout{}%
432 %<latexrelease> {\string\newlabel{#1}{{\@currentlabel}{\thepage}%
433 %<latexrelease> {\@currentlabelname}{\@currentHref}{\@kernel@reserved@label@data}}}%
434 %<latexrelease> \endgroup
435 %<latexrelease> \@esphack}
436 %<latexrelease>\EndIncludeInRelease
437 % \end{macrocode}
438 %
439 % \begin{macrocode}
440 %<latexrelease>\IncludeInRelease{0000/00/00}%
441 %<latexrelease> {\label}{store five label arguments}%
442 %<latexrelease>\def\label#1{\@bsphack
443 %<latexrelease> \protected@write\@auxout{}%
444 %<latexrelease> {\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
445 %<latexrelease> \@esphack}
446 %<latexrelease>\EndIncludeInRelease
447 % \end{macrocode}
448 % \end{macro}
449 %
450 %
451 % \begin{macro}{\refstepcounter}
452 % Step the counter and allow for labels to point to its current value.
453 % \changes{v1.1n}{2020/05/05}{record the counter name in \cs{@currentcounter}}
454 % \changes{v1.1o}{2020/08/23}{add default definition of \cs{@currentcounter}}
455 % \changes{v1.1r}{2024/09/20}{set also \@currentHref}
456 % \changes{v1.1r}{2024/09/20}{provide a kernel copy \@kernel@refstepcounter}
457 % \changes{v1.1r}{2024/09/20}{add sockets}
458 % \changes{v1.1t}{2025/01/22}{Guard * from causing infinite loop}
459 % \begin{macrocode}
460 %<latexrelease>\IncludeInRelease{2024/11/01}%
461 %<latexrelease> {\refstepcounter}{set theHcounter representation}%
462 % \end{macrocode}
463 % \begin{socketdecl}{refstepcounter}
464 % This socket takes the whole code as argument.
465 % The default kernel plug is identity. By changing
466 % the plug hyperref can add a conditional and e.g.
467 % suppress the processing in a PDF context.
468 % \begin{macrocode}
469 \NewSocket{refstepcounter}{1}
470 % \end{macrocode}
471 % \end{socketdecl}
472 % \begin{socketdecl}{refstepcounter/target}
473 % This socket takes an argument, the counter name, and
474 % should at least set from it the target name |\@currentHref|.
475 % With hyperref it sets also the actual target.
476 % This is done with a socket so that the target name
477 % is not set more than once to (possibly) different names.
478 % The socket is not used in |\@kernel@refstepcounter|.
479 % The tagging code needs the target name so it is added after
480 % this socket.
481 % \begin{macrocode}
482 \NewSocket{refstepcounter/target}{1}
483 % \end{macrocode}
484 % \end{socketdecl}
485 % \begin{plugdecl}{kernel (refstepcounter/target)}
486 % \begin{macrocode}
487 \NewSocketPlug{refstepcounter/target}{kernel}
488 {\xdef\@currentHref {#1.\csname theH#1\endcsname}}%
489 \AssignSocketPlug{refstepcounter/target}{kernel}
490 % \end{macrocode}
491 % \end{plugdecl}
492 %
493 %
494 % \begin{macro}{\@currentcounter}
495 % A default definition for \cs{@currentcounter}.
496 % \begin{macrocode}
497 \def\@currentcounter{}
498 % \end{macrocode}
499 % \end{macro}
500 %
501 % \begin{macro}{\ltx@star@counter}
502 % \changes{v1.1t}{2025/01/22}{Macro added}
503 % Saved |*| for testing the argument of \cs{refstepcounter}. This was
504 % implemented as part of a hotfix which is why we have it in
505 % 2024/11 rollback.
506 % \begin{macrocode}
507 \def\ltx@star@counter{*}
508 % \end{macrocode}
509 % \end{macro}
510 %
511 %
512 % \begin{macrocode}
513 \def\refstepcounter#1{%
514 \UseSocket{refstepcounter}{%
515 \stepcounter{#1}%
516 \edef\reserved@a{#1}%
517 \ifx\reserved@a\ltx@star@counter\else
518 \let\@currentcounter\reserved@a
519 \fi
520 \protected@edef\@currentlabel
521 % \end{macrocode}
522 % By generating the second csname first the |\p@...| command can
523 % grab it as an argument which can be helpful for more complicated
524 % typesetting arrangements.
525 %
526 % The trick is to ensure that |\csname the#1\endcsname| is turned
527 % into a single token before |\p@...| is expanded further. This
528 % way, if the |\p@...| command is a macro with one argument it will
529 % receive |\the...|. With the original kernel code (i.e., without the
530 % |\expandafter|) it will instead pick up |\csname| which would be
531 % disastrous.
532 %
533 % Using |\expandafter| instead of braces delimiting the argument is
534 % better because, assuming that the |\p@...| command is not defined
535 % as a macro with one argument, the braces will stay and prohibit
536 % kerning that might otherwise happen between the glyphs generated
537 % by |\the...| and surrounding glyphs.
538 %
539 % \changes{v1.1l}{2019/08/22}{Allow \cs{p@...} to have an
540 % argument}
541 % \begin{macrocode}
542 {\csname p@#1\expandafter\endcsname\csname the#1\endcsname}%
543 \UseSocket{refstepcounter/target}{#1}%
544 \UseTaggingSocket{recordtarget}%
545 }%
546 }
547 % \end{macrocode}
548 % \begin{macro}{\@kernel@refstepcounter}
549 % This is a version of \cs{refstepcounter} which does not set and use
550 % targets.
551 % \begin{macrocode}
552 \def\@kernel@refstepcounter#1{%
553 \UseSocket{refstepcounter}{%
554 \stepcounter{#1}%
555 \edef\reserved@a{#1}%
556 \ifx\reserved@a\ltx@star@counter\else
557 \let\@currentcounter\reserved@a
558 \fi
559 \protected@edef\@currentlabel
560 {\csname p@#1\expandafter\endcsname\csname the#1\endcsname}}}%
561 % \end{macrocode}
562 % \end{macro}
563 % \begin{macrocode}
564 %<latexrelease>\EndIncludeInRelease
565 % \end{macrocode}
566 %
567 % \begin{macrocode}
568 %<latexrelease>\IncludeInRelease{2022/06/01}%
569 %<latexrelease> {\refstepcounter}{set theHcounter representation}%
570 %<latexrelease>\def\refstepcounter#1{\stepcounter{#1}%
571 %<latexrelease> \edef\@currentcounter{#1}%
572 %<latexrelease> \protected@edef\@currentlabel
573 %<latexrelease> {\csname p@#1\expandafter\endcsname\csname the#1\endcsname}%
574 %<latexrelease>}
575 %<latexrelease>\let\@kernel@refstepcounter\refstepcounter
576 %<latexrelease>\let\ltx@star@counter\@undefined
577 %<latexrelease>\EndIncludeInRelease
578 % \end{macrocode}
579 %
580 % \begin{macrocode}
581 %<latexrelease>\IncludeInRelease{2020/10/01}%
582 %<latexrelease> {\refstepcounter}{Add starred version}%
583 %<latexrelease>\def\@currentcounter{}
584 %<latexrelease>\def\refstepcounter#1{\stepcounter{#1}%
585 %<latexrelease> \edef\@currentcounter{#1}%
586 %<latexrelease> \protected@edef\@currentlabel
587 %<latexrelease> {\csname p@#1\expandafter\endcsname\csname the#1\endcsname}%
588 %<latexrelease>}
589 %<latexrelease>\EndIncludeInRelease
590 % \end{macrocode}
591 %
592 % \begin{macrocode}
593 %<latexrelease>\IncludeInRelease{2019/10/01}%
594 %<latexrelease> {\refstepcounter}{Support for \labelformat}%
595 %<latexrelease>\let\@currentcounter\@undefined
596 %<latexrelease>\def\refstepcounter#1{\stepcounter{#1}%
597 %<latexrelease> \protected@edef\@currentlabel
598 %<latexrelease> {\csname p@#1\expandafter\endcsname\csname the#1\endcsname}%
599 %<latexrelease>}
600 %<latexrelease>\EndIncludeInRelease
601 % \end{macrocode}
602 %
603 % \begin{macrocode}
604 %<latexrelease>\IncludeInRelease{0000/00/00}%
605 %<latexrelease> {\refstepcounter}{Original from 2.09}%
606 %<latexrelease>\def\refstepcounter#1{\stepcounter{#1}%
607 %<latexrelease> \protected@edef\@currentlabel
608 %<latexrelease> {\csname p@#1\endcsname\csname the#1\endcsname}%
609 %<latexrelease>}
610 %<latexrelease>\EndIncludeInRelease
611 % \end{macrocode}
612 %
613 % \end{macro}
614 %
615 %
616 %
617 % \begin{macrocode}
618 %<latexrelease>\IncludeInRelease{2022/06/01}%
619 %<latexrelease> {\Ref}{Add starred version}%
620 % \end{macrocode}
621 % \begin{macro}{\labelformat}
622 % A shortcut to set the |\p@...| macro for a counter. It will pick
623 % up the counter representation as an argument so that it can be
624 % specially formatted.
625 % \changes{v1.1l}{2019/08/22}{Commanded moved from \texttt{varioref.sty}}
626 % \begin{macrocode}
627 \def\labelformat#1{\expandafter\def\csname p@#1\endcsname##1}
628 % \end{macrocode}
629 % \end{macro}
630 %
631 % \begin{macro}{\Ref}
632 % This macro expands the result of |\ref| and then uppercases the
633 % first token. Only useful if the label was generated via
634 % |\labelformat| and contains some lower case letter at its start. If
635 % the label starts with a complicated construct (e.g., an accented
636 % letter that is provided via a command, e.g., \verb=\"a= instead
637 % of a UTF-8 character like ä) one has to surround everything that
638 % needs uppercasing in
639 % a brace group in the definition of |\labelformat|.\footnote{There
640 % is one problem with this approach: the braces are kept in a
641 % normal \texttt{\textbackslash ref} which might spoil kerning.
642 % Perhaps one day this needs redoing.}
643 % \changes{v1.1l}{2019/08/22}{Commanded moved from \texttt{varioref.sty}}
644 % \changes{v1.1p}{2022/04/12}{Macro reimplemented with a starred version}%
645 % \begin{macrocode}
646 % \changes{v1.1s}{2024/12/10}{Replace \cs{@tempa} with \cs{reserved@a} (gh/1579)}
647 \def\@kernel@Ref#1{\protected@edef\reserved@a{\@kernel@ref{#1}}%
648 \expandafter\MakeUppercase\reserved@a}
649 \def\@kernel@sRef#1{\protected@edef\reserved@a{\@kernel@sref{#1}}%
650 \expandafter\MakeUppercase\reserved@a}
651 \NewDocumentCommand\Ref{s}
652 {\IfBooleanTF{#1}{\@kernel@sRef}{\@kernel@Ref}}
653 % \end{macrocode}
654 % \end{macro}
655 %
656 %
657 %
658 % \changes{v1.1m}{2019/09/16}{Correctly revert the \cs{p@...} change}
659 % \begin{macrocode}
660 %</2ekernel|latexrelease>
661 %<latexrelease>\EndIncludeInRelease
662 %<latexrelease>\IncludeInRelease{2020/10/01}%
663 %<latexrelease> {\Ref}{Add starred version}%
664 %<latexrelease>\def\labelformat#1{\expandafter\def\csname p@#1\endcsname##1}
665 %<latexrelease>\DeclareRobustCommand\Ref[1]{\protected@edef\reserved@a{\ref{#1}}%
666 %<latexrelease> \expandafter\MakeUppercase\reserved@a}
667 %<latexrelease>\EndIncludeInRelease
668 % \end{macrocode}
669 %
670 % \begin{macrocode}
671 %<latexrelease>\IncludeInRelease{2019/10/01}%
672 %<latexrelease> {\Ref}{Add \labelformat and \Ref}%
673 %<latexrelease>\def\labelformat#1{\expandafter\def\csname p@#1\endcsname##1}
674 %<latexrelease>\DeclareRobustCommand\Ref[1]{\protected@edef\reserved@a{\ref{#1}}%
675 %<latexrelease> \expandafter\MakeUppercase\reserved@a}
676 %<latexrelease>\EndIncludeInRelease
677 % \end{macrocode}
678 %
679 % \begin{macrocode}
680 %<latexrelease>\IncludeInRelease{0000/00/00}%
681 %<latexrelease> {\Ref}{Add \labelformat and \Ref}%
682 %<latexrelease>
683 %<latexrelease>\let\labelformat\@undefined
684 %<latexrelease>\let\Ref\@undefined
685 %<latexrelease>
686 %<latexrelease>\EndIncludeInRelease
687 %<*2ekernel>
688 % \end{macrocode}
689 %
690 %
691 %
692 %
693 %
694 %
695 %
696 % \begin{macro}{\@currentlabel}
697 % Default for |\label| commands that come before any environment.
698 % \begin{macrocode}
699 \def\@currentlabel{}
700 % \end{macrocode}
701 % \end{macro}
702 %
703 % \begin{macrocode}
704 %</2ekernel>
705 % \end{macrocode}
706 %
707 %
708 % \Finale
709 %