# Record multiple indexes in the table of contents

I have a document with multiple indexes. All of the indexes should be mentioned in the table of contents (as well as similar elements such as the bibliography). I use the index package to define alternative indexes and the tocbibind package to list them in the table of contents.

\documentclass{article}
\usepackage{index}
\usepackage{tocbibind}
\newindex{other}{odx}{ond}{Other index}
\makeindex
\begin{document}
\tableofcontents
\index{foo}
\index[other]{bar}
This page is intentionally not left blank.
\printindex
\printindex[other]
\end{document}


I'd expect the second index to be called “Other Index”, but both the title on the last page and the corresponding entry in the table of contents read “Index” instead. This is the fault of the tocbibind package: without it, the title appearing on the last page is correct — but of course the indexes aren't listed in the table of content.

This is kind of mentioned in the tocbibind documentation:

the heading text is picked up from the \indexname [command]. The heading texts can be changed by changing the standard commands, or by using \setindexname{name} […]

Ok, but how do I do this for multiple indexes with different titles?

I'd prefer to stick to index, but I'll switch to an alternative if I really need to. However the problem seems to be in tocbibind. Is there an alternative for that?

## 2 Answers

Isn't this what you want? For a quick setup, using \setindexname{Other Index} is perhaps the easiest way to achieve this.

index is an old package and most likely the authors of tocbibind hadn't this package in mind when they developed tocbibind.

Another possibility would be imakeidx.

\documentclass{article}
\usepackage{index}
\usepackage{tocbibind}
\newindex{other}{odx}{ond}{Other index}
\makeindex
\begin{document}
\tableofcontents
\index{foo}
\index[other]{bar}
This page is intentionally not left blank.
\printindex
\setindexname{Other index}
\printindex[other]
\end{document}

• Thanks but I'd rather keep the nastiness in the preamble (actually I'm stuffing it into a local package) and keep the documents clean. The document-side solution also doesn't work for the index package's prologue feature (which admittedly I'm not using right now). – Gilles 'SO- stop being evil' Apr 14 '16 at 12:39

The problem is that the tocbinind package and the index package both redefine the theindex environment, so whichever gets loaded last destroys the customizations made by the other one.

The tocbibind package does some relatively complex analysis to determine which kind of section heading to insert. The index package adds two simple things: it redefines \indexname according to the first optional argument to \printindex, and it adds a prologue below the section or chapter title. So I'll load index first, then tocbibind, and then patch in the functionality from the index package.

\usepackage{index}
\usepackage{tocbibind}
% Patch the functionality from the index package into the {theindex}
% environment, where it was overridden by the tocbibind package. Note that
% this assumes that index was loaded first, then tocbibind.
\let\theindex@beforeindex\theindex
\def\theindex{%
\edef\indexname{\the\@nameuse{idxtitle@\@indextype}}%
\let\@topnewpage@real\@topnewpage
\def\@topnewpage[##1]{\@topnewpage@real[##1%
\ifx\index@prologue\@empty\else%
\index@prologue%
\bigskip%
\fi%
]%
\let\@topnewpage\@topnewpage@real%
}%
\theindex@beforeindex%
}


For just the multiple index feature of index, and not the prologue feature, the redefinition would be a lot simpler:

\let\theindex@beforeindex\theindex
\def\theindex{%
\edef\indexname{\the\@nameuse{idxtitle@\@indextype}}%
\theindex@beforeindex%
}


or

\def\index@redefine@indexname{\edef\indexname{\the\@nameuse{idxtitle@\@indextype}}}
\expandafter\def\expandafter\theindex\expandafter{%
\expandafter\index@redefine@indexname%
\theindex@beforeindex%
}