summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/chngcntr/chngcntr.sty
blob: 3af1325129b0688e30d5472aa1d1913cc0f4a12c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
% chngcntr.sty
%
% Provides commands to change the resetting of counters.
% Instructions for use are at the end of this file.
%
% Author: Peter Wilson, Herries Press
% Maintainer: Will Robertson (will dot robertson at latex-project dot org)
% Released under the Latex Project Public License
%
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{chngcntr}[2018/04/09 v1.1a change counter resetting]

% version 1.1 this package has been adoped into the format so does not 
% need to do anything in current latex releases.

\@ifundefined{counterwithout}{}{%
\PackageInfo{chngcntr}{\string\counterwithout\space already defined.\MessageBreak
Quitting chngcntr}%
\endinput
}


%
% This package uses David Carlisle's \@removefromreset command as
% specified in the remreset package available from CTAN as
% macros/latex/contrib/supported/carlisle/remreset.sty
% It is \provided here as a convenience to the user, and with
% David Carlisle's permission.
% START OF DAVID CARLISLE'S CODE
\providecommand{\@removefromreset}[2]{{%
  \expandafter\let\csname c@#1\endcsname\@removefromreset
  \def\@elt##1{%
    \expandafter\ifx\csname c@##1\endcsname\@removefromreset
    \else
      \noexpand\@elt{##1}%
    \fi}%
  \expandafter\xdef\csname cl@#2\endcsname{%
    \csname cl@#2\endcsname}}}
% END OF DAVID CARLISLE'S CODE

%%\@ifbothc@t@s{<package>}{<counter>}{<within>}{<code when both are counters>}
\newcommand{\@ifbothc@t@s}[4]{%
  \@ifundefined{c@#2}{% counter undefined
    \PackageError{#1}{#2 is not a counter}{\@eha}}%
  {% else counter is defined
    \@ifundefined{c@#3}{% within undefined
      \PackageError{#1}{#3 is not a counter}{\@eha}}%
    {% else both counter and within  are defined
     #4}}}

%%\counterwithout*{<counter>}{<within>}
\newcommand{\counterwithout}{\@ifstar{\c@t@soutstar}{\c@t@sout}}
\newcommand{\c@t@soutstar}[2]{%
  \@ifbothc@t@s{chngcntr}{#1}{#2}{\@removefromreset{#1}{#2}}}
\newcommand{\c@t@sout}[2]{%
  \@ifbothc@t@s{chngcntr}{#1}{#2}{\@removefromreset{#1}{#2}%
                        \@namedef{the#1}{\arabic{#1}}}}


%%\counterwithin*{<counter>}{<within>}
\newcommand{\counterwithin}{\@ifstar{\c@t@sinstar}{\c@t@sin}}
\newcommand{\c@t@sinstar}[2]{%
  \@ifbothc@t@s{chngcntr}{#1}{#2}{\@addtoreset{#1}{#2}}}
\newcommand{\c@t@sin}[2]{%
  \@ifbothc@t@s{chngcntr}{#1}{#2}{\@addtoreset{#1}{#2}%
                        \@namedef{the#1}{\@nameuse{the#2}.\arabic{#1}}}}


\endinput

%%%%%%%%%%%%%%%%%%
% USAGE
%%%%%%%%%%%%%%%%%%
%
%     In LaTeX, a new counter called, say `ctr', is created by the command
% \newcounter{ctr}[within]. If the optional within argument is given
% the the counter `ctr' is reset to zero each time the counter `within'
% changes. The command \thectr typesets the value of the counter ctr.
% This is automatically defined by \newcounter and is initialised
% to typeset arabic numerals.	
%
%%%%%%%%%%%%%%%%%
% \counterwithin
% \counterwithin*
%%%%%%%%%%%%%%%%%
%    It is sometimes desireable to change a counter that has been defined
% by \newcounter{ctr} to act as though it had been defined as 
% \newcounter{ctr}[within]. The package provides the command
% \counterwithin{ctr}{within} that accomplishes this. By default,
% it also redefines the \thectr command so that it typesets values
% in the style \thewithin.\arabic{ctr}. The starred version of the
% command suppresses the redefinition of \thectr 
% (e.g., \counterwithin*{ctr}{within}).
%
%%%%%%%%%%%%%%%%%%
% \counterwithout
% \counterwithout*
%%%%%%%%%%%%%%%%%%
%    Likewise, the command \counterwithout{ctr}{within} changes a
% counter that has been created by \newcounter{ctr}[within] to act
% as though it had been created by \newcounter{ctr}. By default it
% also redefines the \thectr command so that it just typesets an arabic
% numeral. The starred version of the command suppresses the redefinition
% of \thectr.
%
%    Any number of \counterwithin{ctr}{...} and \counterwithout{ctr}{...}
% commands can be issued for a given counter, ctr, if you wish to toggle
% between the two styles. The current value of ctr is unaffected by
% \counterwithin and \counterwithout. If you want to change the value
% after one of these commands, use \setcounter{ctr}{...}, and to change
% the typeseting style use \renewcommand{\thectr}{...}.
%
%
% Peter W.
% 2001/03/30
%
% Change History:
% v1.0a - New maintainer (Will Robertson)
%