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.

使用 makeidx[編輯]

To enable the indexing feature of LaTeX, the makeidx package must be loaded in the preamble with: \documentclass{artical} \begin{document} Hallo! \end{document}

and the special indexing commands must be enabled by putting the \documentclass{artical} \begin{document} Hallo! \end{document}

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 \documentclass{artical} \begin{document} Hallo! \end{document}

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 \documentclass{artical} \begin{document} Hallo! \end{document} can be re-written as \documentclass{artical} \begin{document} Hallo! \end{document} 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 \documentclass{artical} \begin{document} Hallo! \end{document} 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.

Compiling Indexes[編輯]

When the input file is processed with LaTeX, each ± 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 ±.

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:

MakeIndex Settings in WinEdt[編輯]

Say you want to add an index style file named

  • Texify/PDFTexify: Options→Execution Modes→Accessories→PDFTeXify, add to the Switches: --mkidx-option="-s"
  • MakeIndex alone: Options->Execution Modes→Accessories→MakeIndex, add to command line: -s

Sophisticated Indexing[編輯]

Below are examples of ± entries:

Example Index Entry Comment
±} hello, 1 Plain entry
±}   Peter, 3 Subentry under 'hello'
±}} Sam, 2 Formatted entry
±}} Lin, 7 Same as above
±} Jenny, 3 Formatted page number
±} Joe, 5 Same as above
±} école, 4 Handling of accents
±}} Peter, see hello Cross-references
±}} Jen, see also Jenny Same as above


If some entry has subsections, these can be marked off with !. For example, \documentclass{artical} \begin{document} Hallo! \end{document} would an index 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 \documentclass{artical} \begin{document} Hallo! \end{document} so that the entry in the index will show as '' but be sorted as 'F'.

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 \documentclass{artical} \begin{document} Hallo! \end{document} and on page 10 of the same book you wish to show the main section on bulldogs with a bold page number, use \documentclass{artical} \begin{document} Hallo! \end{document} 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 ± command, as in \documentclass{artical} \begin{document} Hallo! \end{document} The entry in the index for the subentry 'History' will be the range of pages between the two ± commands.

Using special characters[編輯]

In order to place values with !, @, or | in the ± 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 ±}).

This rule does not hold for \", so to put ä in the index, one may still use ±}}.


Note that the ± command can affect your layout if not used carefully. Here is an example:

θ 斜體文字

Abbreviation list[編輯]

You can make a list of abbreviations with the package nomencl [1]. You may also be interested in using the glossaries package described in the Glossary chapter.

To enable the Nomenclature feature of LaTeX, the nomencl package must be loaded in the preamble with: \documentclass{artical} \begin{document} Hallo! \end{document}

Issue the ± 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 ± at the place you want to have your nomenclature list.

Run LaTeX 2 times then

makeindex filename.nlo  -s -o filename.nls

followed by running LaTeX once again.

To add the abbreviation list to the table of content, \left.\begin{array}{r}

 \frac{1}{m}\lg C=\frac{1}{n}\left(\sum_{i=1}^n{Y_i+\frac{1}{m}\sum_{i=1}^n{X_i}}\right)\\

\end{array} \right\} option can be used when declare the nomencl package, i.e. \documentclass{artical} \begin{document} Hallo! \end{document} 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: \documentclass{artical} \begin{document} Hallo! \end{document}

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. \documentclass{artical} \begin{document} Hallo! \end{document}

Adding Index to Table Of Contents[編輯]

By default, Index won't show in Table Of Contents, you have to add it manually.

To add index as a chapter, use this commands: \documentclass{artical} \begin{document} Hallo! \end{document}

If you use book class, you may want to start it on odd page, for this, use ±.

International indexes[編輯]

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.

Generating index[編輯]

Unfortunately, current version of xindy and hyperref are incompatible. When you use \left.\begin{array}{r}

 \frac{1}{m}\lg C=\frac{1}{n}\left(\sum_{i=1}^n{Y_i+\frac{1}{m}\sum_{i=1}^n{X_i}}\right)\\

\end{array} \right\} or \left.\begin{array}{r}

 \frac{1}{m}\lg C=\frac{1}{n}\left(\sum_{i=1}^n{Y_i+\frac{1}{m}\sum_{i=1}^n{X_i}}\right)\\

\end{array} \right\} modifiers, texindy will print error message:unknown cross-reference-class `hyperindexformat'! (ignored) and won't add those pages to index. Work-around for this bug is described on the talk page.

To generate 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: \documentclass{artical} \begin{document} Hallo! \end{document} to get the Lin entry after LAN and before LZA, instead, it's enough to write \documentclass{artical} \begin{document} Hallo! \end{document}

But what is much more important, it can properly sort index files in many languages, not only english.

Unfortunately, generating indexes 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 indexes in albanian, dutch, hebrew, latin, norwegian, slovak, belarusian, english, georgian, hungarian, latvian, polish, slovenian, vietnamese, bulgarian, esperanto, german, icelandic, lithuanian, portuguese, spanish, croatian, estonian, greek, italian, romanian, sorbian, swedish, czech, finnish, gypsy, klingon, macedonian, russian, turkish, danish, french, hausa, kurdish, mongolian, serbian and ukrainian.

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 IS-8859-2. The obvious solution (adding -C utf8) doesn't work, texindy stops with

ERROR: Could not find file "tex/inputenc/utf8.xdy"

error. The fix this, you have to load the definiton style for the headings using -M switch:

-M lang/polish/utf8

In the end we have to run such command:

texindy -L polish -M lang/polish/utf8 filename.idx

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.

The xindy definition should look similar to this:

 Command: texindy
 Options: -L polish -M lang/polish/utf8 -I latex '%S.idx'
 Type: Run Outside of Kile
 Class: Compile
 Source extension: idx
 Target extension: ind
 Target file: <empty>
 Relative dir: <empty>
 State: Editor
 Add tool to Build menu: Compile
 Icon: the one you like

Previous: Labels and Cross-referencing Index Next: Glossary