# Create arbitrary sorting of index entries

How does one go about setting an arbitrary sorting order in an index? For example, I would like to create an index of citations to Roman and canon law, which should not be sorted alphabetically. (All the citations in the text are already written by macros, so it seems like getting them into an index is trivial enough.)

A long example of what I mean, which I hope shows the complexity of how things need to be sorted:

Index of Roman law citations: [= heading division]

Inst. 1.2 pr. [pr. = prologue]

Inst. 1.2.2

Inst. 3.17 pr.

Dig. 1.1.1.3

Dig. 1.10.1.2

Dig. 27.1.2

Dig. 50.16.289

Cod. 1.1.1

Cod. 4.2

Canon law is different again:

D. 1 c. 1

D. 6 c. 3

D. 6 d.p.c. 3 [p. = post = after c. 3]

D. 8 d.a.c 1 [a. = ante = before c. 1]

D. 8 c. 1

C. 1 q. 1 c. 10

C. 1 q. 3 c. 7

C. 1 q. 3 c. 15

C. 23 q. 4 c. 5

C. 33 q. 3 (De penitentia) [= subsection in Causa 33, quaestio 3]

D. 5 c. 8

D. 6 c. 1

Tertia pars (De consecratione): [= heading subdivision]

D. 2 c. 2

D. 4 c. 1

-
I guess theoretically this should be possible with xindy. But I have no idea how. –  Caramdir Sep 23 '11 at 19:15

The bibleref package has a feature that does that for Bible books (which are sorted by Bible order usually). There's two suggested ways.

The native way inserts numbers before the entry, so the index looks like:

\indexentry{01\relax @\BRbooktitlestyle {\BRbookof Gen\ese}!001:026@\BRchapterstyle {1}\BRchvsep \BRversestyle {26}|textrm}{12}


Where 01 is the order for the book of Genesis.

The other way involves using xindy with a custom dictionary. See the xindy manual for that.

-
Ah, thanks for the suggestions. I had not known about bibleref; it is certainly worth a look. I knew about xindy`, but I was hoping someone had already had to do something similar to this. –  jon Sep 26 '11 at 15:22