The glossaries package v4.46: a guide for beginners
Nicola L.C. Talbot |
dickimaw-books.com |
2020-03-19
Abstract
The glossaries package is very flexible, but this means that it has a lot of options, and since a user guide is supposed to provide a complete list of all the high-level user commands, the main user manual is quite big. This can be rather daunting for beginners, so this document is a brief introduction just to help get you started. If you find yourself saying, “Yeah, but how can I do…?” then it’s time to move on to the main user manual.
I’ve made some statements in this document that don’t actually tell you the full truth, but it would clutter the document and cause confusion if I keep writing “except when …” or “but you can also do this, that or the other” or “you can do it this way but you can also do it that way, but that way may cause complications under certain circumstances”.
As with all packages, you need to load glossaries with \usepackage, but there are certain packages that must be loaded before glossaries, if they are required: hyperref, babel, polyglossia, inputenc and fontenc. (You don’t have to load these packages, but if you want them, you must load them before glossaries.)
Once you have loaded glossaries, you need to define your terms in the preamble and then you can use them throughout the document. Here’s a simple example:
This produces:
Here’s my sample term.
Here’s another example:
This produces:
First use: support vector machine (SVM). Second use: SVM.
In this case, the text produced by \gls{svm} changed after the first use. The first use produced the long form followed by the short form in parentheses because I set the acronym style to long-short. I suggest you try the above two examples to make sure you have the package correctly installed. If you get an undefined control sequence error, check that the version number at the top of this document matches the version you have installed. (Open the .log file and search for the line that starts with Package: glossaries followed by a date and version.)
Abbreviations are slightly different if you use the extension package glossaries-extra (which needs to be installed separately):
Since long-short happens to be the default for \newabbreviation (if you haven’t set the category key) you may omit the \setabbreviationstyle line in this example.
If you still want to use \newacronym (rather than \newabbreviation) then you need the optional argument of \setabbreviationstyle:
In this example, if you omit the \setabbreviationstyle line you will notice a difference because the short-nolong style (not the long-short style) is the default with \newacronym. With the short-nolong style the first use simply shows just the short form.
If you like, you can put all your definitions in another file (for example, defns.tex) and load that file in the preamble using \loadglsentries with the filename as the argument. For example:
If you find you have a really large number of definitions that are hard to manage in a .tex file, you might want to have a look at bib2gls (installed separately) which requires a .bib format instead that can be managed by an application such as JabRef.
Don’t try inserting formatting commands into the definitions as they can interfere with the underlying mechanism. Instead, the formatting should be done by the style. For example, suppose I want to replace SVM with \textsc{svm}, then I need to select a style that uses \textsc, like this (for the base glossaries style):
The abbreviation styles have a different naming scheme with glossaries-extra:
With glossaries-extra you can have multiple abbreviation styles for different categories. Many of these styles have their own associated formatting commands that can be redefined for minor adjustments. For example:
This produces:
First use: support vector machine (svm), Clostridium botulinum.
Next use: svm, C. botulinum.
As you can hopefully see from the above examples, there are two main ways of defining a term: as a general entry (\newglossaryentry) or as an abbreviation (\newacronym or, with glossaries-extra, \newabbreviation).
Regardless of the method of defining a term, the term is always given a label. In the first example, the label was ex and in the other examples the label was svm (and cbot in the last example). The label is used to uniquely identify the term (like the standard \label/\ref or \cite mechanism). It’s best to just use the following alphanumerics in the labels: a, …, z, A, …, Z, 0, …, 9. Sometimes you can also use punctuation characters but not if another package (such as babel) makes them active. Don’t try using any characters outside of the basic Latin set with inputenc (for example, é or ß) or things will go horribly wrong. This warning only applies to the label. It doesn’t apply to the text that appears in the document. If you really need UTF-8 characters in your labels then you’ll need to use XeLaTeX or LuaLaTeX.
The above examples are reasonably straightforward. The difficulty comes if you want to display a sorted list of all the entries you have used in the document. The glossaries-extra package provides a really easy way of listing all the defined entries:
However this method doesn’t sort the entries (they’re listed in order of definition) and it will display all the defined entries, regardless of whether or not you’ve used them all in the document, so “turnip” appears in the glossary even though there’s no \gls{turnip} (or similar) in the document.
The sort=none option isn’t essential in this case (there’s no other sort option available for this document), but it prevents the automatic construction of the sort value and so slightly improves the document build time.
Note that this example document uses the same command (\printunsrtglossaries) that’s used with bib2gls (Option 4) but with bib2gls you instead need to use the record package option and one or more instances of \GlsXtrLoadResources in the preamble (see below).
Most users prefer to have an automatically sorted list that only contains entries that have been used in the document. The glossaries package provides three options: use TeX to perform the sorting (Option 1); use makeindex to perform the sorting (Option 2); use xindy to perform the sorting (Option 3). The extension package glossaries-extra provides a fourth method: use bib2gls (Option 4).
The first option (using TeX) is the simplest method, as it doesn’t require an external tool, but it’s very inefficient and the sorting is done according to lower case character code (which matches basic Latin alphabets, such as English, but not extended Latin alphabets, such as Icelandic). To use this method, add \makenoidxglossaries to the preamble and put \printnoidxglossaries at the place where you want your glossary. For example:
Try this out and run LaTeX (or pdfLaTeX) twice. The first run won’t show the glossary. It will only appear on the second run. This doesn’t include “turnip” in the glossary because that term hasn’t been used (with commands like \gls{turnip}) in the document.
The glossary has a vertical gap between the “carrot” term and the “potato” term. This is because the entries in the glossaries are grouped according to their first letter. If you don’t want this gap, just add nogroupskip to the package options:
or you may want to try out a style that shows the group headings:
If you try out this example you may also notice that the description is followed by a full stop (period) and a number. The number is the location in the document where the entry was used (page 1 in this case), so you can lookup the term in the glossary and be directed to the relevant pages. It may be that you don’t want this back-reference, in which case you can suppress it using the nonumberlist package option:
If you don’t like the terminating full stop, you can suppress that with the nopostdot package option:
If you try out the earlier example with glossaries-extra and \printunsrtglossaries you may notice that the terminating full stop is missing and there are no number lists. You can add the full stop back with
or
If you want the number lists then you need to use an indexing option.
You may have noticed that I’ve used another command in the above examples: \glspl. This displays the plural form. By default, this is just the singular form with the letter “s” appended, but in the case of “potato” I had to specify the correct plural using the plural key.
As I mentioned earlier, using TeX to sort the entries is the simplest but least efficient method. If you have a large glossary or if your terms contain non-Latin or extended Latin characters, then you will have a much faster build time if you use makeindex (Option 2) or xindy (Option 3) or bib2gls (Option 4). If you are using extended Latin or non-Latin characters, then xindy or bib2gls are the recommended methods. These methods are described in more detail in §4 Displaying a List of Entries.
The rest of this document briefly describes the main commands provided by the glossaries package. (Most of these are also available with glossaries-extra but may behave slightly differently.)
When you use the glossaries package, you need to define glossary entries in the document preamble. These entries could be a word, phrase, abbreviation 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.) The ⟨name⟩ is the word, phrase or symbol you are defining, and ⟨description⟩ is the description to be displayed in the glossary.
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:
(This will also need a sort key if you use Options 1 or 3, see below.)
(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
(This isn’t necessary for UTF-8 characters with XeLaTeX or LuaLaTeX. For further details, see the section “UTF-8” of the mfirstuc user manual.)
If you use bib2gls with glossaries-extra then the terms must be defined in a .bib file. For example:
and the .bib file is specified in the resource command. For example, if the .bib file is called entries.bib then put the following line in the document preamble:
You can have a comma-separated list. For example, if you also have entries defined in the file entries2.bib:
There are other keys you can use when you define an entry. For example, the name key indicates how the term should appear in the list of entries (glossary), but if the term should appear differently when you reference it with \gls{⟨label⟩} 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”. With bib2gls this entry is defined in the .bib file as:
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.)
Abbreviations can be defined using:
where ⟨label⟩ is the label (as per \newglossaryentry), ⟨short⟩ is the short form and ⟨long⟩ is the long form. For example, the following defines an abbreviation:
This internally uses \newglossaryentry to define an entry with the label svm. By default, the name key is set to ⟨short⟩ (“SVM” in the above example) and the description key 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:
Before you define your acronyms (or other types of abbreviations), you need to specify which style to use with:
where ⟨style name⟩ is the name of the style. There are a number of predefined styles, such as: long-short (on first use display the long form with the short form in parentheses); short-long (on first use display the short form with the long form in parentheses); long-short-desc (like long-short but you need to specify the description); or short-long-desc (like short-long but you need to specify the description). There are some other styles as well that use \textsc to typeset the acronym or that use a footnote on first use. See the main user guide for further details.
The glossaries-extra package provides improved abbreviation handling with a lot more predefined styles. With this extension package, abbreviations are defined using:
You can still use \newacronym but it’s redefined to use the new abbreviation interface. The style must now be set using:
The default ⟨category⟩ is abbreviation. If you use \newacronym the category is acronym, which is why you need to use the optional argument if you define abbreviations with \newacronym when glossaries-extra has been loaded:
The plural forms for abbreviations 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. With bib2gls, the definition in the .bib file is:
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:
or with bib2gls the definition in the .bib file is:
If you want the symbol in the name field then you must supply a sort value with Options 1 and 3 otherwise you’ll end up with errors from TeX or xindy. With Option 2 (makeindex) it’s not quite so important but you may find the resulting order is a little odd. For example:
This displays the symbol as ∅ but sorts according to “empty set”. You may want to consider using glossaries-extra’s symbols package option which provides
This internally uses \newglossaryentry but automatically sets the sort key to the ⟨label⟩. For example:
Now the sort value is “emptyset” rather than the previous “empty set”.
With bib2gls you can define this in the .bib file as
in which case bib2gls will try to interpret the name field to determine the sort value. Alternatively you can use:
which will use the label (emptyset) as the sort value. (You don’t need the symbols package option in this case, unless you want a separate symbols list.) The corresponding document (where the definition is in the file entries.bib) is now:
Note that while the sort key is advised for symbols when using \makeglossaries or \makenoidxglossaries it shouldn’t be used with bib2gls. Instead, bib2gls has its own algorithm for determining the sort value based on the entry type (@entry, @symbol etc). See bib2gls gallery: sorting for further details.
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 you are using bib2gls then this will display ?? (like \ref and \cite) until bib2gls has created the relevant files and LaTeX is rerun.
If you are using the hyperref package (remember to load it before glossaries) \gls will create a hyperlink to the corresponding entry in the glossary. If you want to suppress the hyperlink for a particular instance, use the starred form \gls* for example, \gls*{fishage}. The other commands described in this section all have a similar starred form.
If the entry was defined as an acronym (using \newacronym with glossaries described above) or an abbreviation (using \newabbreviation with glossaries-extra), then \gls will display the full form the first time it’s used and just the short form on subsequent use. For example, if the style is set to long-short, then \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 use \newacronym with glossaries-extra the default doesn’t show the long form on first use. You’ll need to change the style first, as described earlier.)
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:
In §1 Getting Started, I mentioned that there are three options you can choose from to create an automatically sorted glossary with the base glossaries package. These are also available with the extension package glossaries-extra along with a fourth option. These four options are listed below in a little more detail. Table 1 summarises the main advantages and disadvantages. (There’s a more detailed summary in the main glossaries user manual.) See also Incorporating makeglossaries or makeglossaries-lite or bib2gls into the document build.
| Option 1 | Option 2 | Option 3 | Option 4 |
✘ | ✘ | ✘ | ✔ | |
Requires an external application? | ✘ | ✔ | ✔ | ✔ |
Requires Perl? | ✘ | ✘ | ✔ | ✘ |
Requires Java? | ✘ | ✘ | ✘ | ✔ |
Can sort extended Latin or non-Latin alphabets? | ✘ | ✘ | ✔ | ✔ |
Efficient sort algorithm? | ✘ | ✔ | ✔ | ✔ |
Can use different sort methods for each glossary? | ✔ | ✘ | ✘ | ✔ |
Any problematic sort values? | ✔ | ✔ | ✔ | ✘ |
Can form ranges in the location lists? | ✘ | ✔ | ✔ | ✔ |
Can have non-standard locations? | ✔ | ✘ | ✔† | ✔ |
† Requires some setting up.
This is the simplest option but it’s slow and if you want a sorted list, it doesn’t work for extended or non-Latin alphabets. The name mustn’t contain commands (or, if it does, the sort value must be supplied) unless you have the package option sanitizesort or sort=def or sort=use.
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). Alternatively, use
to display all your glossaries (if you have more than one). This command doesn’t have any arguments.
This option allows you to have different sort methods. For example:
Here’s a complete document (myDoc.tex):
Document build:
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. The makeindex application is automatically invoked by the helper makeglossaries script, which works out all the appropriate settings from the .aux file.
Use this as soon as possible after you’ve loaded the glossaries package.
where you want your list of entries (glossary) to appear. (The sort key isn’t available in ⟨options⟩.) Alternatively, use
which will display all glossaries (if you have more than one). This command doesn’t have any arguments.
(Replace myDoc with the base name of your LaTeX document file without the .tex extension. Avoid spaces in the file name.) If you don’t have Perl installed use makeglossaries-lite instead:
If you don’t know how to use the command prompt, then you can probably configure your text editor to add makeglossaries (or makeglossaries-lite) as a build tool, 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. (There are some guidelines in Incorporating makeglossaries or makeglossaries-lite or bib2gls into the document build.) If you still have problems, try adding the automake package option:
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
Here’s a complete document (myDoc.tex):
Document build:
or
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 both TeX Live and MiKTeX. Since xindy is a Perl script, you will also need to ensure that Perl is installed. 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. The xindy application is automatically invoked by the helper makeglossaries script, which works out all the appropriate settings from the .aux file.
where you want your list of entries (glossary) to appear. (The sort key isn’t available in ⟨options⟩.) Alternatively, use
(Replace myDoc with the base name of your LaTeX document file without the .tex extension. Avoid spaces in the file name. If you don’t know how to use the command prompt, then as mentioned above, you may be able to configure your text editor to add makeglossaries as a build tool.
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:
Here’s a complete document (myDoc.tex):
Document build:
This requires the extension package glossaries-extra and an application called bib2gls. This application is able to sort extended Latin or non-Latin alphabets. It comes with both TeX Live and MiKTeX but requires at least Java 8. This method works differently to Options 2 and 3. Instead of creating a file containing the code to typeset the glossary it creates a .glstex file containing the entry definitions fetched from the .bib file (or files), but only those entries that are required in the document are defined and they are defined in the order obtained from the chosen sort method. This means that you can just use \printunsrtglossary to display each glossary (or \printunsrtglossaries to display them all).
to your preamble where ⟨bib list⟩ is the list of .bib files containing the entries. You may use different sort methods for each resource set. For example:
The last resource set assumes that the entries defined in the file constants.bib have a number stored in the user1 field. For example:
where you want your list of entries (glossary) to appear. (The sort key isn’t available in ⟨options⟩. It needs to be used in \GlsXtrLoadResources instead.) Alternatively, use
or (if you need letter groups)
Here’s a complete document (myDoc.tex):
The accompanying entries.bib file:
Document build:
If you are having difficulty integrating makeglossaries into your document build process, you may want to consider using arara, which is a Java application that searches the document for special comment lines that tell arara which applications to run. For example, the file myDoc.tex might start with:
then to build the document you just need the single system call:
(As from version 4.0, arara also has directives for makeglossaries-lite and bib2gls. See the arara manual for further details.)
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:
Note that even if the name is given as {\’e}lite, the letter group heading (if the --group switch is used) may end up with the character É depending on the locale used by the sort comparator. In this case you will need to ensure the document can support this character either with inputenc or by switching to a LaTeX engine with native UTF-8 support.
There’s more information on how bib2gls obtains the sort value in bib2gls gallery: sorting.
If the inputenc package is used:
and the entry is defined as:
With the correct encoding set up, bib2gls will determine that the sort value is élite and will place it in whatever letter group is appropriate for the given sort rule. For example, sort=en-GB (or just sort=en) will put élite in the “E” letter group, but another language might put it in the “É” letter group.
Therefore if you have extended Latin or non-Latin characters, your best option is to use either xindy (Option 3) or bib2gls (Option 4) with the inputenc or fontspec package. If you use makeindex (Option 2) you need to specify the sort key like this:
or
If you use Option 3 and the name only contains a command or commands (such as \P or \ensuremath{\pi}) you must add the sort key. This is also advisable for the other options (except Option 4), but is essential for Option 3. For example:
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:
Some classes and packages redefine the description environment in such as way that’s incompatible with the glossaries package. In which case you’ll need to select a different glossary style (see below).
By default, a full stop is appended to the description (unless you use glossaries-extra). To prevent this from happening use the nopostdot package option:
or to add it with glossaries-extra:
By default, a location list is displayed for each entry (unless you use \printunsrtglossary without bib2gls). 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 or Option 4 (with bib2gls and glossaries-extra) then location ranges will be compressed. For example, if an entry was used on pages 1, 2 and 3, with Options 2 or 3 or Option 4 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:
or with bib2gls use save-locations=false in the optional argument of the appropriate \GlsXtrLoadResources (it’s possible to have some resource sets with locations and some without).
Entries are grouped according to the first letter of each entry’s sort key. By default a vertical gap is placed between letter groups for most of the predefined styles. 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. For example:
You can also use the style package option for the preloaded styles. For example:
Examples:
or
or
or one of the “tree” styles:
If your glossary consists of a list of abbreviations and you also want to specify a description as well as the long form, then you need to use an abbreviation style that will suit the glossary style. For example, use the long-short-desc acronym style:
Define the acronyms with a description:
Alternatively with glossaries-extra:
Choose a glossary style that suits wide entry names. For example:
The glossaries package predefines a default main glossary. When you define an entry (using one of the commands described in §2 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 (or bib2gls and \printunsrtglossaries), then the ⟨glg⟩, ⟨gls⟩ and ⟨glo⟩ arguments aren’t relevant, in which case you may prefer to use the starred version where you don’t specify the extensions:
In the case of Options 2 or 3, all glossary definitions must come before \makeglossaries. (Entry definitions should come after \makeglossaries.) In the case of Option 4, all glossary definitions must come before any \GlsXtrLoadResources that requires them.
Since it’s quite common for documents to have both a list of terms and a list of abbreviations, the glossaries package provides the package option acronym (or acronyms), which is a convenient shortcut for
The option also changes the behaviour of \newacronym so that acronyms are automatically put in the list of acronyms instead of the main glossary. The glossaries-extra package also provides this option for abbreviations defined using \newacronym but additionally has the package option abbreviations to create a list of abbreviations for \newabbreviation.
There are some other package options for creating commonly used lists: symbols (lists of symbols), numbers (lists of numbers), index (index of terms without descriptions defined with \newterm[⟨options⟩]{⟨label⟩}).
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 in the preamble. 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.
If you’re using bib2gls then each glossary is displayed using:
With this method you don’t use \makeglossaries or \makenoidxglossaries. Instead you can assign the entry type with the resource command. For example:
Later in the document:
There’s a convenient shortcut that will display all the defined glossaries depending on the indexing method:
(Option 1) or
(Options 2 and 3) or (glossaries-extra only)
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 or the makeglossaries-lite Lua script, you similarly don’t need to do anything else. If you use Options 2 or 3 without the makeglossaries Perl script or makeglossaries-lite Lua 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):
or
Or you need to run makeindex three times:
Or you need to run xindy three times (be careful not to insert line breaks where the line has wrapped.)
(Omit --group if you don’t need letter groups.)
Take care if you use the glossaries package with hyperref. Contrary to the usual advice that hyperref should be loaded last, glossaries (and glossaries-extra) 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 want to disable this 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:
The glossaries-extra extension package provides another method using category attributes. See the glossaries-extra user manual for further details.
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 page in your location list. Instead you can use
This is expandable provided that the text key doesn’t contain non-expandable code. For example, the following works:
and it doesn’t put the table of contents in the location list.
If you use glossaries-extra then use the commands that are provided specifically for use in section headers. For example:
You can add a reference to another entry in a location list using the see={⟨label list⟩} key when you define an entry. The referenced entry (or entries) 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:
The glossaries-extra package provides a seealso key. This doesn’t allow a tag but behaves much like see={[\seealsoname]{⟨label⟩}}. For example:
Since the cross-reference appears in the location list, if you suppress the location list using the nonumberlist package option, then the cross-reference will also be suppressed. With bib2gls, don’t use the nonumberlist package option. Instead use the save-locations=false in the resource options. For example:
The Dickimaw Books Gallery provides additional example documents.
1deprecated, use babel instead