Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 18, 2024
A glossary is an alphabetical list of terms with their definitions. Just like creating a reference section, creating a glossary can be done automatically in LaTeX with the support of specific packages.
In this tutorial, we’ll study step-by-step how to create a glossary in a LaTeX document.
The current active LaTeX packages dedicated to creating glossaries are nomencl and glossaries. These packages support acronyms and multiple glossaries and can work in several languages (using babel or polyglossia).
Obviously, as for all other LaTeX packages, we need to use the \usepackage command to load the nomencl or glossaries package. There are also certain packages that need to be loaded before glossaries, if they are required: hyperref, babel, polyglossia, inputenc, and fontenc. In that case, these packages must be loaded before glossaries.
The following steps describe the procedure to generate a glossary in LaTeX documents:
In what follows, we’ll introduce a step-by-step tutorial for generating a glossary with the glossaries package.
First, we need to load the glossaries package:
\usepackage{glossaries}
Once glossaries have been loaded, the following command is used to generate the glossary:
\makeglossaries
Now, we can create entries to define our terms and definitions using the command \newglossaryentry:
\newglossaryentry{<label>}{name={<key>}, description={<value>}}
For example:
\newglossaryentry{latex}{name=latex}, description={LaTeX is a document preparation system}
As we can see, there are three parameters that are passed to the \newglossaryentry command. For the above example, here are details of the three parameters:
We then can produce the desired term in the document, we can use the standard command \gls{} as follows:
In this phrase, the user-defined term \gls{latex} is inserted.
The \gls{} command prints the term in lowercase letters. For instance, \gls{latex} will print latex.
To capitalize the first letter or pluralize the term, we use the following additional commands:
% Standard command
\gls{<label>}
% Capitalize first letter. For example, \Gls{latex} will print Latex
\Gls{<label>}
% Pluralize term. For example, \glspl{latex} will print latexs
\glspl{<label>}
% Capitalize and pluralize term. For example, \Glspl{latex} will print Latexs
\Glspl{<label>}
The last step is to display the glossary in the document. To do this, we use the command \printglossaries.
Now, let’s create a simple glossary following the above steps:
\begin{document}
\section{Section with glossaries}
% Term definitions
\newglossaryentry{fondue}{
name=fondue,
description={is a Swiss dish consisting of melted cheese that is served in a
communal pot heated over a portable stove using a candle or a spirit lamp}
}
\newglossaryentry{raclette}{
name=raclette,
description={is a Swiss dish that involves heating cheese and
scraping off the melted portion and topping it onto meats or vegetables}
}
% Use the terms
\Gls{fondue} is a very popular dish and is often associated with \gls{raclette}.
% Print the glossary
\printglossaries
\end{document}
This will generate the following result:
We can see that, resulting from the usage of the commands \Gls{} and \gls, here the term Fondue is capitalized, and raclette is in lowercase letters.
Acronyms are different from glossary entries. For acronyms, the definition is produced in the text with the acronym in parentheses. For glossary entries, only the name is produced. The package distinguishes between a glossary and a list of acronyms.
By default, acronyms are produced as part of the glossary. To generate a separate list of acronyms, the package needs to be loaded with the acronym option:
\usepackage[acronym]{glossaries}
To define an acronym entry, here is the command:
\newacronym{⟨label⟩}{⟨abbrv⟩}{⟨full⟩}
Let’s understand the \newacronym command usage and parameter description with an example:
\newacronym{e2e}{E2E}{End to End}
To print the list of all acronyms with their definition/description, we can use:
\printglossary[type=\acronymtype]
Please note that if we use an online LaTeX platform such as Overleaf to compile our LaTeX documents, this command works just fine. Nevertheless, it may happen that the command \printglossary[type=\acronymtype] needs a temporary file that is created by \printglossary to work properly. To solve this problem, the only thing we need is to put the command \printglossary just before the command \printglossary[type=\acronymtype]. After the first compilation, we can delete the \printglossary command.
Now let’s see what the basic example above looks like when we define the terms as acronyms and use the acronym option:
\documentclass{article}
% Load the package with the acronym option
\usepackage[acronym,nomain]{glossaries}
% Generate the glossary
\makeglossaries
\begin{document}
\section*{Section with acronyms}
% Acronym definitions
\newacronym{e2e}{E2E}{End To End}
% Use the acronyms
\begin{itemize}
\item The command \verb+\acrlong{e2e}+ will produce: \acrlong{e2e}
\item The command \verb+\acrshort{e2e}+ will produce: \acrshort{e2e}
\item The command \verb+\acrfull{e2e}+ will produce: \acrfull{e2e}
\end{itemize}
% Print the glossary
\printglossaries[type=\acronymtype]
\end{document}
This will generate the following result:
In the above examples, we showed that LaTeX creates the glossary section in the final document with the title “Glossary” (or “Acronyms” with the \acronymtype option). It is possible that we may need to use a different title for our glossary in some situations. To do so, we need to add the additional parameters to the \printglossary command:
\printglossary[title=<User-defined title>, toctitle=<User-defined TOC title>]
Following are the two parameters that are passed with \printglossary command:
To display the glossary section in the table of content, we need to add an option when loading the glossaries package:
\usepackage[toc]{glossaries}
Finally, let’s take a look at the following simple example:
\begin{document}
\tableofcontents
\section{Section with glossaries}
% Term definitions
\newglossaryentry{fondue}{
name=fondue,
description={is a Swiss dish consisting of melted cheese that is served in a communal pot heated over a portable stove using a candle or a spirit lamp}
}
\newglossaryentry{raclette}{
name=raclette,
description={is a Swiss dish that involves heating cheese and scraping off the melted portion and topping it onto meats or vegetables}
}
% Use the terms
\Gls{fondue} is a very popular dish and is often associated with \gls{raclette}.
% Print the glossary
\printglossary[type=\acronymtype,title=Used Terms, toctitle=List of Used Terms]
\end{document}
This will yield the following result:
As we can see, the title of the glossary section appears as Used Terms instead of the default one (Glossary). Also, in the table of contents, the glossary section is listed as a List of Used Terms.
In this article, we’ve presented a step-by-step tutorial to generate a list of glossaries or acronyms in LaTeX using the glossaries package. We have also learned how to customize the glossary section and how to change its appearance on the table of contents of the LaTeX document.