summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/nth
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2020-03-12 16:59:44 +0000
committerKarl Berry <karl@freefriends.org>2020-03-12 16:59:44 +0000
commit53e17bc8a3cd2a7046b87e53478f5bb5a844a8a3 (patch)
treeb49290877715674ca859b2411cb173ae48b310e4 /Master/texmf-dist/tex/generic/nth
parent5688c276c8e48bb31022cdf3e11d9efc6ca4bd42 (diff)
nth own package, from genmisc
git-svn-id: svn://tug.org/texlive/trunk@54252 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/nth')
-rw-r--r--Master/texmf-dist/tex/generic/nth/nth.sty56
1 files changed, 56 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/generic/nth/nth.sty b/Master/texmf-dist/tex/generic/nth/nth.sty
new file mode 100644
index 00000000000..8a96c73903d
--- /dev/null
+++ b/Master/texmf-dist/tex/generic/nth/nth.sty
@@ -0,0 +1,56 @@
+% nth.sty version 2002/27/02 Donald Arseneau
+% Ordinal numbering style, 1st 2nd 3rd 4th 5th... 12th... 101st 102nd...
+%
+% (Public domain: take, include, extract, whatever)
+%
+% In LaTeX:
+% \usepackage[super,negative]{nth}
+% where option [super] gives superscript `th'
+% and option [negative] allows ``st, nd, rd'' suffixes on negative numbers.
+%
+% example: \renewcommand{\thesection}{\ordinal{section}}
+% or \renewcommand{\thesection}{\@ordinal\c@section}
+% or \renewcommand{\thesection}{\nth\c@section}
+%
+% In plain TeX:
+% \input nth.sty
+% use: \nth{<number>}.
+% Change formatting by redefining \nthscript and \nthtest
+
+\def\nth#1{% First print number:
+ \expandafter\nthM \number #1\relax
+ \nthscript{%
+ \ifnum#1\nthtest0 th\else % negatives are all ``th'' (depending on \nthtest)
+ \expandafter \nthSuff \expandafter 0\number\ifnum #1<0-\fi#1\delimiter
+ \fi
+ }}
+
+% Minus sign using math mode:
+\def\nthM#1{\if -#1\ifmmode-\else$-$\fi\else #1\fi}
+
+% Print suffix depending on last two digits:
+\def\nthSuff#1#2#3{%
+ \ifx \delimiter#3% #1#2 are last two digits
+ \ifnum #1=1 th% teens are always ``th''
+ \else % use appropriate suffix
+ \ifcase #2 th\or st\or nd\or rd\else th\fi
+ \fi
+ \else % continue scanning for last two digits
+ \expandafter \nthSuff \expandafter #2\expandafter #3%
+ \fi}
+
+% Formatting hook for ordinals (\let\nthscript\textsuperscript)
+\def\nthscript#1{#1}% alternate: \def\nthscript#1{$\rm^{#1}$}
+
+% Formatting hook for all negative numbers giving ``th''
+\def\nthtest{<} % alternate: \def\nthtest{=}
+
+\ifx\Alph\undefined\else
+ \def\ordinal#1{\expandafter\@ordinal\csname c@#1\endcsname}
+ \let\@ordinal\nth
+ \ProvidesPackage{nth}[2002/02/27]
+ \DeclareOption{super}{\def\nthscript{\textsuperscript}}
+ \DeclareOption{negative}{\def\nthtest{=}}
+ \ProcessOptions
+\fi
+