docs/Development-Case
view chngcntr.sty @ 0:662d647b9e94
initial commit
author | meillo@marmaro.de |
---|---|
date | Mon, 14 Jan 2008 06:44:49 +0100 |
parents | |
children |
line source
1 % chngcntr.sty
2 %
3 % Provides commands to change the resetting of counters.
4 % Instructions for use are at the end of this file.
5 %
6 % author: Peter Wilson (CUA)
7 % (now at peter.r.wilson@boeing.com)
8 % Released under the Latex Project Public License
9 %
10 %
11 \NeedsTeXFormat{LaTeX2e}
12 \ProvidesPackage{chngcntr}[2001/03/30 v1.0 change counter resetting]
13 %
14 % This package uses David Carlisle's \@removefromreset command as
15 % specified in the remreset package available from CTAN as
16 % macros/latex/contrib/supported/carlisle/remreset.sty
17 % It is \provided here as a convenience to the user, and with
18 % David Carlisle's permission.
19 % START OF DAVID CARLISLE'S CODE
20 \providecommand{\@removefromreset}[2]{{%
21 \expandafter\let\csname c@#1\endcsname\@removefromreset
22 \def\@elt##1{%
23 \expandafter\ifx\csname c@##1\endcsname\@removefromreset
24 \else
25 \noexpand\@elt{##1}%
26 \fi}%
27 \expandafter\xdef\csname cl@#2\endcsname{%
28 \csname cl@#2\endcsname}}}
29 % END OF DAVID CARLISLE'S CODE
31 %%\@ifbothc@t@s{<package>}{<counter>}{<within>}{<code when both are counters>}
32 \newcommand{\@ifbothc@t@s}[4]{%
33 \@ifundefined{c@#2}{% counter undefined
34 \PackageError{#1}{#2 is not a counter}{\@eha}}%
35 {% else counter is defined
36 \@ifundefined{c@#3}{% within undefined
37 \PackageError{#1}{#3 is not a counter}{\@eha}}%
38 {% else both counter and within are defined
39 #4}}}
41 %%\counterwithout*{<counter>}{<within>}
42 \newcommand{\counterwithout}{\@ifstar{\c@t@soutstar}{\c@t@sout}}
43 \newcommand{\c@t@soutstar}[2]{%
44 \@ifbothc@t@s{chngcntr}{#1}{#2}{\@removefromreset{#1}{#2}}}
45 \newcommand{\c@t@sout}[2]{%
46 \@ifbothc@t@s{chngcntr}{#1}{#2}{\@removefromreset{#1}{#2}%
47 \@namedef{the#1}{\arabic{#1}}}}
50 %%\counterwithin*{<counter>}{<within>}
51 \newcommand{\counterwithin}{\@ifstar{\c@t@sinstar}{\c@t@sin}}
52 \newcommand{\c@t@sinstar}[2]{%
53 \@ifbothc@t@s{chngcntr}{#1}{#2}{\@addtoreset{#1}{#2}}}
54 \newcommand{\c@t@sin}[2]{%
55 \@ifbothc@t@s{chngcntr}{#1}{#2}{\@addtoreset{#1}{#2}%
56 \@namedef{the#1}{\@nameuse{the#2}.\arabic{#1}}}}
59 \endinput
61 %%%%%%%%%%%%%%%%%%
62 % USAGE
63 %%%%%%%%%%%%%%%%%%
64 %
65 % In LaTeX, a new counter called, say `ctr', is created by the command
66 % \newcounter{ctr}[within]. If the optional within argument is given
67 % the the counter `ctr' is reset to zero each time the counter `within'
68 % changes. The command \thectr typesets the value of the counter ctr.
69 % This is automatically defined by \newcounter and is initialised
70 % to typeset arabic numerals.
71 %
72 %%%%%%%%%%%%%%%%%
73 % \counterwithin
74 % \counterwithin*
75 %%%%%%%%%%%%%%%%%
76 % It is sometimes desireable to change a counter that has been defined
77 % by \newcounter{ctr} to act as though it had been defined as
78 % \newcounter{ctr}[within]. The package provides the command
79 % \counterwithin{ctr}{within} that accomplishes this. By default,
80 % it also redefines the \thectr command so that it typesets values
81 % in the style \thewithin.\arabic{ctr}. The starred version of the
82 % command suppresses the redefinition of \thectr
83 % (e.g., \counterwithin*{ctr}{within}).
84 %
85 %%%%%%%%%%%%%%%%%%
86 % \counterwithout
87 % \counterwithout*
88 %%%%%%%%%%%%%%%%%%
89 % Likewise, the command \counterwithout{ctr}{within} changes a
90 % counter that has been created by \newcounter{ctr}[within] to act
91 % as though it had been created by \newcounter{ctr}. By default it
92 % also redefines the \thectr command so that it just typesets an arabic
93 % numeral. The starred version of the command suppresses the redefinition
94 % of \thectr.
95 %
96 % Any number of \counterwithin{ctr}{...} and \counterwithout{ctr}{...}
97 % commands can be issued for a given counter, ctr, if you wish to toggle
98 % between the two styles. The current value of ctr is unaffected by
99 % \counterwithin and \counterwithout. If you want to change the value
100 % after one of these commands, use \setcounter{ctr}{...}, and to change
101 % the typeseting style use \renewcommand{\thectr}{...}.
102 %
103 %
104 % Peter W.
105 % 2001/03/30
106 %