
meillo@0: % chngcntr.sty
meillo@0: %
meillo@0: % Provides commands to change the resetting of counters.
meillo@0: % Instructions for use are at the end of this file.
meillo@0: %
meillo@0: % author: Peter Wilson (CUA)
meillo@0: %         (now at peter.r.wilson@boeing.com)
meillo@0: % Released under the Latex Project Public License
meillo@0: %
meillo@0: %
meillo@0: \NeedsTeXFormat{LaTeX2e}
meillo@0: \ProvidesPackage{chngcntr}[2001/03/30 v1.0 change counter resetting]
meillo@0: %
meillo@0: % This package uses David Carlisle's \@removefromreset command as
meillo@0: % specified in the remreset package available from CTAN as
meillo@0: % macros/latex/contrib/supported/carlisle/remreset.sty
meillo@0: % It is \provided here as a convenience to the user, and with
meillo@0: % David Carlisle's permission.
meillo@0: % START OF DAVID CARLISLE'S CODE
meillo@0: \providecommand{\@removefromreset}[2]{{%
meillo@0:   \expandafter\let\csname c@#1\endcsname\@removefromreset
meillo@0:   \def\@elt##1{%
meillo@0:     \expandafter\ifx\csname c@##1\endcsname\@removefromreset
meillo@0:     \else
meillo@0:       \noexpand\@elt{##1}%
meillo@0:     \fi}%
meillo@0:   \expandafter\xdef\csname cl@#2\endcsname{%
meillo@0:     \csname cl@#2\endcsname}}}
meillo@0: % END OF DAVID CARLISLE'S CODE
meillo@0: 
meillo@0: %%\@ifbothc@t@s{<package>}{<counter>}{<within>}{<code when both are counters>}
meillo@0: \newcommand{\@ifbothc@t@s}[4]{%
meillo@0:   \@ifundefined{c@#2}{% counter undefined
meillo@0:     \PackageError{#1}{#2 is not a counter}{\@eha}}%
meillo@0:   {% else counter is defined
meillo@0:     \@ifundefined{c@#3}{% within undefined
meillo@0:       \PackageError{#1}{#3 is not a counter}{\@eha}}%
meillo@0:     {% else both counter and within  are defined
meillo@0:      #4}}}
meillo@0: 
meillo@0: %%\counterwithout*{<counter>}{<within>}
meillo@0: \newcommand{\counterwithout}{\@ifstar{\c@t@soutstar}{\c@t@sout}}
meillo@0: \newcommand{\c@t@soutstar}[2]{%
meillo@0:   \@ifbothc@t@s{chngcntr}{#1}{#2}{\@removefromreset{#1}{#2}}}
meillo@0: \newcommand{\c@t@sout}[2]{%
meillo@0:   \@ifbothc@t@s{chngcntr}{#1}{#2}{\@removefromreset{#1}{#2}%
meillo@0:                         \@namedef{the#1}{\arabic{#1}}}}
meillo@0: 
meillo@0: 
meillo@0: %%\counterwithin*{<counter>}{<within>}
meillo@0: \newcommand{\counterwithin}{\@ifstar{\c@t@sinstar}{\c@t@sin}}
meillo@0: \newcommand{\c@t@sinstar}[2]{%
meillo@0:   \@ifbothc@t@s{chngcntr}{#1}{#2}{\@addtoreset{#1}{#2}}}
meillo@0: \newcommand{\c@t@sin}[2]{%
meillo@0:   \@ifbothc@t@s{chngcntr}{#1}{#2}{\@addtoreset{#1}{#2}%
meillo@0:                         \@namedef{the#1}{\@nameuse{the#2}.\arabic{#1}}}}
meillo@0: 
meillo@0: 
meillo@0: \endinput
meillo@0: 
meillo@0: %%%%%%%%%%%%%%%%%%
meillo@0: % USAGE
meillo@0: %%%%%%%%%%%%%%%%%%
meillo@0: %
meillo@0: %     In LaTeX, a new counter called, say `ctr', is created by the command
meillo@0: % \newcounter{ctr}[within]. If the optional within argument is given
meillo@0: % the the counter `ctr' is reset to zero each time the counter `within'
meillo@0: % changes. The command \thectr typesets the value of the counter ctr.
meillo@0: % This is automatically defined by \newcounter and is initialised
meillo@0: % to typeset arabic numerals.	
meillo@0: %
meillo@0: %%%%%%%%%%%%%%%%%
meillo@0: % \counterwithin
meillo@0: % \counterwithin*
meillo@0: %%%%%%%%%%%%%%%%%
meillo@0: %    It is sometimes desireable to change a counter that has been defined
meillo@0: % by \newcounter{ctr} to act as though it had been defined as 
meillo@0: % \newcounter{ctr}[within]. The package provides the command
meillo@0: % \counterwithin{ctr}{within} that accomplishes this. By default,
meillo@0: % it also redefines the \thectr command so that it typesets values
meillo@0: % in the style \thewithin.\arabic{ctr}. The starred version of the
meillo@0: % command suppresses the redefinition of \thectr 
meillo@0: % (e.g., \counterwithin*{ctr}{within}).
meillo@0: %
meillo@0: %%%%%%%%%%%%%%%%%%
meillo@0: % \counterwithout
meillo@0: % \counterwithout*
meillo@0: %%%%%%%%%%%%%%%%%%
meillo@0: %    Likewise, the command \counterwithout{ctr}{within} changes a
meillo@0: % counter that has been created by \newcounter{ctr}[within] to act
meillo@0: % as though it had been created by \newcounter{ctr}. By default it
meillo@0: % also redefines the \thectr command so that it just typesets an arabic
meillo@0: % numeral. The starred version of the command suppresses the redefinition
meillo@0: % of \thectr.
meillo@0: %
meillo@0: %    Any number of \counterwithin{ctr}{...} and \counterwithout{ctr}{...}
meillo@0: % commands can be issued for a given counter, ctr, if you wish to toggle
meillo@0: % between the two styles. The current value of ctr is unaffected by
meillo@0: % \counterwithin and \counterwithout. If you want to change the value
meillo@0: % after one of these commands, use \setcounter{ctr}{...}, and to change
meillo@0: % the typeseting style use \renewcommand{\thectr}{...}.
meillo@0: %
meillo@0: %
meillo@0: % Peter W.
meillo@0: % 2001/03/30
meillo@0: %
meillo@0: 




