[Tex/LaTex] Using the nth package for Roman Numerals

document-classesroman numerals

\documentclass{book}
\usepackage{nth}
\begin{document}
\nth{3} is not the same as $\nth{3}$
\end{document}

This code works fine for numbers.Now , In the argument if I want to pass III , what should I do?

I want the output as III(in slanting–> I achieved this using Math Mode)rd(in super script)

Best Answer

If I understand your question correctly, then (as has been suggested in comments to the question) I think it is not a standard practice in English to write something like III^{rd}, let alone using italicized font, and I would suggest you not to use this.

That being said, one way to achieve what you want is to define a command similar to \nth, but converting the argument to (upper case) Roman numerals. Three options: one, using roman font for the complete expression; another one using slanted font for the numeral and roman font for the superscript, and the third one, using slanted font for the complete expression:

\documentclass{book}
\usepackage[super]{nth}

\def\Rnth#1{{% First print number:
  \expandafter\nthM \MakeUppercase{\romannumeral\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
 }}}
\def\RSnth#1{{% First print number:
  \expandafter\nthM \slshape\MakeUppercase{\romannumeral\number#1}\kern1pt\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
 }}}
\def\Rsnth#1{{% First print number:
  \expandafter\nthM \slshape\MakeUppercase{\romannumeral\number#1}\kern-1pt\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
 }}

\begin{document}

\Rnth{3} is not the same as \nth{3}.

\Rnth{2} is not the same as \nth{2}.

\RSnth{3} is not the same as \nth{3}.

\RSnth{2} is not the same as \nth{2}.

\Rsnth{3} is not the same as \nth{3}.

\Rsnth{2} is not the same as \nth{2}.

\end{document}

enter image description here

If you want the numeral to be in italics shape, replace \slshape with \itshape in the corresponding definition(s).

In my opinion, the two options using slanted font look really ugly; please consider not using those.