# Middle age roman numerals formatting

I've recently read about a middle age variation on roman numerals where the last "i" character is replaced by a "j". I was thinking about writing my own \roman and \Roman variations, but hit a stone wall... does anyone have any idea how one may go about doing something like this? Thanks in advance!

PS: I'd like to change a final "v" to a "y" while we're at it ;)

edit: clarifying the issue, I'd only like to replace the last "i" and "v" in a roman numeral for "j" and "y" respectively. I'm not interested (at the moment at least :P) in every other middle age variation.

-
Are you going use it also for counters and calculations or just for typesetting? –  Yiannis Lazarides Oct 19 '11 at 13:45
Hmm... on the one hand, i'd like it to behave like \roman and \Roman (ie. accepting a counter as an argument and producing the typeset numerals); on the other hand, it would be nice to have a \MiddleAgeRoman sort of thing that would get a number and typeset it accordingly. –  mpr Oct 19 '11 at 13:53
It is possible, but not easy, especially as the wikipedia article is partially incomplete. The approach is to rather use your own macro, i.e., \MiddleAgeRoman I cannot see it possible hacking \roman or \Roman but I can be wrong. I have posted some code at pastebin.com/caS5mAnR, if you modify the table to typest the middle age variation, either me or someone would be able to post the code. –  Yiannis Lazarides Oct 19 '11 at 14:07
I've created a revision at link. It looks admittedly bad in uppercase, it should lok better in lowercase ;) –  mpr Oct 19 '11 at 14:19
If you want only the last i to be changed to j it will be easier to do. Is that the only change? It doesn't appear to be so from wikipedia. –  Yiannis Lazarides Oct 19 '11 at 14:28

Here is a start,

\def\MiddleAgeRoman#1{%
\ifcase#1 zero not allowed
\or i\or ij\or iij\or iv\or v \or vi
\or vij \or viij \or ix\or x
\else Not available for #1\fi\relax}

\MiddleAgeRoman{7}


Will have a look at the revised link and try and get some more code later.

Also check out the package http://www.ctan.org/tex-archive/macros/latex/contrib/modroman, it appears to be able to do what you want.

-
This works great! (the "custom command" part) I just don't see how I can extend it to accommodate for arbitrary roman numerals... On the other hand, will this work \pagenumbering{MiddleAgeRoman}? –  mpr Oct 19 '11 at 14:45
@mpr No it will not work for sectioning commands, if you after that look at ctan.org/tex-archive/macros/latex/contrib/romannum –  Yiannis Lazarides Oct 19 '11 at 14:47
+1 for having found the package –  egreg Oct 19 '11 at 15:37
+1 for the package as well :) –  mpr Oct 19 '11 at 18:03
\def\Middleage#1{%
\ifnum#1>0
\expandafter\Middleagei\romannumeral#1\expandafter\relax
\else
\errmessage{Invalid number}%
\fi}
\def\Middleagei#1#2{%
\ifx#2\relax
\expandafter\Middleageii\expandafter#1%
\else
#1\expandafter\Middleagei\expandafter#2%
\fi}
\def\Middleageii#1{%
\expandafter\if\string i#1%
j%
\else
#1%
\fi}

\Middleage{100}

\Middleage{128}

\Middleage{41}


We read two tokens from the expansion of \romannumeral#1\relax; if the second is \relax, then we are at the end; so we have to decide if the last token of the Roman numeral is i; if it is, we print j, otherwise the character.

## Using this for representing counters in LaTeX

Add to the code above also

\makeatletter
\def\MAroman#1{\expandafter\@MAroman\csname c@#1\endcsname}
\def\@MAroman#1{\expandafter\Middleage\expandafter{\number#1}}
\makeatother


Now

\pagenumbering{MAroman}
\newcounter{mycount}
\renewcommand{\themycount}{\MAroman{mycount}}


will work as expected.

## Different version

The following version will print "i", "ij", "iij", "iv", "v", "vi", "vij" and so on (a final "i" becomes "j" only if preceded by "i").

\makeatletter
\def\Middleage#1{\expandafter\@middleage\expandafter{\number#1}}
\def\@middleage#1{%
\ifnum#1>\z@
\expandafter\@middle@ge\romannumeral#1\expandafter @\expandafter @%
\else
\errmessage{Invalid number}%
\fi}
\def\@middle@ge#1#2#3{%
\if#2@%
#1%
\else
\expandafter\@middl@@ge\expandafter#1\expandafter#2\expandafter#3%
\fi}
\def\@middl@@ge#1#2#3{%
\if#3@%
\expandafter\@m@ddl@@ge\expandafter#1\expandafter#2%
\else
#1\expandafter\@middle@ge\expandafter#2\expandafter#3%
\fi}
\def\@m@ddl@@ge#1#2{%
\expandafter\if\string i#2%
\expandafter\if\string i#1%
ij%
\else
#1#2%
\fi
\expandafter\@gobble
\else
#1#2\expandafter\@gobble
\fi}
\makeatother

-
Nice way to catch the last letter of the argument, I was going to try it out with a loop and @cdr. Me thinks though that this is not the only difference in Middle Age Roman, one will have to build a more complicated algo to get other alphabet letters in. –  Yiannis Lazarides Oct 19 '11 at 15:05
This works like a charm for the whole range of values! Alas, I can't still use it for page numbering (is that what you meant by "not expandable"?)... –  mpr Oct 19 '11 at 15:09
@mpr The first version was not expandable; the present one is and I've added the code for representing counters with it. Of course it's not perfect, as 1 is represented as j. –  egreg Oct 19 '11 at 15:26
@egreg Sorry, but I can't seem to get it to work with page numbers... using \pagenumbering{MAroman} still displays the "normal" roman numerals. One being represented as "j" is ok as far as I can tell :) –  mpr Oct 19 '11 at 16:25
@mpr Where are you putting \pagenumbering{MAroman}? If before \frontmatter it won't work. –  egreg Oct 19 '11 at 19:45