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. |
\printindex | Prints 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}Compiled with pdfLaTeX from TeX Live 2023. Tools run in this order: pdflatex → makeindex → pdflatex.
Pitfalls
- Load
imakeidxinstead ofmakeidx, not in addition to it. - The characters
!,@and|have a meaning inside\index. To index one of them literally, put a straight double quote in front of it. \index{Font}and\index{font}are two different entries, and so are entries that differ in a space. Write an entry the same way every time.- With the option
intoc, the line in the table of contents needs one more LaTeX run after the index exists.
Related pages
- How-to Create an index in LaTeX
- Package
glossaries - Package
nomencl - How-to Create a table of contents in LaTeX