0

I'm trying to insert some Roman and Greek numerals in a beamer presentation compliled with XeLaTeX (the choice is determined by the fact that I have also to insert some Egyptian, Babylonian and Maya numerals)

Can romannum be adapted to deal with numbers bigger than 3999 using overbars, and not using repeating M's?

1
  • 5
    You need to explain what you mean. Provide some clear direction in terms of the packages you're using, the current limitations, and visuals of what features you want in the output. Can you do that?
    – Werner
    Apr 5, 2023 at 17:22

1 Answer 1

3

I've never used (or heard of) romannum, but I bet it works something like:

\documentclass{article}

\newcounter{fingers}
\def\romannum#1{\setcounter{fingers}{#1}\Roman{fingers}}

\begin{document}
\romannum{4005}
\end{document}

Revised solution:

\documentclass{article}

\makeatletter
\def\romannum#1{\bgroup
  \count1=#1\relax
  \ifnum\count1<4000\relax\@Roman{\count1}%
  \else
    \count2=\numexpr \count1/1000\relax
    \sbox0{\@Roman{\count2}}%
    \count1=\numexpr \count1-1000*\count2\relax
    \usebox0\llap{\rule[\dimexpr \ht0+1pt]{\wd0}{0.5pt}}\@Roman{\count1}%
  \fi
\egroup}
\makeatother    

\begin{document}
\romannum{4005}

\romannum{5000}

\romannum{9005}
\end{document}

This version uses the xstring package to replace I with M etc. in the times 1000 roman numerals.

\documentclass{article}
\usepackage{xstring}

\newsavebox{\vbar}
\sbox0{V}\savebox\vbar{\usebox0\llap{\rule[\dimexpr \ht0+1pt]{\wd0}{0.5pt}}}%
\newsavebox{\xbar}
\sbox0{X}\savebox\xbar{\usebox0\llap{\rule[\dimexpr \ht0+1pt]{\wd0}{0.5pt}}}%
\newsavebox{\lbar}
\sbox0{L}\savebox\lbar{\usebox0\llap{\rule[\dimexpr \ht0+1pt]{\wd0}{0.5pt}}}%
\newsavebox{\cbar}
\sbox0{C}\savebox\cbar{\usebox0\llap{\rule[\dimexpr \ht0+1pt]{\wd0}{0.5pt}}}%
\newsavebox{\dbar}
\sbox0{D}\savebox\dbar{\usebox0\llap{\rule[\dimexpr \ht0+1pt]{\wd0}{0.5pt}}}%
\newsavebox{\mbar}
\sbox0{M}\savebox\mbar{\usebox0\llap{\rule[\dimexpr \ht0+1pt]{\wd0}{0.5pt}}}%

\makeatletter
\def\romannum#1{\bgroup
  \count1=#1\relax
  \ifnum\count1<4000\relax
    \@Roman{\count1}%
  \else
    \count2=\numexpr \count1/1000\relax
    \count1=\numexpr \count1-1000*\count2\relax
    \edef\tempstr{\@Roman{\count2}}% substitute letters
    \StrSubstitute{\tempstr}{M}{\usebox\mbar}[\tempstr]% goes first
    \StrSubstitute{\tempstr}{I}{M}[\tempstr]%
    \StrSubstitute{\tempstr}{V}{\usebox\vbar}[\tempstr]%
    \StrSubstitute{\tempstr}{X}{\usebox\xbar}[\tempstr]%
    \StrSubstitute{\tempstr}{L}{\usebox\lbar}[\tempstr]%
    \StrSubstitute{\tempstr}{C}{\usebox\cbar}[\tempstr]%
    \StrSubstitute{\tempstr}{D}{\usebox\dbar}\@Roman{\count1}%
  \fi
\egroup}
\makeatother    

\begin{document}
\romannum{4005}

\romannum{5000}

\romannum{9005}

\romannum{17005}

\romannum{1000000}
\end{document}
5
  • 1
    It doesn't work since 4005 should be $M\bar{V}V$ and not MMMMV. Similarly 10000 should be $\bar{X}$ and not MMMMMMMMMM.....
    – Mathland
    Apr 5, 2023 at 21:02
  • Intersting, so 5000 is \bar{V}? (That's a lot of fingers!) Apr 6, 2023 at 2:17
  • Never heard of using a \bar multiplier in Roman numerals. Roman numerals, IMO, are good for dates, years, chapter numbers, Superbowl, etc. but it becomes tedious after 3 or so thousand – which might be the reason that there is little demand for it and, consequently, no corresponding LaTeX package.
    – Ingmar
    Apr 6, 2023 at 7:08
  • See britannica.com/topic/Roman-numeral It should be noted that there are muiltiple ways to handle numbers > 4000, but not only is it easy to implement, \bar{IV} is relatively easy to read (as opposed to M\bar{V}). Apr 6, 2023 at 13:51
  • However, M\bar{v} is also possible. Apr 9, 2023 at 20:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .