Debian Codegraph @

texmf-dist/source/latex/base/ltcounts.dtx

raw
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: ltcounts.dtx
32 %
33 %<*driver>
34 % \fi
35 \ProvidesFile{ltcounts.dtx}
36 [2025/03/01 v1.2b LaTeX Kernel (Counters)]
37 % \iffalse
38 \documentclass{ltxdoc}
39 \GetFileInfo{ltcounts.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 % \providecommand\env[1]{\texttt{#1}}
60 %
61 % \changes{v1.0c}{1994/03/29}
62 % {Create file from parts of ltmiscen and ltherest.}
63 % \changes{v1.1a}{1994/05/19}{Extracted file from ltcntlen.}
64 % \changes{v1.1d}{1996/04/23}{Documentation improvements}
65 %
66 % \section{Counters and Lengths}
67 % Commands for defining and using counters.
68 % This file defines the following commands. In each case \marg{counter} may be
69 % |*| denoting the current counter as set by a previous |\refstepcounter|.
70 %
71 % \DescribeMacro{\newcounter}
72 % To define a new counter.
73 %
74 % \DescribeMacro{\setcounter}
75 % To set the value of counters.
76 %
77 % \DescribeMacro{\addtocounter}
78 % Increase the \marg{counter} |#1| by the number |#2|.
79 %
80 % \DescribeMacro{\stepcounter}
81 % Increase the \marg{counter} by one.
82 %
83 % \DescribeMacro{\refstepcounter}
84 % Increase the \marg{counter} by one, also setting the value used by |\label|.
85 %
86 %
87 % \DescribeMacro{\value}
88 % For accessing the value of the counter as a \TeX\ number (as opposed
89 % to |\the|\meta{counter} which expands to the \emph{printed}
90 % representation of \meta{counter})
91 %
92 % \DescribeMacro\arabic
93 % |\arabic|\marg{counter}: 1, 2, 3, \ldots
94 %
95 % \DescribeMacro\roman
96 % |\roman|\marg{counter}: i, ii, iii, \ldots
97 %
98 % \DescribeMacro\Roman
99 % |\Roman|\marg{counter}: I, II, III, \ldots
100 %
101 % \DescribeMacro\alph
102 % |\alph|\marg{counter}: a, b, c, \ldots
103 %
104 % \DescribeMacro\Alph
105 % |\Alph|\marg{counter}: A, B, C, \ldots
106 %
107 % \DescribeMacro\fnsymbol
108 % |\fnsymbol|\marg{counter}: $*$, $\dagger$, $\ddagger$, \ldots
109 %
110 %
111 % \DescribeMacro\counterwithin
112 % |\counterwithin|\oarg{format}\marg{counter}\marg{within-counter}:
113 % Resets \meta{counter} whenever
114 % \meta{within-counter} is stepped. Also
115 % redefines |\the|\meta{counter} command to produce
116 % |\the|\meta{within-counter}.\meta{format}\marg{counter} with \cs{arabic} as
117 % the default for \meta{format}.
118 % Star form omits redefining the print representation.
119 %
120 % The |*| alias for the current counter may not be used in either argument.
121 %
122 % \DescribeMacro\counterwithout
123 % |\counterwithout|\oarg{format}\marg{counter}\marg{within-counter}:
124 % Removes \meta{counter} from the reset list of \meta{within-counter}.
125 % Also
126 % redefines |\the|\meta{counter} command to produce
127 % \meta{format}\marg{counter} with \cs{arabic} as
128 % the default for \meta{format}.
129 % Star form omits redefining the print representation.
130 %
131 % The |*| alias for the current counter may not be used in either argument.
132 %
133 % \MaybeStop{}
134 %
135 % \begin{macrocode}
136 %<*2ekernel>
137 % \end{macrocode}
138 %
139 % \subsection{Document command and environment counter macros}
140 %
141 % An environment \texttt{foo} has an associated counter defined by the
142 % following control sequences:
143 % \begin{center}
144 % \begin{tabular}{lp{.75\textwidth}}
145 % |\c@foo| & Contains the counter's numerical value.
146 % It is defined by |\newcount\foocounter|.\\
147 % |\thefoo| & Macro that expands to the printed value of |\foocounter|.
148 % For example, if sections are numbered within chapters,
149 % and section headings look like
150 %
151 % Section II-3. The Nature of Counters
152 %
153 % then |\thesection| might be defined by:\newline
154 % |\def\thesection|\newline\hspace*{2em}
155 % |{\@Roman{\c@chapter}-\@arabic{\c@section}}|\\
156 %
157 % |\p@foo| & Macro that expands to a printed `reference prefix' of
158 % counter foo. Any |\ref| to a value created by counter
159 % foo will produce the expansion of |\p@foo\thefoo| when
160 % the |\label| command is executed. See file \texttt{ltxref.dtx}
161 % for an extension of this mechanism.\\
162 % |\cl@foo| & List of counters to be reset when foo stepped.
163 % Has format
164 % |\@elt{countera}\@elt{counterb}\@elt{counterc}|.
165 % \end{tabular}
166 % \end{center}
167 % For some environments the counter is named slightly differently,
168 % e.g., the counters associated with the \texttt{enumerate}
169 % environment have the names \texttt{enumi}, \texttt{enumii},
170 % \texttt{enumiii}, and \texttt{enumiv} depending on the nesting
171 % level.
172 %
173 % The same internal macros are defined for counters used by commands
174 % such as \cs{chapter}, \cs{section}, etc.
175 %
176 % \textbf{NOTE:}\\
177 % |\thefoo| and |\p@foo| \emph{must} be defined in such a way that
178 % |\edef\bar{\thefoo}| or |\edef\bar{\p@foo}|
179 % defines |\bar| so that it will evaluate to the counter value at the
180 % time of the |\edef|, even after |\foocounter| and any other counters
181 % have been changed. This will happen if you use the standard commands
182 % |\@arabic|, |\@Roman|, etc.
183 %
184 %
185 % The following commands are used to define and modify counters.
186 %
187 % |\refstepcounter|\marg{foo}\\
188 % Same as |\stepcounter|, but it also defines
189 % |\@currentlabel|, |\@currentHref| and |\@currentcounter|
190 % and so that a subsequent
191 % |\label|\marg{bar} command causes |\ref|\marg{bar} to
192 % generate the current value of counter \meta{foo}.
193 %
194 % |\@definecounter|\marg{foo}\\
195 % Initializes counter \marg{foo} (with empty reset list), defines
196 % |\p@foo| and |\thefoo| to be null and |\theHfoo| to be
197 % |\number\value{foo}|. Also adds \meta{foo}
198 % to |\cl@@ckpt| --
199 % the reset list of a dummy counter |@ckpt| used for taking
200 % checkpoints for the |\include| system.
201 %
202 % |\@addtoreset|\marg{foo}\marg{bar} :
203 % Adds counter \meta{foo} to the list of counters
204 % |\cl@bar| to be reset when counter \meta{bar} is stepped.
205 %
206 % |\@removefromreset|\marg{foo}\marg{bar} :
207 % Removes counter \meta{foo} to the list of counters
208 % |\cl@bar| to be reset when counter \meta{bar} is stepped.
209 %
210 %
211 % \begin{macro}{\setcounter}
212 % \changes{v1.0d}{1994/04/09}
213 % {\cs{@nocnterr} now has counter name argument}
214 % \changes{v1.0e}{1994/04/17}
215 % {Use \cs{@nocounterr} instead of \cs{@nocnterr}}
216 % |\setcounter|\marg{foo}\marg{val} :
217 % Globally sets |\foocounter| equal to \meta{val}.
218 % \begin{macrocode}
219 \def\setcounter#1#2{%
220 \@ifundefined{c@#1}%
221 {\@nocounterr{#1}}%
222 {\global\csname c@#1\endcsname#2\relax}}
223 % \end{macrocode}
224 % \end{macro}
225 %
226 % \begin{macro}{\addtocounter}
227 % \changes{v1.0d}{1994/04/09}
228 % {\cs{@nocnterr} now has counter name argument}
229 % \changes{v1.0e}{1994/04/17}
230 % {Use \cs{@nocounterr} instead of \cs{@nocnterr}}
231 % |\addtocounter|\marg{foo}\marg{val}
232 % Globally increments |\foocounter| by \meta{val}.
233 % \begin{macrocode}
234 \def\addtocounter#1#2{%
235 \@ifundefined{c@#1}%
236 {\@nocounterr{#1}}%
237 {\global\advance\csname c@#1\endcsname #2\relax}}
238 % \end{macrocode}
239 % \end{macro}
240 %
241 % \begin{macro}{\newcounter}
242 % |\newcounter|\marg{newctr}\oarg{oldctr}
243 % Defines \meta{newctr} to be a counter, which is reset when counter
244 % \meta{oldctr} is stepped. If \meta{newctr} already defined
245 % produces
246 % `|c@newctr already defined|' error.
247 % \begin{macrocode}
248 \def\newcounter#1{%
249 \expandafter\@ifdefinable \csname c@#1\endcsname
250 {\@definecounter{#1}}%
251 \@ifnextchar[{\@newctr{#1}}{}}
252 % \end{macrocode}
253 % \end{macro}
254 %
255 % \begin{macro}{\value}
256 % |\value|\marg{ctr}
257 % produces the value of counter \meta{ctr}, for use with
258 % a |\setcounter| or |\addtocounter| command.
259 % \begin{macrocode}
260 \def\value#1{\csname c@#1\endcsname}
261 % \end{macrocode}
262 % \end{macro}
263 %
264 % \begin{macro}{\c@*}
265 % \changes{v1.2a}{2025/01/22}{\cs{c@*} added (gh/1632)}
266 % Make the current counter available as a \LaTeX\ counter
267 % with name |*|, so |\alph*| returns the current
268 % counter as a letter, |\stepcounter{*}| increments the current
269 % counter, etc.
270 % \begin{macrocode}
271 \protected\expandafter
272 \def\csname c@*\endcsname{\value\@currentcounter}
273 % \end{macrocode}
274 % \end{macro}
275 %
276 %\begin{macro}{\@newctr}
277 % \changes{v1.0d}{1994/04/09}
278 % {\cs{@nocnterr} now has counter name argument}
279 % \changes{v1.0e}{1994/04/17}
280 % {Use \cs{@nocounterr} instead of \cs{@nocnterr}}
281 % \begin{macrocode}
282 \def\@newctr#1[#2]{%
283 \@ifundefined{c@#2}{\@nocounterr{#2}}{\@addtoreset{#1}{#2}}}
284 % \end{macrocode}
285 % \end{macro}
286 %
287 % \begin{macro}{\stepcounter}
288 % \changes{LaTeX209}{1992/11/23}{Replaced \{\} in \cs{stepcounter} by
289 % \cs{begingroup} \cs{endgroup} to avoid adding an empty ord in
290 % math mode}
291 % \changes{v1.0d}{1994/04/09}
292 % {Use \cs{addtocounter} to have name checked}
293 % |\stepcounter|{foo}
294 % Globally increments counter |\c@FOO|
295 % and resets all subsidiary counters.
296 % \begin{macrocode}
297 \def\stepcounter#1{%
298 \addtocounter{#1}\@ne
299 \begingroup
300 \let\@elt\@stpelt
301 \csname cl@#1\endcsname
302 \endgroup}
303 % \end{macrocode}
304 % \end{macro}
305 %
306 % \begin{macro}{\@stpelt}
307 % \changes{v1.1h}{2015/01/10}{Reset all within counters in one go (latexrelease)}
308 %
309 % Rather than resetting the ``within'' counter to zero we set it to
310 % $-1$ and then run |\stepcounter| that moves it to $0$ and also
311 % initiates resetting the next level down.
312 % \begin{macrocode}
313 %</2ekernel>
314 %<latexrelease>\IncludeInRelease{2015/01/01}{\@stpelt}
315 %<latexrelease> {Reset nested counters}%
316 %<*2ekernel|latexrelease>
317 \def\@stpelt#1{\global\csname c@#1\endcsname \m@ne\stepcounter{#1}}%
318 %<latexrelease>\EndIncludeInRelease
319 %</2ekernel|latexrelease>
320 %<latexrelease>\IncludeInRelease{0000/00/00}{\@stpelt}
321 %<latexrelease> {Reset nested counters}%%
322 %<latexrelease>\def\@stpelt#1{\global\csname c@#1\endcsname \z@}%
323 %<latexrelease>\EndIncludeInRelease
324 %<*2ekernel>
325 % \end{macrocode}
326 % \end{macro}
327 %
328 % \begin{macro}{\cl@@ckpt}
329 % \begin{macrocode}
330 \def\cl@@ckpt{\@elt{page}}
331 % \end{macrocode}
332 % \end{macro}
333 %
334 % \begin{macro}{\@definecounter}
335 % \changes{v1.1b}{1995/05/20}{Streamlined code}
336 % \changes{v1.1c}{1995/05/20}{And do it right}
337 % \changes{v1.1n}{2023/11/07}{Do not change \cs{the...} if already defined (gh/823)}
338 % \changes{v1.1o}{2024/09/20}{define theHfoo (used for internal links)}
339 % \changes{v1.1p}{2024/10/26}{Fully expand counter name in theHfoo commands (gh/1508)}
340 % \begin{macrocode}
341 %</2ekernel>
342 %<latexrelease>\IncludeInRelease{2024/11/01}{\@definecounter}
343 %<latexrelease> {provide theHfoo commands}%
344 %<*2ekernel|latexrelease>
345 \def\@definecounter#1{\expandafter\newcount\csname c@#1\endcsname
346 \setcounter{#1}\z@
347 \global\expandafter\let\csname cl@#1\endcsname\@empty
348 \@addtoreset{#1}{@ckpt}%
349 \global\expandafter\let\csname p@#1\endcsname\@empty
350 \expandafter\xdef\csname theH#1\endcsname{%
351 \noexpand\the\noexpand\value{#1}}%
352 % \end{macrocode}
353 % If \cs{the\#1} is undefined or \cs{relax} we define it with the
354 % standard definition for counters, otherwise we warn. This will
355 % catch, for example, that somebody defines a counter named
356 % ``index'' conflicting with the \env{theindex} environment.
357 % \begin{macrocode}
358 \expandafter
359 \ifx\csname the#1\endcsname\relax
360 \expandafter
361 \gdef\csname the#1\expandafter\endcsname\expandafter
362 {\expandafter\@arabic\csname c@#1\endcsname}%
363 \else
364 \@latex@warning{Command `\string\the#1' already
365 defined -- not changed}%
366 \fi}
367 %<latexrelease>\EndIncludeInRelease
368 %</2ekernel|latexrelease>
369 %<latexrelease>\IncludeInRelease{0000/00/00}{\@definecounter}
370 %<latexrelease> {provide theHfoo commands}%%
371 %<latexrelease>\def\@definecounter#1{\expandafter\newcount\csname c@#1\endcsname
372 %<latexrelease> \setcounter{#1}\z@
373 %<latexrelease> \global\expandafter\let\csname cl@#1\endcsname\@empty
374 %<latexrelease> \@addtoreset{#1}{@ckpt}%
375 %<latexrelease> \global\expandafter\let\csname p@#1\endcsname\@empty
376 %<latexrelease> \expandafter
377 %<latexrelease> \ifx\csname the#1\endcsname\relax
378 %<latexrelease> \expandafter
379 %<latexrelease> \gdef\csname the#1\expandafter\endcsname\expandafter
380 %<latexrelease> {\expandafter\@arabic\csname c@#1\endcsname}%
381 %<latexrelease> \else
382 %<latexrelease> \@latex@warning{Command `\string\the#1' already
383 %<latexrelease> defined -- not changed}%
384 %<latexrelease> \fi}
385 %<latexrelease>\EndIncludeInRelease
386 %<*2ekernel>
387 % \end{macrocode}
388 % \end{macro}
389 %
390 % \begin{macro}{\@addtoreset}
391 % \changes{v1.1o}{2024/09/20}{add the parent theHfoo if a counter is reset}
392 % \changes{v1.1p}{2024/10/26}{Fully expand counter name in theHfoo commands (gh/1508)}
393 % If a counter is reset when a parent counter changes it no longer has an unique value
394 % across the document. As |\theH<counter>| should be unique
395 % this representation is changed to include also the
396 % representation of the parent. This is not 100\% guaranteed to work
397 % but has been used this way by hyperref for many years without causing problems.
398 % \begin{macrocode}
399 %</2ekernel>
400 %<latexrelease>\IncludeInRelease{2024/11/01}{\@addtoreset}
401 %<latexrelease> {provide theHfoo commands}%
402 %<*2ekernel|latexrelease>
403 \def\@addtoreset#1#2{\expandafter\@cons\csname cl@#2\endcsname {{#1}}%
404 \expandafter\xdef\csname theH#1\endcsname{%
405 \expandafter\noexpand\csname theH#2\endcsname.%
406 \noexpand\the\noexpand\value{#1}}%
407 }
408 %<latexrelease>\EndIncludeInRelease
409 %</2ekernel|latexrelease>
410 %<latexrelease>\IncludeInRelease{0000/00/00}{\@addtoreset}
411 %<latexrelease> {provide theHfoo commands}%%
412 %<latexrelease>\def\@addtoreset#1#2{\expandafter\@cons\csname cl@#2\endcsname {{#1}}}
413 %<latexrelease>\EndIncludeInRelease
414 %<*2ekernel>
415 % \end{macrocode}
416 % \end{macro}
417 %
418 %
419 % \begin{macrocode}
420 %</2ekernel>
421 % \end{macrocode}
422 %
423 %
424 % \begin{macro}{\@removefromreset}
425 % \changes{v1.1k}{2018/03/08}{Interface added}
426 % \begin{macrocode}
427 %<latexrelease>\IncludeInRelease{2018-04-01}
428 %<latexrelease> {\@removefromreset}{Add interfaces}%
429 %<*2ekernel|latexrelease>
430 % \end{macrocode}
431 %
432 % \begin{macrocode}
433 \def\@removefromreset#1#2{%
434 % \end{macrocode}
435 % Even through this is internal and the programmer should know what
436 % he/she is doing we test here if counter |#2| is defined. If not,
437 % the execution would run into a tight loop.
438 % \begin{macrocode}
439 \@ifundefined{c@#2}\relax
440 {\begingroup
441 \expandafter\let\csname c@#1\endcsname\@removefromreset
442 \def\@elt##1{%
443 \expandafter\ifx\csname c@##1\endcsname\@removefromreset
444 \else
445 \noexpand\@elt{##1}%
446 \fi}%
447 \expandafter\xdef\csname cl@#2\endcsname
448 {\csname cl@#2\endcsname}%
449 \endgroup}}
450 % \end{macrocode}
451 % \end{macro}
452 %
453 % \begin{macro}{\@ifbothcounters}
454 % \changes{v1.1k}{2018/03/08}{Interface added}
455 % \changes{v1.2a}{2025/01/22}{Guard against star alias.}
456 % Test if arg |#1| and |#2| are counters and if so execute |#3|.
457 % \begin{macrocode}
458 \begingroup\catcode`\*=11 \lowercase{\endgroup
459 \def\@ifbothcounters#1#2#3{%
460 % \end{macrocode}
461 % \begin{macrocode}
462 \begingroup\let\c@*\@undefined
463 % \end{macrocode}
464 % \begin{macrocode}
465 \@ifundefined{c@#1}{\@nocounterr{#1}}%
466 {% else counter is defined
467 \@ifundefined{c@#2}{\@nocounterr{#2}}%
468 {% else both counter and within are defined
469 #3}}%
470 % \end{macrocode}
471 % \begin{macrocode}
472 \endgroup}}
473 % \end{macrocode}
474 % \end{macro}
475 %
476 % \begin{macrocode}
477 %</2ekernel|latexrelease>
478 %<latexrelease>\EndIncludeInRelease
479 %<latexrelease>\IncludeInRelease{0000-00-00}
480 %<latexrelease> {\@removefromreset}{Add interfaces}%
481 %<latexrelease>\let \@removefromreset \undefined
482 %<latexrelease>\let \@ifbothcounters \undefined
483 %<latexrelease>\EndIncludeInRelease
484 %<*2ekernel>
485 % \end{macrocode}
486 %
487 %
488 %
489 %
490 % \begin{macro}{\counterwithin}
491 % New implementation using xparse and supporting an optional
492 % format argument.
493 % \changes{v1.1m}{2021/07/08}{New implementation for
494 % \cs{counterwithin}}
495 % \changes{v1.2b}{2025/02/22}{\cs{counterwithin} needs to expand
496 % its arguments (gh/1675)}
497 % \begin{macrocode}
498 %</2ekernel>
499 %<*2ekernel|latexrelease>
500 %<latexrelease>\IncludeInRelease{2025/06/01}%
501 %<latexrelease> {\counterwithin}{counter within}%
502 % \end{macrocode}
503 %
504 % \begin{macrocode}
505 \NewDocumentCommand \counterwithin {sO{\arabic}mm}{%
506 \@ifbothcounters{#3}{#4}{%
507 \@addtoreset{#3}{#4}%
508 \IfBooleanF #1%
509 {\expandafter
510 \xdef\csname the#3\expandafter\endcsname
511 {\expandafter\noexpand\csname the#4\endcsname
512 .\unexpanded{#2}{#3}}}%
513 }%
514 }
515 % \end{macrocode}
516 %
517 % \changes{v1.1k}{2018/03/08}{Interface added}
518 % \begin{macrocode}
519 %</2ekernel|latexrelease>
520 %<latexrelease>\EndIncludeInRelease
521 %<latexrelease>\IncludeInRelease{2021/11/15}%
522 %<latexrelease> {\counterwithin}{counter within}%
523 %<latexrelease>
524 %<latexrelease>\NewDocumentCommand \counterwithin {sO{\arabic}mm}{%
525 %<latexrelease> \@ifbothcounters{#3}{#4}{%
526 %<latexrelease> \@addtoreset{#3}{#4}%
527 %<latexrelease> \IfBooleanF #1%
528 %<latexrelease> {\expandafter
529 %<latexrelease> \gdef\csname the#3\expandafter\endcsname
530 %<latexrelease> \expandafter
531 %<latexrelease> {\csname the#4\endcsname .#2{#3}}}%
532 %<latexrelease> }%
533 %<latexrelease>}
534 %<latexrelease>\EndIncludeInRelease
535 % \end{macrocode}
536 %
537 % \begin{macrocode}
538 %<latexrelease>\IncludeInRelease{2018-04-01}
539 %<latexrelease> {\counterwithin}{counter within}%
540 %<latexrelease>
541 %<latexrelease>\def\counterwithin{\@ifstar\counterwithin@s\counterwithin@x}
542 %<latexrelease>\def\counterwithin@s#1#2{%
543 %<latexrelease> \@ifbothcounters{#1}{#2}{\@addtoreset{#1}{#2}}}
544 % \end{macrocode}
545 %
546 % \changes{v1.1l}{2018/04/11}{Correct default (issue/38)}
547 % \begin{macrocode}
548 %<latexrelease>\def\counterwithin@x#1#2{%
549 %<latexrelease> \@ifbothcounters{#1}{#2}%
550 %<latexrelease> {\@addtoreset{#1}{#2}%
551 %<latexrelease> \expandafter
552 %<latexrelease> \gdef\csname the#1\expandafter\endcsname\expandafter
553 %<latexrelease> {\csname the#2\expandafter\endcsname\expandafter
554 %<latexrelease> .\expandafter
555 %<latexrelease> \@arabic\csname c@#1\endcsname}}}
556 %<latexrelease>
557 %<latexrelease>\EndIncludeInRelease
558 %<latexrelease>\IncludeInRelease{0000-00-00}
559 %<latexrelease> {\counterwithin}{counter within}%
560 %<latexrelease>\let \counterwithin \undefined
561 %<latexrelease>\let \counterwithin@s \undefined
562 %<latexrelease>\let \counterwithin@x \undefined
563 %<latexrelease>\EndIncludeInRelease
564 %<*2ekernel>
565 % \end{macrocode}
566 % \end{macro}
567 %
568 %
569 %
570 %
571 % \begin{macro}{\counterwithout}
572 % New implementation using xparse and supporting an optional
573 % format argument.
574 % \changes{v1.1m}{2021/07/08}{New implementation for
575 % \cs{counterwithout}}
576 % \changes{v1.2b}{2025/03/01}{\cs{counterwithout} needs to expand
577 % its arguments (gh/1675)}
578 % \begin{macrocode}
579 %</2ekernel>
580 %<*2ekernel|latexrelease>
581 %<latexrelease>\IncludeInRelease{2025/06/01}%
582 %<latexrelease> {\counterwithout}{counter without}%
583 % \end{macrocode}
584 %
585 % \begin{macrocode}
586 \NewDocumentCommand \counterwithout {sO{\arabic}mm}{%
587 \@ifbothcounters{#3}{#4}{%
588 \@removefromreset{#3}{#4}%
589 \IfBooleanF #1%
590 {\expandafter
591 \xdef\csname the#3\endcsname {\unexpanded{#2}{#3}}}%
592 }%
593 }
594 % \end{macrocode}
595 %
596 % \changes{v1.1k}{2018/03/08}{Interface added}
597 % \begin{macrocode}
598 %</2ekernel|latexrelease>
599 %<latexrelease>\EndIncludeInRelease
600 % \end{macrocode}
601 %
602 % \begin{macrocode}
603 %<latexrelease>\IncludeInRelease{2021/11/15}%
604 %<latexrelease> {\counterwithout}{counter without}%
605 %<latexrelease>\NewDocumentCommand \counterwithout {sO{\arabic}mm}{%
606 %<latexrelease> \@ifbothcounters{#3}{#4}{%
607 %<latexrelease> \@removefromreset{#3}{#4}%
608 %<latexrelease> \IfBooleanF #1%
609 %<latexrelease> {\expandafter
610 %<latexrelease> \gdef\csname the#3\endcsname {#2{#3}}}%
611 %<latexrelease> }%
612 %<latexrelease>}
613 %<latexrelease>\EndIncludeInRelease
614 % \end{macrocode}
615 %
616 % \begin{macrocode}
617 %<latexrelease>\IncludeInRelease{2018-04-01}
618 %<latexrelease> {\counterwithout}{counter without}%
619 %<latexrelease>
620 %<latexrelease>\def\counterwithout {\@ifstar\counterwithout@s\counterwithout@x}
621 %<latexrelease>\def\counterwithout@s#1#2{%
622 %<latexrelease> \@ifbothcounters{#1}{#2}{\@removefromreset{#1}{#2}}}
623 %<latexrelease>\def\counterwithout@x#1#2{%
624 %<latexrelease> \@ifbothcounters{#1}{#2}%
625 %<latexrelease> {\@removefromreset{#1}{#2}%
626 %<latexrelease> \expandafter
627 %<latexrelease> \gdef\csname the#1\expandafter\endcsname\expandafter
628 %<latexrelease> {\expandafter
629 %<latexrelease> \@arabic\csname c@#1\endcsname}}}
630 %<latexrelease>\EndIncludeInRelease
631 %<latexrelease>
632 %<latexrelease>\IncludeInRelease{0000-00-00}
633 %<latexrelease> {\counterwithout}{counter without}%
634 %<latexrelease>\let \counterwithout \undefined
635 %<latexrelease>\let \counterwithout@s \undefined
636 %<latexrelease>\let \counterwithout@x \undefined
637 %<latexrelease>\EndIncludeInRelease
638 %<*2ekernel>
639 % \end{macrocode}
640 % \end{macro}
641 %
642 %
643 %
644 %
645 % Numbering commands for definitions of |\theCOUNTER| and |\list|
646 % arguments.
647 %
648 % All commands can now be used in text and math mode.
649 %
650 % \begin{macro}{\arabic}
651 % Representation of\meta{counter} as arabic numerals.
652 % Changed 29 Apr 86 to make it print the obvious thing
653 % it COUNTER not positive.
654 % \begin{macrocode}
655 \def\arabic#1{\expandafter\@arabic\csname c@#1\endcsname}
656 % \end{macrocode}
657 % \end{macro}
658 %
659 % \begin{macro}{\roman}
660 % Representation of \meta{counter} as lower-case
661 % Roman numerals.
662 % \begin{macrocode}
663 \def\roman#1{\expandafter\@roman\csname c@#1\endcsname}
664 % \end{macrocode}
665 % \end{macro}
666 %
667 % \begin{macro}{\Roman}
668 % Representation of \meta{counter} as upper-case
669 % Roman numerals.
670 % \begin{macrocode}
671 \def\Roman#1{\expandafter\@Roman\csname c@#1\endcsname}
672 % \end{macrocode}
673 % \end{macro}
674 %
675 % \begin{macro}{\alph}
676 % Representation of \meta{counter} as a lower-case
677 % letter: 1 = a, 2 = b, etc.
678 % \begin{macrocode}
679 \def\alph#1{\expandafter\@alph\csname c@#1\endcsname}
680 % \end{macrocode}
681 % \end{macro}
682 %
683 % \begin{macro}{\Alph}
684 % Representation of \meta{counter} as an upper-case
685 % letter: 1 = A, 2 = B, etc.
686 % \begin{macrocode}
687 \def\Alph#1{\expandafter\@Alph\csname c@#1\endcsname}
688 % \end{macrocode}
689 % \end{macro}
690 %
691 % \begin{macro}{\fnsymbol}
692 % \changes{v1.1b}{1995/05/20}{Streamlined code}
693 % \changes{v1.1e}{1997/03/21}
694 % {Use \cs{mathsection} and \cs{mathparagraph}. latex/2445}
695 %
696 % Representation of \meta{COUNTER} as a footnote
697 % symbol: 1 = $*$, 2 = $\dagger$, etc.
698 % \begin{macrocode}
699 \def\fnsymbol#1{\expandafter\@fnsymbol\csname c@#1\endcsname}
700 % \end{macrocode}
701 % \end{macro}
702 %
703 % \changes{v1.0f}{1994/05/13}{Removed \cs{@ialph}}
704 % \changes{v1.0f}{1994/05/13}{Removed \cs{@Ialph}}
705 %
706 % \begin{macro}{\@arabic}
707 % |\@arabic\FOOcounter|
708 % Representation of |\FOOcounter| as arabic numerals.
709 % \begin{macrocode}
710 \def\@arabic#1{\number #1} %% changed 29 Apr 86
711 % \end{macrocode}
712 % \end{macro}
713 %
714 % \begin{macro}{\@roman}
715 % |\@roman\FOOcounter|
716 % Representation of |\FOOcounter| as lower-case
717 % Roman numerals.
718 % \begin{macrocode}
719 \def\@roman#1{\romannumeral #1}
720 % \end{macrocode}
721 % \end{macro}
722 %
723 % \begin{macro}{\@Roman}
724 % |\@Roman\FOOcounter|
725 % Representation of |\FOOcounter| as upper-case
726 % Roman numerals.
727 %
728 % \changes{v1.1f}{1997/10/06}{Change \cs{@Roman} to be fully
729 % expandable, so that the result is written properly to files.}
730 % \begin{macrocode}
731 \def\@Roman#1{\expandafter\@slowromancap\romannumeral #1@}
732 % \end{macrocode}
733 % \end{macro}
734 %
735 % \begin{macro}{\@slowromancap}
736 % \changes{v1.1f}{1997/10/06}{Macro added.}
737 % Fully expandable macro to change a roman number to uppercase.
738 % \begin{macrocode}
739 \def\@slowromancap#1{\ifx @#1% then terminate
740 \else
741 \if i#1I\else\if v#1V\else\if x#1X\else\if l#1L\else\if
742 c#1C\else\if d#1D\else \if m#1M\else#1\fi\fi\fi\fi\fi\fi\fi
743 \expandafter\@slowromancap
744 \fi
745 }
746 % \end{macrocode}
747 % \end{macro}
748 %
749 % \begin{macro}{\@alph}
750 % |\@alph\FOOcounter|
751 % Representation of |\FOOcounter| as a lower-case
752 % letter: 1 = a, 2 = b, etc.
753 % \begin{macrocode}
754 \def\@alph#1{%
755 \ifcase#1\or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or
756 k\or l\or m\or n\or o\or p\or q\or r\or s\or t\or u\or v\or w\or x\or
757 y\or z\else\@ctrerr\fi}
758 % \end{macrocode}
759 % \end{macro}
760 %
761 % \begin{macro}{\@Alph}
762 % |\@Alph\FOOcounter|
763 % Representation of |\FOOcounter| as an upper-case
764 % letter: 1 = A, 2 = B, etc.
765 % \begin{macrocode}
766 \def\@Alph#1{%
767 \ifcase#1\or A\or B\or C\or D\or E\or F\or G\or H\or I\or J\or
768 K\or L\or M\or N\or O\or P\or Q\or R\or S\or T\or U\or V\or W\or X\or
769 Y\or Z\else\@ctrerr\fi}
770 % \end{macrocode}
771 % \end{macro}
772 %
773 % \begin{macro}{\@fnsymbol}
774 % \changes{v1.1b}{1995/05/20}{Allowing both text and math}
775 % Typesetting old fashioned footnote symbols.
776 % This can be done both in text or math mode now.
777 %
778 % \changes{v1.1h}{2015/01/10}{Unse \cs{TextOrMath} (latexrelease)}
779 % This macro is another example of an ever recurring problem in
780 % \TeX: Determining if something is text-mode or math-mode. It is
781 % imperative for the decision between text and math to be delayed
782 % until the actual typesetting is done as the code in question may
783 % go through an |\edef| or |\write| where an |\ifmmode| test would
784 % be executed prematurely. Hence in the implementation below,
785 % |\@fnsymbol| is not robust in itself but the parts doing the
786 % actual typesetting are.
787 %
788 % In the case of |\@fnsymbol| we make use of the robust command
789 % |\TextOrMath| which takes two arguments and typesets the first if
790 % in text-mode and the second if in math-mode. Note that in order
791 % for this command to make the correct decision, it must insert a
792 % |\relax| token if run under regular \TeX, which ruins any kerning
793 % between the preceding characters and whatever awaits
794 % typesetting. If you use e\TeX\ as engine for \LaTeX\ (as
795 % recommended) this unfortunate side effect is not present.
796 % \begin{macrocode}
797 %</2ekernel>
798 %<latexrelease>\IncludeInRelease{2015/01/01}{\@fnsymbol}{Use \TextOrMath}%
799 %<*2ekernel|latexrelease>
800 \def\@fnsymbol#1{%
801 \ifcase#1\or \TextOrMath\textasteriskcentered *\or
802 \TextOrMath \textdagger \dagger\or
803 \TextOrMath \textdaggerdbl \ddagger \or
804 \TextOrMath \textsection \mathsection\or
805 \TextOrMath \textparagraph \mathparagraph\or
806 \TextOrMath \textbardbl \|\or
807 \TextOrMath {\textasteriskcentered\textasteriskcentered}{**}\or
808 \TextOrMath {\textdagger\textdagger}{\dagger\dagger}\or
809 \TextOrMath {\textdaggerdbl\textdaggerdbl}{\ddagger\ddagger}\else
810 \@ctrerr \fi
811 }%
812 %</2ekernel|latexrelease>
813 %<latexrelease>\EndIncludeInRelease
814 %<latexrelease>\IncludeInRelease{0000/00/00}{\@fnsymbol}{Use \TextOrMath}%
815 %<latexrelease>\def\@fnsymbol#1{\ensuremath{%
816 %<latexrelease> \ifcase#1\or *\or \dagger\or \ddagger\or \mathsection\or
817 %<latexrelease> \mathparagraph\or \|\or **\or \dagger\dagger
818 %<latexrelease> \or \ddagger\ddagger \else\@ctrerr\fi}}%
819 %<latexrelease>\EndIncludeInRelease
820 %<*2ekernel>
821 % \end{macrocode}
822 % \end{macro}
823 %
824 % \begin{macro}{\TextOrMath}
825 % \changes{v1.1h}{2015/01/11}{Add command to solve robustness
826 % issues (pr/3752) (latexrelease)}
827 % \changes{v1.1j}{2016/10/19}{Test directly for \cs{protected}}
828 % When using regular \TeX, we make this command robust so that it
829 % always selects the correct branch in an |\ifmmode| switch with
830 % the usual disadvantage of ruining kerning. For the application we
831 % use it for here that shouldn't matter. The alternative would be
832 % to mimic |\IeC| from \textsf{inputenc} but then it will have the
833 % disadvantage of choosing the wrong branch if appearing at the
834 % beginning of an alignment cell. However, users of e\TeX\ will be
835 % pleasantly surprised to get the best of both worlds and no bad
836 % side effects.
837 %
838 % First some code for checking if we are running e\TeX\ but making
839 % sure not to permanently turn |\protected| into |\relax|.
840 % \begin{macrocode}
841 %</2ekernel>
842 %<latexrelease>\IncludeInRelease{2015/01/01}{\TextOrMath}{\TextOrMath}%
843 %<*2ekernel|latexrelease>
844 \begingroup\expandafter\expandafter\expandafter\endgroup
845 \expandafter\ifx\csname protected\endcsname\relax
846 % \end{macrocode}
847 % In case of ordinary \TeX\ we define |\TextOrMath| as a robust
848 % command but make sure it always grabs its arguments. If we didn't do
849 % this it might very well gobble spaces in the input stream.
850 % \begin{macrocode}
851 \DeclareRobustCommand\TextOrMath{%
852 \ifmmode \expandafter\@secondoftwo
853 \else \expandafter\@firstoftwo \fi}
854 \protected@edef\TextOrMath#1#2{\TextOrMath{#1}{#2}}
855 \else
856 % \end{macrocode}
857 % For e\TeX\ the situation is similar. The robust macro is a hidden
858 % one so that we again avoid problems of gobbling spaces in the input.
859 % \begin{macrocode}
860 \protected\expandafter\def\csname TextOrMath\space\endcsname{%
861 \ifmmode \expandafter\@secondoftwo
862 \else \expandafter\@firstoftwo \fi}
863 \edef\TextOrMath#1#2{%
864 \expandafter\noexpand\csname TextOrMath\space\endcsname
865 {#1}{#2}}
866 \fi
867 %</2ekernel|latexrelease>
868 %<latexrelease>\EndIncludeInRelease
869 %<latexrelease>\IncludeInRelease{0000/00/00}{\TextOrMath}{\TextOrMath}%
870 %<latexrelease>\let\TextOrMath\@undefined
871 %<latexrelease>\EndIncludeInRelease
872 %<*2ekernel>
873 % \end{macrocode}
874 % \end{macro}
875 %
876 % \begin{macrocode}
877 %</2ekernel>
878 % \end{macrocode}
879 %
880 % \Finale
881 %