# Fixing page number references when adding multiple indices to ToC

Friends, I'm stuck with a funny error: when I add multiple indices in my table of contents, all page number references mess up. It's probably something easy to solve, but I can't figure out what it is.

Consider this non-so-minimum example (sorry, I had no choice):

\documentclass[twoside]{book}

\usepackage{idxlayout}

\usepackage[useindex]{splitidx}

\makeindex

\newindex[Index A]{ia}
\newindex[Index B]{ib}
\newindex[Index C]{ic}
\newindex[Index D]{id}

\newcommand*\indexall[1]{%
\sindex[ia]{#1}%
\sindex[ia]{#1#1}%
\sindex[ia]{#1#1#1}%
\sindex[ia]{#1#1#1#1}%
\sindex[ia]{#1#1#1#1#1}%
\sindex[ia]{#1#1#1#1#1#1}%
\sindex[ia]{#1#1#1#1#1#1#1}%
\sindex[ia]{#1#1#1#1#1#1#1#1}%
\sindex[ib]{#1}%
\sindex[ib]{#1#1}%
\sindex[ib]{#1#1#1}%
\sindex[ib]{#1#1#1#1}%
\sindex[ib]{#1#1#1#1#1}%
\sindex[ib]{#1#1#1#1#1#1}%
\sindex[ib]{#1#1#1#1#1#1#1}%
\sindex[ib]{#1#1#1#1#1#1#1#1}%
\sindex[ic]{#1}%
\sindex[ic]{#1#1}%
\sindex[ic]{#1#1#1}%
\sindex[ic]{#1#1#1#1}%
\sindex[ic]{#1#1#1#1#1}%
\sindex[ic]{#1#1#1#1#1#1}%
\sindex[ic]{#1#1#1#1#1#1#1}%
\sindex[ic]{#1#1#1#1#1#1#1#1}%
\sindex[id]{#1}%
\sindex[id]{#1#1}%
\sindex[id]{#1#1#1}%
\sindex[id]{#1#1#1#1}%
\sindex[id]{#1#1#1#1#1}%
\sindex[id]{#1#1#1#1#1#1}%
\sindex[id]{#1#1#1#1#1#1#1}%
\sindex[id]{#1#1#1#1#1#1#1#1}}%
\begin{document}

\tableofcontents

\chapter{My text}

Hello world.

\indexall{A}
\indexall{B}
\indexall{C}
\indexall{D}
\indexall{E}
\indexall{F}
\indexall{G}
\indexall{H}
\indexall{I}
\indexall{J}
\indexall{K}
\indexall{L}
\indexall{M}
\indexall{N}
\indexall{O}
\indexall{P}
\indexall{Q}
\indexall{R}
\indexall{S}
\indexall{T}
\indexall{U}
\indexall{V}
\indexall{W}
\indexall{X}
\indexall{Y}
\indexall{Z}

\printindex[ia]
\printindex[ib]
\printindex[ic]
\printindex[id]

\end{document}


(every time you run this code, a kitten dies)

At least, this time I got odd numbers in my ToC. The previous attempt raised even numbers (!).

The correct reference should be:

Index A -  5
Index B -  9
Index C - 13
Index D - 17


If I put \cleardoublepage before the indices, I get this ToC (the first index is fixed):

I really can't understand what's going on. I can't even establish a pattern.

Does anyone have a suggestion?

(no animals were harmed in the making of this question)

-

Have you tried issuing a \cleardoublepage command before each \addcontentsline command?
I think the problem lies with the way that the TeX engine determines page numbers; judging from some of the discussions I've followed in comp.text.tex on just this subject, TeX's algorithm is unfortunately anything but fail-safe. Hence it's sometimes necessary to add a few \clearpage and/or \cleardoublepage commands here and there to help TeX out. –  Mico Aug 26 '11 at 20:39