summaryrefslogtreecommitdiff
path: root/macros/lamstex/inputs/cardord.tex
blob: 469e2ac9bad4f2b1b7ff2a8cfaa906661d78b4fa (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
\catcode`\@=11
\def\cardnine@#1{\ifcase#1\or one\or two\or three\or four\or five\or
 six\or seven\or eight\or nine\fi}
\def\cardinal#1{\count@#1\relax
 \ifnum\count@>99 \number\count@
 \else
  \ifnum\count@=\z@ zero%
  \else
   \ifnum\count@<\ten@\cardnine@\count@
   \else
    \ifnum\count@<20
     \advance\count@-\ten@
     \ifcase\count@ ten\or eleven\or twelve\or thirteen\or fourteen\or
      fifteen\or sixteen\or seventeen\or eighteen\or nineteen\fi
    \else
     \count@@\count@\count@@@\count@@
     \divide\count@\ten@\multiply\count@\ten@
     \advance\count@@@-\count@\divide\count@\ten@
     \ifcase\count@\or\or twenty\or thirty\or forty\or fifty\or sixty\or
      seventy\or eighty\or ninety\fi
     \ifnum\count@@@=\z@\else-\cardnine@\count@@@\fi
    \fi
   \fi
  \fi
 \fi}
\def\ordnine@#1{\ifcase#1\or first\or second\or third\or fourth\or fifth\or
 sixth\or seventh\or eighth\or ninth\fi}
\def\ordsuffix@{\count@@@@\count@
 \divide\count@\ten@
 \count@@@\count@\count@@\count@
 \divide\count@@\ten@\multiply\count@@\ten@
 \advance\count@@@-\count@@
 \ifnum\count@@@=\@ne th%
 \else
  \count@@@\count@@@@
  \count@@\count@@@@
  \divide\count@@\ten@\multiply\count@@\ten@
  \advance\count@@@-\count@@
  \ifcase\count@@@ th\or st\or nd\or rd\else th\fi
 \fi}
\def\nordinal#1{\count@#1\relax\number\count@\ordsuffix@}
\def\spordinal#1{\count@#1\relax\number\count@$^{\text{\ordsuffix@}}$}
\def\ordinal#1{\count@#1\relax
 \ifnum\count@>99 \number\count@\ordsuffix@
 \else
   \ifnum\count@=\z@ zeroth%
  \else
    \ifnum\count@<\ten@\ordnine@\count@
    \else
     \ifnum\count@<20 \advance\count@-\ten@
      \ifcase\count@ tenth\or eleventh\or twelfth\or thirteenth\or
       fourteenth\or fifteenth\or sixteenth\or seventeenth\or eighteenth\or
       nineteenth\fi
     \else
      \count@@\count@
      \divide\count@\ten@\multiply\count@\ten@
      \count@@@\count@@\advance\count@@@-\count@
      \divide\count@\ten@
      \ifcase\count@\or\or twent\or thirt\or fort\or fift\or sixt\or sevent\or
       eight\or ninet\fi
      \ifnum\count@@@=\z@ ieth\else y-\ordnine@\count@@@\fi
     \fi
    \fi
  \fi
 \fi}
\catcode`\@=\active