[OS X TeX] Superscripts for ordinals
Gary L. Gray
gray at engr.psu.edu
Mon Feb 28 22:31:55 CET 2005
On Feb 28, 2005, at 2:47 PM, Doug Fields wrote:
> However, to continue on in this thread... If nothing exists, would
> someone give me a definition for doing something like
>
> \ss{th}
>
> or even
>
> \th{}
> \nd{}
> \st{}
> \rd{}
>
> Or even better
>
> \ord{} which checks the previous character and gives the appropriate
> superscript ordinal extension (for English, anyway; I'm sure others
> can add the iemes and whatever they want). Possibly \ord{21} which
> does the same thing but takes the information in there.
We use:
% Define the \nth command.
\makeatletter
\newcount\T at stCount \newcount\TestCount
\def\nth#1{%
\def\reserved at a##1##2\@nil{\ifcat##1n%
0%
\let\reserved at b\ensuremath
\else##1##2%
\let\reserved at b\relax
\fi}%
\TestCount=\reserved at a#1\@nil\relax
\ifnum\TestCount <0 \multiply\TestCount by\m at ne \fi % subdue
negatives
\T at stCount=\TestCount
\divide\T at stCount by 100 \multiply\T at stCount by 100
\advance\TestCount by-\T at stCount % n mod 100
\ifnum\TestCount >20 \T at stCount=\TestCount
\divide\T at stCount by 10 \multiply\T at stCount by 10
\advance\TestCount by-\T at stCount % n mod 10
\fi
\reserved at b{#1}%
\textsuperscript{\ifcase\TestCount th% 0th
\or st% 1st
\or nd% 2nd
\or rd% 3rd
\else th% nth
\fi}%
}
\makeatother
Good luck!
-- Gary
--------------------- Info ---------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
& FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>
More information about the macostex-archives
mailing list