docs/Development-Case

diff chngcntr.sty @ 0:662d647b9e94

initial commit
author meillo@marmaro.de
date Mon, 14 Jan 2008 06:44:49 +0100
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/chngcntr.sty	Mon Jan 14 06:44:49 2008 +0100
     1.3 @@ -0,0 +1,107 @@
     1.4 +% chngcntr.sty
     1.5 +%
     1.6 +% Provides commands to change the resetting of counters.
     1.7 +% Instructions for use are at the end of this file.
     1.8 +%
     1.9 +% author: Peter Wilson (CUA)
    1.10 +%         (now at peter.r.wilson@boeing.com)
    1.11 +% Released under the Latex Project Public License
    1.12 +%
    1.13 +%
    1.14 +\NeedsTeXFormat{LaTeX2e}
    1.15 +\ProvidesPackage{chngcntr}[2001/03/30 v1.0 change counter resetting]
    1.16 +%
    1.17 +% This package uses David Carlisle's \@removefromreset command as
    1.18 +% specified in the remreset package available from CTAN as
    1.19 +% macros/latex/contrib/supported/carlisle/remreset.sty
    1.20 +% It is \provided here as a convenience to the user, and with
    1.21 +% David Carlisle's permission.
    1.22 +% START OF DAVID CARLISLE'S CODE
    1.23 +\providecommand{\@removefromreset}[2]{{%
    1.24 +  \expandafter\let\csname c@#1\endcsname\@removefromreset
    1.25 +  \def\@elt##1{%
    1.26 +    \expandafter\ifx\csname c@##1\endcsname\@removefromreset
    1.27 +    \else
    1.28 +      \noexpand\@elt{##1}%
    1.29 +    \fi}%
    1.30 +  \expandafter\xdef\csname cl@#2\endcsname{%
    1.31 +    \csname cl@#2\endcsname}}}
    1.32 +% END OF DAVID CARLISLE'S CODE
    1.33 +
    1.34 +%%\@ifbothc@t@s{<package>}{<counter>}{<within>}{<code when both are counters>}
    1.35 +\newcommand{\@ifbothc@t@s}[4]{%
    1.36 +  \@ifundefined{c@#2}{% counter undefined
    1.37 +    \PackageError{#1}{#2 is not a counter}{\@eha}}%
    1.38 +  {% else counter is defined
    1.39 +    \@ifundefined{c@#3}{% within undefined
    1.40 +      \PackageError{#1}{#3 is not a counter}{\@eha}}%
    1.41 +    {% else both counter and within  are defined
    1.42 +     #4}}}
    1.43 +
    1.44 +%%\counterwithout*{<counter>}{<within>}
    1.45 +\newcommand{\counterwithout}{\@ifstar{\c@t@soutstar}{\c@t@sout}}
    1.46 +\newcommand{\c@t@soutstar}[2]{%
    1.47 +  \@ifbothc@t@s{chngcntr}{#1}{#2}{\@removefromreset{#1}{#2}}}
    1.48 +\newcommand{\c@t@sout}[2]{%
    1.49 +  \@ifbothc@t@s{chngcntr}{#1}{#2}{\@removefromreset{#1}{#2}%
    1.50 +                        \@namedef{the#1}{\arabic{#1}}}}
    1.51 +
    1.52 +
    1.53 +%%\counterwithin*{<counter>}{<within>}
    1.54 +\newcommand{\counterwithin}{\@ifstar{\c@t@sinstar}{\c@t@sin}}
    1.55 +\newcommand{\c@t@sinstar}[2]{%
    1.56 +  \@ifbothc@t@s{chngcntr}{#1}{#2}{\@addtoreset{#1}{#2}}}
    1.57 +\newcommand{\c@t@sin}[2]{%
    1.58 +  \@ifbothc@t@s{chngcntr}{#1}{#2}{\@addtoreset{#1}{#2}%
    1.59 +                        \@namedef{the#1}{\@nameuse{the#2}.\arabic{#1}}}}
    1.60 +
    1.61 +
    1.62 +\endinput
    1.63 +
    1.64 +%%%%%%%%%%%%%%%%%%
    1.65 +% USAGE
    1.66 +%%%%%%%%%%%%%%%%%%
    1.67 +%
    1.68 +%     In LaTeX, a new counter called, say `ctr', is created by the command
    1.69 +% \newcounter{ctr}[within]. If the optional within argument is given
    1.70 +% the the counter `ctr' is reset to zero each time the counter `within'
    1.71 +% changes. The command \thectr typesets the value of the counter ctr.
    1.72 +% This is automatically defined by \newcounter and is initialised
    1.73 +% to typeset arabic numerals.	
    1.74 +%
    1.75 +%%%%%%%%%%%%%%%%%
    1.76 +% \counterwithin
    1.77 +% \counterwithin*
    1.78 +%%%%%%%%%%%%%%%%%
    1.79 +%    It is sometimes desireable to change a counter that has been defined
    1.80 +% by \newcounter{ctr} to act as though it had been defined as 
    1.81 +% \newcounter{ctr}[within]. The package provides the command
    1.82 +% \counterwithin{ctr}{within} that accomplishes this. By default,
    1.83 +% it also redefines the \thectr command so that it typesets values
    1.84 +% in the style \thewithin.\arabic{ctr}. The starred version of the
    1.85 +% command suppresses the redefinition of \thectr 
    1.86 +% (e.g., \counterwithin*{ctr}{within}).
    1.87 +%
    1.88 +%%%%%%%%%%%%%%%%%%
    1.89 +% \counterwithout
    1.90 +% \counterwithout*
    1.91 +%%%%%%%%%%%%%%%%%%
    1.92 +%    Likewise, the command \counterwithout{ctr}{within} changes a
    1.93 +% counter that has been created by \newcounter{ctr}[within] to act
    1.94 +% as though it had been created by \newcounter{ctr}. By default it
    1.95 +% also redefines the \thectr command so that it just typesets an arabic
    1.96 +% numeral. The starred version of the command suppresses the redefinition
    1.97 +% of \thectr.
    1.98 +%
    1.99 +%    Any number of \counterwithin{ctr}{...} and \counterwithout{ctr}{...}
   1.100 +% commands can be issued for a given counter, ctr, if you wish to toggle
   1.101 +% between the two styles. The current value of ctr is unaffected by
   1.102 +% \counterwithin and \counterwithout. If you want to change the value
   1.103 +% after one of these commands, use \setcounter{ctr}{...}, and to change
   1.104 +% the typeseting style use \renewcommand{\thectr}{...}.
   1.105 +%
   1.106 +%
   1.107 +% Peter W.
   1.108 +% 2001/03/30
   1.109 +%
   1.110 +