Creating an index using LATEX

Local guide at Communication Systems.


Contents


Introduction

LATEX itself does not support the making of an index. However it supports writing index information onto a file and it supports importing an already formatted index. There is another program called MakeIndex that processes the index information into a formatted index. This document is a short manual for making an index in a LATEX file using this approach.


Necessary LATEX-code

You need the following in your LATEX-file

  \usepackage{makeidx}   in the preamble to define commands.
  \makeindex             in the preamble to create a .idx file.
  \printindex            in the end of the document to print the .ind file.

Syntax:

  \documentclass[...]{...}
  ...
  \usepackage{makeidx}
  ...
  \makeindex
  ...
  \begin{document}
    ...
    \printindex
  \end{document}


The program MakeIndex

You also need the program MakeIndex to compile the .idx file to a .ind file.

To create an index in your document,

If you are using AUCTEX in EMACS you can run MakeIndex using the command C-c C-c Index.


The \index command

The \index command is used in your text to create an index entry pointing at that page. The syntax of this command is as follows.

  Normal entries:
    Simple index entry:     \index{alpha}                
    Subindex entry:         \index{alpha!beta}           
    Subsubindex entry:      \index{alpha!beta!gamma}     

In the following, alpha may be replaced by alpha!beta or alpha!beta!gamma.

  Page number effects:
    Emphasized page number: \index{alpha|mainidx}
    Boldfaced page number:  \index{alpha|boldidx}

    Page range:             \index{alpha|(}        Begin command
                            ...                    Intermediate text
                            \index{alpha|)}        End command

    Emphasized page range:  \index{alpha|(mainidx} Begin command
                            ...                    Intermediate text
                            \index{alpha|)}        End command

    Bold page range:        \index{alpha|(boldidx} Begin command
                            ...                    Intermediate text
                            \index{alpha|)}        End command

  Special effects:
    Cross ref in index:     \index{alpha|see{delta}}
    Alternative appearence: \index{alpha@delta}    alpha is used for sorting,
                                                   but delta is printed.


OBS!

If you use the mainidx or boldidx syntax above, you will have to add the following definitions in the preamble:

  \newcommand{\mainidx}[1]{{\it #1}}
  \newcommand{\boldidx}[1]{{\bf #1}}

This defines the commands \mainidx and \boldidx that will appear in the .ind file after running MakeIndex.


Creating own effects

The effects mainidx or boldidx above rely on the commands \mainidx and \boldidx defined above. You can create your own effect using the same syntax. After processing the .idx file to the .ind file, an \index{alpha|foo} command will result in the command \foo{n}, where n is the page number. Hence, if you have defined a command \foo taking one argument (the page number) it will work.

Actually you can create more powerful commands if you want to. The effect see{delta}, which uses the predefined command \see, is a good example. After processing the .idx file to the .ind file, an \index{alpha|foo{delta}} command will result in the command \foo{delta}{n}, where n is the page number. Hence, if you have defined a command \foo taking two arguments (your own argument 'delta' and the page number) it will work.

Naturally you can have as many arguments as LATEX accepts if you wish. That normally is 10 arguments including the page number. Hence you can create as powerful commands as you wish. Your fantasy is the limit.


Further reading

More information on LATEX and MakeIndex can be found at Good luck!
Created: Fri Mar 26 1999 by Mikael Olofsson
Last modified: Wed Mar 17, 2010 by Mikael Olofsson
Comments to: Mikael Olofsson ( mikael@isy.liu.se).