%--------------------------------------------
% Ole Michael Selberg, October 5, 1995
% TeX macros to make a Roman number Arabic
%
% Syntax: \arabicnumeral <Roman number >
%--------------------------------------------
\catcode`@=11
\newcount\r@mancount \newcount\current \newcount\previous
\def\@valueofcurrent{%
   \ifx\next i\global\current=1 \else
     \ifx\next v\global\current=5 \else
      \ifx\next x\global\current=10 \else
       \ifx\next l\global\current=50 \else
        \ifx\next c\global\current=100 \else
         \ifx\next d\global\current=500 \else
          \ifx\next m\global\current=1000 \else 
           \global\r@mancount=-100000
            \immediate\write16{Line \the\inputlineno: non-Roman digit!}
   \fi\fi\fi\fi\fi\fi\fi}
\def\stop{\stop}
\def\arabicnumeral #1 {\r@mancount=0 \current=0 \previous=10000 
              \fr@mroman#1\stop}
\def\fr@mroman {\afterassignment\@testchar\let\next}
\def\@testchar{%
    \ifx\next\stop 
          \ifnum\r@mancount<0 (Wrong Roman numeral: ???)
               \else
                   \the\r@mancount 
          \fi 
          \let\next\relax
       \else \@valueofcurrent
                   \advance\r@mancount by\current       
                   \ifnum\previous<\current
                         \multiply\previous by2
                         \advance\r@mancount by -\previous
                   \fi
           \let\next\fr@mroman
   \fi  
   \previous=\current  
   \next}
\catcode`@=12
\endinput


---------------------------------------------------------------------------
Ole Michael Selberg,
Institutt for oesteuropeiske og orientalske studier 
Universitetet i Oslo
Pb. 1030 Blindern 
N-0315 Oslo

Phone: (47) 22 85 67 94
Fax:   (47) 22 85 41 40


