[XeTeX] Roman Numerals as stylistic alternatives

enrico.gregorio at univr.it enrico.gregorio at univr.it
Sat Jun 18 12:51:45 CEST 2011


> Hi,
> 
> what is the preferred way of producing roman numerals as stylistic 
> alternatives (while still inputing arabic numerals)?  Unicode says, that 
> using the codepoints for roman numerals is deprecated and it seems fair 
> to me, as the meaning is the same.
> 
> \romand{<counter>} works of course, but that will probably 
> use letters.

You can try this:


%%% XeTeX code starts
\makeatletter
\def\UniRoman#1{\expandafter\@UniRoman\csname c@#1\endcsname}
\def\uniroman#1{\expandafter\@uniroman\csname c@#1\endcsname}

\def\@UniRoman#1{\ifcase#1\or
  Ⅰ\or Ⅱ\or Ⅲ\or Ⅳ\or Ⅴ\or Ⅵ\or Ⅶ\or Ⅷ\or Ⅸ\or Ⅹ\or Ⅺ\or Ⅻ\else
  \expandafter\@slowUniRoman\romannumeral #1@\fi}
\def\@slowUniRoman#1{\ifx @#1% then terminate
     \else
       \if i#1Ⅰ\else\if v#1Ⅴ\else\if x#1Ⅹ\else\if
       l#1Ⅼ\else\if c#1Ⅽ\else\if d#1Ⅾ\else \if
       m#1Ⅿ\else#1\fi\fi\fi\fi\fi\fi\fi
       \expandafter\@slowUniRoman
     \fi
}
\def\@uniroman#1{\ifcase#1\or
  ⅰ\or ⅱ\or ⅲ\or ⅳ\or ⅴ\or ⅵ\or ⅶ\or ⅷ\or ⅸ\or ⅹ\or ⅺ\or ⅻ\else
  \expandafter\@slowuniroman\romannumeral #1@\fi}
\def\@slowuniroman#1{\ifx @#1% then terminate
     \else
       \if i#1ⅰ\else\if v#1ⅴ\else\if x#1ⅹ\else\if
       l#1ⅼ\else\if c#1ⅽ\else\if d#1ⅾ\else \if
       m#1ⅿ\else#1\fi\fi\fi\fi\fi\fi\fi
       \expandafter\@slowuniroman
     \fi
}
\makeatother

\newcounter{cnta}
\renewcommand{\thecnta}{\uniroman{cnta}} % lowercase Roman numerals
\newcounter{cntb}
\renewcommand{\thecnta}{\UniRoman{cntb}} % uppercase Roman numerals
%%% XeTeX code ends

Since Unicode defines numerals from 1 to 12, I use those when the counter's value is in that range; otherwise I mimick the procedure for getting uppercase Roman numerals of the LaTeX kernel.

Ciao
Enrico

--
Enrico Gregorio          + Dipartimento di Informatica          + Tel: +39 045 8027937
Enrico.Gregorio at univr.it + Università degli Studi di Verona     +
(gregorio at math.unipd.it) + Strada le Grazie 15 / I-37134 Verona + Fax: +39 045 8027928




More information about the XeTeX mailing list