summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/numberpt/numberpt.sty
blob: 5f56ac25f4aadbf17b3a322543a47855069a6ba9 (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
%%
%% This is file `numberpt.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% numberpt.dtx 
%% 
%% Copyright (C) 2019 Miguel V. S. Frasson (mvsfrasson@gmail.com)
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% 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.3c or later is part of all distributions of LaTeX
%% version 2008/05/04 or later.
%% 
%% This work has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is the author.
%% 
%% This work consists of the files numberpt.dtx and numberpt.ins
%% and the derived file numberpt.sty.
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{numberpt}[2019/07/12 v1.0 Counters as numbers in Portuguese]
\RequirePackage{expl3,xparse}
\ExplSyntaxOn
\bool_new:N \NumberPT_catorze
\bool_new:N \NumberPT_dezesseis
\newcommand{\NumberPTcatorze}{\bool_set_true:N  \NumberPT_catorze}
\newcommand{\NumberPTquatorze}{\bool_set_false:N  \NumberPT_catorze}
\DeclareOption{ catorze  }{ \NumberPTcatorze }
\DeclareOption{ quatorze }{ \NumberPTquatorze }
\ExecuteOptions{ catorze }
\newcommand{\NumberPTdezesseis}{\bool_set_true:N  \NumberPT_dezesseis}
\newcommand{\NumberPTdezasseis}{\bool_set_false:N  \NumberPT_dezesseis}
\DeclareOption{ dezasseis  }{ \NumberPTdezasseis}
\DeclareOption{ dezesseis  }{ \NumberPTdezesseis}
\ExecuteOptions{ dezesseis }
\ProcessOptions
\bool_new:N \NumberPT_capital
\bool_new:N \NumberPT_capitalfirst
\bool_new:N \NumberPT_capitale
\bool_new:N \NumberPT_uppercase
\cs_new:Nn \NumberPT_case:nn {
  \bool_if:NTF \NumberPT_capital {
    \uppercase { #1 }
  } {
    #1
  }
  \bool_if:NTF \NumberPT_uppercase {
    \uppercase { #2 }
  } {
    #2 }
  \bool_if:NT \NumberPT_capitalfirst {
    \bool_set_false:N \NumberPT_capital
  }
}
\cs_new:Nn \NumberPT_u:n {
  \if_case:w #1
    \NumberPT_case:nn {z}{ero}\or:
    \NumberPT_case:nn {u}{m}\or:
    \NumberPT_case:nn {d}{ois}\or:
    \NumberPT_case:nn {t}{r\^es}\or:
    \NumberPT_case:nn {q}{uatro}\or:
    \NumberPT_case:nn {c}{inco}\or:
    \NumberPT_case:nn {s}{eis}\or:
    \NumberPT_case:nn {s}{ete}\or:
    \NumberPT_case:nn {o}{ito}\or:
    \NumberPT_case:nn {n}{ove}%
  \fi:}
\cs_new:Nn \NumberPT_e_u:n {
  \int_compare:nNnT #1 > 0 {
    \space \bool_if:nTF \NumberPT_capitale {E}{e} \space \NumberPT_u:n #1
  }
}
\cs_new:Nn \NumberPT_du:nn {
  \if_case:w #1 % #1=0
    \NumberPT_u:n #2
  \or: % #1=1
    \if_case:w #2
      \NumberPT_case:nn {d}{ez}\or:
      \NumberPT_case:nn {o}{nze}\or:
      \NumberPT_case:nn {d}{oze}\or:
      \NumberPT_case:nn {t}{reze}\or:
      \bool_if:NTF \NumberPT_catorze {
        \NumberPT_case:nn {c}{atorze}
      } {
        \NumberPT_case:nn {q}{uatorze}
      }\or:
      \NumberPT_case:nn {q}{uinze}\or:
      \bool_if:NTF \NumberPT_dezesseis {
        \NumberPT_case:nn {d}{ezesseis}
      } {
        \NumberPT_case:nn {d}{ezasseis}
      }\or:
      \bool_if:NTF \NumberPT_dezesseis {
        \NumberPT_case:nn {d}{ezessete}
      } {
        \NumberPT_case:nn {d}{ezassete}
      }\or:
      \NumberPT_case:nn {d}{ezoito}\or:
      \bool_if:NTF \NumberPT_dezesseis {
        \NumberPT_case:nn {d}{ezenove}
      } {
        \NumberPT_case:nn {d}{ezanove}
      }\or:
    \fi:
  \or: % #1>1
    \NumberPT_case:nn {v}{inte} \NumberPT_e_u:n #2
  \or:
    \NumberPT_case:nn {t}{rinta} \NumberPT_e_u:n #2
  \or:
    \NumberPT_case:nn {q}{uarenta} \NumberPT_e_u:n #2
  \or:
    \NumberPT_case:nn {c}{inquenta} \NumberPT_e_u:n #2
  \or:
    \NumberPT_case:nn {s}{essenta} \NumberPT_e_u:n #2
  \or:
    \NumberPT_case:nn {s}{etenta} \NumberPT_e_u:n #2
  \or:
    \NumberPT_case:nn {o}{itenta} \NumberPT_e_u:n #2
  \or:
    \NumberPT_case:nn {n}{oventa} \NumberPT_e_u:n #2
  \fi:
}

\cs_new:Nn \NumberPT_e_du:nn {
  \int_compare:nNnT { #1 + #2 } > 0 {
    \space \bool_if:nTF \NumberPT_capitale {E}{e} \space \NumberPT_du:nn #1 #2
  }
}
\cs_new:Nn \NumberPT_cdu:nnn {%
  \if_case:w #1 % #1=0
    \NumberPT_du:nn #2 #3
  \or: % #1=1
    \int_compare:nNnTF { #2 + #3 } = 0  % "cem" if 00 or "cento e " + finish
      { \NumberPT_case:nn {c}{em} }
      { \NumberPT_case:nn {c}{ento} \NumberPT_e_du:nn #2 #3 }
  \or: % #1>1
    \NumberPT_case:nn {d}{uzentos}  \NumberPT_e_du:nn #2 #3
  \or:
    \NumberPT_case:nn {t}{rezentos} \NumberPT_e_du:nn #2 #3
  \or:
    \NumberPT_case:nn {q}{uatrocentos} \NumberPT_e_du:nn #2 #3
  \or:
    \NumberPT_case:nn {q}{uinhentos} \NumberPT_e_du:nn #2 #3
  \or:
    \NumberPT_case:nn {s}{eiscentos} \NumberPT_e_du:nn #2 #3
  \or:
    \NumberPT_case:nn {s}{etecentos} \NumberPT_e_du:nn #2 #3
  \or:
    \NumberPT_case:nn {o}{itocentos} \NumberPT_e_du:nn #2 #3
  \or:
    \NumberPT_case:nn {n}{ovecentos} \NumberPT_e_du:nn #2 #3
  \fi:
}
\cs_new:Nn \NumberPT_e_cdu:nnn {
  \int_compare:nNnF {#1 + #2 + #3} = 0 {
    \space
    \bool_if:nT { \int_compare_p:nNn #1 = 0 || \int_compare_p:nNn {#2 + #3} = 0 }
    {
      \bool_if:nTF \NumberPT_capitale {E}{e}
      \space
    }
    \NumberPT_cdu:nnn #1 #2 #3
  }
}
\cs_new:Nn \NumberPT_abcdef:nnnnnn {
  \int_compare:nNnTF {#1 + #2 + #3} = 0 %abc=000
  {
    \NumberPT_cdu:nnn #4 #5 #6
  }
  % else
  {
    % avoid "um mil", using just "mil"
    \int_compare:nNnF {100 * #1 + 10 * #2 + #3} = 1 {
      \NumberPT_cdu:nnn #1 #2 #3
      \space
    }
    \NumberPT_case:nn {m}{il}
    \NumberPT_e_cdu:nnn #4 #5 #6
  }
}
\cs_generate_variant:Nn \NumberPT_abcdef:nnnnnn {xxxxxx}
\int_new:N \NumberPT_digit_u
\int_new:N \NumberPT_digit_d
\int_new:N \NumberPT_digit_c
\int_new:N \NumberPT_digit_um
\int_new:N \NumberPT_digit_dm
\int_new:N \NumberPT_digit_cm

\cs_new:Nn \NumberPT_decompose:n {
  \int_set:Nn \l_tmpa_int { #1 }
  \int_set:Nn \NumberPT_digit_u { \int_mod:nn { \l_tmpa_int } { 10 } }
  \int_set:Nn \l_tmpa_int { ( \l_tmpa_int - \NumberPT_digit_u ) / 10 }
  \int_set:Nn \NumberPT_digit_d { \int_mod:nn { \l_tmpa_int } { 10 } }
  \int_set:Nn \l_tmpa_int { ( \l_tmpa_int - \NumberPT_digit_d ) / 10 }
  \int_set:Nn \NumberPT_digit_c { \int_mod:nn { \l_tmpa_int } { 10 } }
  \int_set:Nn \l_tmpa_int { ( \l_tmpa_int - \NumberPT_digit_c ) / 10 }
  \int_set:Nn \NumberPT_digit_um { \int_mod:nn { \l_tmpa_int } { 10 } }
  \int_set:Nn \l_tmpa_int { ( \l_tmpa_int - \NumberPT_digit_um ) / 10 }
  \int_set:Nn \NumberPT_digit_dm { \int_mod:nn { \l_tmpa_int } { 10 } }
  \int_set:Nn \l_tmpa_int { ( \l_tmpa_int - \NumberPT_digit_dm ) / 10 }
  \int_set:Nn \NumberPT_digit_cm { \int_mod:nn { \l_tmpa_int } { 10 } }
}
\msg_new:nnn
{ numberpt } { counter-out-of-range } {Counter~`#1'~out~of~range~0~...~999999}

\cs_new:Nn \NumberPT_print_counter:n {
  \int_set:Nn \l_tmpa_int { \value{#1} }
  \bool_if:nTF {
    \int_compare_p:n { \l_tmpa_int >= 0 } &&
    \int_compare_p:n { \l_tmpa_int < 1000000 }
  }
  {
    \NumberPT_decompose:n { \l_tmpa_int }
    \NumberPT_abcdef:xxxxxx
    { \int_use:N \NumberPT_digit_cm }
    { \int_use:N \NumberPT_digit_dm }
    { \int_use:N \NumberPT_digit_um }
    { \int_use:N \NumberPT_digit_c  }
    { \int_use:N \NumberPT_digit_d  }
    { \int_use:N \NumberPT_digit_u  }
  }
  {
    \msg_error:nnn { numberpt } { counter-out-of-range } {#1}
    \arabic{#1}
  }
}
\NewDocumentCommand{\numberpt}{m}{
  \bool_set_false:N \NumberPT_capital
  \bool_set_false:N \NumberPT_capitale
  \bool_set_false:N \NumberPT_uppercase
  \NumberPT_print_counter:n { #1 }
}

\NewDocumentCommand{\NumberPt}{s m}{
  \bool_set_true:N \NumberPT_capital
  \bool_set:Nn \NumberPT_capitale {! #1}
  \bool_set_false:N \NumberPT_capitalfirst
  \bool_set_false:N \NumberPT_uppercase
  \NumberPT_print_counter:n { #2 }
}

\NewDocumentCommand{\Numberpt}{m}{
  \bool_set_true:N \NumberPT_capital
  \bool_set_false:N \NumberPT_capitale
  \bool_set_true:N \NumberPT_capitalfirst
  \bool_set_false:N \NumberPT_uppercase
  \NumberPT_print_counter:n { #1 }
}

\NewDocumentCommand{\NUMBERPT}{m}{
  \bool_set_true:N \NumberPT_capital
  \bool_set_true:N \NumberPT_capitale
  \bool_set_true:N \NumberPT_uppercase
  \NumberPT_print_counter:n { #1 }
}
\ExplSyntaxOff
\endinput
%%
%% End of file `numberpt.sty'.