# imakeidx: Is it safe to direct \index to an undefined index?

I am (still!) writing a biblatex style for legal citations. I am about to tackle indexing, and I want to make sure I have a viable plan. It's a pretty critical part of the project.

Here's the issue. Legal books use lots of indices. Even a modest work could easily index English cases in one index, EU cases alphabetically in another, EU cases by number in a third, English statutes in a fourth, English secondary legislation in a fifth, rules of court in a sixth, EU directives, regulations and decisions, alphabetically and by number in a seventh, eighth, ninth, tenth, eleventh and twelfth.

Using a combination of entrytype, subentrytype and a user field, I can determine what sort of literature I'm dealing with. And assume for present purposes that I can construct indexing "strings" which will enable correct sorting and printing of index entries (actually, not easy, but that's another question). What I'm worrying about at the moment is how to allocate entries to particular indexes.

You see, it has to be flexible. If I'm writing a book about (say) English law, I might be quite happy to put all non-English cases in a single index. But if I'm writing a book on comparative law, the prevailing standard would undoubtedly want me to have separate indexes for US, Canadian, Australian cases.

I'm planning to (suggest/provide for) the use of imakeidx, which I like because it offers what seems a simple and convenient system which will work nicely with splitindex, which is likely to be needed, given the number of indexes. My current plan is to "write" to indexes defined by macros. So, for instance, a citation of an EU case would do something like:

\index[\eualphabetical]{title}
\index[\eunumerical]{number@number, title}


And so forth. The user can then \renewcommand{\eualphabetical} and so on, to direct entries to appropriate indexes, set up as required for a particular document. So, for instance, if the user wanted statutes and statutory instruments in the same index, s/he could do

\renewcommand{\ukstatutes}{statutes}
\renewcommand{\ukstatutoryinstruments}{statutes}


and set up a suitable statutes index, which would be fed data for both types of literature.

Here's my question. One likely use case is that a user won't really want every possible index. Suppose we have

\renewcommand{\eunumerical}{dummy}% DUMMY NOT DEFINED


where dummy is not defined in any \makeindex command. On the face of it this would be very convenient. I've tested it myself, and I don't seem to get errors from imakeidx or splitindex; but I'm worried that I don't understand enough to be sure that there's not something going on underneath the surface that might bite me later. Is it safe? Or do I need to check for undefined indexes and prevent any attempt to write to them.

-
If you don't say \printindex[name] the index is produced, but not used. I'd suggest to define the dummy index; the corresponding file will collect what's not needed. – egreg Apr 30 '12 at 21:13

This should be something like you are trying to use:

\documentclass{book}
\usepackage{imakeidx}
\makeindex[name=statutes,title=Statutes]
\makeindex[name=dummy]
\newcommand{\eunumerical}{statutes}
\newcommand{\eualphabetical}{dummy}

\begin{document}
\chapter{abc}
\index[\eualphabetical]{title}
\index[\eunumerical]{number@number, title}

\printindex[\eunumerical]

\end{document}


If no \printindex[dummy] command is issued, the relative index is not printed. However, if no

\makeindex[name=dummy]


command is present, you'll get warnings such as

Package imakeidx Warning: Undefined index file dummy' on input line 10.
`

so it's best to define it.

-