glossary.sty v 2.4: LaTeX2e Package to Assist Generating Glossaries

Nicola L.C. Talbot

20th July 2006


Contents

Introduction

The glossary package is provided to assist generating a glossary. It has a certain amount of flexibility, allowing the user to customize the format of the glossary, and define new glossary-style objects.

Installation

You need to make sure you have downloaded the following three files:

glossary.ins
glossary.dtx
README
To extract the code from the glossary.dtx file, you will need to run the installation file through LaTeX:
latex glossary.ins
This will create the following files:
glossary.sty
glossary.perl
makeglos.pl
makeglos.bat
along with several sample files. The file glossary.sty should be placed somewhere in the LaTeX path, e.g. texmf/tex/latex/glossary/ or localtexmf/tex/latex/glossary/. Remember to update the TEX database if you are installing this package for the first time. The file glossary.perl is a LaTeX2HTML style file, and should be placed in the LaTeX2HTML style file directory (usually latex2html/styles/). The file makeglos.pl is a Perl script which calls makeindex. If you are using UNIX or Linux, you will need to set the permissions so that you can execute the file:
chmod a+x makeglos.pl
You should then place this file somewhere on your path. (You may also need to edit the first line of this file, if perl is located in a directory other than /usr/bin/1.)

If you are not using UNIX or Linux etc, you may have to explicitly load the file into Perl, so you would need to do perl makeglos.pl instead of just makeglos.pl. If you are using Windows, a batch file, makeglos.bat is provided which will run Perl on makeglos.pl. Both makeglos.pl and makeglos.bat should be placed somewhere specified by the PATH environment variable. (For example, put them both in the same directory as makeindex, which will probably be in \texmf\miktex\bin\).

If you don't have Perl installed on your system, you can just use makeindex, only you will have to remember all the command line switches, and you won't be able to merge entries that have the same name, but different descriptions.

Note that if you are updating the glossary package, it is a good idea to update makeglos.pl as it may also have been modified.

Generating Glossary Information

The standard LaTeX command \makeglossary (analogous to \makeindex) should be placed in the document preamble. If this command is omitted, glossary information will be ignored. Glossary entries are generated using the command \glossary{key-val list}. This command is a slightly modified version of the standard \glossary command, in order to separate out the information into entry-name and entry-description. The argument to \glossary must be a comma-separated list of key=value pairs. The following keys are available:

Key Value
name The entry name
description A description about the entry
sort How to sort the entry. (Entry name used if sort omitted)
format How to format the page number
number Override the page number with a different counter. The value should be the name of a counter (e.g. number=section).
For example:
\glossary{name={singular matrix},
          description={A matrix with zero determinant}}
The following example sorts on the text U instead of $\mathcal{U}$:
\glossary{name={$\mathcal{U}$},
          description={The universal set},
          sort=U}
Note that you should always use the sort key if the name key contains commands, this is particularly important if you are using hyperlinks, as the target is constructed from the name key if the sort key is omitted.

In the glossary, each entry is followed by a list of page numbers that correspond to the pages where the relevant \glossary command is placed. By default the numbers are formatted in the current font, but the page number format for individual entries can be changed using the format key. This should be the name of a LaTeX formatting command without the preceding \ (as with the | operator in \index.) For example:

\glossary{name={$\mathbb{R}$},
          description={The set of real numbers},
          sort=R,
          format=textbf}
In addition, the following formats are also available:
hyperrm The number is a hyper link in roman
hypersf The number is a hyper link in sans-serif
hypertt The number is a hyper link in typewriter font
hyperbf The number is a hyper link in bold
hypermd The number is a hyper link in medium weight
hyperit The number is a hyper link in italic
hypersl The number is a hyper link in slanted font
hyperup The number is a hyper link in upright font
hypersc The number is a hyper link in small caps
hyperem The number is a hyper link using \emph
If the hyper option has not been set, hyperem is equivalent to emph, and the remaining hyperrm etc are equivalent to textrm etc. Note that it is important the you use hyperrm instead of hyperpage, as the \hyperpage command won't work on a list or range of numbers in the glossary2. If you want to define your own command that uses hyper links, it must be defined in an analogous manner to \hyperrm. For example, if you want to display a page number in a bold italic format, that contains a hyperlink to the appropriate page, you would need to define it as follows:
\newcommand{\hyperbfit}[2][\gls@number]{%
\textbf{\itshape\glshyper{#1}{#2}}}
As can be seen from the definition, all the \hyperxx commands have an optional argument. This argument is the name of the counter being used. You do not need to worry about this argument if you only use these commands within the \glossary command. So the previous example can simply be rewritten as:
\glossary{name={$\mathbb{R}$},
          description={The set of real numbers},
          sort=R,
          format=hyperbf}

Note: although the numbers in the glossary are referred to as ``page'' numbers in this manual, they may in fact refer to some other counter, such as the section counter, depending on whether the number key has been used.

As with the \index command, care must be taken if you want to use the special characters: @ | " and !. These characters should be preceded by the double quote character. For example:

\glossary{name={$"|\mathcal{S}"|$,
description=The cardinality of the set \mathcal{S}}}
There is no provision for sub-entries, as these are generally only applicable in an index, and not in a glossary.

As from version 2.14, there is an additional command available:

\xglossary{gls-entry}{text}

This is equivalent to text\glossary{gls-entry}, where text will be made a hyper link to the relevant entry in the glossary, if hyper links are supported.

Storing Glossary Information

It is very cumbersome having to use the \glossary command throughout your document, every time you use a term that you want in your glossary. This is particularly true for terms with a long description. The glossary package provides a means of storing the glossary information at the beginning of the document, and then using it whenever required. It is strongly recommended that you use this approach, rather than explicity using the \glossary command.

The following command:

\storeglosentry[ gls-type]{ label}{ gls-entry}

can be used to store glossary information, where label is a unique label assigned to this entry. The information can then be used later with any of the following commands:

\useglosentry[ opt]{ label}
\useGlosentry[
opt]{ label}{ text}
\gls[
opt]{ label}

\useglosentry adds the glossary entry whose label is given by label to the appropriate glossary, \useGlosentry adds the glossary entry, and makes text a hyperlink to that entry (if hyperlinks are supported). The third command, \gls, is like \useGlosentry, but forms text from the name given in the glossary entry.

Returning to an earlier example, instead of typing:

\glossary{name={$\mathcal{U}$},
          description={The universal set},
          sort=U}
every time you want to add this entry to the glossary, you can instead store the information:
\storeglosentry{glos:U}{name={$\mathcal{U}$},
          description={The universal set},
          sort=U}
Now, instead of continually copying and pasting the glossary command for this entry (which can have quite a large description field), you can use either:
\useglosentry{glos:U}
which is equivalent to:
\glossary{name={$\mathcal{U}$},
          description={The universal set},
          sort=U}
or you can use:
\useGlosentry{glos:U}{text}
which is equivalent to:
\xglossary{name={$\mathcal{U}$},
          description={The universal set},
          sort=U}{text}
or you can use:
\gls{glos:U}
which is equivalent to:
\xglossary{name={$\mathcal{U}$},
          description={The universal set},
          sort=U}{$\mathcal{U}$}
If you want to use glossary entries in an equation, it is better to use \ensuremath instead of $...$. For example:
\storeglosentry{Gamma}{name=\ensuremath{\Gamma(z)},
description=Gamma function,
sort=Gamma}
You can then use this entry in either text or math mode:
The \useGlosentry{Gamma}{Gamma function} is defined as
\begin{equation}
\gls{Gamma} = \int_{0}^{\infty}e^{-t}t^{z-1}\,dt
\end{equation}
If you are using hyper links, and you want to use \useGlosentry within math mode, you must use \ensuremath:
\begin{equation}
\useGlosentry{Gamma}{\ensuremath{\Gamma(x+1)}} = x\Gamma(x)
\end{equation}

The optional argument to \storeglosentry (gls-type) indicates the glossary type (see later to find out how to define new glossary types). If omitted, the standard glossary is used.

The optional argument to \useglosentry, \useGlosentry and \gls (opt) allows you to add additional information to the glossary entry, for example:

\useglosentry[format=textbf]{glos:U}
is equivalent to:
\glossary{name={$\mathcal{U}$},
          description={The universal set},
          sort=U,
          format=textbf}
Since version 2.4, \storeglosentry is robust, and \protect should no longer be needed, however the identifying label, label, should not contain any special characters.

As from version 2.36, if you want to use all glossary entries which have been defined using \storeglosentry, do: \useglosentry{*}. (Note that this option is not available for \useGlosentry and \gls.)

makeglos.pl

Whenever a glossary entry is used, either explicity using \glossary or \xglossary or implicitly using \useglosentry, \useGlosentry and \gls, the information is saved in a file with the extension glo (unless the \makeglossary command is omitted, in which case the glossary information is simply ignored.) A makeindex style file (ist) is also created, which is customized for the document, and can be passed to makeindex.

For example, suppose your document is called mydoc.tex, the glossary will be saved in the file mydoc.glo, and the makeindex style file mydoc.ist will be created. These files can then be passed to makeindex as follows:

makeindex -s mydoc.ist -t mydoc.glg -o mydoc.gls mydoc.glo
which generates the output file mydoc.gls, with transcript written to mydoc.glg.

The Perl script makeglos.pl provided with this package allows you to use makeindex without having to remember all the command line options. The command

makeglos.pl mydoc
will perform the command:
makeindex -s mydoc.ist -t mydoc.glg -o mydoc.gls mydoc.glo
In addition, makeglos.pl also takes the option -m which can be used to collate entries where the same name has multiple descriptions.

makeglos.pl has the following syntax:

makeglos.pl [-ilqrgm] [-s sty] [-o gls] [-t log] [-p num] <filename>
where all switches, apart from -m are the same as those for makeindex. If there are multiple glossary types (see later) and the file extension is omitted, makeglos.pl will iterate through each glossary type (it will pick up the relevant information from the auxiliary file).

The name of the ist file can be changed by redefining the command \istfilename before \makeglossary. For example:

\renewcommand{\istfilename}{foo.ist}
\makeglossary
Only one ist file will be created per document, even if you have multiple glossaries with different styles. The only circumstance where you will need multiple ist files for a single document is when you have multiple glossaries that use different counters with different compositors, but this is rarely likely to occur.

Creation of the ist file can be suppressed by issuing the command \noist before \makeglossary. It will also be suppressed when the command \nofiles is used, or if the command \makeglossary is omitted.

It should be noted that there are a few packages that can cause problems with the creation of the ist file, for example ngerman. If you encounter problems when LaTeX is processing the \makeglossary command, or if you get errors from makeindex complaining about the style file, this is the most probable cause. See later for information on how to fix this.

Displaying the Glossary

Once the gls file has been created by makeindex (as described in the previous section) the glossary can then be included in the document with the command \printglossary. If chapters are defined, the glossary will start with

\chapter*{\glossaryname}
If not, it will start with
\section*{\glossaryname}
The format of the main body of the glossary depends on the options passed to the package.


Package Options

The package options must be specified as a comma-separated list of key=value pairs. Available options are:

style
The glossary style. Values:
list
use description environment in the glossary
altlist
modified version of style=list. The description starts on the line following the name of the term being defined.
super
use supertabular environment in the glossary
long
use longtable environment in the glossary (Default)

header
Glossary header. Values:
none
The glossary doesn't have a heading (Default)
plain
The glossary has a heading

border
Glossary border. Values:
none
The glossary doesn't have a border (Default)
plain
Border around the main body of the glossary

cols
Number of columns. Values:
2
The entry name and description are in two separate columns with the associated page numbers in the same column as the description. (Default)
3
The entry name, description and associated page numbers are in three separate columns.

number
Associated number corresponding to each entry. This may either be the keyword none indicating that the corresponding numbers should be suppressed, or it can be the name of a LaTeX counter. The default is number=page.

toc
Boolean variable:
true
Add glossary to table of contents
false
Omit glossary from table of contents (Default)
Note that if you specify this option, you will need to run LaTeX twice after generating the glossary.

hypertoc
Boolean variable. This is similar to the package option toc, but if you are using the hyperref package, hypertoc will generate a link to the point immediately before the glossary title, whereas toc will have a hyperlink to just after the glossary title. Note that you can not use both toc=true and hypertoc=true. Default value: hypertoc=false.

hyper
Boolean variable:
true
Make associated numbers in the glossary a hypertext link, and also make acronyms, and the text given by \xglossary have a hyperlink to their corresponding entries in the glossary.
false
Don't make associated numbers a hypertext link
If the hyperref or html package has been loaded prior to loading glossary.sty, hyper=true is set, otherwise the default is hyper=false. Note that this package option now encompasses the old hyperacronym option.

section
Boolean variable:
true
Make the glossary an unnumbered section, even if chapters are defined
false
Only make glossary an unnumbered section if chapters are not defined (default).

acronym
Boolean variable:
true
Make the list of acronyms separate from the main glossary.

false
The acronyms will all be placed in the main glossary. (Default)

global
Boolean variable:
false
Acronym commands only have a local effect. (Default)
true
Acronym commands have a global effect.
The border, header and cols options should not be used in conjunction with style=list or style=altlist, as they only make sense with one of the tabular-style options. The value for the boolean variables can be omitted if they are to be set. For example toc is equivalent to toc=true. Note that the altlist style is better suited to glossaries with long entry names.

You can set up your own preferred defaults in a configuration file. The file must be called glossary.cfg and should be placed somewhere on the TEX path. In this file you can use the command \glossarypackageoptions{option-list} where option-list is a comma-separated list of key=value pairs, as passed to the glossary package. Note that this command may only be used in the configuration file.

Examples

See glossary.pdf (the PDF version of this manual) for examples.


Defining New Glossary Types

A new type of glossary can be defined using the command:

\newglossarytype[log-ext]{name}{out-ext}{in-ext}[style list]

For example, suppose you want your document to have a separate index of terms and index of notation, you could use \makeglossary, \glossary, \xglossary and \printglossary for the first glossary, and define a new type of glossary called say, notation, using

\newglossarytype[nlg]{notation}{not}{ntn}
which will create the analogous commands: \makenotation, \notation, \xnotation and \printnotation which can be used for the second glossary.

As from version 2.3, \newglossarytype now has an additional optional argument style list. This should be a comma separated list of key=value pairs that can be used to specify the style of the new glossary. If omitted, the new glossary will have the same format as the main glossary. The following options are available: number, style, header, border and cols. These can take the same values as those given in the package options (described in section 6).

The command \newglossarytype should only occur in the preamble. The new commands \makename, \name, \xname and \printname all have the same format as their ``glossary'' counter-parts.

The glossary information will be saved to a file with the extension given by out-ext (analogous to glo), which can then be passed to makeindex either directly or via makeglos.pl, and the file to be read in (i.e. the file created by makeindex) will have the extension in-ext (analogous to gls).

The optional argument log-ext indicates the extension for the makeindex log file, if omitted the extension glg is used. This is not used by LaTeX, however makeglos.pl reads in this information from the LaTeX auxiliary file and passes it to makeindex.

For the above notation example, if your document is called, say, mydoc.tex, you will need to do the following:

latex mydoc
makeglos.pl mydoc
latex mydoc
(You may need to do an extra latex mydoc to get cross-references up-to-date.) Note that if you don't specify the file extension when using makeglos.pl, it will check the transcript file from the LaTeX run to determine all the glossary types, so, for this example,
makeglos.pl mydoc
is equivalent to:
makeglos.pl mydoc.glo
makeglos.pl mydoc.not
since makeglos.pl has read in the information for the notation glossary type from the file mydoc.log.

If you don't have Perl installed on your system, or for any other reason are unable to use makeglos.pl, you can call makeindex explicitly:

latex mydoc
makeindex -s mydoc.ist -t mydoc.glg -o mydoc.gls mydoc.glo
makeindex -s mydoc.ist -t mydoc.nlg -o mydoc.ntn mydoc.not
latex mydoc

Note that you can use the command \printglossary[name] instead of \printname. These two commands have the same effect when using LaTeX, however, they have a slightly different effect when using LaTeX2HTML (see later).

If the command \glossary-typename is defined, (e.g. \notationname in the above example) this will be used as the title for the specified glossary. If this command is not defined, \glossaryname will be used instead. If the command \shortglossary-typename is defined, (e.g. \shortnotationname in the above example) this will be used for the table of contents entry, otherwise \glossary-typename will be used instead. For example:

\newglossarytype[nlg]{notation}{not}{ntn}
\newcommand{\notationname}{Index of Notation}
\newcommand{\shortnotationname}{Notation}

Acronyms

The glossary package provides the command:

\newacronym[ cmd-name]{ acronym}{ long}{ glossary entry}

which can be used to define acronyms. The argument long is the full name, the argument acronym is the acronym for long and glossary entry is the glossary information in the form used by the \glossary command. If the optional argument cmd-name is missing, \newacronym will create a command called \acronym, otherwise it will create a command called \cmd-name (henceforth denoted \acr-name). This command can then be used throughout the text. The first instance of this command is equivalent to:

long (\xacronym{name=long (acronym),glossary entry}{acronym})

subsequent instances will be equivalent to:

\xacronym{name=long (acronym),glossary entry}{acronym}

The command \acr-name also has a starred version, which will make the first letter of long uppercase (for use at the start of a sentence).

Note that if you want to change the format of the acronym, for example, if you want the acronym to appear in small caps, you will need to not only use the optional argument, but you will also need to use the sort key, otherwise you will get an error. For example:

\newacronym[SVM]{\textsc{svm}}{Support Vector Machine}%
{description=Statistical pattern recognition 
technique,sort=svm}

If the package option acronym is not set (default) \xacronym, is a synonym for \xglossary, and the acronyms will appear in the main glossary (remember to specify \makeglossary and \printglossary). If the package option acronym=true is specified, a new glossary type called acronym will be defined as:

\newglossarytype[alg]{acronym}{acr}{acn}
\providecommand{\acronymname}{List of Acronyms}
You will then need to use the commands \makeacronym and \printacronym to make the list of acronyms appear. You will also need to run the acr file through makeindex (or makeglos.pl). For example:
makeindex -s mydoc.ist -t mydoc.alg -o mydoc.acn mydoc.acr
alternatively:
makeglos.pl mydoc
Note that the package option acronym=true is only appropriate if you want both a glossary and a separate list of acronyms. If you do not write in English, you can set up your own language definition for \acronymname in the configuration file glossarycfg. For example:
\newcommand{\acronymname}{Akronyme}
(If glossary.cfg does not exist, create a new file, add the appropriate definition of \acronymname, and save it to the same directory as glossary.sty.)

The name key does not need to appear in glossary entry, as it is constructed from long and acronym. By default this will be in the form: long (acronym), however the format can be overridden using the command:

\setacronymnamefmt{format}

Within format the following commands may be used to represent long and acronym: \glolong and \gloshort. For example, suppose you just want the acronym to appear in the glossary entry, and not its full length name, then you would need to do:

\setacronymnamefmt{\gloshort}

As from version 2.32, you can also modify the way the description key is formatted for acronyms using:

\setacronymdescfmt{format}

Within format you may use the commands \glolong and \gloshort (as above), and you can also use the command \glodesc which is the description as specified by the description key in \newacronym. This means that if you are using a tabular style glossary, you can have the abbreviated form in one column and the long form in the second column with the description. For example, the following:

\setacronymnamefmt{\gloshort}
\setacronymdescfmt{\glolong: \glodesc}
\newacronym{svm}{support vector machine}{description=Statistical
pattern recognition technique}
will generate a glossary entry of the form:
\glossary{name=svm,description=support vector machine: Statistical
pattern recognition technique}
Note that if you omit \glodesc from \setacronymdescfmt the description specified in \newacronym will be ignored. So
\setacronymnamefmt{\gloshort}
\setacronymdescfmt{\glolong}
\newacronym{svm}{support vector machine}{description=Statistical
pattern recognition technique}
will generate a glossary entry of the form:
\glossary{name=svm,description=support vector machine}

You will need to specify the name key explicitly if the name contains a makeindex special character. For example:

\newacronym{RNA}{Ribonukleins\"aure}{name={Ribonukleins\""aure (RNA)}}
Note that this will override any formatting specified by \setacronymnamefmt.

Given an acronym named acr-name (the command name associated with the acronym as defined in \newacronym without the preceding backslash), the following commands are also available:



\useacronym[insert]{acr-name}

This command can be used instead of \acr-name. \useacronym also has a starred version equivalent to \acr-name*. The optional argument insert allows you to insert text after long, if this is the first occurrence of the acronym, or after the acronym on subsequent occurrences.



\resetacronym{acr-name}

This command will cause the next use of \acr-name to produce the long version. To reset all acronyms do \resetallacronyms.



\unsetacronym{acr-name}

This command will cause all subsequent uses of \acr-name to produce the short version. To unset all acronyms do \unsetallacronyms.



\ifacronymfirstuse{acr-name}{true text}{false text}

This will test if the acronym has been used yet. If it has been used, true text will be implemented, otherwise false text will be implemented.

The long and short forms of an acronym can be produced explicitly without a corresponding glossary entry, using the commands:

\acrln{acr-name}
\acrsh{acr-name}

Or, alternatively:

\acr-namelong
\acr-nameshort

The first two commands (\acrln and \acrsh) have a starred form that makes the first letter uppercase. The other two commands, simply contain long and acronym.

Note that since these four commands do not generate glossary entries they will therefore not contain any hyperlinks, even if you have specified the hyper package option. They are provided for use in situations where the associated glossary command may cause problems (e.g. in a sectioning command.)

Note that, as with all LaTeX commands, spaces following command names are ignored so if, for example, you defined a new acronym called, say, SVM, then the command \SVM will ignore any spaces following it. To force a space, you can either place an empty set of braces after the command name (e.g. \SVM{}) or use \_ i.e. a backslash followed by a space (e.g. \SVM\ ). Alternatively, as from version 2.22, if you load the xspace package before loading the glossary package, spaces will be put in automatically using \xspace.

If you want the acronym to appear in a particular font, for example, small caps, you can redefine the command \acronymfont. For example:

\renewcommand{\acronymfont}[1]{\textsc{#1}}
The default definition of \acronymfont is:
\newcommand{\acronymfont}[1]{#1}

Examples

\newacronym{SVM}{Support Vector Machine}{description=Statistical 
pattern recognition technique}
This will define the command \SVM. The first time this command is used will display the text: Support Vector Machine (SVM). Subsequent use will simply display: SVM. The next example uses the optional argument cmd-name since the acronym contains a non-alphabetical character:
\newacronym[KSVM]{K-SVM}{Kernel Support Vector 
Machine}{description=Statistical pattern recognition 
technique using the ``kernel trick''}
This will define the command \KSVM. The first time this command is used will display the text: Kernel Support Vector Machine (K-SVM). Subsequent use will simply display: K-SVM.

To test whether or not an acronym has been used:

\ifacronymfirstuse{SVM}{a}{an} \SVM\ is \ldots
If the acronym has not been used, the following text will be produced:

a Support Vector Machine is ...

otherwise it will produce:

an SVM is ...

To expand the acronym a second time:
\chapter{An overview of the \protect\SVM}
\resetacronym{SVM}
The \SVM\ \ldots
Note the use of \protect (see note 15.) In fact, in this situation it would be better to do:
\chapter[An overview of the \SVMlong]{An overview of the \protect\SVM}
\resetacronym{SVM}
The \SVM\ \ldots

Now suppose you want the text: support vector machine, instead of Support Vector Machine (i.e. you don't like the uppercase letters). You can define the acronym as follows:

\newacronym{SVM}{support vector machine}{description=Statistical 
pattern recognition technique}
however, if the command \SVM occurs at the start of the sentence, you would clearly want the first letter as an uppercase letter. This can be done using \SVM* instead of \SVM. For example:
\SVM*\ techniques are widely used \ldots
This will then come out as: Support vector machine (SVM) techniques are widely used ...(Assuming this is the first use of either \SVM or \SVM*.)

Alternatively, \useacronym{SVM} can be used instead of \SVM. For example:

\useacronym*[s]{SVM} are widely used in the area of pattern 
recognition.
If this is the first use of the acronym SVM, it will produce the following text:

Support vector machines (SVM) are widely used in the area of pattern recognition.

If this is not the first use of this acronym, it will produce the following text:

SVMs are widely used in the area of pattern recognition.

Customizing the Glossary

The glossary package provides commands which can be redefined to customize the glossary. The following name commands are defined by this package:
Command Default Value
\glossaryname Glossary
\shortglossaryname \glossaryname
\entryname Notation
\descriptionname Description
The commands \entryname and \descriptionname are put in the first two columns of the header row if you are using one of the tabular glossary styles together with a header row (as specified by the header=true package option). If you are using cols=3, the command \glspageheader will be put in the third column of the header row. By default, this command does nothing.

The command \shortglossaryname is used for the page headers and table of contents entry. Any text required before or after the glossary can be added by redefining the commands \glossarypreamble and \glossarypostamble. For example.

\renewcommand{\glossarypreamble}{Page numbers in 
italic indicate the main definition\par}
By default, \glossarypreamble and \glossarypostamble do nothing.

Any text required before or after the list of page numbers are specified by the commands \glsbeforenum and \glsafternum. By default, these commands do nothing, any redefinition of these commands should come somewhere before the relevant \printglossary command. For example:

\printglossary
\renewcommand{\glsbeforenum}{(}
\renewcommand{\glsafternum}{)}
\printnotation
This will put the page number list in brackets for the second glossary, but not the first.

Individual glossaries can have their styles changed either by setting the style in the final optional argument to \newglossarystyle (see earlier) or using the command:

\setglossarystyle[type]{style list}

For example:

\setglossarystyle[acronym]{style=long,border=true,cols=2}
If type is omitted, the change is applied to the main glossary.

The command \setglossary{key-val list} can be used to modify some of the glossary settings. The argument key-val list is a comma-separated list of key=value pairs. Available keys are:

type
This is the glossary type. If it is omitted, the standard glossary is assumed.

glsnumformat
This is the name of the command, without the preceding backslash3, to format the entry numbers. For example, to make all the entry numbers italic, do:
\setglossary{glsnumformat=textit}
To suppress numbering altogether, you can do:
\setglossary{glsnumformat=ignore}

glodelim
This specifies what to do after the entry description and before the page numbers. The default value is a comma, unless the cols=3 option is specified, in which case it has the value &, or if style=altlist, in which case it is simply a space4. If the package option number=none is specified, glodelim will have an empty value (unless cols=3 is specified, where, again, it will have the value &.) This setting corresponds to the delim_0 key in the makeindex style file.

Note that if you want a new line between the description and the list of page numbers you will need to use \noexpand. For example:

\setglossary{glodelim={\noexpand\newline}}

delimN
The delimiter to be inserted between two page numbers for the same entry. (This corresponds to the delim_n key in the makeindex style file.) By default, this has the value ,_ (comma followed by a space). If the package option number=none is chosen, the value is set to empty.

delimR
The delimiter to be inserted between the starting and ending page number range for the same entry. (This corresponds to the delim_r key in the makeindex style file.) By default, this has the value --. If the package option number=none is chosen, the value is set to empty.

gloskip
This specifies what to do between groups. If style=list or style=altlist this has the value \indexspace, otherwise it creates a blank row in the longtable or supertabular environment. This command corresponds to the group_skip key in the makeindex style file. Note that as from version 2.3, you should no longer redefine the command \gloskip.

delimT
The text to be inserted after the list of page numbers for an entry. (This corresponds to the delim_t key in the makeindex style file.) The default value depends on the glossary style. It does nothing for the list-type styles, and has the value \\ for the tabular-type styles. Note that delimT is separate from \glsafternum.

For example, if you are using a 2 column tabular style, and you want a blank line after every entry (not just after every group) you can do the following:

\setglossary{delimT={\cr & \cr},gloskip={}}
Note the use of \cr instead of \\ and gloskip is set to nothing otherwise there would be a double space between groups.
Note that:
\setglossary{glsnumformat=ignore}
is equivalent to
\setglossary{glsnumformat=ignore,delimN={},delimR={}}

As from version 2.4, you can insert text between groups by redefining the commands \glogroupSymbols, \glogroupNumbers, \glogroupA ... \glogroupZ. For example, if you are using one of the list styles, the following will print the appropriate heading in bold, followed by a gap:

\renewcommand{\glogroupSymbols}{\textbf{Symbols}\indexspace}
\renewcommand{\glogroupNumbers}{\textbf{Numbers}\indexspace}
\renewcommand{\glogroupA}{\textbf{A}\indexspace}
....% similar lines omitted
\renewcommand{\glosgroupZ}{\textbf{Z}\indexspace}

The start and end of the main body of the glossary is given by the commands: \beforeglossary and \afterglossary. If the style=list or style=altlist package options are chosen these commands simply begin and end the description environment, otherwise these commands begin and end the longtable or supertabular environment with argument specified by \glossaryalignment5.

The glossary package no longer conflicts with the array package. Changes can now be made to \glossaryalignment regardless of whether or not the array package has been used.

The command \gloitem indicates what to do at the start of each glossary entry. This command takes one argument, which will be the text specified by the name key in the \glossary command. In the case of the style=list option, \gloitem{text} will do

\item[text]

or if style=altlist:

\item[text]\mbox{}\par

otherwise it will do

text &

This command corresponds to the item_0 key in the makeindex style file.

If the glossary has a tabular style with a header row (header=true and either style=long or style=super), then the header row for cols=2 will be given by:

\bfseries\entryname & \bfseries \descriptionname\\
and the header row for cols=3 will be given by:
\bfseries\entryname & \bfseries\descriptionname & 
\bfseries\glspageheader\\
(It may also contain \hline\hline if the border key is set.)

If you want to override this, you need to define the command \glossaryheader6.

For example, if you are using a tabular style with cols=2, and you want the \descriptionname to be centred, you could do:

\newcommand{\glossaryheader}{\bfseries\entryname & 
 \hfil\bfseries\descriptionname\\}

If you want an extra row below the header row, you can define the command\glossarysubheader For example, if you are using cols=3, and you want an extra row after the header row, you can do:

\newcommand{\glossarysubheader}{ & & \\}

The command \glosstail indicates what to do at the end of the longtable or supertabular environment.

The width of the second column for the tabular-type styles is given by the length \descriptionwidth. This value can be changed using the \setlength command (the default value is 0.6\linewidth).

Sample Documents

This package comes with the following sample documents:


LaTeX2HTML Style File

A LaTeX2HTML Perl script, glossary.perl, is provided with this package for those wishing to use the glossary package with the LaTeX2HTML translator. The file glossary.perl should be extracted along with glossary.sty when you run the installation script (glossary.ins) through LaTeX.

Limitations


Troubleshooting

This is a list of common problems, for a more up-to-date FAQ, see http://theoval.cmp.uea.ac.uk/~nlct/packages/faq/.

  1. My glossary hasn't appeared.

    Check the following:

    If you have defined a new glossary type, have you checked all the analogous commands to the above?

  2. My list of acronyms hasn't appeared.

    Have you used the acronym=true package option? If no, check the answers to the previous item, if yes, make sure you have used \makeacronym and \printacronym. Have you used any of the acronyms you have defined? Remember that \acrsh, \acrln, \acr-nameshort and \acr-namelong don't generate entries in the list of acronyms, where \acr-name is the name of an acronym command.

  3. My acronym has been expanded twice.

    By default, if any of your acronym commands occur within a group (this includes environments which form implicit grouping) the effect will be local to that group. You can either unset the acronym outside the group, or use the global package option.

  4. I get an error when using the command \saveglosentry.

    Don't use this command it's obsolete, use \storeglosentry instead.

  5. One of more of my glossary entries hasn't appeared.

    Check the following

    Check the makeindex log file to see if there are any error messages.

  6. My glossary has duplicate entries on separate lines.

    LaTeX treats multiple spaces equivalent to a single space, but makeindex takes spaces into account when determining whether two entries are identical. For example:

    \glossary{name=Identity matrix,
    description=diagonal matrix with 1's along the diagonal}
    
    and
    \glossary{name=Identity  matrix,
    description=diagonal matrix with 1's along the diagonal}
    
    will be treated as different entries by makeindex, because the first has only one space between `Identity' and `matrix' and the second has two. The easiest way to ensure consistency is to use \storeglosentry together with \useglosentry, \useGlosentry or \gls.

  7. I had an error, fixed it, but I keep getting the same error message.

    Suppose you've made an error in the \glossary command. For example:

    \glossary{name=Java,description=A programming language,format=texbf}
    
    In this case textbf has been mis-spelt. This error will be copied to the glo file, which in turn will be copied to the gls file by makeindex. A subsequent run of LaTeX will read this error in. If you fix the error in your main document, the error will still be read in from the gls file. The best thing to do is to delete the gls file, and try again.

  8. My glossary has ended up wider than my page.

    This may occur if you have long entry names, and you are using either the style=long or style=super options. The width of the description column is proportional to the line width (in fact, it's 0.6\linewidth) but the first column is as wide as the widest entry name. You can either redefine \glossaryalignment to change the column specifications, or use one of the list-type styles.

  9. The page numbers in my glossary don't match up with the actual page numbers where the entry was defined.

    You may need to LaTeX your document again (just as you have to do with \tableofcontents, \listoffigures etc).

  10. I'm getting a keyval error.

    The glossary package uses the keyval package to extract the information from key=value comma separated lists. You need to make sure the syntax is correct. If your value contains a comma, you will need to enclose value in curly braces. See the keyval documentation for further information7.

  11. I've used the hyper option, but nothing happens when I click on the numbers in the glossary.

    Check the following:

    1. Have you remembered to use PDFLaTeX instead of LaTeX, or used a driver that understands hyperlinks?
    2. Have you remembered to use the hyperref or html package?
    3. Have you remembered to use a formatting command which uses \hyperlink? (E.g. using hyperbf instead of textbf)? Remember to check the format key in your \glossary commands, and the glsnumformat key in the \setglossary command.
    4. What application are you using to view the PDF file? Ghostview can display a PDF file, but ignores the links. If you are using Windows, try using Adobe's Acrobat Reader, or if you are using UNIX or Linux, try using xpdf or acroread.

  12. The glossary package conflicts with the datetime package.

    This has been fixed in version 2.01.

  13. I get an error when using certain commands, such as \cite or ~ in \newacronym.

    This has been fixed in version 2.1.

  14. I get the following error:
    ! Package array Error: Illegal pream-token (\glossaryalignment): `c' used.
    

    The glossary package used to conflict with the array package. This was fixed in version 2.1. As from version 2.3, it doesn't matter whether you load the glossary package before or after the array package.

  15. I get the following error:
    Use of \@chapter doesn't match its definition
    
    or
    ! Argument of \@sect has an extra }
    

    If you want to use an acronym command in a moving argument (such as a chapter heading) you need to \protect it first. Note that if you do put an acronym in a chapter etc heading, it will be expanded for the first time in the table of contents, not in the chapter heading. The best way to get around this is to use the optional argument, e.g.

    \chapter[Introduction to Kernel Support Vector Machines]{Introduction 
    to \protect\KSVM}
    
    You will also need to do this if you are using bookmarks in a PDF document.

    Alternatively, you can do:

    \resetacronym{KSVM}
    \chapter{Introduction to \protect\KSVM}
    
    or if you are using PDFLaTeX:
    \resetacronym{KSVM}
    \chapter{Introduction to \texorpdfstring{\protect\KSVM}{KSVM}}
    

  16. The glossary package conflicts with ngerman.

    This problem is caused by the fact that ngerman redefines the effect of the double quote character, but this character is used in the creation of the ist makeindex style file. Try one of the following methods:

    1. Include the ngerman package after the \makeglossary command:
      \usepackage{glossary}
      \makeglossary
      \usepackage{ngerman}
      

    2. First omit the ngerman package and include \makeglossary then LaTeX your document. This will create the ist file. Then include the ngerman package, and insert \noist before the \makeglossary command, this will prevent further attempts to generate the ist file.
      \usepackage{ngerman}
      \usepackage{glossary}
      \noist\makeglossary
      

    3. Use \noist, as above, and create the ist file in an ordinary text editor. The file should contain the following lines:
      keyword "\\glossaryentry"
      preamble "\\begin{theglossary}"
      postamble "\n\\end{theglossary}\n"
      group_skip "\\gloskip "
      item_0 "\n\\gloitem "
      delim_0 "\n\\glodelim "
      page_compositor "-"
      delim_n "\\delimN "
      delim_r "\\delimR "
      
    It is possible that there may be other packages which will also cause a problem, if so, try any of the above.

  17. makeglos.pl gives the following error message:
    unable to extract name from glossary item:
    

    You are using an old version of makeglos.pl with a new version of the glossary package. You will need to update your version makeglos.pl.

Let me know if you encounter any other problems or if you have any comments regarding this package.

Obsolete Commands

The commands described in this section are now obsolete, but are currently still provided for backwards compatibility. Their use is deprecated.

\saveglosentry{ name}{description}
This command has now been replaced by \storeglosentry.

The command \glsprimaryfmt has now been removed.

The package option hyperacronym is now superseded by the package option hyper. This option was implemented prior to the introduction of the command \xglossary. Since the acronyms now use \xglossary, there is no difference between the hyperacronym and hyper options. This option has a boolean value:

true
Make acronyms link to their corresponding entry in the glossary
false
Acronyms don't have a hyperlink.
If the hyperref package has been loaded prior to loading glossary.sty or if hyper=true is set, hyperacronym=true otherwise hyperacronym=false.

Contact Details

Dr Nicola Talbot
School of Computing Sciences
University of East Anglia
Norwich. Norfolk
NR4 7TJ. United Kingdom.
http://theoval.cmp.uea.ac.uk/~nlct/

Acknowledgements

I would like to thank all the many people who have made suggestions and pointed out bugs.


Index

acroread
Troubleshooting
array
Customizing the Glossary | Customizing the Glossary | Troubleshooting | Troubleshooting
datetime
Troubleshooting
\descriptionname
Customizing the Glossary | Sample Documents
\entryname
Sample Documents
file types
acr
Acronyms
cfg
Package Options | Acronyms
glg
makeglos.pl | Defining New Glossary Types | Troubleshooting
glo
makeglos.pl | makeglos.pl | Defining New Glossary Types | Troubleshooting
gls
makeglos.pl | Displaying the Glossary | Defining New Glossary Types | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting
ist
makeglos.pl | makeglos.pl | makeglos.pl | makeglos.pl | makeglos.pl | makeglos.pl | makeglos.pl | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting
perl
LaTeX2HTML Style File | LaTeX2HTML Style File
\glodesc
Acronyms | Acronyms
\glolong
Acronyms | Acronyms
\gloshort
Acronyms | Acronyms
glossary
Introduction | Generating Glossary Information | Generating Glossary Information | Storing Glossary Information | Storing Glossary Information | Storing Glossary Information | Package Options | Examples | Defining New Glossary Types | Acronyms | Acronyms | Acronyms | Customizing the Glossary | Customizing the Glossary | Sample Documents | Limitations | Limitations | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting
glossary border
see package options, border
glossary columns
see package options, cols
glossary header
see package options, header
\glossary keys
description
Generating Glossary Information | Storing Glossary Information | Acronyms
format
Generating Glossary Information | Generating Glossary Information | Troubleshooting
hyperbf
Generating Glossary Information | Troubleshooting
hyperem
Generating Glossary Information | Generating Glossary Information
hyperit
Generating Glossary Information
hypermd
Generating Glossary Information
hyperrm
Generating Glossary Information | Generating Glossary Information
hypersc
Generating Glossary Information
hypersf
Generating Glossary Information
hypersl
Generating Glossary Information
hypertt
Generating Glossary Information
hyperup
Generating Glossary Information
name
Generating Glossary Information | Generating Glossary Information | Generating Glossary Information | Acronyms | Acronyms | Acronyms | Acronyms | Customizing the Glossary
number
Generating Glossary Information | Generating Glossary Information
sort
Generating Glossary Information | Generating Glossary Information | Generating Glossary Information | Acronyms
glossary style
see package options, style
glossary.cfg
see file type, cfg
\glossaryalignment
Troubleshooting
\glossaryname
Displaying the Glossary | Defining New Glossary Types | Sample Documents
\gls
Storing Glossary Information | Troubleshooting | Troubleshooting | Troubleshooting
\glspageheader
Sample Documents
html
Package Options | Troubleshooting
hyperref
Package Options | Package Options | Sample Documents | Sample Documents | Troubleshooting | Obsolete Commands
\hyperrm
Generating Glossary Information
keyval
Troubleshooting | Troubleshooting | Troubleshooting
\makeacronym
Acronyms | Troubleshooting
makeglos.pl
makeglos.pl | makeglos.pl | makeglos.pl | makeglos.pl | Defining New Glossary Types | Defining New Glossary Types | Defining New Glossary Types | Defining New Glossary Types | Defining New Glossary Types | Acronyms | Sample Documents | Sample Documents | Sample Documents | Sample Documents | Sample Documents | Sample Documents | Sample Documents | Sample Documents | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting
\makeglossary
makeglos.pl | makeglos.pl | makeglos.pl | makeglos.pl | Defining New Glossary Types | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting
makeindex
Installation | Installation | Installation | makeglos.pl | makeglos.pl | makeglos.pl | makeglos.pl | makeglos.pl | makeglos.pl | makeglos.pl | Displaying the Glossary | Defining New Glossary Types | Defining New Glossary Types | Defining New Glossary Types | Defining New Glossary Types | Defining New Glossary Types | Acronyms | Acronyms | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Sample Documents | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting
makeindex key
delim_0
Customizing the Glossary
delim_n
Customizing the Glossary
delim_r
Customizing the Glossary
delim_t
Customizing the Glossary
group_skip
Customizing the Glossary
item_0
Customizing the Glossary
makeindex style file (.ist)
see file types, ist
\newacronym
Acronyms | Troubleshooting
\newglossarystyle
Customizing the Glossary
ngerman
makeglos.pl | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting
\nofiles
makeglos.pl
\noist
Troubleshooting | Troubleshooting
package options
,
none
Package Options
acronym
Package Options | Package Options | Acronyms | Acronyms | Acronyms | Acronyms | Limitations | Limitations | Troubleshooting
false
Package Options | Limitations
true
Package Options | Acronyms | Acronyms | Limitations | Troubleshooting
border
Package Options | Package Options | Package Options | Package Options | Examples | Examples | Examples | Examples | Customizing the Glossary | Customizing the Glossary
none
Package Options | Examples | Examples
plain
Package Options | Examples | Examples
cols
Package Options | Package Options | Package Options | Package Options | Examples | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary
2
Package Options | Customizing the Glossary | Customizing the Glossary
3
Package Options | Examples | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary
global
Package Options | Package Options | Troubleshooting | Troubleshooting
false
Package Options
true
Package Options
header
Package Options | Package Options | Package Options | Package Options | Examples | Examples | Examples | Examples | Customizing the Glossary | Customizing the Glossary
none
Package Options | Examples | Examples
plain
Package Options | Examples | Examples
true
Customizing the Glossary | Customizing the Glossary
hyper
Generating Glossary Information | Generating Glossary Information | Package Options | Package Options | Package Options | Package Options | Acronyms | Acronyms | Limitations | Troubleshooting | Troubleshooting | Obsolete Commands | Obsolete Commands | Obsolete Commands | Obsolete Commands | Obsolete Commands
false
Package Options | Package Options
true
Package Options | Package Options | Limitations | Obsolete Commands
hyperacronym
Package Options | Package Options | Obsolete Commands | Obsolete Commands | Obsolete Commands | Obsolete Commands | Obsolete Commands | Obsolete Commands
false
Obsolete Commands | Obsolete Commands
true
Obsolete Commands | Obsolete Commands
hypertoc
Package Options | Package Options | Package Options | Package Options | Package Options | Package Options
false
Package Options
true
Package Options
number
Package Options | Package Options | Package Options | Examples | Examples | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Sample Documents | Sample Documents
equation
Sample Documents
none
Examples | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary
page
Package Options | Examples
section
Sample Documents
section
Package Options | Package Options
false
Package Options
true
Package Options
style
Package Options | Package Options | Package Options | Package Options | Package Options | Examples | Examples | Examples | Examples | Examples | Examples | Examples | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Sample Documents | Limitations | Troubleshooting | Troubleshooting
altlist
Package Options | Package Options | Package Options | Examples | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary | Sample Documents | Sample Documents | Limitations
list
Package Options | Package Options | Package Options | Examples | Examples | Customizing the Glossary | Customizing the Glossary | Customizing the Glossary
long
Package Options | Examples | Examples | Examples | Examples | Customizing the Glossary | Troubleshooting
super
Package Options | Customizing the Glossary | Troubleshooting
toc
Package Options | Package Options | Package Options | Package Options | Package Options | Package Options | Package Options | Package Options | Package Options | Package Options | Sample Documents | Sample Documents | Limitations
false
Package Options
true
Package Options | Package Options | Package Options | Limitations
page number formats
hyperbf
Generating Glossary Information | Troubleshooting
hyperem
Generating Glossary Information | Generating Glossary Information
hyperit
Generating Glossary Information
hypermd
Generating Glossary Information
hyperrm
Generating Glossary Information | Generating Glossary Information
hypersc
Generating Glossary Information
hypersf
Generating Glossary Information
hypersl
Generating Glossary Information
hypertt
Generating Glossary Information
hyperup
Generating Glossary Information
perl
Installation
\printacronym
Acronyms | Troubleshooting
\printglossary
Defining New Glossary Types | Defining New Glossary Types | Troubleshooting
\protect
Troubleshooting
\saveglosentry
Troubleshooting | Obsolete Commands
\setacronymnamefmt
Acronyms
\setglossary
Limitations | Troubleshooting
\setglossary keys
delimN
Customizing the Glossary
delimR
Customizing the Glossary
delimT
Customizing the Glossary | Customizing the Glossary
glodelim
Customizing the Glossary | Customizing the Glossary
gloskip
Customizing the Glossary | Customizing the Glossary
glsnumformat
Customizing the Glossary | Troubleshooting
type
Customizing the Glossary
\storeglosentry
Storing Glossary Information | Storing Glossary Information | Sample Documents | Limitations | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting
table of contents, adding to
see package options, toc
\useacronym
Examples
\useGlosentry
Storing Glossary Information | Storing Glossary Information | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting | Troubleshooting
\xacronym
Acronyms | Acronyms | Acronyms
\xglossary
Package Options | Defining New Glossary Types | Acronyms | Troubleshooting | Obsolete Commands | Obsolete Commands
xpdf
Troubleshooting
\xspace
Acronyms | Acronyms



Footnotes

... /usr/bin/1
and you can also remove the .pl extension which isn't to everyone's liking.
... glossary2
This is because the list and number ranges are delimited using \delimR and \delimN instead of explicitly using a comma or en-dash.
... backslash3
Note, you should no longer try redefining the command \glsnumformat, as this now takes an optional argument, allowing for different glossary types
... space4
This is because the altlist style is intended for use with long descriptions that will look better ending with a full stop which the user can add if desired.
...\glossaryalignment5
This isn't quite true anymore, see the documented code for clarification
...\glossaryheader6
Note that as from version 2.4, you must use \newcommand not \renewcommand
... information7
This should be in the directory texmf/doc/latex/graphics/


Nicola L. C. Talbot. School of Computing Sciences. University of East Anglia. Last Modified: 2006-07-25

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.