summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/l3ctr2e/l3ctr2e.sty
blob: a9371bc938ed1ffc4cfbe40a91f147086cc87cf7 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
%% This is file `l3ctr2e.sty', generated from `l3ctr2e.tex' (key `package').
%% l3ctr2e LaTeX2e counters in LaTeX3 ways
%%
%% Copyright (C) 2012-2013 by Simon Sigurdhsson <sigurdhsson@gmail.com>
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Simon Sigurdhsson.
%%
%% This work consists of the file l3ctr2e.tex and the  derived file
%% l3ctr2e.sty.

\RequirePackage{expl3,l3keys2e,xparse}
\ProvidesExplClass{l3ctr2e}%
    {2013/05/25}{0.1d}{LaTeX2e counters in LaTeX3 ways}
\keys_define:nn{l3ctr2e}{
    replace .bool_set:N = \g__ctr_replace_latexe_bool,
    replace .default:n = true,
    replace .initial:n = false
}
\ProcessKeysPackageOptions{l3ctr2e}
\msg_new:nnn{l3ctr2e}{no-counter}{No~counter~`#1'~defined!}
\prg_new_conditional:Npnn\__ctr_exists:n#1{T}{
    \int_if_exist:cTF{c@#1}{
        \prg_return_true:
    }{
        \msg_error:nnn{l3ctr2e}{no-counter}{#1}
        \prg_return_false:
    }
}
\tl_new:N\g__ctr_children__ctr_global_tl
\cs_new:Npn\__ctr_define:n#1{
    \int_new:c{c@#1} % actually \newcount, incorrect! FIX!
    \ctr_gzero:n{#1}
    \tl_new:c{g__ctr_children_#1_tl}
    \cs_gset:cpn{cl@#1}{}
    \cs_gset:cpn{p@#1}{}
    \cs_gset:cpn{the#1}{\ctr_use_arabic:n{#1}}
}
\cs_new:Npn\__ctr_add_child:nn#1#2{
    \tl_gput_right:cn{g__ctr_children_#1_tl}{{#2}}
}
\cs_new:Npn\ctr_new:n#1{
    \__ctr_define:n{#1}
    \__ctr_add_child:nn{_ctr_global}{#1}
}
\cs_new:Npn\ctr_new:nn#1#2{
    \__ctr_define:n{#1}
    \__ctr_add_child:nn{#2}{#1}
}
\cs_new:Npn\ctr_gzero:n#1{
    \__ctr_exists:nT{#1}{\int_gzero:c{c@#1}}
}
\cs_new:Npn\ctr_gset:nn#1#2{
    \__ctr_exists:nT{#1}{\int_gset:cn{c@#1}{#2}}
}
\cs_new:Npn\ctr_gadd:nn#1#2{
    \__ctr_exists:nT{#1}{\int_gadd:cn{c@#1}{#2}}
}
\cs_new:Npn\ctr_gincr:n#1{
    \ctr_gadd:nn{#1}{\c_one}
    \tl_if_exist:cT{g__ctr_children_#1_tl}{
        \tl_map_inline:cn{g__ctr_children_#1_tl}{
            \ctr_gincr:n{##1} % To reset children of the child
            \ctr_gzero:n{##1}
        }
    }
}
\cs_new:Npn\ctr_ref_gincr:n#1{
    \ctr_gincr:n{#1}
    \cs_set:Npx\@currentlabel{
        \use:c{p@#1}
        \use:c{the#1}
    }
}
\cs_new:Npn\ctr_value:n#1{
    \use:c{c@#1}
}
\cs_new:Npn\ctr_use:n#1{
    \int_use:c{c@#1}
}
\cs_new:Npn\ctr_use_arabic:n#1{
    \int_to_arabic:n{\ctr_use:n{#1}}
}
\cs_new:Npn\ctr_use_alph:n#1{
    \int_to_alph:n{\ctr_use:n{#1}}
}
\cs_new:Npn\ctr_use_Alph:n#1{
    \int_to_Alph:n{\ctr_use:n{#1}}
}
\cs_new:Npn\ctr_use_binary:n#1{
    \int_to_binary:n{\ctr_use:n{#1}}
}
\cs_new:Npn\ctr_use_hex:n#1{
    \int_to_hexadecimal:n{\ctr_use:n{#1}}
}
\cs_new:Npn\ctr_use_octal:n#1{
    \int_to_octal:n{\ctr_use:n{#1}}
}
\cs_new:Npn\ctr_use_roman:n#1{
    \int_to_roman:n{\ctr_use:n{#1}}
}
\cs_new:Npn\ctr_use_Roman:n#1{
    \int_to_Roman:n{\ctr_use:n{#1}}
}
\cs_new:Npn\ctr_use_fn:n#1{
    \ensuremath{\ctr_use_custom:nn{#1}{
        *,           \dagger,       \ddagger,
        \mathsection,\mathparagraph,\|,
        **,          \dagger\dagger,\ddagger\ddagger
    }}
}
\cs_new:Npn\ctr_use_custom:nn#1#2{
    \clist_set:Nn\l_tmpa_clist{#2}
    \tl_clear:N\l_tmpa_tl
    \int_zero:N\l_tmpa_int
    \clist_map_inline:Nn\l_tmpa_clist{
            \int_incr:N\l_tmpa_int
            \tl_put_right:Nx\l_tmpa_tl{{\int_use:N\l_tmpa_int}{##1}}
    }
    \exp_args:Nnnx\int_to_symbols:nnn{\ctr_use:n{#1}}
        {\clist_count:N\l_tmpa_clist}
        {\tl_use:N\l_tmpa_tl}
}
\bool_if:NT\g__ctr_replace_latexe_bool{
    \RenewDocumentCommand\newcounter{mo}{
        \IfNoValueTF{#2}{\ctr_new:n{#1}}
                        {\ctr_new:nn{#1}{#2}}
    }
    \RenewDocumentCommand\stepcounter{m}{\ctr_gincr:n{#1}}
    \RenewDocumentCommand\refstepcounter{m}{\ctr_ref_gincr:n{#1}}
    \RenewDocumentCommand\addtocounter{mm}{\ctr_gadd:nn{#1}{#2}}
    \RenewDocumentCommand\setcounter{mm}{\ctr_gset:nn{#1}{#2}}
    \RenewDocumentCommand\value{m}{\ctr_value:n{#1}}
    \RenewDocumentCommand\arabic{m}{\ctr_use_arabic:n{#1}}
    \RenewDocumentCommand\alph{m}{\ctr_use_alph:n{#1}}
    \RenewDocumentCommand\Alph{m}{\ctr_use_Alph:n{#1}}
    \RenewDocumentCommand\roman{m}{\ctr_use_roman:n{#1}}
    \RenewDocumentCommand\Roman{m}{\ctr_use_Roman:n{#1}}
    \RenewDocumentCommand\fnsymbol{m}{\ctr_use_fn:n{#1}}
}
\endinput