1. For \ab you might want
\def\ab{\unskip}
since the space is not the same as the width of a digit.
2. Does your solution work with line numbers greater than 99? I tried to implement your idea and I got the order 25.7, 25.117, 25.37. Probably more than 99 lines never occurs on a page, so it's a non-issue. But Homer, for instance, is often referred to by Book.Line, and the lines go past 100. Again, perhaps a non-issue for you.
3. My own attempts: At first I though what a nice opportunity for me to learn a little more Lua, which it was. After, I read you wanted a MKII solution. Well, I'm embarrassed at how long I took to do the MKII, but I'm not good at controlling expansion. Anyway, it automatically generates sort keys for the pages by converting digits to letters and padding with initial a's, so that each page or line number is a fixed length (4 in this case, up to 10000 pages/lines). For instance,
123.4--56 is mapped to abcdaaaeaafg
MKII does not seem to sort digit-based keys reliably; MKIV does, and you can just pad out the digits with zeros. The complete sort key that worked was the catenation of the author, text, and locus key, which is similar to what you have.
MKII:
\defineregister[Passage][Passages]
...
% interface to register -- \locuskey indirectly returns a key in \nextkey
\def\MyPassage#1#2#3{\locuskey{#3}\expandoneargafter\doMyPassage{\nextkey}{#1}{#2}{#3}}
\def\doMyPassage#1#2#3#4{\Passage[#2#3#1]{{#2}+{#3}+{#4}}}
% Def. of \locuskey#1
% In: #1<-p1[.l2[--l3]] Out: key stored in \nextkey
... (see attached file, if interested)
MKIV:
% interface to register -- expansion in MKIV must be different, because a direct approach works:
\def\MyPassage#1#2#3{\Passage[#1#2\locuskey{#3}]{#1+#2+#3}}
% Def. of \locuskey
\startluacode
userdata = userdata or { }
function userdata.locuskey(x)
context(string.gsub(x,"(%d+)",function (s) return string.format("%04d",tonumber(s)) end))
end
\stopluacode
\def\locuskey#1{\ctxlua{userdata.locuskey("#1")}}
The Mark IV/Luatex one was much nicer, less frustrating to figure out.
On May 24, 2012, at 7:06 AM, Alan Bowen wrote:
For anyone interested in producing classical indices locorum, I have devised a way that seems to work, although it is not that elegant.
The first step is to modify the sort keys by counting the number of digits in the page number:
thus,
[AuthorText01] for pages 1–9,
[AuthorText02] for pages 10–99, and so on
The next is to insert the command “ \ab” (note the space) when the line number is a single digit:
thus
391. \ab{}2 but 391.12 in the entry specification {Author+Text+page.line}
For \ab, I have:
\newdimen\digitwidth
\setbox0=\hbox{\tfx\char32}
\digitwidth=\wd0
\def\ab{\tfx\kern-\digitwidth}
The hitch here is that the font size is not context dependent.
Alan
On Tue, May 22, 2012 at 6:39 PM, Alan Bowen