Friday, September 07, 2007

Roman numerals in Latex

Ok, we have to admit that it is not easy to input roman numerals in Latex. There is still a way.

In the preamble, i.e. before \begin{document}, define

\makeatletter
\newcommand{\rmnum}[1]{\romannumeral #1}
\newcommand{\Rmnum}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother

Then in the document part, \rmnum{num} is used to input the roman numeral of num, \Rmnum is for the uppercase. If you prefer to use other commands, just change the red part in the definition part.

If only lowercase roman numerals are occasionally used, \romannumeralnum can do it. In this approach, definition is not necessary.

Someone anonymous commented that "Nice, but it fails for N=4000 and above." However, in my system, it is working for 4000 and above.

Update: again, someone anonymous pointed out that MMMM is not allowed. Based on the information I found on the Internet, it is OK. But once the number goes bigger again, the convert is not correct.

25 comments:

  1. Thumbs up!

    ReplyDelete
  2. Thank you!

    ReplyDelete
  3. Latinista Stockholmiensis12/29/2008 3:49 AM

    Thanks very much. It worked well. There are two ways to represent 1500 in Roman numerals. The one most familiar today is MD, while many manuscripts and early-printed books have (|)|) . It actually looks like a letter c followed by a line followed by a reversed letter c, which represents M. Is there any way to get style Roman numeral in LaTex?

    ReplyDelete
  4. Thanks! I still have a sorting problem, because \Rmnum{10} is sorted before \Rmnum{1}... Any idea?

    ReplyDelete
  5. Nice, but it fails for N=4000 and above.

    ReplyDelete
  6. wow... thats really awesome dude... i could not find anything this useful elsewhere....

    ReplyDelete
  7. Thank you!!

    ReplyDelete
  8. Thanks a lot, very useful! I would never have thought of that myself.

    ReplyDelete
  9. thanks! … to just let you know that your tip is still helpful, after posting it 2.5 years ago :)

    ReplyDelete
  10. Well, this is almost April, 2010 - and your post continues to help people. Thanks a lot!

    ReplyDelete
  11. Your technique worked perfectly for me. Thanks a million!

    Paul

    ReplyDelete
  12. I got a Roman 2 (II) with the serifs of the two capital Is joined together, by doing this:

    I\kern -0.2ex I

    It would be nice if TeX could do that in the general case, rather than just printing out the letters separately.

    ReplyDelete
  13. Thanks, man.

    ReplyDelete
  14. Of course it fails for N=4000 and above! It uses MMMM which is not allowed, try asking it for the number 50000 and see 50 M letters, it's funny :)

    ReplyDelete
  15. Still working, still great.
    Thanks a lot for this

    ReplyDelete
  16. good stuff, thanks

    ReplyDelete