% \iffalse meta-comment
%
% Copyright 1993-1995 the LaTeX3 project and any individual authors
% listed elsewhere in this file.  All rights reserved.
% 
% For further copyright information see the file legal.txt, and any
% other copyright notices in this file.
% 
% This file is part of the LaTeX2e system.
% ----------------------------------------
%   This system is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% 
%   For error reports concerning UNCHANGED versions of this file no more
%   than one year old, see bugs.txt.
% 
%   Please do not request updates from us directly.  Primary
%   distribution is through the CTAN archives.
% 
% 
% IMPORTANT COPYRIGHT NOTICE:
% 
% You are NOT ALLOWED to distribute this file alone.
% 
% You are allowed to distribute this file under the condition that it is
% distributed together with all the files listed in manifest.txt.
% 
% If you receive only some of these files from someone, complain!
% 
% Permission is granted to copy this file to another file with a clearly
% different name and to customize the declarations in that copy to serve
% the needs of your installation, provided that you comply with
% the conditions in the file legal.txt.
% 
% However, NO PERMISSION is granted to produce or to distribute a
% modified version of this file under its original name.
%  
% You are NOT ALLOWED to change this file.
% 
% 
% \fi
%
% \iffalse
%%% File: ltcounts
%
%<*driver>
% \fi
\ProvidesFile{ltcounts.dtx}
             [1995/05/20 v1.1c LaTeX Kernel (Counters)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltcounts.dtx}
\title{\filename}
\date{\filedate}
 \author{%
  Johannes Braams\and
  David Carlisle\and
  Alan Jeffrey\and
  Leslie Lamport\and
  Frank Mittelbach\and
  Chris Rowley\and
  Rainer Sch\"opf}

\begin{document}
\maketitle
 \DocInput{\filename}
\end{document}
%</driver>
% \fi
%
% \CheckSum{230}
%
% \changes{v1.0c}{1994/03/29}
%     {Create file from parts of ltmiscen and ltherest.}
% \changes{v1.1a}{1994/05/19}{Extracted file from ltcntlen.}
%
% \section{Counters and Lengths}
% Commands for defining and using counters. This file defines:
%
% \DescribeMacro{\newcounter}
% To define a new counter.
%
% \DescribeMacro{\setcounter} 
% To set the value of counters.
%
% \DescribeMacro{\addtotcounter}
% Increase the counter |#1| by the number |#2|.
%
% \DescribeMacro{\steptcounter}
% Increase a counter by one.
%
% \DescribeMacro{\refsteptcounter}
% Increase a counter by one, also setting the value used by |\label|.
%
%
% \DescribeMacro{\value}
% For accessing the value of the counter as a \TeX\ number (as opposed
% to |\the|\meta{counter} which expands to the \emph{printed}
% representation of \meta{counter})
%
% \DescribeMacro\arabic
% |\arabic|\marg{counter}: 1, 2, 3, \ldots
%
% \DescribeMacro\roman
% |\roman|\marg{counter}: i, ii, ii, \ldots
%
% \DescribeMacro\Roman
% |\Roman|\marg{counter}: I, II, II, \ldots
%
% \DescribeMacro\alph
% |\alph|\marg{counter}: a, b, c, \ldots
%
% \DescribeMacro\Alph
% |\Alph|\marg{counter}: A, B, C, \ldots
%
% \DescribeMacro\fnsymbol
% |\fnsymbol|\marg{counter}:  $*$, $\dagger$, $\ddagger$, \ldots
%
%
% \StopEventually{}
%
% \begin{oldcomments}
%    \begin{macrocode}
%<*2ekernel>
\message{env. counters,}
%    \end{macrocode}
%
% \subsection{Environment Counter Macros}
%
%  An environment  foo  has an associated counter defined by the
%  following control sequences:
%    \c@foo  :  Contains the counter's numerical value.
%                It is defined by  \newcount\foocounter.
%    \thefoo : Macro that expands to the printed value of \foocounter.
%              For example, if sections are numbered within chapters,
%              and section headings look like
%                  Section II-3.  The Nature of Counters
%              then \thesection might be defined by:
%                 \def\thesection
%                    {\@Roman{\c@chapter}-\@arabic{\c@section}}
%
%    \p@foo  : Macro that expands to a printed 'reference prefix' of
%              counter foo.  Any \ref to a value created by counter
%              foo will produce the expansion of \p@foo\thefoo  when the
%              the \label command is executed.
%
% NOTE: \thefoo and \p@foo MUST BE DEFINED IN SUCH A WAY THAT
% \edef\bar{\thefoo} OR \edef\bar{\p@foo}
% DEFINES \bar SO THAT IT WILL EVALUATE TO THE COUNTER VALUE AT THE TIME
% OF THE \edef, EVEN AFTER \foocounter AND ANY OTHER COUNTERS HAVE BEEN
% CHANGED.  THIS WILL HAPPEN IF YOU USE THE STANDARD COMMANDS \@arabic,
% \@Roman, ETC.
%
%    \cl@foo : List of counters to be reset when foo stepped.
%              Has format
%                  \@elt{countera}\@elt{counterb}\@elt{counterc}.
%
%  The following commands are used to define and modify counters.
%    \setcounter{FOO}{VAL}  : Globally sets \foocounter equal to VAL.
%    \addtocounter{FOO}{VAL}: Globally increments \foocounter by VAL.
%    \newcounter{NEWCTR}[OLDCTR] : 
%           Defines NEWCTR to be a counter, which is reset when counter
%           OLDCTR is stepped.  If NEWCTR already defined produces
%           'c@NEWCTR  already defined' error.
%    \value{CTR} : 
%           produces the value of counter CTR, for use with
%           a \setcounter or \addtocounter command.
%    \stepcounter{FOO}     : Globally increments counter \c@FOO
%                             and resets all subsidiary counters.
%    \refstepcounter{FOO}  : Same a \stepcounter, but it also defines
%                             \@currentreference so that a subsequent
%                             \label{bar} command causes \ref{bar} to
%                             generate the current value of counter foo.
%    \@definecounter{FOO}   : 
%          Initializes counter FOO (with empty reset list), defines
%          \p@FOO and \theFOO to be null. Also adds FOO to \cl@@ckpt --
%          the reset list of a dummy counter @ckpt used for taking
%          checkpoints.  
%    \@addtoreset{FOO}{BAR} : 
%          Adds counter FOO to the list of counters \cl@BAR to be reset
%          when counter bar is stepped.
%
%   NUMBERING MACROS:
%     \arabic{COUNTER} : 
%          Representation of COUNTER as arabic numerals.
%          Changed 29 Apr 86 to make it print the obvious thing
%          it COUNTER not positive.
%
%     \roman{COUNTER}  : Representation of COUNTER as lower-case
%                           Roman numerals.
%     \Roman{COUNTER}  : Representation of COUNTER as upper-case
%                           Roman numerals.
%     \alph{COUNTER}   : Representation of COUNTER as a lower-case
%                           letter: 1 = a, 2 = b, etc.
%     \Alph{COUNTER}   : Representation of COUNTER as an upper-case
%                           letter: 1 = A, 2 = B, etc.
%     \fnsymbol{COUNTER} : Representation of COUNTER as a footnote
%                           symbol: 1 = *, 2 = \dagger, etc.  
%
%  THE ABOVE ARE IMPLEMENTED IN TERMS OF THE FOLLOWING:
%     \@arabic\FOOcounter : 
%                    Representation of \FOOcounter as arabic numerals.
%     \@roman\FOOcounter  : 
%                    Representation of \FOOcounter as lower-case
%                           Roman numerals.
%     \@Roman\FOOcounter  : 
%                    Representation of \FOOcounter as upper-case
%                    Roman numerals.
%     \@alph\FOOcounter   : 
%                    Representation of \FOOcounter as a lower-case
%                    letter: 1 = a, 2 = b, etc.
%     \@Alph\FOOcounter   : 
%                    Representation of \FOOcounter as an upper-case
%                    letter: 1 = A, 2 = B, etc.
%     \@fnsymbol\FOOcounter : 
%                    Representation of \FOOcounter as a footnote
%                    symbol.  
%
% \end{oldcomments}
%
% \changes{v1.0d}{1994/04/09}
%     {\cs{@nocnterr} now has counter name argument}
% \changes{v1.0e}{1994/04/17}
%     {Use \cs{@nocounterr} instead of \cs{@nocnterr}}
%    \begin{macrocode}
\def\setcounter#1#2{\@ifundefined{c@#1}{\@nocounterr{#1}}%
{\global\csname c@#1\endcsname#2\relax}}
%    \end{macrocode}
%
% \changes{v1.0d}{1994/04/09}
%     {\cs{@nocnterr} now has counter name argument}
% \changes{v1.0e}{1994/04/17}
%     {Use \cs{@nocounterr} instead of \cs{@nocnterr}}
%    \begin{macrocode}
\def\addtocounter#1#2{\@ifundefined{c@#1}{\@nocounterr{#1}}%
{\global\advance\csname c@#1\endcsname #2\relax}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\newcounter#1{\expandafter\@ifdefinable \csname c@#1\endcsname
    {\@definecounter{#1}}\@ifnextchar[{\@newctr{#1}}{}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\value#1{\csname c@#1\endcsname}
%    \end{macrocode}
%
% \changes{v1.0d}{1994/04/09}
%     {\cs{@nocnterr} now has counter name argument}
% \changes{v1.0e}{1994/04/17}
%     {Use \cs{@nocounterr} instead of \cs{@nocnterr}}
%    \begin{macrocode}
\def\@newctr#1[#2]{%
  \@ifundefined{c@#2}{\@nocounterr{#2}}{\@addtoreset{#1}{#2}}}
%    \end{macrocode}
%
% \changes{LaTeX209}{1992/11/23}{Replaced \{\} in \cs{stepcounter} by
%       \cs{begingroup} \cs{endgroup} to avoid adding an empty ord in
%       math mode}
% \changes{v1.0d}{1994/04/09}
%     {Use \cs{addtocounter} to have name checked}
%    \begin{macrocode}
\def\stepcounter#1{\addtocounter{#1}\@ne
    \begingroup\let\@elt\@stpelt \csname cl@#1\endcsname\endgroup}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@stpelt#1{\global\csname c@#1\endcsname \z@}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\cl@@ckpt{\@elt{page}}
%    \end{macrocode}
%
%  \begin{macro}{\@definecounter}
%  \changes{v1.1b}{1995/05/20}{Streamlined code}
%  \changes{v1.1c}{1995/05/20}{And do it right}
%
%    \begin{macrocode}
\def\@definecounter#1{\expandafter\newcount\csname c@#1\endcsname
     \setcounter{#1}\z@
     \global\expandafter\let\csname cl@#1\endcsname\@empty
     \@addtoreset{#1}{@ckpt}%
     \global\expandafter\let\csname p@#1\endcsname\@empty
     \expandafter
     \gdef\csname the#1\expandafter\endcsname\expandafter
          {\expandafter\@arabic\csname c@#1\endcsname}}
%    \end{macrocode}
%  \end{macro}
%
%    \begin{macrocode}
\def\@addtoreset#1#2{\expandafter\@cons\csname cl@#2\endcsname {{#1}}}
%    \end{macrocode}
%
%
%
%  \begin{macro}{\arabic}
%  \begin{macro}{\roman}
%  \begin{macro}{\Roman}
%  \begin{macro}{\alph}
%  \begin{macro}{\Alph}
%  \begin{macro}{\fnsymbol}
%  \changes{v1.1b}{1995/05/20}{Steamlined code}
%    Numbering commands for definitions of |\theCOUNTER| and |\list|
%    arguments.
%
%    |\fnsymbol| produces the standard footnoting symbols: asterisk,
%    dagger, etc.
%
%    All commands can now be used in text and math mode.
%    
%    \begin{macrocode}
\def\arabic#1{\expandafter\@arabic\csname c@#1\endcsname}
\def\roman#1{\expandafter\@roman\csname c@#1\endcsname}
\def\Roman#1{\expandafter\@Roman\csname c@#1\endcsname}
\def\alph#1{\expandafter\@alph\csname c@#1\endcsname}
\def\Alph#1{\expandafter\@Alph\csname c@#1\endcsname}
\def\fnsymbol#1{\expandafter\@fnsymbol\csname c@#1\endcsname}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
% \changes{v1.0f}{1994/05/13}{Removed \cs{@ialph}}
% \changes{v1.0f}{1994/05/13}{Removed \cs{@Ialph}}
%
%  \begin{macro}{\@arabic}
%  \begin{macro}{\@roman}
%  \begin{macro}{\@Roman}
%  \begin{macro}{\@alph}
%  \begin{macro}{\@Alph}
%    Internal implementation of the above commands.
%    \begin{macrocode}
\def\@arabic#1{\number #1}  %% changed 29 Apr 86
\def\@roman#1{\romannumeral #1}
\def\@Roman#1{\expandafter\uppercase\expandafter{\romannumeral #1}}
\def\@alph#1{%
  \ifcase#1\or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or
   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
    y\or z\else\@ctrerr\fi}
\def\@Alph#1{%
  \ifcase#1\or A\or B\or C\or D\or E\or F\or G\or H\or I\or J\or
   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
    Y\or Z\else\@ctrerr\fi}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%    
%  \begin{macro}{\@fnsymbol}
%  \changes{v1.1b}{1995/05/20}{Allowing both text and math}
%    Typesetting old fashioned footnote symbols. This can be done both in
%    text or math mode now.
%    \begin{macrocode}
\def\@fnsymbol#1{\ensuremath{\ifcase#1\or *\or \dagger\or \ddagger\or
   \mathchar "278\or \mathchar "27B\or \|\or **\or \dagger\dagger
   \or \ddagger\ddagger \else\@ctrerr\fi}}
%    \end{macrocode}
%  \end{macro}
%
%
%    \begin{macrocode}
%</2ekernel>
%    \end{macrocode}
%
% \Finale
%
