The imakeidx package

Creates an index from \index entries with \makeindex and \printindex, runs MakeIndex during the compilation and supports several indexes in one document.

Loading the package

\usepackage{imakeidx}

The older package makeidx leaves the sorting to you: LaTeX, then the program MakeIndex, then LaTeX again. imakeidx starts MakeIndex itself at the end of the run, so the index is up to date after one LaTeX run. TeX Live permits this call in its default restricted shell mode.

When external programs are switched off completely (-no-shell-escape), the package prints a reminder in the log and you run makeindex main yourself, followed by one more LaTeX run.

Layout settings go into the optional argument of \makeindex: the number of columns, the title and whether the index appears in the table of contents.

Main commands

\makeindex[columns=2, title=Index, intoc]Preamble: switches the index on and sets its layout.
\index{font}Adds the current page to the entry "font". The command prints nothing in the text.
\index{font!encoding}Subentry "encoding" below "font".
\index{alpha@$\alpha$}Sorted as "alpha", printed as the symbol.
\index{kerning|textbf}Page number in bold, for the main reference.
\index{typeface|see{font}}Cross-reference to another entry instead of a page number.
\printindexPrints the index at this place.
\makeindex[name=persons, title=Index of persons]A second index; fill it with \index[persons]{...} and print it with \printindex[persons].

Complete example

\documentclass{article}
\usepackage{imakeidx}
\makeindex[columns=2, title=Index]
\begin{document}
\section{Fonts}
A font\index{font} has an encoding\index{font!encoding}.
Kerning\index{kerning|textbf} adjusts the space between two letters.
The letter $\alpha$\index{alpha@$\alpha$} is sorted under a.
Another word for font is typeface\index{typeface|see{font}}.

\printindex
\end{document}
Result
Page 1 of the compiled examplePage 1
Page 2 of the compiled examplePage 2

Compiled with pdfLaTeX from TeX Live 2023. Tools run in this order: pdflatex → makeindex → pdflatex.

Pitfalls

Related pages