LaTeX/Glossary
Many technical documents use terms or acronyms unknown to the general population. It's common practice to add glossaries to make those works more understandable.
The glossaries package was created to assist users in creating glossaries. It supports multiple glossaries, acronyms and symbols.
It replaces the glossary package and can be used instead of the nomencl package.
Contents |
[edit] Using glossaries
To enable the use of glossaries package, you have to load the package:
|
\usepackage{glossaries} |
if you will be using xindy (highly recommended) rather than makeindex you need to specify xindy option:
|
\usepackage[xindy]{glossaries} |
For the glossary to show up in Table of Contents you need to additionally add toc option:
|
\usepackage[toc]{glossaries} |
See also #Custom_TOC-Entry at the bottom of this page.
The glossary index won't be generated until you place the following command in document preamble:
|
\makeglossaries |
Note that the links in generated glossary won't be “clickable” unless you load this package after the hyperref package.
Windows users will need to install Perl for makeglossaries to work.
[edit] Defining glossary entries
To use an entry from glossary you first need to define it. There are few ways to define an entry depending on what you define and how it is going to be used.
Note that a defined entry won't be included in the printed glossary unless it is used in the document. This enables you to create a glossary of general terms and just \include it in all your documents.
[edit] Defining terms
To define a term in glossary you use \newglossaryentry macro:
|
\newglossaryentry{<label>}{<settings>} |
<label> is a unique label used to identify an entry in glossary, <settings> are comma separated key=value pairs used to define an entry.
For example, to define a computer entry:
|
\newglossaryentry{computer} |
The above example defines an entry that has the same label and entry name. This is not always the case as the next entry will show:
|
\newglossaryentry{naiive} |
When you define terms, you need to remember that they will be sorted by makeindex or xindy. While xindy is a bit more LaTeX aware, it does it by ommiting latex macros (\"{\i}) thus incorrectly sorting the above example as nave. makeindex won't fare much better, because it doesn't understand TeX macros, it will interpret the word exactly as it was defined, putting it inside symbol class, before words beginning with naa. Therefore it's needed to extend our example and specify how to sort the word:
|
\newglossaryentry{naiive} |
You can also specify plural forms, if they are not formed by adding “s” (we will learn how to use them in next section):
|
\newglossaryentry{Linux} |
[edit] Defining symbols
Defined entries can also be symbols:
|
\newglossaryentry{pi} |
You can also define both a name and a symbol:
|
\newglossaryentry{real number} |
Note that not all glossary styles show defined symbols.
[edit] Defining acronyms
To define a new acronym you use the \newacronym macro:
|
\newacronym{<label>}{<abbrv>}{<full>} |
where <label> is the unique label identifying the acronym, <abbrv> is the abbreviated form of the acronym and <full> is the expanded text. For example:
|
\newacronym{lvm}{LVM}{Logical Volume Manager} |
Defined acronyms can be put in separate list if you use acronym package option:
|
\usepackage[acronym]{glossaries} |
[edit] Using defined terms
When you have defined a term, you can use it in a document. There are many different commands used to refer to glossary terms.
[edit] General references
A general reference is used with \gls command. If, for example, you have glossary entries defined as those above, you might use it in this way:
|
\Gls{naiive} people don't know about |
Naïve people don't know about alternative computer opera- |
Description of commands used in above example:
|
\gls{<label>} |
This command prints the term associated with <label> passed as its argument. If the hyperref package was loaded before glossaries it will also be hyperlinked to the entry in glossary.
|
\glspl{<label>} |
This command prints the plural of the defined therm, other than that it behaves in the same way as gls.
|
\Gls{<label>} |
This command prints the singular form of the term with the first character converted to upper case.
|
\Glspl{<label>} |
This command prints the plural form with first letter of the term converted to upper case.
[edit] Referring acronyms
Acronyms behave a bit differently than normal glossary terms. On first use the \gls command will display "<full> (<abbrv>)". On subsequent uses only the abbreviation will be displayed.
To reset the first use of an acronym use:
|
\glsreset{<label>} |
or, if you want to reset the use status of all acronyms:
|
\glsresetall |
[edit] Displaying the Glossary
To display the sorted list of terms you need to put:
|
\printglossaries |
at the place you want the glossary and the list of acronyms to be printed.
If all entries are to be printed the command
|
\glsaddall |
can be inserted before \printglossaries. You may also want to use \usepackage[nonumberlist]{glossaries} to suppress the location list within the glossary.
Then you have to do three steps:
- Build LaTeX document, this will generate the files used by makeglossaries
- Run the indexing/sorting, the recommended way is to use makeglossaries (a script that runs xindy or makeindex depending on options in the document with correct encoding and language settings):
makeglossaries <myDocument>
- Build LaTeX document again to get document with glossary entries
If your entries are interlinked (entries themselves link to other entries with \gls) you will need to run points 1 and 2 twice for a total of five program invocations: 1, 2, 1, 2, 3.
[edit] Custom Name
If you wish to display another sectionname, you can use one of these commands to print a custom name. You can also use this, if your the heading is not printed in the correct language.
|
\renewcommand*{\glossaryname}{List of Terms} |
[edit] Custom TOC-Entry
With the toc-Option in the usepackage-command, the glossary is embedded in the TOC as section. Use this code (without the toc-Parameter), to display it like you want (here as subsection):
|
\addcontentsline{toc}{subsection}{Glossar} |
[edit] Remove the point
If you don't want the annoying point at the end of a description, use this code:
|
% Remove dot at the end the descriptions |
[edit] References
- The glossaries documentation, http://tug.ctan.org/tex-archive/macros/latex/contrib/glossaries/
- Using LaTeX to Write a PhD Thesis, Nicola L.C. Talbot, http://theoval.cmp.uea.ac.uk/~nlct/latex/thesis/node25.html
- glossaries FAQ, Nicola L. C. Talbot, http://theoval.cmp.uea.ac.uk/~nlct/latex/packages/faq/glossariesfaq.html