# LaTeX/Indexing

* LaTeX
* Getting Started
* Introduction
* Installation
* Installing Extra Packages
* Basics
* How to get help
* Common Elements
* Document Structure
* Text Formatting
* Paragraph Formatting
* Colors
* Fonts
* List Structures
* Special Characters
* Internationalization
* Rotations
* Tables
* Title creation
* Page Layout
* Customizing Page Headers and Footers‎
* Importing Graphics
* Floats, Figures and Captions
* Footnotes and Margin Notes
* Hyperlinks
* Labels and Cross-referencing
* Initials
* Mechanics
* Errors and Warnings
* Lengths
* Counters
* Boxes
* Rules and Struts
* Technical Text
* Mathematics
* Advanced Mathematics
* Theorems
* Chemical Graphics
* Algorithms
* Source Code Listings
* Linguistics
* Special Pages
* Indexing
* Glossary
* Bibliography Management
* More Bibliographies
* Special Documents
* Scientific Reports (Bachelor Report, Master Thesis, Dissertation)
* Letters
* Presentations
* Teacher's Corner
* Curriculum Vitae
* Academic Journals (MLA, APA, etc.)
* Creating Graphics
* Introducing Procedural Graphics
* MetaPost
* Picture
* PGF/TikZ
* PSTricks
* Xy-pic
* Creating 3D graphics
* Programming
* Macros
* Plain TeX
* Creating Packages
* Creating Package Documentation
* Themes
* Miscellaneous
* Modular Documents
* Collaborative Writing of LaTeX Documents
* Export To Other Formats
* Help and Recommendations
* FAQ
* Tips and Tricks
* Appendices
* Authors
* Links
* Package Reference
* Sample LaTeX documents
* Index
* Command Glossary
Especially useful in printed books, an index is an alphabetical list of words and expressions with the pages of the book upon which they are to be found. LaTeX supports the creation of indices with its package makeidx, and its support program makeindex, called on some systems makeidx.

## Using makeidx

To enable the indexing feature of LaTeX, the makeidx package must be loaded in the preamble with:
* \usepackage{makeidx}
and the special indexing commands must be enabled by putting the
* \makeindex
command into the input file preamble. This should be done within the preamble, since it tells LaTeX to create the files needed for indexing. To tell LaTeX what to index, use
* \index{key}
where key is the index entry and does not appear in the final layout. You enter the index commands at the points in the text that you want to be referenced in the index, likely near the reason for the key. For example, the text
* To solve various problems in physics, it can be advantageous
* to express any arbitrary piecewise-smooth function as a
* Fourier Series composed of multiples of sine and cosine functions.
can be re-written as
* To solve various problems in physics, it can be advantageous
* to express any arbitrary piecewise-smooth function as a Fourier Series
* \index{Fourier Series}
* composed of multiples of sine and cosine functions.
to create an entry called 'Fourier Series' with a reference to the target page. Multiple uses of \index with the same key on different pages will add those target pages to the same index entry.
To show the index within the document, merely use the command
* \printindex
It is common to place it at the end of the document. The default index format is two columns.
The showidx package that comes with LaTeX prints out all index entries in the right margin of the text. This is quite useful for proofreading a document and verifying the index.

### Compiling indices

When the input file is processed with LaTeX, each \index command writes an appropriate index entry, together with the current page number, to a special file. The file has the same name as the LaTeX input file, but a different extension (.idx). This .idx file can then be processed with the makeindex program. Type in the command line:
Note that filename is without extension: the program will look for filename.idx and use that. You can optionally pass filename.idx directly to the program as an argument. The makeindex program generates a sorted index with the same base file name, but this time with the extension .ind. If now the LaTeX input file is processed again, this sorted index gets included into the document at the point where LaTeX finds \printindex.
The index created by latex with the default options may not look as nice or as suitable as you would like it. To improve the looks of the index makeindex comes with a set of style files, usually located somewhere in the tex directory structure, usually below the makeindex subdirectory. To tell makeindex to use a specific style file, run it with the command line option:
If you use a GUI for compiling latex and index files, you may have to set this in the options. Here are some configuration tips for typical tools:

#### MakeIndex settings in WinEdt

Say you want to add an index style file named simpleidx.ist
* Texify/PDFTexify: Options→Execution Modes→Accessories→PDFTeXify, add to the Switches: --mkidx-option="-s simpleidx.ist"
* MakeIndex alone: Options→Execution Modes→Accessories→MakeIndex, add to command line: -s simpleidx.ist

### Sophisticated indexing

Below are examples of \index entries:
| Example | Index Entry | Comment |
| \index{hello} | hello, 1 | Plain entry |
| \index{hello!Peter} | Peter, 3 | Subentry under 'hello' |
| \index{hello!Sam@\textsl{Sam}} | Sam, 2 | Subentry formatted and sorted |
| \index{Sam@\textsl{Sam}} | Sam, 2 | Formatted entry |
| \index{Lin@\textbf{Lin}} | Lin, 7 | Same as above |
| \index{Jenny|textbf} | Jenny, 3 | Formatted page number |
| \index{Joe|textit} | Joe, 5 | Same as above |
| \index{ecole@\'ecole} | école, 4 | Handling of accents |
| \index{Peter|see {hello}} | Peter, see hello | Cross-references |
| \index{Greeting|see {hello, Peter}} | Greeting, see hello, Peter | Cross-referencing a subentry |
| \index{Jen|seealso{Jenny}} | Jen, see also Jenny | Same as above |

#### Subentries

If some entry has subsections, these can be marked off with !. For example,
* \index{encodings!input!cp850}
would create an index entry with 'cp850' categorized under 'input' (which itself is categorized into 'encodings'). These are called subsubentries and subentries in makeidx terminology.

#### Controlling sorting

In order to determine how an index key is sorted, place a value to sort by before the key with the @ as a separator. This is useful if there is any formatting or math mode, so one example may be
* \index{F@$\vec{F}$}
so that the entry in the index will show as '${\vec {F}}$' but be sorted as 'F'.
To combine with the above feature for subentries, you should style the appropriate component(s):
* \index{bug reports!In re code@\emph{In re} code}
* \index{LaTeX@\LaTeX!Typesetting engine}

#### Changing page number style

To change the formatting of a page number, append a | and the name of some command which does the formatting. This command should only accept one argument.
For example, if on page 3 of a book you introduce bulldogs and include the command
* \index{bulldog}
and on page 10 of the same book you wish to show the main section on bulldogs with a bold page number, use
* \index{bulldog|textbf}
This will appear in the index as bulldog, 3, 10
If you use texindy in place of makeindex, the classified entries will be sorted too, such that all the bolded entries will be placed before all others by default.

#### Multiple pages

To perform multi-page indexing, add a |( and |) to the end of the \index command, as in
* \index{Quantum Mechanics!History|
* In 1901, Max Planck released his theory of radiation dependent on quantized energy.
* While this explained the ultraviolet catastrophe in the spectrum of
* blackbody radiation, this had far larger consequences as the beginnings of quantum mechanics.
* \index{Quantum Mechanics!History|)}
The entry in the index for the subentry 'History' will be the range of pages between the two \index commands.

#### Using special characters

In order to place values with !, @, or |, which are otherwise escape characters, in the index, one must quote these characters in the \index command by putting a double quotation mark (") in front of them, and one can only place a " in the index by quoting it (i.e., a key for " would be \index{""}).
This rule does not hold for \", so to put the letter ä in the index, one may still use \index{a@\"{a}}.

## Abbreviation list

You can make a list of abbreviations with the package nomencl . You may also be interested in using the glossaries package described in the Glossary chapter. Another option is the package acronym .
To enable the Nomenclature feature of LaTeX, the nomencl package must be loaded in the preamble with:
* \usepackage[⟨options ⟩]{nomencl}
* \makenomenclature
Issue the \nomenclature[⟨prefix⟩]{⟨symbol⟩}{⟨description⟩} command for each symbol you want to have included in the nomenclature list. The best place for this command is immediately after you introduce the symbol for the ﬁrst time. Put \printnomenclature at the place you want to have your nomenclature list.
Run LaTeX 2 times then
followed by running LaTeX once again.
To add the abbreviation list to the table of content, intoc option can be used when declare the nomencl package, i.e.
* \usepackage[intoc]{nomencl}
instead of using the code in Adding Index to Table Of Contents section.
The title of the list can be changed using the following command:
* \renewcommand{\nomname}{List of Abbreviations}

## Multiple indices

If you need multiple indices there are various options available.

### imakeidx

The imakeidx package is part of TeX Live and MiKTeX.
This is an extension to makeidx which allows for the creation of other indices besides or instead of the default one. It has many options and commands to manipulate the output generated.
Indices are defined with multiple calls to the \makeindex command, each of which can have their own options. An entry for a specific index is given by adding the name of the index as an optional parameter to the \index command.
* \usepackage{imakeidx}
* \makeindex[title=Concept index] % Create the default index
* \makeindex[name=persons,title=Index of names,columns=3] % Create an index named 'persons'
* \begin{document}
* ...relativity\index{relativity}... % Add an item to the default index
* ... Einstein\index[persons]{Einstein, Albert}... % Add an item to the 'persons' index
* And this is the end of the story.
* \printindex % Ouput the default index here
* \indexprologue{\small In this index you’ll find only famous people’s names}
* \printindex[persons] % Output the 'persons' index
* \end{document}
Entries for either index should be typed as shown above. This example will produce two indices. The default index will be given the title "Concept index", and typeset in the default two columns. The prologue text will be printed only in the 'persons' index, which will have the title “Index of names”, and be typeset in three columns.
Other options for each index allow you to determine if and how the index title appears in the Table of Contents, what style file to use, to set the page headers, and more.
There will be no need to call the makeindex program explicitly from the command line. Similar to ToC generation, the indices will be generated by simply running LaTeX. There are options available to use the xindy program instead of makeindex.
Note that imakeidx can process any TeX source file which was written for MakeIndex directly. If you have an existing source and want to split up the existing index or add extra indices, simply change makeidx to imakeidx in the \usepackage{...} command, and the output will be the same. You can then add commands and options to make multiple indices.

### multind

Also available is multind .
This package provides the same commands as makeidx, but now you also have to pass a name as the first argument to every command.
* \usepackage{multind}
* \makeindex{books}
* \makeindex{authors}
* \index{books}{A book to index}
* \index{authors}{Put this author in the index}
* \printindex{books}{The Books index}
* \printindex{authors}{The Authors index}

## Adding index to table of contents

By default, Index won't show in Table Of Contents, so you have to add it manually.
To add index as a chapter, use these commands:
* \clearpage
* \addcontentsline{toc}{chapter}{Index}
* \printindex
If you use the book class, you may want to start it on an odd page by using \cleardoublepage.

## International indices

If you want to sort entries that have international characters (such as ő, ą, ó, ç, etc.) you may find that the sorting "is not quite right". In most cases the characters are treated as special characters and end up in the same group as @, ¶ or µ. In most languages that use Latin alphabet it's not correct.
The following section describes xindy, but note this program is currently obsolete and there are new alternatives, like upmendex and xindex.

### Generating the index

Unfortunately, the current version of xindy and hyperref are incompatible. When you use textbf or textit modifiers, texindy will print the error message:unknown cross-reference-class `hyperindexformat'! (ignored) and won't add those pages to the index. A work-around for this bug is described on the talk page.
To generate an international index file you have to use texindy instead of makeindex.
xindy is a much more extensible and robust indexing system than the makeindex system.
For example, one does not need to write:
* \index{Lin@\textbf{Lin}}
to get the Lin entry after LAN and before LZA, instead, it's enough to write
* \index{\textbf{Lin}}
But what is much more important, it can properly sort index files in many languages, not only English.
Unfortunately, generating indices ready to use by LaTeX using xindy is a bit more complicated than with makeindex.
First, we need to know in what encoding the .tex project file is saved. In most cases it will be UTF-8 or ISO-8859-1, though if you live, for example in Poland it may be ISO-8859-2 or CP-1250. Check the parameter to the inputenc package.
Second, we need to know which language is prominently used in our document. xindy can natively sort indices in Albanian, Belarusian, Bulgarian, Croatian, Czech, Danish, Dutch, English, Esperanto, Estonian, Finnish, French, Georgian, German, Greek, Gypsy, Hausa, Hebrew, Hungarian, Icelandic, Italian, Klingon, Kurdish, Latin, Latvian, Lithuanian, Macedonian, Mongolian, Norwegian, Polish, Portuguese, Romanian, Russian, Serbian Slovak, Slovenian, Sorbian, Spanish, Swedish, Turkish, Ukrainian and Vietnamese,
I don't know if other languages have similar problems, but with Polish, if your .tex is saved using UTF-8, the .ind produced by texindy will be encoded in ISO-8859-2 if you use only -L polish. While it's not a problem for entries containing polish letters, as LaTeX internally encodes all letters to plain ASCII, it is for accented letters at beginning of words, they create new index entry groups, if you have, for example an "średnia" entry, you'll get a "Ś" encoded in ISO-8859-2 .ind file. LaTeX doesn't like if part of the file is in UTF-8 and part is in ISO-8859-2. The obvious solution (adding -C utf8) doesn't work, texindy stops with
error. To fix this, you have to load the definition style for the headings using -M switch:
In the end we have to run such command:
An additional way to fix this problem is use "iconv" to create utf8.xdy from latin2.xdy
in directory
(You must have root privileges)

#### xindy in kile

To use texindy instead of makeindex in kile, you have to either redefine the MakeIndex tool in Settings → Configure Kile... → Tools → Build, or define new tool and redefine other tools to use it (for example by adding it to QuickBuild).
The xindy definition should look similar to this: