Abstract
This document is a brief guide to the glossaries package for beginners who find the size of the main user manual daunting and, as such, it only covers the basics. For brevity some options to the commands described here are omitted. For a more detailed guide, see the main user manual.
When you use the glossaries package, you need to define glossary entries in the document preamble. These entries could be a word, phrase, acronym or symbol. They’re usually accompanied by a description, which could be a short sentence or an in-depth explanation that spans multiple paragraphs. The simplest method of defining an entry is to use:
where <label> is a unique label that identifies this entry. (Don’t include the angle brackets < >. They just indicate the parts of the code you need to change when you use this command in your document.) As with similar labelling commands, such as \label or \bibitem, the label should not contain active characters, so just use a, …, z, A, …, Z, 0, …, 9. You may also be able to use some punctuation characters, unless they have been made active (for example, via babel’s shorthand activation.) The <name> is the word, phrase or symbol you are defining, and <description> is the description.
This command is a “short” command, which means that <description> can’t contain a paragraph break. If you have a long description, you can instead use:
Examples:
(The percent character discards the end of line character that would otherwise cause an unwanted space to appear at the start of the description.)
or
Acronyms or abbreviations can be defined using
where <label> is the label (as with the \newglossaryentry and the \longnewglossaryentry commands), <short> is the abbreviation or acronym and <long> is the long form. For example:
This defines a glossary entry with the label svm. By default, the <name> is set to <short> (“svm” in the above example) and the <description> is set to <long> (“support vector machine” in the above example). If, instead, you want to be able to specify your own description you can do this using the optional argument:
There are other keys you can use when you define an entry. For example, the name key used above indicates how the term should appear in the list of entries (glossary). If the term should appear differently when you reference it in the document, you need to use the text key as well.
For example:
This will appear in the text as “Latin alphabet” but will be listed in the glossary as “Latin Alphabet”.
Another commonly used key is plural for specifying the plural of the term. This defaults to the value of the text key with an “s” appended, but if this is incorrect, just use the plural key to override it:
(Remember from earlier that the initial ligature \oe needs to be grouped.)
The plural forms for acronyms can be specified using the longplural and shortplural keys. For example:
If omitted, the defaults are again obtained by appending an “s” to the singular versions.
It’s also possible to have both a name and a corresponding symbol. Just use the name key for the name and the symbol key for the symbol. For example:
Once you have defined your entries, as described above, you can reference them in your document. There are a number of commands to do this, but the most common one is:
where <label> is the label you assigned to the entry when you defined it. For example, \gls{fishage} will display “Fish Age” in the text (given the definition from the previous section).
If the entry was defined as an acronym (using \newacronym described above), then \gls will display the full form the first time it’s used and just the short form on subsequent use. For example, \gls{svm} will display “support vector machine (svm)” the first time it’s used, but the next occurrence of \gls{svm} will just display “svm”.
If you want the plural form, you can use:
instead of \gls{<label>}. For example, \glspl{set} displays “sets”.
If the term appears at the start of a sentence, you can convert the first letter to upper case using:
for the singular form or
for the plural form. For example:
produces “Sets are collections”.
If you’ve specified a symbol using the symbol key, you can display it using:
Recall from above, the first time you use an acronym with \gls, it’s full form is displayed but subsequent uses display only the short form. By default, the first use displays <long> (<short>). That is, the long form is displayed followed by the short form in parentheses. You can change this first-use format with:
(This must be used before you start defining your acronyms with \newacronym.) There are a number of predefined styles listed in Predefined Acronym Styles in the main glossaries user manual. Here are a few examples:
This displays the short form followed by the long form in parentheses.
This is like the default style but the short form is displayed in small caps. Remember that when you use \textsc{<text>} to generate small capitals, you must specify <text> in lower case, so the short form of the acronym should be defined in lower case. For example:
This is similar to the previous style but uses \textsmaller to format the short form. Remember to load the relsize package, which defines \textsmaller, if you want to use this style. The short form now needs to be defined in upper case:
Suppose you now want to display a list of all the entries you’ve referenced in your document. This is where things start to get complicated and a lot of new users get bewildered. You have three options:
This is the simplest option but it’s slow and if you want a sorted list, it doesn’t work for non-Latin alphabets.
where you want your list of entries to appear. The sort <order> may be one of: word (word ordering), letter (letter ordering), case (case-sensitive letter ordering), def (in order of definition) or use (in order of use).
This option uses an application called makeindex to sort the entries. This application comes with all modern TEX distributions, but it’s hard-coded for the non-extended Latin alphabet. This process involves making LATEX write the glossary information to a temporary file which makeindex reads. Then makeindex writes a new file containing the code to typeset the glossary. LATEX then reads this file on the next run.
where you want your list of entries (glossary) to appear.
(Replace myDoc with the base name of your LATEX document file. Avoid spaces in the file name.) If you don’t know how to use the command prompt, then you can probably access makeindex via your text editor, but each editor has a different method of doing this, so I can’t give a general description. You will have to check your editor’s manual.
The default sort is word order (“sea lion” comes before “seal”). If you want letter ordering you need to add the -l switch:
This option uses an application called xindy to sort the entries. This application is more flexible than makeindex and is able to sort extended Latin or non-Latin alphabets. It comes with TEX Live but not with MiKTEX. Since xindy is a Perl script, if you are using MiKTEX you will not only need to install xindy, you will also need to install Perl. In a similar way to Option 2, this option involves making LATEX write the glossary information to a temporary file which xindy reads. Then xindy writes a new file containing the code to typeset the glossary. LATEX then reads this file on the next run.
where you want your list of entries (glossary) to appear.
(Replace myDoc with the base name of your LATEX document file. Avoid spaces in the file name. If necessary, also replace english with the name of your language and utf8 with your input encoding.) If you don’t know how to use the command prompt, then you can probably access xindy via your text editor, but each editor has a different method of doing this, so I can’t give a general description. You will have to check your editor’s manual.
The default sort is word order (“sea lion” comes before “seal”). If you want letter ordering you need to add the order=letter package option:
For Options 2 and 3, it can be difficult to remember all the parameters required for makeindex or xindy, so the glossaries package provides a script called makeglossaries that reads the .aux file to determine what settings you have used and will then run makeindex or xindy. Again, this is a command line application and can be run in a terminal or command prompt. For example, if your LATEX document is in the file myDoc.tex, then run:
(Replace myDoc with the base name of your LATEX document file. Avoid spaces in the file name.) If you don’t know how to use the command prompt, you can probably access makeglossaries via your text editor. Check your editor’s manual for advice. If you are using arara then you can just use the directives:
The makeglossaries script is written in Perl, so you need a Perl interpreter installed. If you are using a Unix-like operating system then you most likely have one installed. If you are using Windows with the TEX Live distribution, then you can use the Perl interpreter that comes with TEX Live. If you are using Windows and MiKTEX then you need to install a Perl distribution for Windows. If you are using Option 3, then you need to do this anyway as xindy is also written in Perl. If you are using Option 2 and can’t work out how to install Perl (or for some reason don’t want to install it) then just use makeindex directly, as described above.
When sorting the entries, the string comparisons are made according to each entry’s sort key. If this is omitted, the name key is used. For example, recall the earlier definition:
No sort key was used, so it’s set to the same as the name key: {\’e}lite. How this is interpreted depends on which option you have used:
If the inputenc package is used and the entry is defined as:
Therefore if you have extended Latin or non-Latin characters, your best option is to use xindy (Option 3) with the inputenc package. If you use makeindex (Option 2) you need to specify the sort key like this:
If you use Option 1, you may or may not need to use the sort key, but you will need to be careful about fragile commands in the name key if you don’t set the sort key.
Table 1 summarises the pros and cons of three options described above.
| Option 1 | Option 2 | Option 3 |
Requires an external application? | ✘ | ✔ | ✔ |
Requires Perl? | ✘ | ✘ | ✔ |
Can sort extended Latin or non-Latin alphabets? | ✘† | ✘ | ✔ |
Efficient sort algorithm? | ✘ | ✔ | ✔ |
Can form ranges in the location lists? | ✘ | ✔ | ✔ |
Can have non-standard locations? | ✔ | ✘ | ✔ |
✔ | ✘ | ✘ |
† Strips standard LATEX accents so, for example, \AA is treated the same as A.
The default glossary style uses the description environment to display the entry list. Each entry name is set in the optional argument of \item which means that it will typically be displayed in bold. You can switch to medium weight by redefining \glsnamefont:
By default, a full stop is appended to the description. To prevent this from happening use the nopostdot package option:
By default, a location list is displayed for each entry. This refers to the document locations (for example, the page number) where the entry has been referenced. If you use Options 2 or 3 described in §4 Displaying a List of Entries location ranges will be compressed. For example, if an entry was used on pages 1, 2 and 3, with Options 2 or 3 the location list will appear as 1–3, but with Option 1 it will appear as 1, 2, 3. If you don’t want the locations displayed you can hide them using the nonumberlist package option:
Entries are grouped according to the first letter of each entry’s sort key. By default a vertical gap is placed between letter groups. You can suppress this with the nogroupskip package option:
If the default style doesn’t suit your document, you can change the style using:
There are a number of predefined styles. Glossaries can vary from a list of symbols with a terse description to a list of words or phrases with descriptions that span multiple paragraphs, so there’s no “one style fits all” solution. You need to choose a style that suits your document.
Examples:
or one of the “tree” styles:
If your glossary consists of a list of acronyms and you also want to specify a description as well as the long form, then you need to use an acronym style that will suit the glossary style. For example, use the long-short-desc acronym style:
Define the acronyms with a description:
Choose a glossary style that suits wide entry names:
The glossaries package predefines a default main glossary. When you define an entry (using one of the commands described in §1 Defining Terms), that entry is automatically assigned to the default glossary, unless you indicate otherwise using the type key. However you first need to make sure the desired glossary has been defined. This is done using:
The <label> is a label that uniquely identifies this new glossary. As with other types of identifying labels, be careful not to use active characters in <label>. The final argument <title> is the section or chapter heading used by \printglossary or \printnoidxglossary. The other arguments indicate the file extensions used by makeindex/xindy (described in §4 Displaying a List of Entries). If you use Option 1 described above, the <glg>, <gls> and <glo> arguments are ignored. In the case of Options 2 or 3, all glossary definitions must come before \makeglossaries.
Since it’s quite common for documents to have both a list of terms and a list of acronyms, the glossaries package provides the package option acronyms, which is a convenient shortcut for
It also changes the behaviour of \newacronym so that acronyms are automatically put in the list of acronyms instead of the main glossary.
For example, suppose you want a main glossary for terms, a list of acronyms and a list of notation:
After \makeglossaries (or \makenoidxglossaries) you can define the entries. For example:
or if you don’t like using \ensuremath:
Each glossary is displayed using:
(Option 1) or
(Options 2 and 3). Where <type> is the glossary label. If the type is omitted the default main glossary is assumed.
There’s a convenient shortcut that will display all the defined glossaries:
(Option 1) or
If you use Option 1, you don’t need to do anything else. If you use Options 2 or 3 with the makeglossaries Perl script, you similarly don’t need to do anything else. If you use Options 2 or 3 without the makeglossaries Perl script then you need to make sure you run makeindex/xindy for each defined glossary. The <gls> and <glo> arguments of \newglossary specify the file extensions to use instead of .gls and .glo. The optional argument <glg> is the file extension for the transcript file. This should be different for each glossary in case you need to check for makeindex/xindy errors or warnings if things go wrong.
For example, suppose you have three glossaries in your document (main, acronym and notation), specified using:
Then (assuming your LATEX document is in a file called myDoc.tex):
You need to run makeindex three times:
You need to run xindy three times (be careful not to insert line breaks where the line has wrapped.)
Take care if you use the glossaries package with hyperref. Contrary to the usual advice that hyperref should be loaded last, glossaries must be loaded after hyperref:
If you use hyperref make sure you use PDFLATEX rather than the LATEX to DVI engine. The DVI format can’t break hyperlinks across a line so long glossary entries (such as the full form of acronyms) won’t line wrap with the DVI engine. Also, hyperlinks in sub- or superscripts aren’t correctly sized with the DVI format.
By default, if the hyperref package has been loaded, commands like \gls will form a hyperlink to the relevant entry in the glossary. If you don’t want this to happen for all your glossaries, then use
If you want hyperlinks suppressed for entries in specific glossaries, then use the nohypertypes package option. For example, if you don’t want hyperlinks for entries in the acronym and notation glossaries but you do want them for entries in the main glossary, then do:
If you want the hyperlinks suppressed the first time an entry is used, but you want hyperlinks for subsequence references then use the hyperfirst=false package option:
Take care not to use non-expandable commands in PDF bookmarks. This isn’t specific to the glossaries package but is a limitation of PDF bookmarks. Non-expandable commands include commands like \gls, \glspl, \Gls and \Glspl. The hyperref package provides a way of specifying alternative text for the PDF bookmarks via \texorpdfstring. For example:
However, it’s not a good idea to use commands like \gls in a section heading as you’ll end up with the table of contents in your location list. Instead you can use
This is expandable provided that the text key doesn’t containing non-expandable code. For example, the following works:
and it doesn’t put the table of contents in the location list.
You can add a reference to another entry in a location list using the see={<label>} key when you define an entry. The referenced entry must also be defined.
For example:
The cross-reference will appear as “see Devonian”. You can change the “see” tag using the format see=[<tag>]<label>. For example:
If you use the see key in the optional argument of \newacronym, make sure you enclose the value in braces. For example:
Further information can be found in the main glossaries user manual and there is also an article on the glossaries package on the LATEX Community’s Know How section and a chapter on the glossaries package in Using LATEX to Write a PhD Thesis.