LaTeX/Glossary

From Wikibooks, open books for an open world
Jump to: navigation, search

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}
{
  description={is a programmable machine that receives input,
               stores and manipulates data, and provides
               output in a useful format}
}

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}
{
  name=na\"{\i}ve,
  description={is a French loanword (adjective, form of naïf)
               indicating having or showing a lack of experience,
               understanding or sophistication}
}

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}
{
  name=na\"{\i}ve,
  description={is a French loanword (adjective, form of naïf)
               indicating having or showing a lack of experience,
               understanding or sophistication},
  sort=naive
}

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}
{
  description={is a generic term referring to the family of Unix-like
               computer operating systems that use the Linux kernel},
  plural=Linuces
}

[edit] Defining symbols

Defined entries can also be symbols:

\newglossaryentry{pi}
{
  name={\ensuremath{\pi}},
  description={ratio of circumference of circle to its
               diameter},
  sort=pi
}

You can also define both a name and a symbol:

\newglossaryentry{real number}
{
  name={real number},
  description={include both rational numbers, such as $42$ and
               $\frac{-23}{129}$, and irrational numbers,
               such as $\pi$ and the square root of two; or,
               a real number can be given by an infinite decimal
               representation, such as $2.4871773339\ldots$ where
               the digits continue in some way; or, the real
               numbers may be thought of as points on an infinitely
               long number line},
  symbol={\ensuremath{\mathbb{R}}}
}

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
alternative \gls{computer} operating systems:
\glspl{Linux
}, BSDs and GNU/Hurd.

Naïve people don't know about alternative computer opera-
ting systems: Linuces, BSDs and GNU/Hurd.

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:

  1. Build LaTeX document, this will generate the files used by makeglossaries
  2. 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>
    
  3. 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}
\deftranslation{Glossary}{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}
\printglossaries

[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
\renewcommand*{\glspostdescription}{}

[edit] References


To do:

  • Add advanced usage
  • Add examples of styles


Previous: Indexing Index Next: Letters
Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox
Sister projects
Print/export