LaTeX/Indexing
From Wikibooks, the open-content textbooks collection
A useful feature of many books, 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.
Contents |
[edit] 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 cause an entry called 'Fourier Series' to appear with a reference to where ever the space between the words 'Fourier Series' and 'composed' appear.
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 left margin of the text. This is quite useful for proofreading a document and verifying the index.
[edit] Compiling Indexes
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:
makeindex filename
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:
makeindex -s <style file> filename
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:
[edit] 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
[edit] Sophisticated Indexing
Below are examples of index entries:
[edit] Subentries
If some entry has subsections, these can be marked off with !. For example,
\index{encodings!input!cp850}
would an index with 'cp850' categorized under 'input' (which itself is categorized into 'encodings'). These are called subsubentries and subentries in makeidx terminology.
[edit] 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 '
' but be sorted as 'F'.
[edit] 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
[edit] 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 dependant 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.
[edit] Using special characters
In order to place values with !, @, or | in the \index command, one must quote these characters by using a double quotation mark (") and can only show " by quoting it (i.e., a key for " would be \index{""}).
This rule does not hold for \", so to put ȁ in the index, one may still use \index{a@\"{a}}
[edit] Warnings
Note that the \index command can affect your layout if not used carefully. Here is an example:
My Word \index{Word}. As opposed to Word\index{Word}. Note the position of the full stop. |
My Word . As opposed to Word. Note
the position of the full stop. |
[edit] Abbreviation list
You can make a list of abbreviations with the package nomencl [1].
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 first time. Put \printnomenclature at the place you want to have your nomenclature list.
Run LaTeX 2 times then
makeindex filename.nlo -s nomencl.ist -o filename.nls
followed by running LaTeX once again.
[edit] Multiple indexes
If you need multiple indexes you can use the package multind [2].
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}