1 % \iffalse meta-comment
3 % Copyright 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
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: ltcounts.dtx
35 \ProvidesFile{ltcounts.dtx}
36 [1998/05/16 v1.1g LaTeX Kernel (Counters)]
38 \documentclass{ltxdoc}
39 \GetFileInfo{ltcounts.dtx}
60 % \changes{v1.0c}{1994/03/29}
61 % {Create file from parts of ltmiscen and ltherest.}
62 % \changes{v1.1a}{1994/05/19}{Extracted file from ltcntlen.}
63 % \changes{v1.1d}{1996/04/23}{Documentation improvements}
65 % \section{Counters and Lengths}
66 % Commands for defining and using counters. This file defines:
68 % \DescribeMacro{\newcounter}
69 % To define a new counter.
71 % \DescribeMacro{\setcounter}
72 % To set the value of counters.
74 % \DescribeMacro{\addtocounter}
75 % Increase the counter |#1| by the number |#2|.
77 % \DescribeMacro{\stepcounter}
78 % Increase a counter by one.
80 % \DescribeMacro{\refstepcounter}
81 % Increase a counter by one, also setting the value used by |\label|.
84 % \DescribeMacro{\value}
85 % For accessing the value of the counter as a \TeX\ number (as opposed
86 % to |\the|\meta{counter} which expands to the \emph{printed}
87 % representation of \meta{counter})
89 % \DescribeMacro\arabic
90 % |\arabic|\marg{counter}: 1, 2, 3, \ldots
92 % \DescribeMacro\roman
93 % |\roman|\marg{counter}: i, ii, iii, \ldots
95 % \DescribeMacro\Roman
96 % |\Roman|\marg{counter}: I, II, III, \ldots
99 % |\alph|\marg{counter}: a, b, c, \ldots
101 % \DescribeMacro\Alph
102 % |\Alph|\marg{counter}: A, B, C, \ldots
104 % \DescribeMacro\fnsymbol
105 % |\fnsymbol|\marg{counter}: $*$, $\dagger$, $\ddagger$, \ldots
114 % \subsection{Environment Counter Macros}
116 % An environment foo has an associated counter defined by the
117 % following control sequences:
119 % \begin{tabular}{lp{.75\textwidth}}
120 % |\c@foo| & Contains the counter's numerical value.
121 % It is defined by |\newcount\foocounter|.\\
122 % |\thefoo| & Macro that expands to the printed value of |\foocounter|.
123 % For example, if sections are numbered within chapters,
124 % and section headings look like
126 % Section II-3. The Nature of Counters
128 % then |\thesection| might be defined by:\newline
129 % |\def\thesection|\newline\hspace*{2em}
130 % |{\@Roman{\c@chapter}-\@arabic{\c@section}}|\\
132 % |\p@foo| & Macro that expands to a printed `reference prefix' of
133 % counter foo. Any |\ref| to a value created by counter
134 % foo will produce the expansion of |\p@foo\thefoo| when
135 % the |\label| command is executed. See file \texttt{ltxref.dtx}
136 % for an extension of this mechanism.\\
137 % |\cl@foo| & List of counters to be reset when foo stepped.
139 % |\@elt{countera}\@elt{counterb}\@elt{counterc}|.
143 % |\thefoo| and |\p@foo| \emph{must} be defined in such a way that
144 % |\edef\bar{\thefoo}| or |\edef\bar{\p@foo}|
145 % defines |\bar| so that it will evaluate to the counter value at the
146 % time of the |\edef|, even after |\foocounter| and any other counters
147 % have been changed. This will happen if you use the standard commands
148 % |\@arabic|, |\@Roman|, etc.
151 % The following commands are used to define and modify counters.
153 % |\refstepcounter|\marg{foo}\\
154 % Same as |\stepcounter|, but it also defines
155 % |\@currentreference| so that a subsequent
156 % |\label|\marg{bar} command causes |\ref|\marg{bar} to
157 % generate the current value of counter \meta{foo}.
159 % |\@definecounter|\marg{foo}\\
160 % Initializes counter \marg{foo} (with empty reset list), defines
161 % |\p@foo| and |\thefoo| to be null. Also adds \meta{foo}
163 % the reset list of a dummy counter |@ckpt| used for taking
164 % checkpoints for the |\include| system.
166 % |\@addtoreset|\marg{foo}\marg{bar} :
167 % Adds counter \meta{foo} to the list of counters
168 % |\cl@bar| to be reset when counter \meta{bar} is stepped.
171 % \begin{macro}{\setcounter}
172 % \changes{v1.0d}{1994/04/09}
173 % {\cs{@nocnterr} now has counter name argument}
174 % \changes{v1.0e}{1994/04/17}
175 % {Use \cs{@nocounterr} instead of \cs{@nocnterr}}
176 % |\setcounter|\marg{foo}\marg{val} :
177 % Globally sets |\foocounter| equal to \meta{val}.
179 \def\setcounter#1#2{%
182 {\global\csname c@#1\endcsname#2\relax}}
186 % \begin{macro}{\addtocounter}
187 % \changes{v1.0d}{1994/04/09}
188 % {\cs{@nocnterr} now has counter name argument}
189 % \changes{v1.0e}{1994/04/17}
190 % {Use \cs{@nocounterr} instead of \cs{@nocnterr}}
191 % |\addtocounter|\marg{foo}\marg{val}
192 % Globally increments |\foocounter| by \meta{val}.
194 \def\addtocounter#1#2{%
197 {\global\advance\csname c@#1\endcsname #2\relax}}
201 % \begin{macro}{\newcounter}
202 % |\newcounter|\marg{newctr}\oarg{oldctr}
203 % Defines \meta{newctr} to be a counter, which is reset when counter
204 % \meta{oldctr} is stepped. If \meta{newctr} already defined
206 % `|c@newctr already defined|' error.
209 \expandafter\@ifdefinable \csname c@#1\endcsname
210 {\@definecounter{#1}}%
211 \@ifnextchar[{\@newctr{#1}}{}}
215 % \begin{macro}{\value}
217 % produces the value of counter \meta{ctr}, for use with
218 % a |\setcounter| or |\addtocounter| command.
220 \def\value#1{\csname c@#1\endcsname}
224 % \begin{macro}{\@newctr}
225 % \changes{v1.0d}{1994/04/09}
226 % {\cs{@nocnterr} now has counter name argument}
227 % \changes{v1.0e}{1994/04/17}
228 % {Use \cs{@nocounterr} instead of \cs{@nocnterr}}
231 \@ifundefined{c@#2}{\@nocounterr{#2}}{\@addtoreset{#1}{#2}}}
235 % \begin{macro}{\stepcounter}
236 % \changes{LaTeX209}{1992/11/23}{Replaced \{\} in \cs{stepcounter} by
237 % \cs{begingroup} \cs{endgroup} to avoid adding an empty ord in
239 % \changes{v1.0d}{1994/04/09}
240 % {Use \cs{addtocounter} to have name checked}
241 % |\stepcounter|{foo}
242 % Globally increments counter |\c@FOO|
243 % and resets all subsidiary counters.
246 \addtocounter{#1}\@ne
249 \csname cl@#1\endcsname
254 % \begin{macro}{\@stpelt}
256 \def\@stpelt#1{\global\csname c@#1\endcsname \z@}
260 % \begin{macro}{\cl@@ckpt}
262 \def\cl@@ckpt{\@elt{page}}
266 % \begin{macro}{\@definecounter}
267 % \changes{v1.1b}{1995/05/20}{Streamlined code}
268 % \changes{v1.1c}{1995/05/20}{And do it right}
271 \def\@definecounter#1{\expandafter\newcount\csname c@#1\endcsname
273 \global\expandafter\let\csname cl@#1\endcsname\@empty
274 \@addtoreset{#1}{@ckpt}%
275 \global\expandafter\let\csname p@#1\endcsname\@empty
277 \gdef\csname the#1\expandafter\endcsname\expandafter
278 {\expandafter\@arabic\csname c@#1\endcsname}}
282 % \begin{macro}{\@addtoreset}
284 \def\@addtoreset#1#2{\expandafter\@cons\csname cl@#2\endcsname {{#1}}}
289 % Numbering commands for definitions of |\theCOUNTER| and |\list|
292 % All commands can now be used in text and math mode.
294 % \begin{macro}{\arabic}
295 % Representation of\meta{counter} as arabic numerals.
296 % Changed 29 Apr 86 to make it print the obvious thing
297 % it COUNTER not positive.
299 \def\arabic#1{\expandafter\@arabic\csname c@#1\endcsname}
303 % \begin{macro}{\roman}
304 % Representation of \meta{counter} as lower-case
307 \def\roman#1{\expandafter\@roman\csname c@#1\endcsname}
311 % \begin{macro}{\Roman}
312 % Representation of \meta{counter} as upper-case
315 \def\Roman#1{\expandafter\@Roman\csname c@#1\endcsname}
319 % \begin{macro}{\alph}
320 % Representation of \meta{counter} as a lower-case
321 % letter: 1 = a, 2 = b, etc.
323 \def\alph#1{\expandafter\@alph\csname c@#1\endcsname}
327 % \begin{macro}{\Alph}
328 % Representation of \meta{counter} as an upper-case
329 % letter: 1 = A, 2 = B, etc.
331 \def\Alph#1{\expandafter\@Alph\csname c@#1\endcsname}
335 % \begin{macro}{\fnsymbol}
336 % \changes{v1.1b}{1995/05/20}{Streamlined code}
337 % \changes{v1.1e}{1997/03/21}
338 % {Use \cs{mathsection} and \cs{mathparagraph}. latex/2445}
340 % Representation of \meta{COUNTER} as a footnote
341 % symbol: 1 = $*$, 2 = $\dagger$, etc.
343 \def\fnsymbol#1{\expandafter\@fnsymbol\csname c@#1\endcsname}
347 % \changes{v1.0f}{1994/05/13}{Removed \cs{@ialph}}
348 % \changes{v1.0f}{1994/05/13}{Removed \cs{@Ialph}}
350 % \begin{macro}{\@arabic}
351 % |\@arabic\FOOcounter|
352 % Representation of |\FOOcounter| as arabic numerals.
354 \def\@arabic#1{\number #1} %% changed 29 Apr 86
358 % \begin{macro}{\@roman}
359 % |\@roman\FOOcounter|
360 % Representation of |\FOOcounter| as lower-case
363 \def\@roman#1{\romannumeral #1}
367 % \begin{macro}{\@Roman}
368 % |\@Roman\FOOcounter|
369 % Representation of |\FOOcounter| as upper-case
372 % \changes{v1.1f}{1997/10/06}{Change \cs{@Roman} to be fully
373 % expandable, so that the result is written properly to files.}
375 \def\@Roman#1{\expandafter\@slowromancap\romannumeral #1@}
379 % \begin{macro}{\@slowromancap}
380 % \changes{v1.1f}{1997/10/06}{Macro added.}
381 % Fully expandable macro to change a roman number to uppercase.
383 \def\@slowromancap#1{\ifx @#1% then terminate
385 \if i#1I\else\if v#1V\else\if x#1X\else\if l#1L\else\if
386 c#1C\else\if d#1D\else \if m#1M\else#1\fi\fi\fi\fi\fi\fi\fi
387 \expandafter\@slowromancap
393 % \begin{macro}{\@alph}
394 % |\@alph\FOOcounter|
395 % Representation of |\FOOcounter| as a lower-case
396 % letter: 1 = a, 2 = b, etc.
399 \ifcase#1\or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or
400 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
401 y\or z\else\@ctrerr\fi}
405 % \begin{macro}{\@Alph}
406 % |\@Alph\FOOcounter|
407 % Representation of |\FOOcounter| as an upper-case
408 % letter: 1 = A, 2 = B, etc.
411 \ifcase#1\or A\or B\or C\or D\or E\or F\or G\or H\or I\or J\or
412 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
413 Y\or Z\else\@ctrerr\fi}
417 % \begin{macro}{\@fnsymbol}
418 % \changes{v1.1b}{1995/05/20}{Allowing both text and math}
419 % Typesetting old fashioned footnote symbols.
420 % This can be done both in text or math mode now.
422 \def\@fnsymbol#1{\ensuremath{\ifcase#1\or *\or \dagger\or \ddagger\or
423 \mathsection\or \mathparagraph\or \|\or **\or \dagger\dagger
424 \or \ddagger\ddagger \else\@ctrerr\fi}}