summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/genmisc/arabic.tex
blob: acba65e59f0aab353102ae589b00ad2008e3127e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%--------------------------------------------
% 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