summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/ordinalpt/ordinalpt.dtx
blob: 01a70f558df9837d188bc3e8c58d9dff53dd094d (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
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
%% \CheckSum{242}
% \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[T1]{fontenc}
\usepackage{amstext,makeidx}
\makeindex
\newcommand{\ordm}{\textordmasculine}
\newcommand{\ordf}{\textordfeminine}
\begin{document}
  \DocInput{ordinalpt.dtx}
\end{document}
%</driver>
% \fi
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \StopEventually
%
% \changes{1.0}{2007/01/10}{initial version}
% \changes{2.0}{2007/01/27}{reimplemented to make macros freely expandable}
% \changes{3.0}{2007/02/08}{add options for ordinals of 11, 12 and 13;
%                           changed default behavior for these numbers}
%
% \MakeShortVerb+
%
% \title{\textsf{ordinalpt}: counters as ordinal numbers in Portuguese}
% \author{Miguel Vin\'\i cius Santini Frasson}
% \date{2007--02--08 version 3.0}
%
% \maketitle
%
% \tableofcontents
%
% \section{Introduction}
%
%    The package \textsf{ordinalpt} provides a counter style like
%    +\arabic+, +\alph+, etc., but that produces as
%    output strings like ``primeiro'' (first in Portuguese),
%    ``segundo'' (second), ``terceiro'' (third), \ldots, up to
%    ``mil\'esimo noningent\'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{11-12-curtos}
% \DescribeEnv{11-13-curtos}
% \DescribeEnv{11-13-longos}
%   For the ordinals of 11, 12 and 13 there are two correct forms each:\par
%   \begin{tabular}{cll}
%     Number & Shorter & Longer\\\hline
%     11 & und\'ecimo & d\'ecimo primeiro\\
%     12 & duod\'ecimo & d\'ecimo segundo\\
%     13 & tred\'ecimo & d\'ecimo terceiro
%   \end{tabular}\par\noindent
%   It is usual to find the shorter forms for 11\ordm\ and 12\ordm\ in
%   texts, including some grammars.  The shorter form for 13\ordm\ is
%   a bit harder to find.  It is kind of strange to see shorter for
%   11\ordm\ and longer for 12\ordm\ and the other way around, so it
%   should not happen.  If 13\ordm\ is presented in shorter form,
%   then definitely the shorter forms should be used for 11\ordm\ and
%   12\ordm.  Therefore we provide three package options
%   `\texttt{11-12-curtos}', `\texttt{11-13-curtos}' and
%   `\texttt{11-13-longos}' with the following results: \par
%   \begin{tabular}{llll}
%     Option & 11\ordm & 12\ordm & 13\ordm\\\hline 
%     \texttt{11-12-curtos} (default) & und\'ecimo & duod\'ecimo & d\'ecimo terceiro\\
%     \texttt{11-13-curtos} & und\'ecimo & duod\'ecimo & tred\'ecimo\\
%     \texttt{11-13-longos} & d\'ecimo primeiro & d\'ecimo segundo & d\'ecimo terceiro
%   \end{tabular}\par\noindent
%   \textit{Nota bene}: These options affect all ordinals that
%   finish in 11, 12 and 13.  For instance, with option
%   \texttt{11-12-curtos}, the ordinal for 112 becomes ``cent\'esimo
%   duod\'ecimo''. 
%
% \DescribeEnv{tricentesimo}
% \DescribeEnv{trecentesimo}
%   The options `\texttt{tricentesimo}' (default; closer to latin
%   \textit{tricentesimu}) and `\texttt{trecentesimo}' are provided
%   to choose between ``tricent\'esimo'' and ``trecent\'esimo'', since
%   both forms are correct for the ordinal of 300.\par
%   \begin{tabular}{ll}
%     Option & 300\ordm\\\hline
%     \texttt{tricentesimo} (default) & tricent\'esimo\\
%     \texttt{trecentesimo} & trecent\'esimo\\
%   \end{tabular}
%
% \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.\par
%   \begin{tabular}{ll}
%     Option & 600\ordm\\\hline
%     \texttt{sexcentesimo} (default) & sexcent\'esimo\\
%     \texttt{seiscentesimo} & seiscent\'esimo\\
%   \end{tabular}
%
% \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.\par
%   \begin{tabular}{ll}
%     Option & 900\ordm\\\hline
%     \texttt{noningentesimo} (default) & noningent\'esimo\\
%     \texttt{nongentesimo} & nongent\'esimo\\
%   \end{tabular}
%
% \section{Code}
%
% Identidication of the package.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ordinalpt}[2007/02/08 v2.1 Ordinal numbers in Portuguese]
%    \end{macrocode}
%
% \DescribeEnv{11-12-curtos}
% \DescribeEnv{11-13-curtos}
% \DescribeEnv{11-13-longos}
% Declaring options `\texttt{11-12-curtos}' (default) and
% `\texttt{11-13-curtos}' and 
% `\texttt{11-13-longos}', for the various situations for ordinals of
% 11, 12 and 13, as discussed before.
%    \begin{macrocode}
\newif\if@ordpt@twelveshort
\newif\if@ordpt@thirteenshort
\@ordpt@twelveshorttrue
\@ordpt@thirteenshortfalse
\DeclareOption{11-12-curtos}{%
  \@ordpt@twelveshorttrue
  \@ordpt@thirteenshortfalse}
\DeclareOption{11-13-curtos}{%
  \@ordpt@twelveshorttrue
  \@ordpt@thirteenshorttrue}
\DeclareOption{11-13-longos}{%
  \@ordpt@twelveshortfalse
  \@ordpt@thirteenshortfalse}
\ExecuteOptions{11-12-curtos}
%    \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}
%
% \DescribeMacro{\@ordpt@lowercase}
% \DescribeMacro{\@ordpt@capitalize}
% \DescribeMacro{\@ordpt@uppercase}
% Commands that deal with letter case.
%    \begin{macrocode}
\newcommand{\@ordpt@lowercase}[2]{#1#2}
\newcommand{\@ordpt@capitalize}[2]{\uppercase{#1}#2}
\newcommand{\@ordpt@uppercase}[2]{\uppercase{#1#2}}
%    \end{macrocode}
%
% \DescribeMacro{\@ordpt@printunits}
% \DescribeMacro{\@ordpt@printtens}
% \DescribeMacro{\@ordpt@printhundreds}
% \DescribeMacro{\@ordpt@printthousands}
%   These commands take as first and second parameters the command
%   that deals with lettercase (commands above) and a letter ``o'' or
%   ``a'' for the masculine or feminine genders.  The other parameters
%   are the digits necessary to print the number: one for numbers less
%   than 10, two for numbers between 10 and 99, etc.  This commands
%   also have to take care of spaces that separate the words.
%    \begin{macrocode}
\newcommand{\@ordpt@printunits}[3]{%
  \ifcase#3 \or
    #1{p}{rimeir#2}\or
    #1{s}{egund#2}\or
    #1{t}{erceir#2}\or
    #1{q}{uart#2}\or
    #1{q}{uint#2}\or
    #1{s}{ext#2}\or
    #1{s}{\'etim#2}\or
    #1{o}{itav#2}\or
    #1{n}{on#2}%
  \fi}
\newcommand{\@ordpt@printtens}[4]{%
  \ifx#31%
    \ifx#41%
      \if@ordpt@twelveshort
        #1{u}{nd\'ecim#2}%
      \else
        #1{d}{\'ecim#2}\space#1{p}{rimeir#2}%
      \fi
    \else
      \ifx#42%
        \if@ordpt@twelveshort
          #1{d}{uod\'ecim#2}%
        \else
          #1{d}{\'ecim#2}\space#1{s}{egund#2}%%
        \fi
      \else
        \ifx#43%
          \if@ordpt@thirteenshort
            #1{t}{red\'ecim#2}%
          \else
            #1{d}{\'ecim#2}\space#1{t}{erceir#2}%%
          \fi
        \else
          #1{d}{\'ecim#2}%
          \ifx#40%
          \else
            \space\@ordpt@printunits#1#2#4%
          \fi
        \fi
      \fi
    \fi
  \else
    \ifcase#3 \or\or
      #1{v}{ig\'esim#2}\or
      #1{t}{rig\'esim#2}\or
      #1{q}{uadrag\'esim#2}\or
      #1{q}{uinquag\'esim#2}\or
      #1{s}{exag\'esim#2}\or
      #1{s}{eptuag\'esim#2}\or
      #1{o}{ctog\'esim#2}\or
      #1{n}{onag\'esim#2}%
    \fi
    \ifx#40%
    \else
      \space\@ordpt@printunits#1#2#4%
    \fi
  \fi}
\newcommand{\@ordpt@printhundreds}[5]{%
  \ifcase#3 \or
    #1{c}{ent\'esim#2}\or
    #1{d}{ucent\'esim#2}\or
    #1{t}{r\@ordpt@tricent cent\'esim#2}\or
    #1{q}{uadringent\'esim#2}\or
    #1{q}{uingent\'esim#2}\or
    #1{s}{e\@ordpt@sexcent cent\'esim#2}\or
    #1{s}{eptingent\'esim#2}\or
    #1{o}{ctingent\'esim#2}\or
    #1{n}{on\@ordpt@noningent gent\'esim#2}%
  \fi
  \ifx#40%
    \ifx#50%
    \else
      \space\@ordpt@printunits#1#2#5%
    \fi
  \else
    \space\@ordpt@printtens#1#2#4#5%
  \fi}
\newcommand{\@ordpt@printthousands}[6]{%
  \ifcase#3 \or
    #1{m}{il\'esim#2}%
  \fi
  \ifx#40%
    \ifx#50%
      \ifx#60%
      \else
        \space\@ordpt@printunits#1#2#6%
      \fi
    \else
      \space\@ordpt@printtens#1#2#5#6%
    \fi
  \else
    \space\@ordpt@printhundreds#1#2#4#5#6
  \fi}
%    \end{macrocode}
%
% \DescribeMacro{\@ordpt@print}
%    The command +\@ordpt@print+ is defined with special arguments
%    (not possible to be defined with +\newcommand+).  The arguments
%    are expected as follows:\\
% +  #1+ lettercase command\\
% +  #2+ gender letter o or a\\
% +  #3+ digit\\
% +  #4+ digit or ? (only units)\\
% +  #5+ digit or ? (up to tens)\\
% +  #6+ digit or ? (up to hundreds)\\
% +  #7+ ? (up to thousands) or nothing
%    \begin{macrocode}
\newcommand{\@ordpt@print}{}
\def\@ordpt@print#1#2#3#4#5#6#7!{%
  \ifx#4?%
    \@ordpt@printunits#1#2#3%
  \else
    \ifx#5?%
      \@ordpt@printtens#1#2#3#4%
    \else
      \ifx#6?%
        \@ordpt@printhundreds#1#2#3#4#5%
      \else
        \@ordpt@printthousands#1#2#3#4#5#6%
      \fi
    \fi
  \fi}
%    \end{macrocode}
%
% \DescribeMacro{\@ordpt@ordinal}
%   In this command the value of the counter (third argument) is
%   expanded, via +\expandafter+, to a list of digits, and four ``?''
%   and a ``!'' are added and expected to be goobled by
%   +\@ordpt@print+.  We need the ``?'' because of the +\ifx+ on
%   detecting how many digits the number has.  This command checks if
%   the value of the counter is between 1 and 1999 (including both).
%   After the expansion of the +\the+, the command +\@ordpt@print+ is
%   used.
%    \begin{macrocode}
\newcommand{\@ordpt@ordinal}[3]{%
  \ifnum\csname c@#3\endcsname<1
    \@ctrerr
  \else
    \ifnum\csname c@#3\endcsname>1999
      \@ctrerr
    \else
      \expandafter\@ordpt@print
      \expandafter#1\expandafter#2\the\csname c@#3\endcsname????!%
    \fi
  \fi}
%    \end{macrocode}
%
% \DescribeMacro{\ordptmasc}
% \DescribeMacro{\Ordptmasc}
% \DescribeMacro{\ORDPTMASC}
% \DescribeMacro{\ordptfem}
% \DescribeMacro{\Ordptfem}
% \DescribeMacro{\ORDPTFEM}
%    The user commands.  The diference between them is that the
%    pass to +\@ordpt@ordinal+ the letter case commands as first
%    argument and the final gender vowel as second, and the counter
%    name as third argument.
%    \begin{macrocode}
\newcommand{\ordptmasc}[1]{\@ordpt@ordinal\@ordpt@lowercase o{#1}}
\newcommand{\Ordptmasc}[1]{\@ordpt@ordinal\@ordpt@capitalize o{#1}}
\newcommand{\ORDPTMASC}[1]{\@ordpt@ordinal\@ordpt@uppercase o{#1}}
\newcommand{\ordptfem}[1]{\@ordpt@ordinal\@ordpt@lowercase a{#1}}
\newcommand{\Ordptfem}[1]{\@ordpt@ordinal\@ordpt@capitalize a{#1}}
\newcommand{\ORDPTFEM}[1]{\@ordpt@ordinal\@ordpt@uppercase a{#1}}
%    \end{macrocode}
% \Finale \addcontentsline{toc}{section}{Index}\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         \~}