When writing a document that contain some filed-specific concepts it might be convenient to add a glossary. A glossary is a list of terms in a particular domain of knowledge with definitions for those terms. This article explains how to create one.
Contents |
Let's start with a simple example.
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage{glossaries} \makeglossaries \newglossaryentry{latex} { name=latex, description={Is a mark up language specially suited for scientific documents} } \newglossaryentry{maths} { name=mathematics, description={Mathematics is what mathematicians do} } \title{How to create a glossary} \author{ } \date{ } \begin{document} \maketitle The \Gls{latex} typesetting markup language is specially suitable for documents that include \gls{maths}. \clearpage \printglossaries \end{document}
To create a glossary the package glossaries has to be imported. This is accomplished by the line
\usepackage{glossaries}
in the preamble. The command \makeglossaries
must be written before the first glossary entry.
Each glossary entry is created by the command \newglossaryentry
which takes two parameters, then each entry can be referenced later in the document by the command \gls
. See the subsection about terms for a more complete description.
The command \printglossaries
is the one that will actually render the list of words and definitions typed in each entry, with the title "Glossary". In this case it's shown at the end of the document, but \printglossaries can be used in any other location.
Open an example of the glossaries package in Overleaf
Usually there are two types of entries in a glossary: terms and their definitions, or acronyms and their meaning. This two types can be printed separately in your LaTeX document.
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[acronym]{glossaries} \makeglossaries \newglossaryentry{latex} { name=latex, description={Is a mark up language specially suited for scientific documents} } \newglossaryentry{maths} { name=mathematics, description={Mathematics is what mathematicians do} } \newglossaryentry{formula} { name=formula, description={A mathematical expression} } \newacronym{gcd}{GCD}{Greatest Common Divisor} \newacronym{lcm}{LCM}{Least Common Multiple} \begin{document} The \Gls{latex} typesetting markup language is specially suitable for documents that include \gls{maths}. \Glspl{formula} are rendered properly an easily once one gets used to the commands. Given a set of numbers, there are elementary methods to compute its \acrlong{gcd}, which is abbreviated \acrshort{gcd}. This process is similar to that used for the \acrfull{lcm}. \clearpage \printglossary[type=\acronymtype] \printglossary \end{document}
In the next subsections a detailed description on how to create each one of the lists is provided.
Open an example of the glossaries package in Overleaf
As seen in the introduction, terms are defined by means of the command \newglossaryentry
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage{glossaries} \makeglossaries \newglossaryentry{maths} { name=mathematics, description={Mathematics is what mathematicians do} } \newglossaryentry{latex} { name=latex, description={Is a mark up language specially suited for scientific documents} } \newglossaryentry{formula} { name=formula, description={A mathematical expression} } \begin{document} The \Gls{latex} typesetting markup language is specially suitable for documents that include \gls{maths}. \Glspl{formula} are rendered properly an easily once one gets used to the commands. \clearpage \printglossary \end{document}
Let's see in more detail the syntax of each parameter passed to the command \newglossaryentry
. The first term defined in the example is "mathematics".
maths
. This first parameter is the label of this term and is used to reference it within the document with gls
name=mathematics
. Includes The word to be defined, in this case "mathematics". It's recommended to write it in lowercase letters and singular form.
description={Mathematics is what mathematicians do}
. Inside the braces is the definition of the current term.
After you have defined the terms, to use them while you are typing your LaTeX file use one of the commands describe below:
\gls{ }
\gls{maths}
prints mathematics when used.
\Gls{ }
\Gls{maths}
prints Mathematics
\glspl{ }
\glspl{formula}
will write formulas in your final document.
\Glspl{ }
\Glspl{formula}
renders as Formulas.
Finally, to print the glossary use the command
\printglossary
Open an example of the glossaries package in Overleaf
An acronym is a word formed from the initial letters in a phrase. Below is an example of acronyms in LaTeX
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[acronym]{glossaries} \makeglossaries \newacronym{gcd}{GCD}{Greatest Common Divisor} \newacronym{lcm}{LCM}{Least Common Multiple} \begin{document} Given a set of numbers, there are elementary methods to compute its \acrlong{gcd}, which is abbreviated \acrshort{gcd}. This process is similar to that used for the \acrfull{lcm}. \clearpage \printglossary[type=\acronymtype] \end{document}
To use acronyms an additional parameter must be used when importing the glossaries package. The line to be added to the preamble is
\usepackage[acronym]{glossaries}
Once this line is added, the command \newacronym
will declare a new acronym. For the sake of an example, below is a description of the command \newacronym{gcd}{GCD}{Greatest Common Divisor}
gcd
is the label, used latter in the document to reference this acronym.
GCD
the acronym itself. Usually acronyms are written in capital letters.
Greatest Common Divisor
is the phrase this acronym is used for.
After the acronyms have been included in the preamble, they can be used by means on the next commands:
\acrlong{ }
\acrlong{gcd}
prints Greatest Common Divisor.
\acrshort{ }
\acrshort{gcd}
renders as GCD.
\acrfull{ }
\acrfull{lcm}
is Least Common Multiple (LCM).
To print the list of acronyms use the command
\printglossary[type=\acronymtype]
The acronyms list needs a temporary file generated by \printglossary
to work, thereby you must add said command right before the line \printglossary[type=\acronymtype]
and compile your document, once you've compiled your document for the first time you can remove the line \printglossary
.
Open an example of the glossaries package in Overleaf
If you want to change the default title of the glossary for something else, this is straightforward, two parameters must be added when printing the glossary. Below is an example.
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage{glossaries} \makeglossaries \newglossaryentry{maths} { name=mathematics, description={Mathematics is what mathematicians do} } ... [the rest of the example is the one in the sub section "Terms"] \printglossary[title=Special Terms, toctitle=List of terms] \end{document}
Notice that the command \printglossary
has two comma-separated parameters:
title=Special Terms
is the title to be displayed on top of the glossary.
toctitle=List of terms
this is the entry to be displayed in the table of contents. See the next section.
Open an example of the glossaries package in Overleaf
For the glossary to show up in the table of contents put
\usepackage[toc]{glossaries}
in the preamble of your document
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[toc]{glossaries} \makeglossaries \newglossaryentry{maths} { name=mathematics, description={Mathematics is what mathematicians do} } [...] \begin{document} \tableofcontents \section{First Section} [...] \printglossary \end{document}
Open an example of the glossaries package in Overleaf
To compile a document that contains a glossary in Overleaf you don't have to do anything special, but if you add new terms to the glossary once you compiled it, make sure to click on Clear cached files first under logs option).
If you are compiling the document, for instance one called "glossaries.tex", in your local machine, you have to use these commands:
pdflatex glossaries.tex
makeglossaries glossaries
pdflatex glossaries.tex
Open an example of the glossaries package in Overleaf
Styles available for glossaries
The command \glossarystyle{style}
must be inserted before \printglossaries
. Below a list of available styles:
Open an example of the glossaries package in Overleaf
For more information see: