% From: asnd@reg.triumf.ca (Donald Arseneau)
% Newsgroups: comp.text.tex
% Subject: Re: Ordinal Numbers in LaTeX
% Date: 26 May 1993 15:04 PST
% Keywords: ordinals, tex, latex
%
%  Takes an integer and returns the proper suffix for an 
%  ordinal number: \nth{1}  -> 1st
%                  \nth{23} -> 23rd   etc.
%
\def\nth#1{\begingroup % [call parameter (#1) "n"]
 \@tempcnta#1\relax \the\@tempcnta % emit n
 \ifnum\@tempcnta<\z@ \@tempcnta\z@\fi % negatives all get th
 \@tempcntb\@tempcnta \divide\@tempcntb100 % hundreds
 \multiply\@tempcntb100 \advance\@tempcnta-\@tempcntb % n mod 100
 \ifnum\@tempcnta<20 \ifnum\@tempcnta>9 \@tempcnta\z@\fi\fi % teens get th
 \@tempcntb\@tempcnta \divide\@tempcntb10 % tens
 \multiply\@tempcntb10 \advance\@tempcnta-\@tempcntb % n mod 10
 \ifcase\@tempcnta th\or st\or nd\or rd\else th\fi % emit suffix
 \endgroup}
%
% Example of use:
% \def\labelenumi{\theenumi.}
% \def\theenumi{\nth{enumi}}
% to make enumerated lists come out as 1st, 2nd, 3rd, 4th, ... 123rd...
