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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
%% \CheckSum{260}
% \iffalse
% File: ordinalpt.dtx
% Copyright (C) 2007 Miguel V. S. Frasson (mvsfrasson@gmail.com)
%
% This package may be distributed under the terms of the LaTeX
% Project Public License, as described in lppl.txt in the base
% LaTeX distribution, either version 1.2 or (at your option)
% any later version.
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{doc}
\usepackage{amstext,makeidx}
\makeindex
\begin{document}
\DocInput{ordinalpt.dtx}
\end{document}
%</driver>
% \fi
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \StopEventually
%
% \changes{1.0}{2007/01/10}{initial version}
%
% \MakeShortVerb+
%
% \title{\textsf{ordinalpt}: counters as ordinal numbers in Portuguese}
% \author{Miguel Vin\'\i cius Santini Frasson}
% \date{2007--01--10 version 1.0}
%
% \maketitle
%
% \section{Introduction}
%
% The package \textsf{ordinalpt} provides a counter style (like
% +\arabic+, +\alph+ and others) but that produces as
% output strings like ``primeiro'' (first in Portuguese),
% ``segundo'' (second), ``terceiro'' (third), \ldots, up to
% ``mil\'esimo nongent\'esimo nonag\'esimo nono''
% (1999$^{\text{th}}$). There are counter commands to output the
% text in UPPERCASE, Capitalized or in lowercase, with masculine or
% feminine gender.
%
% \section{User commands}
%
% \newcommand{\countername}{\texttt{\textit{counter}}}
%
% \DescribeMacro{\ordptmasc}
% \DescribeMacro{\Ordptmasc}
% \DescribeMacro{\ORDPTMASC}
% \DescribeMacro{\ordptfem}
% \DescribeMacro{\Ordptfem}
% \DescribeMacro{\ORDPTFEM}
% Six commands to output all incarnations of ordinal numbers in
% portuguese --- masculine or feminine, in ``lowercase'',
% ``Capitalized'' or in ``UPPERCASE''---:\\
% + \ordptmasc{+\countername+}+ (lowercase masculine),\\
% + \Ordptmasc{+\countername+}+ (capitalized masculine),\\
% + \ORDPTMASC{+\countername+}+ (uppercase masculine),\\
% + \ordptfem{+\countername+}+ (lowercase feminine),\\
% + \Ordptfem{+\countername+}+ (capitalized feminine) and\\
% + \ORDPTFEM{+\countername+}+ (uppercase feminine).
%
% Example:
%
%\begin{verbatim}
%\renewcommand{\thepage}{--- \Ordptfem{page} p\'agina ---}
%\end{verbatim}
% will produce in the place for page numbers:
%
%\centerline{--- Primeira p\'agina ---}
%\centerline{--- Segunda p\'agina ---}
%
% \section{User options}
%
% \DescribeEnv{tricentesimo}
% \DescribeEnv{trecentesimo}
% The options `\texttt{tricentesimo}' (default; closer to latin
% \textit{tricentesimu}) and `\texttt{trecentesimo}' are provided
% to use between ``tricent\'esimo'' and ``trecent\'esimo'', since
% both forms are correct for the ordinal of 300.
%
% \DescribeEnv{sexcentesimo}
% \DescribeEnv{seiscentesimo}
% The options `\texttt{sexcentesimo}' (default; closer to the latin
% \textit{sexcentesimu}) and `\texttt{seiscentesimo}' are provided
% to choose between ``sexcent\'esimo'' and ``seiscent\'esimo'',
% since both forms are correct for the ordinal of 600.
%
% \DescribeEnv{noningentesimo}
% \DescribeEnv{nongentesimo}
% The options `\texttt{noningentesimo}' (default; from latin
% \textit{noningentesimu}) and `\texttt{nongentesimo} (from latin
% \textit{nongentesimu})' are provided to choose between
% ``noningent\'esimo'' and ``nongent\'esimo'', since both forms are
% correct for the ordinal of 900.
%
% \section{Code}
%
% Identidication of the package and use of the package \textsf{ifthen}.
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ordinalpt}[2007/01/11 v1.0 Ordinal numbers in Portuguese]
\RequirePackage{ifthen}
% \end{macrocode}
%
% \DescribeEnv{tricentesimo}
% \DescribeEnv{trecentesimo}
% Declaring options `\texttt{tricentesimo}' (default) and
% `\texttt{trecentesimo}', since both forms ``tricent\'esimo'' and
% ``trecent\'esimo'' are correct for the ordinal of 300.
% \begin{macrocode}
\DeclareOption{tricentesimo}{\def\@ordpt@tricent{i}}
\DeclareOption{trecentesimo}{\def\@ordpt@tricent{e}}
\ExecuteOptions{tricentesimo}
% \end{macrocode}
%
% \DescribeEnv{sexcentesimo}
% \DescribeEnv{seiscentesimo}
% Declaring options `\texttt{sexcentesimo}' (default; closer to the
% latin \textit{sexcentesimu}) and
% `\texttt{seiscentesimo}', since both forms ``sexcent\'esimo'' and
% ``seiscent\'esimo'' are correct for the ordinal of 600.
% \begin{macrocode}
\DeclareOption{sexcentesimo}{\def\@ordpt@sexcent{x}}
\DeclareOption{seiscentesimo}{\def\@ordpt@sexcent{is}}
\ExecuteOptions{sexcentesimo}
% \end{macrocode}
%
% \DescribeEnv{noningentesimo}
% \DescribeEnv{nongentesimo}
% Declaring options `\texttt{noningentesimo}' (default; from latin
% \textit{noningentesimu}) and `\texttt{nongentesimo} (from latin
% \textit{nongentesimu})', since both forms ``noningent\'esimo'' and
% ``nongent\'esimo'' are correct for the ordinal of 900.
% \begin{macrocode}
\DeclareOption{noningentesimo}{\def\@ordpt@noningent{in}}
\DeclareOption{nongentesimo}{\def\@ordpt@noningent{}}
\ExecuteOptions{noningentesimo}
% \end{macrocode}
%
% Processing options.
% \begin{macrocode}
\ProcessOptions
% \end{macrocode}
%
% \DescribeEnv{@ordpt@putspace}
% \DescribeEnv{@ordpt@counter}
% \DescribeEnv{@ordpt@alg}
% \DescribeMacro{\@ordpt@case}
% \DescribeMacro{\@ordpt@masc}
% \DescribeMacro{\@ordpt@fem}
% \DescribeMacro{\@ordpt@ul}
% Declaring internals.
% \begin{macrocode}
\newboolean{@ordpt@putspace}
\newcounter{@ordpt@counter}
\newcounter{@ordpt@alg}
\newcommand{\@ordpt@case}{}
\newcommand{\@ordpt@masc}{o}
\newcommand{\@ordpt@fem}{a}
\newcommand{\@ordpt@ul}{o}
% \end{macrocode}
%
% \DescribeMacro{\@ordpt@capitalize}
% \begin{macrocode}
\newcommand{\@ordpt@capitalize}[1]{\MakeUppercase#1}
% \end{macrocode}
%
% \DescribeMacro{\@ordpt@ordunits}
% \DescribeMacro{\@ordpt@ordtens}
% \DescribeMacro{\@ordpt@ordcents}
% These commands take a number between 0 and 9 and return ordinal in
% Portuguese from ``first'' to ``nineth'', ``tenth'' to
% ``ninetieth'' (by 10) and ``one hundredieth'' to ``nine
% hundredieth'' (by 100). Inside the user commands the command
% +\@ordpt@case+ will be redefined to be identity (lowercase),
% +\@ordpt@capitalize+ (capitalized) or +\MakeUppercase+ (uppercase) and
% +\@ordpt@ul+ will be defined as ``o'' (masculine) or ``a''
% (feminine).
% \begin{macrocode}
\newcommand{\@ordpt@ordunits}[1]{%
\ifcase#1\or
\@ordpt@case{primeir\@ordpt@ul}\or
\@ordpt@case{segund\@ordpt@ul}\or
\@ordpt@case{terceir\@ordpt@ul}\or
\@ordpt@case{quart\@ordpt@ul}\or
\@ordpt@case{quint\@ordpt@ul}\or
\@ordpt@case{sext\@ordpt@ul}\or
\@ordpt@case{s\'etim\@ordpt@ul}\or
\@ordpt@case{oitav\@ordpt@ul}\or
\@ordpt@case{non\@ordpt@ul}%
\fi}
\newcommand{\@ordpt@ordtens}[1]{%
\ifcase#1\or
\@ordpt@case{d\'ecim\@ordpt@ul}\or
\@ordpt@case{vig\'esim\@ordpt@ul}\or
\@ordpt@case{trig\'esim\@ordpt@ul}\or
\@ordpt@case{quadrag\'esim\@ordpt@ul}\or
\@ordpt@case{quinquag\'esim\@ordpt@ul}\or
\@ordpt@case{sexag\'esim\@ordpt@ul}\or
\@ordpt@case{septuag\'esim\@ordpt@ul}\or
\@ordpt@case{octog\'esim\@ordpt@ul}\or
\@ordpt@case{nonag\'esim\@ordpt@ul}%
\fi}
\newcommand{\@ordpt@ordcents}[1]{%
\ifcase#1\or
\@ordpt@case{cent\'esim\@ordpt@ul}\or
\@ordpt@case{ducent\'esim\@ordpt@ul}\or
\@ordpt@case{tr\@ordpt@tricent cent\'esim\@ordpt@ul}\or
\@ordpt@case{quadringent\'esim\@ordpt@ul}\or
\@ordpt@case{quingent\'esim\@ordpt@ul}\or
\@ordpt@case{se\@ordpt@sexcent cent\'esim\@ordpt@ul}\or
\@ordpt@case{septingent\'esim\@ordpt@ul}\or
\@ordpt@case{octingent\'esim\@ordpt@ul}\or
\@ordpt@case{non\@ordpt@noningent gent\'esim\@ordpt@ul}%
\fi}
% \end{macrocode}
%
% \DescribeMacro{\@ordpt@ordinal}
% This command does all the work of mount the words.
% \begin{macrocode}
\newcommand{\@ordpt@ordinal}[1]{%
% \end{macrocode}
% It checks whether the number is between 0 and 1999.
% \begin{macrocode}
\ifthenelse{\value{#1}>0\and\value{#1}<2000}
% \end{macrocode}
% Save original counter to the counter \texttt{@ordpt@counter}.
% \begin{macrocode}
{%
\setcounter{@ordpt@counter}{\value{#1}}%
% \end{macrocode}
% Then, if it is larger than 999, adds ``milesimo(a)'' in front of it.
% \begin{macrocode}
\ifthenelse{\value{@ordpt@counter}>999}
{%
\@ordpt@case{mil\'esim\@ordpt@ul}%
% \end{macrocode}
% Save in the boolean \texttt{@ordpt@putspace} to put a space if
% something else is to be written.
% \begin{macrocode}
\setboolean{@ordpt@putspace}{true}%
% \end{macrocode}
% Subtract 1000 from the counter
% \begin{macrocode}
\addtocounter{@ordpt@counter}{-1000}%
}
% \end{macrocode}
% If counter is less than 1000, set the boolean
% \texttt{@ordpt@putspace} to not put a space if
% something else is to be written.
% \begin{macrocode}
{%
\setboolean{@ordpt@putspace}{false}%
}%
% \end{macrocode}
% Starts to parse the counter. Gets the algarism of cents, reseting
% counter \texttt{@ordpt@alg} and does a loop, steping
% \texttt{@ordpt@alg} and subtracting 100 from
% \texttt{@ordpt@counter} while this counter is larger than 100.
% \begin{macrocode}
\setcounter{@ordpt@alg}{0}%
\whiledo{\value{@ordpt@counter}>99}
{%
\stepcounter{@ordpt@alg}%
\addtocounter{@ordpt@counter}{-100}%
}%
% \end{macrocode}
% If the algarism of the cents is positive, checks if it has to add a
% space, writes with +\@ordpt@ordcents+ and set boolean
% \texttt{@ordpt@putspace} accordingly.
% \begin{macrocode}
\ifthenelse{\value{@ordpt@alg}>0}
{%
\ifthenelse{\boolean{@ordpt@putspace}}{\space}{}%
\@ordpt@ordcents{\value{@ordpt@alg}}%
\setboolean{@ordpt@putspace}{true}%
}
{}%
% \end{macrocode}
% Gets the digits of tens analogously it did before.
% \begin{macrocode}
\setcounter{@ordpt@alg}{0}%
\whiledo{\value{@ordpt@counter}>9}
{%
\stepcounter{@ordpt@alg}%
\addtocounter{@ordpt@counter}{-10}%
}%
\ifthenelse{\value{@ordpt@alg}>0}
{%
\ifthenelse{\boolean{@ordpt@putspace}}{\space}{}%
\@ordpt@ordtens{\value{@ordpt@alg}}%
\setboolean{@ordpt@putspace}{true}%
}
{}%
% \end{macrocode}
% Now counter \texttt{@ordpt@counter} is left with the units digit.
% Print as before.
% \begin{macrocode}
\ifthenelse{\value{@ordpt@counter}>0}
{%
\ifthenelse{\boolean{@ordpt@putspace}}{\space}{}%
\@ordpt@ordunits{\value{@ordpt@counter}}%
}
{}%
}
% end of the first +\ifthenelse+: sign counter error if argument
% counter is not between 1 and 1999 inclusively.
% \begin{macrocode}
{\@ctrerr}%
}
% \end{macrocode}
%
% \DescribeMacro{\ordptmasc}
% \DescribeMacro{\Ordptmasc}
% \DescribeMacro{\ORDPTMASC}
% \DescribeMacro{\ordptfem}
% \DescribeMacro{\Ordptfem}
% \DescribeMacro{\ORDPTFEM}
% The end user commands. The diference between them is the +\let+
% binds of +\@ordpt@case+ to +\@fisrtofone+, +\@ordpt@capitalize+ or
% +\MakeUppercase+, and binds of +\@ordpt@ul+ to +\@ordpt@masc+=``o'' or
% +\@ordpt@fem+=``a''.
% \begin{macrocode}
\newcommand{\ordptmasc}[1]{%
\let\@ordpt@case\@firstofone
\let\@ordpt@ul\@ordpt@masc
\@ordpt@ordinal{#1}}
\newcommand{\Ordptmasc}[1]{%
\let\@ordpt@case\@ordpt@capitalize
\let\@ordpt@ul\@ordpt@masc
\@ordpt@ordinal{#1}}
\newcommand{\ORDPTMASC}[1]{%
\let\@ordpt@case\MakeUppercase
\let\@ordpt@ul\@ordpt@masc
\@ordpt@ordinal{#1}}
\newcommand{\ordptfem}[1]{%
\let\@ordpt@case\@firstofone
\let\@ordpt@ul\@ordpt@fem
\@ordpt@ordinal{#1}}
\newcommand{\Ordptfem}[1]{%
\let\@ordpt@case\@ordpt@capitalize
\let\@ordpt@ul\@ordpt@fem
\@ordpt@ordinal{#1}}
\newcommand{\ORDPTFEM}[1]{%
\let\@ordpt@case\MakeUppercase
\let\@ordpt@ul\@ordpt@fem
\@ordpt@ordinal{#1}}
% \end{macrocode}
% \Finale \PrintIndex %\PrintChanges
%
\endinput
%
%% \CharacterTable
%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%% Digits \0\1\2\3\4\5\6\7\8\9
%% Exclamation \! Double quote \" Hash (number) \#
%% Dollar \$ Percent \% Ampersand \&
%% Acute accent \' Left paren \( Right paren \)
%% Asterisk \* Plus \+ Comma \,
%% Minus \- Point \. Solidus \/
%% Colon \: Semicolon \; Less than \<
%% Equals \= Greater than \> Question mark \?
%% Commercial at \@ Left bracket \[ Backslash \\
%% Right bracket \] Circumflex \^ Underscore \_
%% Grave accent \` Left brace \{ Vertical bar \|
%% Right brace \} Tilde \~}
|