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