星期三, 九月 16, 2009

LaTeX: Indexes and Glossaries

Indexes/Indices

LaTeX can automatically create indexes while you work on your document. To use LaTeX indexing, you must first include the makeidx command in the preamble. The full command is:
\usepackage{makeidx}
\makeindex

When you want to index something, use the command:
\index{Index Entry}

There are several types of index entries that LaTeX can create. These are:

  • Plain entry: uses the basic command \index{cheese} to make an entry for cheese with the current page number
  • Subindex Entry: uses the basic command with an exclamation point to separate the first main entry from the subentry. The command for a single level of subentry appears as such:
    \index{cheese!gouda}
    Subentries can be up to one additional level deep, and the command appears as such:
    \index{cheese!gouda!brie}
  • Cross-references: Entries which are simple "See" and another entry are created using the vertical bar with this command:
    \index{cheese|see{crackers}}
  • Font changes: To change the style of an index entry, use the @ sign followed by a font change command like this:
    \index{Kraft@\textit{Kraft}}
    This example indexes Kraft and italicizes it at the same time. Any of the standard font change commands which use \text... will work within this syntax.
  • Out of sequence: This can be used to make index entries appear out of sequence, so that they appear with the work they represent. For instance:
    \index{cheese@gouda}
    Would place gouda in the list right next to cheese, as if gouda was actually spelled cheese.

When the document has been processed through LaTeX with the index commands included, it will create a .idx file. You will then need to run the .idx file through the makeindex program by typing:
makeindex filename

The filename here is without a file extension. The program will look for the .idx file and will output a .ind file. This file is used by the command:
\printindex

The print index command goes at the end of your document files (the .tex file) and then takes the information from the .ind file to build and include the full index in your paper.

Glossaries

Glossaries are made in the same manner as indexes. Glossaries simply use the commands:
\makeglossary (this is used in the preamble, like the \makeindex command)
\glossary (this is used for the particular entries, like the \index command)

There are some minor differences in how glossaries and indexes are handled. Please see the books by Lamport or Samarin for more information.

没有评论: