It seems that there is a built-in assumption that a \printindex command cannot be followed by further \index commands.

I am working on a document that continues past the pages the \printindex command creates. And this part contains a citation. Each citation is followed by its author, whose name should go into the nameindex.

Here is a MWE derived from the document:


Every \index command is doubled, so both indices should contain the same entries. However the created test.pdf on my system has two entries (backmatter, afterindex) missing in the default index and one (afterindex) missing from the nameindex.

I'm using a recent LuaTeX version 0.79.1 from TL2014 to process it. The relevant part of the log is the following:

Writing index file test.idx
Writing index file nameindex.idx
(./test.aux) [1{/usr/local/texlive/2014/texmf-var/fonts/map/pdftex/updma/pdftex.map}] [2] (./test.toc) [3] [4]
Chapter 1.
[1] [2]
Chapter 2.
[3] [4]
Appendix A.
[5] [6]
Appendix B.
[7] [8] (./test.ind) [9
] [10] (./nameindex.ind)

Package imakeidx Warning: Remember to run lualatex again after calling
(imakeidx)                `texindy test.idx'.

Package imakeidx Warning: Remember to run lualatex again after calling
(imakeidx)                `texindy nameindex.idx'.

] (./test.aux))
 328 words of node memory still in use:
Output written on test.pdf (15 pages, 47727 bytes).

I was under the impression that the general scheme for index generation is as follows:

  1. First TeX run, collect all the \index entries in the .idx file.
  2. Run makeindex or xindy on the .idx file to generate the .ind file.
  3. Second TeX run, the \printindex command imports the .ind file.

Thus my assumptions was that the collection part and the import part are fully decoupled. All \index commands are collected in the .idx file no matter if the appear before or after the \printindex command. And the \printindex command does not participate in the collection process and only imports the generated .ind file.

But the MWE obviously invalidates my assumption. While doing my RTFM-chores I found that the imakeidx documentation clearly states:

\printindex is used to typeset the particular index named if no optional argument is specified, the default index with name \jobname.ind is typeset. Actually this command activates all the mechanism of closing the output to the raw index file, shelling out, possibly calling the splitindex script in order to divide the single raw file generated by the typesetting engine into distinct raw files according to the default or specified for each index, calling the sorting and formatting program on each of these split raw files (unless inhibited by a noautomatic option; in which case a warning is issued in order to remember the typesetter that this particular index has not been processed), producing the sorted and formatted .ind files, and eventually inputs and typesets these formatted files. Deep breath.

So \printindex is indeed \involved in both the collection and import part. Is there a way to split this in two commands? So I could write something like:

  • 1
    With imakeidx you cannot have \index after \printindex unless you use the noautomatic option and run makeindex manually. So the answer is short: no, if you want the automatic run of makeindex. – egreg Jan 16 '15 at 22:45
  • @egreg The MWE uses the noautomatic option and I did run xindy manually, however the result is as described. – uli Jan 16 '15 at 22:51
  • For a 2018 1Q example of using \index after \printindex, see tex.stackexchange.com/questions/423330/… – Saphar Koshet Oct 30 '18 at 17:58

Your Answer

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

Browse other questions tagged or ask your own question.