The Basics

Each \index command causes LATEX to write an entry on the idx file. The following example shows some simple \index commands and the index entries that they produce. The page number refers to the page containing the text where the \index command appears.1

 Page ii \index{Alpha}  
 Page viii: \index{alpha}  
 Page ix: \index{alpha}  
   \index{Alphabet}  
 Page 22: \index{alpha}  
   \index{alphas}  
 Page 23: \index{alphabet}  
   \index{alphabet}  
 Page 24: \index{alpha bet}  


Alpha, ii 

alpha, viii, ix, 22
alpha bet, 24
Alphabet, ix
alphabet, 23
alphas, 22
Note that the duplicate \index{alphabet} commands on page 23 produce only one ``23'' in the index.

To produce a subentry, the argument of the \index command should contain both the main entry and the subentry, separated by a ! character.

 Page 7: \index{gnat!size of}  
 Page 32: \index{gnat}  
 Page 35: \index{gnat!anatomy}  
   \index{gnus!good}  
 Page 38: \index{gnus!bad}  
      


gnat, 32 

anatomy, 35
size of, 7
gnus
bad, 38
good, 35
You can also have subsubentries.
 Page 8: \index{bites!animal!gnats}  
 Page 10: \index{bites!animal!gnus}  
 Page 12 : \index{bites!vegetable}  
      
      


bites              

animal
gnats, 8
gnus, 10
vegetable, 12
LATEX and MakeIndex support only three levels of indexing; you can't have subsubsubentries.

To specify a page range, put an \index{...|(} command at the beginning of the range and an \index{...|)} command at the end of the range.

 Page vi: \index{gnat|(}  
 Page x: \index{gnat|)}  
 Page 22: \index{gnat}  
   \index{gnus!bad|(}  
   \index{gnus!bad|)}  
 Page 28: \index{gnus!good|(}  
 Page 30: \index{gnus!good}  
 Page 32: \index{gnus!good|)}  


gnat, vi–x, 22 

gnus
bad, 22
good, 28–32
Note that MakeIndex does the right thing when both ends of the range fall on the same page.2

Sometimes, you want to add a cross-reference with no page number. This is done as follows;

 Page 2: \index{at}  
 Page 2: \index{at!bat|see{bat, at}}  


at, 2 

bat, see bat, at
Since the ``see'' entry does not print any page number, it doesn't matter where the \index{...|see{...}} command goes, so long as it follows the \begin{document} command. You might want to put all such cross-referencing commands in one place.

If you specify an entry of the form σ@τ, the string σ determines the alphabetical position of the entry, while the string τ produces the text of the entry.

 Page 44: \index{twenty}  
 Page 46: \index{twenty-one}  
 Page 55: \index{twenty@xx}  


twenty, 44 

xx, 55
twenty-one, 46
This feature is useful because the argument of the \index command provides the actual input string that LATEX uses to generate the index entry. In the following example, the input $\alpha$ produces the symbol α,
 Page 12: \index{alphas}  
 Page 13: \index{alpha}  
 Page 14: \index{alpha@$\alpha$}  


alpha, 13 

α, 14
alphas, 12
Similarly, the command \index{gnu@{\bf gnu}} produces a boldface gnu index entry.

In some indexes, certain page numbers are specially formatted—for example, an italic page number may indicate the primary reference, and an n after a page number may denote that the item appears in a footnote on that page. MakeIndex makes it easy to format an individual page number any way you want. For any string of characters σ, the command \index{...|σ} produces a page number of the form \σ{n}. Similarly, the command \index{...|(σ} may produce a page number of the form \σ{nm}. Thus, suppose the document contains the following command definitions:

\newcommand{\ii}[1]{{\it #1}}
\newcommand{\nn}[1]{#1n}
We could then have:
 Page 3: \index{gnat|ii}  
 Page 4: \index{gnat|nn}  
 Page 5: \index{gnu}  
 Page 44: \index{gnu|(ii}  
 Page 46: \index{gnu|)}  


gnat, 3, 4n 

gnu, 5, 44–46
The ``see'' option is a special case of this facility, where the \see command is predefined by the makeidx document-style option.