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:
\documentclass{scrbook}
\usepackage{showidx}
\usepackage[noautomatic]{imakeidx}
\makeindex[program=texindy]
\makeindex[name=nameindex,program=texindy,title=Namensindex]
\title{title}
\author{author}
\begin{document}
\frontmatter
\index{frontmatter}
\index[nameindex]{frontmatter}
\maketitle
\index{aftertitle}
\index[nameindex]{aftertitle}
\tableofcontents
\index{aftertoc}
\index[nameindex]{aftertoc}
\mainmatter
\index{mainmatter}
\index[nameindex]{mainmatter}
\chapter{A}
\index{chapA}
\index[nameindex]{chapA}
\chapter{B}
\index{chapB}
\index[nameindex]{chapB}
\appendix
\index{appendix}
\index[nameindex]{appendix}
\chapter{1}
\index{chap1}
\index[nameindex]{chap1}
\chapter{2}
\index{chap2}
\index[nameindex]{chap2}
\backmatter
\index{backmatter}
\index[nameindex]{backmatter}
\printindex
\printindex[nameindex]
\index{afterindex}
\index[nameindex]{afterindex}
\end{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
\indexentry{backmatter}{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'.
[11
\indexentry{afterindex}{11}
\indexentry{afterindex}{11}
] (./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:
- First TeX run, collect all the
\index
entries in the .idx file. - Run makeindex or xindy on the .idx file to generate the .ind file.
- 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:
[...]
\printindex
\printindex[nameindex]
\index{afterindex}
\index[nameindex]{afterindex}
\prepareindex
\prepareindex[nameindex]
\end{document}
imakeidx
you cannot have\index
after\printindex
unless you use thenoautomatic
option and runmakeindex
manually. So the answer is short: no, if you want the automatic run ofmakeindex
.noautomatic
option and I did run xindy manually, however the result is as described.\index
after\printindex
, see tex.stackexchange.com/questions/423330/…