# \indexsetup and intoc from imakeidx package problem

I'm writing a little documentation in which I'll use some indexes per section, everything is OK using the default options of the imakeidx package, but, when trying to use \indexsetup things don't work as I wish. This is my MWE (it's data taken from other posts but it exemplifies the problem)

\begin{filecontents*}{mydotfill.ist}
delim_0 "\\nobreak\\dotfill"
\end{filecontents*}
\documentclass{article}
\usepackage{imakeidx}
\usepackage{lipsum}
\usepackage{hyperref}
% \indexsetup{level=\section,toclevel=section}
\makeindex[options={-s mydotfill.ist},intoc,name=person,title={Index of persons}]
\makeindex[options={-s mydotfill.ist},intoc]
\begin{document}
\tableofcontents
\section{First}
\lipsum[1]
Einstein\index[person]{Einstein}
\lipsum[2]
\section{Second}
Heisenberg\index[person]{Heisenberg} % Person index
\lipsum[3]
\index{foo}
\index{bar}
\lipsum[4]
\indexprologue{\small In this index you’ll find only
famous people’s names}
\printindex[person]
\printindex
\end{document}


The index and table of contents generated are correct, but when using \indexsetup the output is:

I tried to do it using the noautomatic option and running makeindex manually, but the result is the same and I have to compile three times (instead of two).

If the question is duplicated I would appreciate the link to it (I have searched a long time in the forum and have not found the answer).

Minor (related) questions: Is it necessary for imakeidx to run makeindex every time it is compiled? ... or would it be sufficient to run makeindex on the first build?

This happens because you do level=\section, which makes \section{\indexname} at the beginning of the index (which adds a ToC entry), and then you do intoc,toclevel=section, which adds a section ToC entry for the index. Then you get what you get :-)

You should use only one of the two. If you want numbered index sections, then just use level=\section:

\indexsetup{level=\section}
\makeindex[options={-s mydotfill.ist},name=person,title={Index of persons}]
\makeindex[options={-s mydotfill.ist}]


then the indexes will already start with \section, and LaTeX will do the right thing. The output looks like:

And if you want unnumbered sections for the indexes, then you have to explicitly ask for intoc and tell imakeidx to make a section-level ToC entry:

\indexsetup{toclevel=section}
\makeindex[options={-s mydotfill.ist},intoc,name=person,title={Index of persons}]
\makeindex[options={-s mydotfill.ist},intoc]


(here level=\section* is the default). The output will look like:

Minor (related) answers: It's not strictly necessary to run makeindex in every run. You just need a makeindex run when you add/remove/change an index entry. But for imakeidx to detect that it would either require -shell-escape (and something like md5sum or whatnot) or it would need to manually check for every index entry, which would probably be more time- and memory-consuming than running makeindex every time.

• Thank you very much for the answer and clarification from makeindex, seeing your answer I feel a little silly, when I checked the documentation I didn't realize that the two options were disjointed :) – Pablo González L Mar 8 at 1:59