% counter.cd % Anders G S Svensson % Source: counter.nw % $Revision: 1.7 $ % $Date: 1996/02/20 10:35:33 $ \edef\counter@newcount@{\noexpand\newcount} \def\newcounter#1{% \@ifundefined@{counter@ctn@#1}% {\@def@{counter@ctn@#1}{#1}\@csafter@\counter@newcount@{counter@ctr@#1}% \@def@{counter@ctr++@#1}{\counter@stepcounter@{#1}}% \@def@{the#1}{\@csafter@\counter@arabic@{counter@ctr@#1}}% \@cs@{counter@ctr@#1}=0 }% {}% \@ifnextchar@[% {\counter@numberwithin@{\@cs@{counter@ctn@#1}}}% {}} \def\stepcounter#1{\@cs@{counter@ctr++@\@cs@{counter@ctn@#1}}} \def\counter#1{\@cs@{counter@ctr@\@cs@{counter@ctn@#1}}} \def\arabic#1{\@csafter@\counter@arabic@{counter@ctr@\@cs@{counter@ctn@#1}}} \def\roman#1{\@csafter@\counter@roman@{counter@ctr@\@cs@{counter@ctn@#1}}} \def\Roman#1{\@csafter@\counter@Roman@{counter@ctr@\@cs@{counter@ctn@#1}}} \def\alph#1{\@csafter@\counter@alph@{counter@ctr@\@cs@{counter@ctn@#1}}} \def\Alph#1{\@csafter@\counter@Alph@{counter@ctr@\@cs@{counter@ctn@#1}}} \def\counter@arabic@{\number} \def\counter@roman@{\romannumeral} \def\counter@Roman@#1{\uppercase{\romannumeral#1}} \def\counter@alph@#1{{\count0=\number#1 \advance\count0 by 96 \char\count0}} \def\counter@Alph@#1{{\count0=\number#1 \advance\count0 by 64 \char\count0}} \def\numberwithin#1#2{% \newcounter{#1}[#2]} \def\numberwith#1#2{% \newcounter{#2}% \@def@{counter@ctn@#1}{\@cs@{counter@ctn@#2}}% \@def@{the#1}{\@cs@{the\@cs@{counter@ctn@#2}}}} \def\counter@numberwithin@#1[#2]{% \newcounter{#2}% \@def@{the#1}{\@cs@{the#2}.\@csafter@\counter@arabic@{counter@ctr@#1}}% \@ifundefined@{counter@container@#1}% {}% {\edef\@action@{\noexpand\counter@removeitem@ \expandafter\noexpand \csname counter@within@\@cs@{counter@container@#1}\endcsname {\@cs@{counter@ctn@#1}}% \@cs@{counter@within@\@cs@{counter@container@#1}}{}}% \@action@} \@def@{counter@container@#1}{\@cs@{counter@ctn@#2}}% \@ifundefined@{counter@within@\@cs@{counter@ctn@#2}}% {\@edef@{counter@within@\@cs@{counter@ctn@#2}}{{#1}}}% {\@edef@{counter@within@\@cs@{counter@ctn@#2}}{% \@cs@{counter@within@\@cs@{counter@ctn@#2}}{#1}}}} \def\counter@removeitem@#1#2#3{% \@ifempty@{#3}% {}% {\@strcmp@{#2}{#3}% {}% {\edef#2{#2{#3}}}% \counter@removeitem@{#1}{#2}}} \def\counter@stepcounter@#1{% \global\advance\@cs@{counter@ctr@#1} by 1 \@ifundefined@{counter@within@#1}% {}% {\expandafter\expandafter\expandafter \counter@initcounter@\csname counter@within@#1\endcsname{}}} \def\counter@initcounter@#1{% \@ifempty@{#1}% {}% {\global\@cs@{counter@ctr@#1}=0 \counter@initcounter@}}