Documents that contain a large number of terms or acronyms may require special Glossaries in LaTeX section at the end. This glossary typically includes a list of these terms and their definitions.
If you intend to create a professional document in LaTeX, you should know that it is possible to create glossaries in LaTeX relatively easily. Let’s look at the different ways to do this.
What is a Glossary?
Before we look at how to create glossaries in LaTeX, it is worth discussing what exactly they are. A glossary can be defined as a list of words that relate to a specific subject. They are usually set in alphabetical order and offer brief explanations of each term. You can view a Glossaries in LaTeX as a list of definitions for terms contained within the preceding text.
How to Create a Glossary in LaTeX
Creating glossaries in LaTeX is a relatively straightforward process. However, you should be aware of the different commands and packages required to do this properly. The main package required for glossaries in LaTeX is called glossaries. You can use this package using the command \usepackage{glossaries} in your document’s preamble. Then, you can use the command \makeglossaries prior to adding the first glossary entry.
Finally, you can start adding glossary entries using the command \newglossaryentry{YOUR GLOSSARY TERM}. Following this, you can reference the glossary entry in your document text by using the command gls.
Once this is complete, it is possible to print each of your glossaries in LaTeX entries along with their corresponding definitions and descriptions using the command \printglossaries. Each of these terms will automatically be printed under the section title Glossary.
We demonstrate the code for creating glossaries in LaTeX and adding a single term in the example below:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{glossaries}
\makeglossaries
\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. It is eaten with bread using long-stemmed forks. }
}
\newglossaryentry{raclette}
{
name=raclette,
description={is a Swiss dish that is also popular in France. It involves heating cheese and scraping off the melted portion and topping it onto meats or vegetables.}
}
\title{Different Types of Cheese Dishes in Europe}
\author{ }
\date{ }
\begin{document}
\maketitle
\Gls{fondue} is a very popular dish and is often associated with \gls{raclette}.
\clearpage
\printglossaries
\end{document}
When compiled, the output code resembles the following:
Referencing Terms in Uppercase and Lowercase
You may have noticed that we used the commands gls and Gls in different places in the code above. As mentioned earlier, gls informs LaTeX to reference the entry. However, this lowercase version references the term in a slightly different manner than Gls does. We explain the differences between the two as well as similar commands below.
\gls{TERM TEXT }: This will print your term with lowercase lettering. For example, \gls{fondue} prints fondue when used.
\Gls{TERM TEXT}: This is similar to the \gls command, except that the first letter of the term will be printed in uppercase. For example: \Gls{fondue} prints Fondue.
\glspl{TERM TEXT}: This is similar to the \gls command, except that the term will be shown in its plural form. For example, \glspl{cheese} will show up as cheeses in the final document.
\Glspl{TERM TEXT}: This is similar to the command \Gls, except that the term will be put in its plural form. For example, \Glspl{cheese} will show up as Cheeses.
Using Terms and Acronyms in LaTeX
In the above example, we demonstrated how to add definitions for terms in LaTeX. However, glossaries in LaTeX are also useful for explaining what different acronyms mean.
You can print both terms and acronyms separately within a glossary in LaTeX. This is demonstrated in the following example:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[acronym]{glossaries}
\makeglossaries
\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. It is eaten with bread using long-stemmed forks. }
}
\newglossaryentry{raclette}
{
name=raclette,
description={is a Swiss dish that is also popular in France. It involves heating cheese and scraping off the melted portion and topping it onto meats or vegetables.}
}
\newacronym{msg}{MSG}{Monosodium glutamate}
\newacronym{oz}{OZ}{Ounce}
\title{Different Types of Cheese Dishes in Europe}
\author{ }
\date{ }
\begin{document}
\maketitle
\Gls{fondue} is a very popular dish and is often associated with \gls{raclette}.
\clearpage
\printglossaries
\end{document}
When compiled, the output will resemble:
As you can see, the acronyms section appears before the glossary section in LaTeX. The acronyms section contains only abbreviations and their corresponding terms, while the glossary section contains terms and their descriptions.
Adding Acronyms to LaTeX
Let’s examine how to add only acronyms to LaTeX. In the code above, you may have noticed the commands \usepackage[acronym]{glossaries} and \newacronym.
Adding the command \usepackage[acronym]{glossaries} in the preamble informs LaTeX to create an acronyms section. Once this is done, the command \newacronym lets you declare new acronyms for your document.
For example, we used the code \newacronym{msg}{MSG}{Monosodium glutamate}.
In the above code, msg can be viewed as the label that references the acronym in the document. MSG is the acronym itself and is normally denoted in all capital letters. Finally, Monosodium glutamate is the full term the acronym denotes.
Once the acronyms have been added to your preamble, you can use additional commands to describe how they should be denoted.
- \acrlong{ACRONYM LABEL}: This command displays the full phrase that the acronym stands for. So \acrlong{msg} will be shown as Monosodium glutamate in the final document.
- \acrshort{ACRONYM LABEL}: This command displays the acronym that the label is associated with. So \arshort{msg} will be shown as MSG in the final document.
- \acrfull{ACRONYM LABEL}: This command displays both the acronym as well as its definition. So \acrfull{msg} will be shown as Monosodium glutamate (MSG) in the final document.
Printing Your List of Acronyms
LaTeX allows you to print your list of acronyms using the command \printglossary[type=\acronymtype]. You should note that LaTeX requires a temporary file to print your acronyms. This temporary file is generated using the command \printglossary, so it must be added just before \printglossary[type=\acronymtype] in your code. After this, you should compile the code and remove the \printglossary line.
Changing the Glossary Title
In the above examples, we showed that LaTeX creates the glossary section in the final document with the title “Glossary”. However, in some situations, you may need to use a different title for your glossary. You can do this by adding parameters to the \printglossary command near the end of your code.
For example:
\printglossary[title=Terms Explained, toctitle=List of Different Terms Used]
This sets the glossary title as Terms Explained and the table of contents title as List of Different Terms Used.
Displaying Your Glossaries in LaTeX via Document Table of Contents
It is possible to include your glossary in the document’s table of contents using the command \usepackage
Table of Contents
How to Compile Your Glossaries in LaTeX
Compiling glossaries in LaTeX is straightforward. However, if you intend to add new terms to it after it has been compiled, you will need to select the Clear cached files option under logs. If you intend to compile your document on your local device using pdflatex, you can use the following code:
pdflatex myglossaries.tex
makeglossaries glossaries
pdflatex myglossaries.tex
myglossaries.tex is the document name in this example.
Using Different Glossary Styles
Glossaries in LaTeX also allows you to set different styles for your glossary. This can be accomplished using the command \glossarystyle{YOUR CHOSEN STYLE} before the command \printglossaries. The different glossary styles and their corresponding codes are listed below:
- list: This style shows each defined term using boldface font
- altlist: This style inserts a new line after the displayed term and indents its description.
- listgroup: This style groups each term based on their first letter.
- listhypergroup: This style adds hyperlinks at the very top of the glossary index.
Final Thoughts
As you can see, creating glossaries in LaTeX is a simple task. You can enhance the content of your documents using glossaries. So try offering readers additional information about terms and acronyms by adding a glossary to your next LaTeX Document.
Frequently Asked Questions
Some frequently asked questions related to glossaries in LaTeX are shown below:
Q1. How Can I Link an Acronym (e.g: MVP) to the Glossary at Occurrence but Spell It Out at the First Occurrence (e.g: Minimal Viable Product)?
You can use the command \acrshort{ACRONYM LABEL} to display the acronym and the command \acrlong{ACRONYM LABEL} to display the full term.
Q2. How Do I Add Acronyms in LaTex?
You can easily add acronyms in LaTeX documents by first using the command \usepackage[acronym]{glossaries} and then \newacronym{LOWERCASE LABEL}{UPPERCASE LABEL}{THE FULL TERM}.
Q3. How Do I Reference Terms So That the First Letter is Uppercase?
You can reference terms in a manner that displays the first letter as uppercase using the command \Gls{TERM TEXT }.
Further Reading
LaTex Tutorial
- 27 Pros and Cons of Using LaTex for Scientific Writing
- 6 easy steps to create your first Latex document examples
- How to add circuit diagrams in Latex
- How to change Latex font and font size
- How to create a Latex table of contents
- How to create footnotes in LaTeX and how to refer to them, using the builtin commands
- How to create plots in Latex – codes and examples
- How to create symbols in LaTeX – commands for Latex greek alphabet
- How to create tables in LaTeX – rows, columns, pages and landscape tables
- How to drawing graphs in Latex – vector graphics with tikz
- How to highlight source code in LaTeX
- How to insert an image in LaTeX – Managing Latex figure and picture
- How to Itemize and Number List – Adding Latex Bullet Points
- How to make hyperlink in latex – Clickable links
- How to reference in Latex – 5 steps to bibliography with Bibtex
- How to use Latex Packages with examples
- How to use LaTeX paragraphs and sections
- LaTeX Installation Guide – Easy to follow steps to install LaTex
- Learn to typeset and align Latex equations and math