updated
[latex2e.git] / base / ltcounts.dtx
blob8935968fdc16b505e8428b2eb35befc86d1856be
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
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 %    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.
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
30 % \iffalse
31 %%% From File: ltcounts.dtx
33 %<*driver>
34 % \fi
35 \ProvidesFile{ltcounts.dtx}
36              [1998/05/16 v1.1g 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}
51 \begin{document}
52 \maketitle
53  \DocInput{\filename}
54 \end{document}
55 %</driver>
56 % \fi
58 % \CheckSum{256}
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
98 % \DescribeMacro\alph
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
108 % \StopEventually{}
110 %    \begin{macrocode}
111 %<*2ekernel>
112 %    \end{macrocode}
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.
138 %              Has format
139 %                  |\@elt{countera}\@elt{counterb}\@elt{counterc}|.
140 % \end{tabular}
142 % \textbf{NOTE:}\\
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}
162 %        to |\cl@@ckpt| --
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}.
178 %    \begin{macrocode}
179 \def\setcounter#1#2{%
180   \@ifundefined{c@#1}%
181     {\@nocounterr{#1}}%
182     {\global\csname c@#1\endcsname#2\relax}}
183 %    \end{macrocode}
184 % \end{macro}
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}.
193 %    \begin{macrocode}
194 \def\addtocounter#1#2{%
195   \@ifundefined{c@#1}%
196     {\@nocounterr{#1}}%
197     {\global\advance\csname c@#1\endcsname #2\relax}}
198 %    \end{macrocode}
199 % \end{macro}
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 
205 % produces
206 %           `|c@newctr  already defined|' error.
207 %    \begin{macrocode}
208 \def\newcounter#1{%
209   \expandafter\@ifdefinable \csname c@#1\endcsname
210     {\@definecounter{#1}}%
211   \@ifnextchar[{\@newctr{#1}}{}}
212 %    \end{macrocode}
213 % \end{macro}
215 % \begin{macro}{\value}
216 %    |\value|\marg{ctr}
217 %           produces the value of counter \meta{ctr}, for use with
218 %           a |\setcounter| or |\addtocounter| command.
219 %    \begin{macrocode}
220 \def\value#1{\csname c@#1\endcsname}
221 %    \end{macrocode}
222 % \end{macro}
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}}
229 %    \begin{macrocode}
230 \def\@newctr#1[#2]{%
231   \@ifundefined{c@#2}{\@nocounterr{#2}}{\@addtoreset{#1}{#2}}}
232 %    \end{macrocode}
233 % \end{macro}
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
238 %       math mode}
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.
244 %    \begin{macrocode}
245 \def\stepcounter#1{%
246   \addtocounter{#1}\@ne
247   \begingroup
248     \let\@elt\@stpelt
249     \csname cl@#1\endcsname
250   \endgroup}
251 %    \end{macrocode}
252 % \end{macro}
254 % \begin{macro}{\@stpelt}
255 %    \begin{macrocode}
256 \def\@stpelt#1{\global\csname c@#1\endcsname \z@}
257 %    \end{macrocode}
258 % \end{macro}
260 % \begin{macro}{\cl@@ckpt}
261 %    \begin{macrocode}
262 \def\cl@@ckpt{\@elt{page}}
263 %    \end{macrocode}
264 % \end{macro}
266 %  \begin{macro}{\@definecounter}
267 %  \changes{v1.1b}{1995/05/20}{Streamlined code}
268 %  \changes{v1.1c}{1995/05/20}{And do it right}
270 %    \begin{macrocode}
271 \def\@definecounter#1{\expandafter\newcount\csname c@#1\endcsname
272      \setcounter{#1}\z@
273      \global\expandafter\let\csname cl@#1\endcsname\@empty
274      \@addtoreset{#1}{@ckpt}%
275      \global\expandafter\let\csname p@#1\endcsname\@empty
276      \expandafter
277      \gdef\csname the#1\expandafter\endcsname\expandafter
278           {\expandafter\@arabic\csname c@#1\endcsname}}
279 %    \end{macrocode}
280 %  \end{macro}
282 % \begin{macro}{\@addtoreset}
283 %    \begin{macrocode}
284 \def\@addtoreset#1#2{\expandafter\@cons\csname cl@#2\endcsname {{#1}}}
285 %    \end{macrocode}
286 %  \end{macro}
289 %    Numbering commands for definitions of |\theCOUNTER| and |\list|
290 %    arguments.
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.
298 %    \begin{macrocode}
299 \def\arabic#1{\expandafter\@arabic\csname c@#1\endcsname}
300 %    \end{macrocode}
301 % \end{macro}
303 %  \begin{macro}{\roman}
304 %  Representation of \meta{counter} as lower-case
305 %                           Roman numerals.
306 %    \begin{macrocode}
307 \def\roman#1{\expandafter\@roman\csname c@#1\endcsname}
308 %    \end{macrocode}
309 % \end{macro}
311 %  \begin{macro}{\Roman}
312 %  Representation of \meta{counter} as upper-case
313 %                           Roman numerals.
314 %    \begin{macrocode}
315 \def\Roman#1{\expandafter\@Roman\csname c@#1\endcsname}
316 %    \end{macrocode}
317 % \end{macro}
319 %  \begin{macro}{\alph}
320 %  Representation of \meta{counter} as a lower-case
321 %                           letter: 1 = a, 2 = b, etc.
322 %    \begin{macrocode}
323 \def\alph#1{\expandafter\@alph\csname c@#1\endcsname}
324 %    \end{macrocode}
325 % \end{macro}
327 %  \begin{macro}{\Alph}
328 %  Representation of \meta{counter} as an upper-case
329 %                           letter: 1 = A, 2 = B, etc.
330 %    \begin{macrocode}
331 \def\Alph#1{\expandafter\@Alph\csname c@#1\endcsname}
332 %    \end{macrocode}
333 % \end{macro}
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.      
342 %    \begin{macrocode}
343 \def\fnsymbol#1{\expandafter\@fnsymbol\csname c@#1\endcsname}
344 %    \end{macrocode}
345 %  \end{macro}
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.
353 %    \begin{macrocode}
354 \def\@arabic#1{\number #1}  %% changed 29 Apr 86
355 %    \end{macrocode}
356 %  \end{macro}
358 %  \begin{macro}{\@roman}
359 %   |\@roman\FOOcounter|
360 %    Representation of |\FOOcounter| as lower-case
361 %                           Roman numerals.
362 %    \begin{macrocode}
363 \def\@roman#1{\romannumeral #1}
364 %    \end{macrocode}
365 %  \end{macro}
367 %  \begin{macro}{\@Roman}
368 %     |\@Roman\FOOcounter|
369 %     Representation of |\FOOcounter| as upper-case
370 %                    Roman numerals.
372 % \changes{v1.1f}{1997/10/06}{Change \cs{@Roman} to be fully
373 %    expandable, so that the result is written properly to files.}
374 %    \begin{macrocode}
375 \def\@Roman#1{\expandafter\@slowromancap\romannumeral #1@}
376 %    \end{macrocode}
377 %  \end{macro}
379 %  \begin{macro}{\@slowromancap}
380 % \changes{v1.1f}{1997/10/06}{Macro added.}
381 %    Fully expandable macro to change a roman number to uppercase.
382 %    \begin{macrocode}
383 \def\@slowromancap#1{\ifx @#1% then terminate
384      \else
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
388      \fi
390 %    \end{macrocode}
391 %  \end{macro}
393 %  \begin{macro}{\@alph}
394 %     |\@alph\FOOcounter|
395 %     Representation of |\FOOcounter| as a lower-case
396 %                    letter: 1 = a, 2 = b, etc.
397 %    \begin{macrocode}
398 \def\@alph#1{%
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}
402 %    \end{macrocode}
403 %  \end{macro}
405 %  \begin{macro}{\@Alph}
406 %     |\@Alph\FOOcounter|
407 %       Representation of |\FOOcounter| as an upper-case
408 %                    letter: 1 = A, 2 = B, etc.
409 %    \begin{macrocode}
410 \def\@Alph#1{%
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}
414 %    \end{macrocode}
415 %  \end{macro}
416 %    
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.
421 %    \begin{macrocode}
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}}
425 %    \end{macrocode}
426 %  \end{macro}
429 %    \begin{macrocode}
430 %</2ekernel>
431 %    \end{macrocode}
433 % \Finale