LaTeX Glossary

Posted by Beauford on Fri, 21 Jan 2022 13:24:48 +0100

Original: Glossaries
Translated by: Xovee
Translation time: July 7, 2021

Glossary

When writing scientific and technological articles, we sometimes need a glossary to summarize some concepts in specific fields in the article for the convenience of readers. The glossary consists of a series of domain specific terms and their definitions. This article describes how to use LaTeX to create a glossary.

introduce

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}


First, we introduce the glossary package in the preamble of the document:

\usepackage{glossaries}

The command \ makeglossaries must precede the first term entry.

Each term entry is created by the command \ newglossary entry, which has two parameters. Each entry can be referenced later using the command \ gls.

The command \ printglossaries will print out the Glossary we created in the document with the title Glossary. In the example above, it appears at the end of the document. You can print the Glossary anywhere in the document.

Terms and Acronyms

There are generally two types of entries in the glossary:

  1. Terms and their definitions
  2. Acronyms and their full names

These two types of items can be displayed separately in the 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}

Let's introduce the specific use methods.

Term Terms

As we saw earlier, the term is defined by the command \ newglossary entry:

\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 introduce their syntax next. The first defined term is mathematics.

  • maths
    The first parameter is the label of the term. We can use the \ gls command to refer to the term later.

  • name=mathematics
    The name of the term. In this example, the name of the term is mathematics. The recommended writing is lowercase + singular.

  • description={Mathematics is what mathematicians do}
    Definition of terms.

After you define the term entry, you can use the following command to refer to it:

\gls{ }
Print the term in lowercase letters. For example, \ GLS {math} outputs mathematics.

\Gls{ }
Capitalize. For example, \ GLS {math} outputs Mathematics.

\glspl{ }
Plural form. For example, \ glspl{formula} will become formulas.

\Glspl{ }
Capitalized plural. For example, \ glspl{formula} will become Formulas.

Finally, use the \ printglossary command to print the glossary.

Acronyms acronyms

An abbreviation is the initial capital of a phrase. Here is a basic example:

\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}


In order to use abbreviations, you must pass a parameter when introducing the glossaries package:

\usepackage[acronym]{glossaries}

You can then use the \ newaronym command to declare new abbreviations. The following is an interpretation of the command \ newacronym {GCD} {GCD} {greater common divisor}:

  • gcd is a label that refers to abbreviations.
  • GCD is the abbreviation itself. Abbreviations are generally expressed in capital letters.
  • Greater common division is the original phrase of the abbreviation.

After the abbreviation is defined in the preamble of the document, you can use the following command:

\acrlong{ }
Displays the original phrase of the abbreviation. For example, \ acrlong{gcd} prints the greatest common distributor.

\acrshort{ }
Print abbreviations. For example, \ acrshort{gcd} prints the GCD.

\acrfull{ }
Print abbreviations and their original phrases. For example, \ acrfull{lcm} prints Least Common Multiple (LCM).

To print a list of abbreviations, use the following command:

\printglossary[type=\acronymtype]

Because the list of abbreviations requires a temporary file generated by the \ printglossary command, you must add the \ printglossary command before the \ printglossary[type=\acronymtype] command and compile the document. Once you have successfully compiled the document, you can delete the \ printglossary command.

Change the title of the glossary

If you want to change the default title of the glossary, you only need to pass two additional parameters when printing the glossary. Here 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}


The command \ printglossary has two comma separated arguments:

  • title=Special Terms, the title of the glossary
  • toctitle=List of term, the title of the glossary in the table of contents

Show glossary in catalog

To display the glossary in the table of contents, add the following command:

\usepackage[toc]{glossaries}

example:

\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}

Compile Glossary

No additional action is required to compile the glossary in overflow. If you add a new glossary after compiling the document, make sure you clean up the cache files (click Clear cached files in the logs option).

If you compile the document locally (assuming that the document is glossaries.tex), you need to use the following command:

pdflatex glossaries.tex

makeglossaries glossaries

pdflatex glossaries.tex

Reference guide

Available glossary styles

The command \ glossarystyle{style} must precede the command \ printglossaries. Here are some styles available:

  • list
    Defined terms are displayed in bold

  • altlist
    Add a new line after the term and indent the description of the term.

  • listgroup
    Group terms with initials.

  • listhypergroup
    Add a hyperlink at the top of the index.

Topics: Latex