5

This minimum example is behaving very strangely on my computer:

\documentclass[a4paper]{book}
\usepackage{imakeidx}
\makeindex
\makeindex[name=foo]

\begin{document}
    \printindex %if I delete this line, both indices at the end show up as expected
    %if it is here, there is no index at the beginning of the file
    %and only the foo index shows up after the "content"
    \index[foo]{Some word} asdadas
    \index{Another} asdadas
    \printindex
    \printindex[foo]
\end{document}

Problem is, I want the index to be at the beginning of the book. What seems to happen is that the first printindex somehow causes the .idx and the resulting .ind file to be empty.

Is this a configuration error or is something wrong in the code I provided?

Taxel
  • 329
  • imakeidx is intended as a one-pass mechanism, so the index data will only be available at the end of the run. you might try using the [original] option (not tested), but i am pretty sure that the simple fact of specifying \makeindexwill cause the.idxfile to be deleted. with[original], it will be necessary to runmakeindexseparately, but the deletion of the.ind` file might be spared. – barbara beeton Mar 26 '18 at 20:45
  • thanks for the answer. I conclude from your answer that it is not a configuration issue but indended behavior. Unfortunately, [original] does not work. Is there another package you can recomment which supports multiple indices? – Taxel Mar 26 '18 at 21:12
  • a quick look at ctan shows the following possibilities: index, multind, splitindex and xindy. i don't have experience with any of those. but imakeidx is the most up to date, and its author is active in this forum. i'll poke him and ask him to look at this question. – barbara beeton Mar 26 '18 at 21:20

2 Answers2

4

You cannot have anything producing an index entry after the corresponding \printindex command, because the .idx file needs to be closed for being processed by MakeIndex.

You can use the noautomatic option, but you will need to run manually MakeIndex. If you don't need special formatting for the various indices, using splitindex will ease the job.

\documentclass[a4paper]{book}
\usepackage[splitindex,noautomatic]{imakeidx}

\makeindex
\makeindex[name=foo]

\begin{document}

\printindex

\index[foo]{Some word} asdadas
\index{Another} asdadas

\printindex

\printindex[foo]

\end{document}

After running LaTeX on this file, say taxel.tex, call

splitindex taxel

and rerun LaTeX.

Otherwise, you will need to run MakeIndex separately.

You will find some advice in the log file and the console:

Package imakeidx Warning: Remember to run (pdf)latex again after calling
(imakeidx)                `splitindex' and processing the indices.

for the splitindex case and

Package imakeidx Warning: Remember to run (pdf)latex again after calling
(imakeidx)                `makeindex taxel.idx'.


Package imakeidx Warning: Remember to run (pdf)latex again after calling
(imakeidx)                `makeindex foo.idx'.

for the other case.

egreg
  • 1,121,712
0

Here is a trick you could use if you have a small number of words to index following the \printindex command(s).

(I know the question was about a case with the full document following the indexpage, in which case the answer given earlier is a better approach, but I felt it to be useful to present this trick as well.)

I had a (largish) document with one page following the index-pages. On that last page I had two (pst-geo) maps displaying the most important towns in the main document. I wanted those towns to be referenced in the place-names index (along with the references into the main document) .

At some convenient place before the call to \printindex[places], I included the following:

\newcommand{\mapspage}[1]{119} % Check and adjust page-number
\index[places]{Amsterdam|mapspage}
\index[places]{Jakarta|mapspage}

The page-number (119 in my case) needs to be checked and adjusted by hand, just before the final print run of LaTeX.

Of course, this only works for a small number of \index entries on a very small number of pages following the index, but if that's your case, this could do the trick.

pe1aqp
  • 13