Upgrading from the glossary package to the glossaries package
Nicola L.C. Talbot |
2020-03-19
Abstract
The purpose of this document is to provide advice if you want to convert a LaTeX document from using the obsolete glossary package to the replacement glossaries package.
The glossary package started out as an example in a tutorial, but I decided that I may as well package it up and upload it to CTAN. Unfortunately it was fairly rigid and unable to adapt well to the wide variation in glossary styles. Users began making requests for enhancements, but with each enhancement the code became more complicated and bugs crept in. Each fix in one place seemed to cause another problem elsewhere. In the end, it was taking up too much of my time to maintain, so I decided to replace it with a much better designed package. With the new glossaries package:
When converting a document that currently uses the obsolete glossary package to the replacement glossaries package, it should be fairly obvious that the first thing you need to do is replace \usepackage{glossary} with \usepackage{glossaries}, however some of the package options are different, so you may need to change those as well. Table 1 shows the mappings from the glossary to the glossaries package options.
glossary option | glossaries option |
style=list | style=list |
style=altlist | style=altlist |
style=long,header=none,border=none,cols=2 | style=long |
style=long,header=plain,border=none,cols=2 | style=longheader |
style=long,header=none,border=plain,cols=2 | style=longborder |
style=long,header=plain,border=plain,cols=2 | style=longheaderborder |
style=long,header=none,border=none,cols=3 | style=long3col |
style=long,header=plain,border=none,cols=3 | style=long3colheader |
style=long,header=none,border=plain,cols=3 | style=long3colborder |
style=long,header=plain,border=plain,cols=3 | style=long3colheaderborder |
style=super,header=none,border=none,cols=2 | style=super |
style=super,header=plain,border=none,cols=2 | style=superheader |
style=super,header=none,border=plain,cols=2 | style=superborder |
style=super,header=plain,border=plain,cols=2 | style=superheaderborder |
style=super,header=none,border=none,cols=3 | style=super3col |
style=super,header=plain,border=none,cols=3 | style=super3colheader |
style=super,header=none,border=plain,cols=3 | style=super3colborder |
style=super,header=plain,border=plain,cols=3 | style=super3colheaderborder |
number=none | nonumberlist |
number=⟨counter name⟩ | counter=⟨counter name⟩ |
toc | toc |
hypertoc | toc |
hyper | no corresponding option |
section=true | section |
section=false | no corresponding option |
acronym | acronym |
global | no corresponding option |
If you have created new glossary types, you will need to replace all instances of
The ⟨old style list⟩ optional argument can be converted to ⟨new style⟩ using the same mapping given in Table 1.
For example, if your document contains the following:
You will need to replace the above two lines with:
in the preamble and
immediately prior to displaying this glossary. Alternatively, you can specify the style using the style key in the optional argument of \printglossary. For example:
Note that the glossary title is no longer specified using \⟨glossary-type⟩name (except for \glossaryname and \acronymname) but is instead specified in the ⟨title⟩ argument of \newglossary. The short title which is specified in the glossary package by the command \short⟨glossary-name⟩name is now specified using the toctitle key in the optional argument to \printglossary.
All instances of \make⟨glossary name⟩ (e.g. \makeglossary and \makeacronym) should be replaced by the single command \makeglossaries. For example, if your document contained the following:
then you should replace both lines with the single line:
With the old glossary package you could optionally store glossary information for later use, or you could simply use \glossary whenever you wanted to add information to the glossary. With the new glossaries package, the latter option is no longer available.3 If you have stored all the glossary information using \storeglosentry, then you will need to convert these commands into the equivalent \newglossaryentry. If you have only used \glossary, then see §6.4 \glossary.
Substitute all instances of
If you have used the optional argument of \storeglosentry (i.e. you have multiple glossaries) then you will need to substitute
The glossary entry information ⟨gls-entry⟩ may also need changing. If ⟨gls-entry⟩ contains any of makeindex’s special characters (i.e. @ ! " or |) then they should no longer be escaped with " since the glossaries package deals with these characters internally. For example, if your document contains the following:
then you will need to replace it with:
The format and number keys available in \storeglosentry are not available with \newglossaryentry.
The glossary package provided two basic means to add information to the glossary: firstly, the term was defined using \storeglosentry and the entries for that term were added using \useglosentry, \useGlosentry and \gls. Secondly, the term was added to the glossary using \glossary. This second approach is unavailable with the glossaries package.
The glossary package allows you to add information to the glossary for a predefined term without producing any text in the document using
The glossary package allows you to add information to the glossary for a predefined term with the given text using
Both the glossary and the glossaries packages define the command \gls. In this case, the only thing you need to change is the number key in the optional argument to counter. Note that the new form of \gls also takes a final optional argument which can be used to insert text into the automatically generated text.
When using the glossaries package, you should not use \glossary directly.4 If, with the old package, you have opted to explicitly use \glossary instead of storing the glossary information with \storeglosentry, then converting from glossary to glossaries will be more time-consuming, although in the end, I hope you will see the benefits.5 If you have used \glossary with the old glossary package, you will instead need to define the relevant glossary terms using \newglossaryentry and reference the terms using \glsadd, \glslink, \gls etc.
If you don’t like the idea of continually scrolling back to the preamble to type all your \newglossaryentry commands, you may prefer to create a new file, in which to store all these commands, and then input that file in your document’s preamble. Most text editors and front-ends allow you to have multiple files open, and you can tab back and forth between them.
In the glossary package, acronyms were treated differently to glossary entries. This resulted in inconsistencies and sprawling unmaintainable code. The new glossaries package treats acronyms in exactly the same way as normal glossary terms. In fact, in the glossaries package, the default definition of:
This is different to the glossary package which set the name key to ⟨long⟩ (⟨abbrv⟩) and allowed you to set a description using the description key. If you still want to do this, you can use one of the description styles, such as long-short-desc, and use the description key in the optional argument of \newacronym.
For example, if your document originally had the following:
Then you would need to first set the style:
and change the acronym definition to:
You can then reference the acronym using any of the new referencing commands, such as \gls or \glsadd.
With the old glossary package, when you defined an acronym, it also defined a command \⟨acr-name⟩ which could be used to display the acronym in the text. So the above SVM example would create the command \SVM with the old package. In the new glossaries package, the acronyms are just another type of glossary entry, so they are displayed using \gls{⟨label⟩}. Therefore, in the above example, you will also need to replace all occurrences of \SVM with \gls{svm}.
If you have used \useacronym instead of \⟨acr-name⟩, then you will need to replace all occurrences of
Alternatively (as from v1.18 of the glossaries package), you can use \oldacronym which uses the same syntax as the old glossary package’s \newacronym and also defines \⟨acr-name⟩. For example, if your document originally had the following:
\newacronym{SVM}{Support Vector Machine}{description=Statistical
pattern recognition technique}
\oldacronym{SVM}{Support Vector Machine}{description=Statistical
pattern recognition technique}
In the glossary package, it is possible to produce the long and short forms of an acronym without adding an entry to the glossary using \acrln and \acrsh. With the glossaries package (provided you defined the acronym using \newacronym or \oldacronym and provided you haven’t redefined \newacronym) you can replace
See Acronyms of the glossaries manual for further details of how to use these commands.
The glossary package command
The glossary package allows you to reset and unset the acronym flag which is used to determine whether the acronym has been used in the document. The glossaries package also provides a means to do this on either a local or a global level. To reset an acronym, you will need to replace:
To unset an acronym, you will need to replace:
To reset all acronyms, you will need to replace:
The glossary package provides the command \printglossary (or \print⟨type⟩ for other glossary types) which can be used to print individual glossaries. The glossaries package provides the command \printglossaries which will print all the glossaries which have been defined, or \printglossary[⟨options⟩] to print individual glossaries. So if you just have \printglossary, then you can leave it as it is, but if you have, say:
or
then you will need to replace this with either
or
The glossary package allows you to specify a short title (for the table of contents and page header) by defining a command of the form \short⟨glossary-type⟩name. The glossaries package doesn’t do this, but instead provides the toctitle key which can be used in the optional argument to \printglossary. For example, if you have created a new glossary type called notation, and you had defined
then you would need to use the toctitle key:
The glossaries package will ignore \shortnotationname, so unless you have used it elsewhere in the document, you may as well remove the definition.
If you convert your document from using the glossary package to the glossaries package, you will need to delete any of the additional files, such as the .glo file, that were created by the glossary package, as the glossaries package uses a different format. Remember also, that if you used the makeglos Perl script, you will need to use the makeglossaries Perl script instead. As from v1.17, the glossaries package can be used with either makeindex or xindy. Since xindy was designed to be multilingual, the new glossaries package is a much better option for non-English documents. If you use the extension package, glossaries-extra, then you also have the option of using bib2gls instead (which also provides multilingual support).
For further information on using makeglossaries, makeindex or xindy to create your glossaries, see Generating the Associated Glossary Files of the glossaries documentation.
Please check the FAQ for the glossaries package if you have any problems.
B
F
file types
.glo 2
G
glossaries-extra package 3
\gls options
counter 4
number 5
\glsadd options
counter 6
M
makeglos 7
makeglossaries 8, 9
makeindex 10, 11, 12, 13, 14, 15, 16, 17, 18
N
\newglossaryentry options
description 19, 20
name 21
P
\printglossary options
style 22
toctitle 23, 24, 25
S
\storeglosentry options
format 26
number 27
1as from v1.17. Previous versions were designed to be used with makeindex only
2as from v1.17
3mainly because having a key value list in \glossary caused problems, but it also helps consistency.
4This is because \glossary requires the argument to be in a specific format and doesn’t use the ⟨key⟩=⟨value⟩ format that the old glossary package used. The new package’s internal commands set this format, as well as escaping any of makeindex’s or xindy’s special characters. What’s more, the format has changed as from v1.17 to allow the new package to be used with either makeindex or xindy.
5From the user’s point of view, using \glossary throughout the document is time consuming, and if you use it more than once for the same term, there’s a chance extra spaces may creep in which will cause makeindex to treat the two entries as different terms, even though they look the same in the document.