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)

delim_0 "\\nobreak\\dotfill"
% \indexsetup{level=\section,toclevel=section}
\makeindex[options={-s mydotfill.ist},intoc,name=person,title={Index of persons}]
\makeindex[options={-s mydotfill.ist},intoc]
Heisenberg\index[person]{Heisenberg} % Person index
\indexprologue{\small In this index you’ll find only
famous people’s names}

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

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:

\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:

enter image description here

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:

\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:

enter image description here

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.

| improve this answer | |
  • 1
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.