Strona domowa

Witam na mojej prywatnej stronie internetowej!

[If this is all Polish to you, click here: English]

Uwaga: z oczywistych powodów nie mogę zagwarantować swojej nieomylności, choć staram się o zgodność tego, co piszę, z Prawdą. Jest również oczywiste, że nie gwarantuję takiej zgodności w przypadku komentarzy. Umieszczenie linku do strony spoza niniejszego serwisu nie musi oznaczać, że podzielam poglądy autora tej strony, a jedynie, że uważam ją za wartościową z takich czy innych powodów.

Marcin ‘mbork’ Borkowski

2015-07-25 Multiple indices in a LaTeX document with splitidx

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:


\newindex[Index of notions and theorems]{idx}
\newindex[Index of symbols]{isy}

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)$}.


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.



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.]

\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)$.]

After compiling it, I called splitindex indices-example from the command line (I could as well call 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!

CategoryEnglish, CategoryBlog, CategoryTeX, CategoryLaTeX

Komentarze na tej stronie