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.

26 comments:

  1. Thumbs up!

    ReplyDelete
  2. Thank you!

    ReplyDelete
  3. thanks a bunch

    ReplyDelete
  4. 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
  5. Thanks! I still have a sorting problem, because \Rmnum{10} is sorted before \Rmnum{1}... Any idea?

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

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

    ReplyDelete
  8. Thank you!!

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

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

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

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

    Paul

    ReplyDelete
  13. 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
  14. Thanks, man.

    ReplyDelete
  15. 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
  16. Still working, still great.
    Thanks a lot for this

    ReplyDelete
  17. good stuff, thanks

    ReplyDelete
  18. how to get romans in latex software witout use usepackege command

    ReplyDelete