Tuesday, January 6, 2009

Adding an index to your document in Latex

Source code required:

  • Include the package makeidx, e.g. \usepackage{makeidx}.
  • Call \makeindex in your preamble.
  • Add index to keywords where desired, e.g. \index{keyword}, \index{keyword!subkeyword},
  • \index{keyword!subkeyword!subsubkeyword}.
  • Call \printindex where your want the index to be generated (usually at the end of the document).

Compiling:

  • Run latex on your main latex file, e.g. latex main.tex. This will create a main.idx file.
  • Run makeindex on the index file, e.g. makeindex main.idx, to generate the index file main.ind.
  • Run latex again on your main file, e.g. latex main.tex.

or

  • Run texify on your main latex file (e.g. texify main.tex) to automatically do all the necessary steps outlined above (and more if necessary).

Example:

  \documentclass{book}
 \usepackage{index}

 \makeindex

 \begin{document}

 This is some very important text about
 Latex \index{latex}. Here is some more.

 \printindex

 \end{document}

References

  1. Leslie Lamport, MakeIndex: An Index Processor For Latex, 1987.