An often requested feature in a book is multiple indices. Typically, there are separate indices of notions and theorems, of people’s names, and/or of symbols. Unfortunately (and unsurprisingly, I regret to say), standard LaTeX provides only one bare-bones index. There are of course a few tools to solve this problem. One of them is the splitidx
package.
Let’s start with its main disadvantage, so that we have that said and don’t have to repeat it: it either lets create only a limited number of indices, or needs a separate external program. The reason for that is simple: standard LaTeX can’t open too many files simultaneously, so if you have too many indices (each made using a separate idx
file), you’re out of luck. Then, splitidx
can just write all the entries to one common file, which is then postprocessed using the SplitIndex
program in order to divide the indices.
The consequence of that is also obvious: if you are on a real operating system, you just run the Perl script (there are also a few other versions: a C one, a Java one, a Lua one and a TeX one, though the latter is limited in its possibilities) and that’s it. If you’re on Windows, though, it is also possible to use splitidx
, but you have to figure it out yourself, and I won’t help you; most probably, though, you’ll have Java installed anyway, so you could go that route. Consult the manual for details.
So let’s get to business now. How to use splitidx
? Basically, instead of \usepackage{makeidx}
you just say \usepackage{splitidx}
(with option [split]
, if you don’t have too many indices and want to avoid the SplitIndex
program). Then, you can use \printindex*
to typeset all the indices automatically.
Let us see a simple example. Let’s make an indices-example.tex
file like this:
\documentclass{article} \usepackage[split]{splitidx} \makeindex \newindex[Index of notions and theorems]{idx} \newindex[Index of symbols]{isy} \begin{document} We will first define the notion of a~\emph{metric space}\sindex{space!metric}, which we will usually denote by $(X,d)$\sindex[isy]{Xd@$(X,d)$}. \printindex* \end{document}
Compiling it will generate two idx files: indices-example.idx
and indices-example-isy.idx
. Of course, you’ll have to run makeindex
(or texindy
) more than once – once for each idx file. Then, you recompile your LaTeX file and that’s it!
Let us stop for a moment yet, and do one more thing, which is not trivial with splitidx
. Assume that we want to start each index with a short introductory text. It turns out that it’s easy, if you know how to do it. Here’s an example. This time – just for the sake of demonstration – we won’t use the [split]
option. Again, assume that these are the contents of the indices-example.tex
file.
\documentclass{article} \usepackage{splitidx} \makeindex \newindex{idx} \newindex{isy} \begin{document} We will first define the notion of a~\emph{metric space}\sindex{space!metric}, which we will usually denote by $(X,d)$\sindex[isy]{Xd@$(X,d)$}. Then we will define a~\emph{ball}\sindex{ball}, which we will denote by $B(x_0,r)$\sindex[isy]{Bx0r@$B(x_0,r)$}. \twocolumn[\section*{Index of notions and theorems}Here is the index of notions, with page number referring to the place where the relevant notion is defined, and theorems.] \printsubindex[idx][] \twocolumn[\section*{Index of symbols}Here is the index of symbols, in (roughly) alphabetic order -- for instance, $B(x_0,r)$ is before $(X,d)$.] \printsubindex[isy][] \end{document}
After compiling it, I called splitindex indices-example
from the command line (I could as well call splitindex.pl indices-example
, or java splitindex indices-example
, or even tex splitindex
. In the last case, I would have to enter the filename (indices-example
) from the keyboard, ad then run makeindex
manually on indices-example-idx
and indices-example-isy
. Then, I can compile indices-example
again and that’s it!
Now that’s pretty much enough if you are satisfied with documents in English. Assume, however, that you write in some other language (in my case, Polish), and want to sort index entries according to Polish rules (that means that the order is not ASCII, but UTF-8-aware, so that “ą” comes between “a” and “b”, for example). Since splitindex
calls makeindex
itself, we can either use the [split]
option again and run texindy
with proper arguments ourselves, or instruct splitindex
to do that. Here’s how you can do it:
splitindex -m texindy -- indices-example -L polish -C utf8
It works like this: the -m
option defines the name of the makeindex
replacement, the filename is after --
, and everything after that is passed to the index generating program (in this case, texindy). Quite a mouthful.
Of course, you have even more options than that. For instance, you can write out section numbers instead of page numbers into the index. Also, you can play around with running headers and/or one- and twocolumn typesetting. All these are covered by splitidx
’s documentation, so if you are interested in those options, read the friendly manual.
Happy TeXing!