[Tex/LaTex] Package glossaries errors

glossaries

I wanted to use a glossary for the first time. I choose to go with the glossaries package and imported it with:

\usepackage[toc, acronym]{glossaries}

and later used the

\makeglossaries

command and wanted to print the acronyms short after the table of contents with:

\printglossary[type=acronymtype]

Therefore I created a file with all acronyms in it right before the print statement.
Then nothing was shown, in the glossary. So I went on, and used some entries in the document (text and headlines of sections).

My file structure is a main file with one included LaTeX document for every chapter. So I included the file the the acronyms in the main file and wanted to use them in the included LaTeX documents. The acronyms were imported before the LaTeX files.

But now I get the error message:

Glossary entry: '...' has not been defined

What I have checked: names of the files are correct.
Tested to include the acronym list also to in the files for the chapters.

Did a short web search. Does anyone have an idea where such an error might come from?


Update:

I found the error, why the document did not compile. I used \include instead of \input for importing the acronym file. Here is a minimal example:

main file:

 % This file is public domain
 % If you want to use arara, you need the following directives:
 % arara: pdflatex
 % arara: makeglossaries
 % arara: pdflatex
\documentclass{book}

\usepackage[toc, acronym]{glossaries}

\makeglossaries

\newglossaryentry{apple}{name={apple},description={a fruit}}

\begin{document}

\input{acronyms.tex}
\author{my Name}
\title{Glossary Test}
\maketitle

\newpage
\tableofcontents

\newpage
\printglossary[type=\acronymtype]

\chapter{\acrlong{xml}}
\Gls{apple} or \gls{apple} or \glspl{apple}.


\end{document}

The imported file has following lines:

\newacronym{autosar}{AUTOSAR}{AUTomotive Open System ARchitecture}
\newacronym{xml}{XML}{Extensible Markup Language}

The problem that is left over is, that neither the used nor the unused acronyms are showing up in a glossary.

Attempts to solve the problem:

  1. I normaly use xelatex as processor, but a change to pdflatex did not change anything.

  2. Also defining the acronmys in the main file did not change anything.

I hope, that is description may help to solve the problem.

Best Answer

First move \input{acronyms} to the preamble and delete the .glsdefs file.

\documentclass{book}

\usepackage[toc, acronym]{glossaries}

\makeglossaries

\newglossaryentry{apple}{name={apple},description={a fruit}}

\input{acronyms.tex}% input somewhere before \begin{document}

\begin{document}

\author{my Name}
\title{Glossary Test}
\maketitle

\newpage
\tableofcontents

\newpage
\printglossary[type=\acronymtype]

\chapter{\acrlong{xml}}
\Gls{apple} or \gls{apple} or \glspl{apple}.

\end{document}

If the document is called, say, myDoc.tex then the complete document can be built with¹:

pdflatex myDoc
makeglossaries myDoc
pdflatex myDoc
pdflatex myDoc

or

xelatex myDoc
makeglossaries myDoc
xelatex myDoc
xelatex myDoc

This shows the list of acronyms containing just the xml entry, because the autosar entry hasn't been indexed in the document.

Acronyms XML Extensible Markup Language. 3, 7

The location list includes page 3 (after a rebuild) because \acrlong{xml} is in the table of contents (which is on page 3). To avoid that, use the optional argument of \chapter with one of the non-indexing commands:

\documentclass{book}

\usepackage[toc, acronym]{glossaries}

\makeglossaries

\newglossaryentry{apple}{name={apple},description={a fruit}}

\input{acronyms.tex}% input somewhere before \begin{document}

\begin{document}

\author{my Name}
\title{Glossary Test}
\maketitle

\newpage
\tableofcontents

\newpage
\printglossary[type=\acronymtype]

\chapter[\glsentrylong{xml}]{\acrlong{xml}}
\Gls{apple} or \gls{apple} or \glspl{apple}.

\end{document}

Now only page 5 appears in the location list:

Acronyms XML Extensible Markup Language. 5

If you want the unused entries to also appear in the list (without an associated page number) add \glsaddallunused at the end of the document.

\documentclass{book}

\usepackage[toc, acronym]{glossaries}

\makeglossaries

\newglossaryentry{apple}{name={apple},description={a fruit}}

\input{acronyms.tex}% input somewhere before \begin{document}

\begin{document}

\author{my Name}
\title{Glossary Test}
\maketitle

\newpage
\tableofcontents

\newpage
\printglossary[type=\acronymtype]

\chapter[\glsentrylong{xml}]{\acrlong{xml}}
\Gls{apple} or \gls{apple} or \glspl{apple}.

\glsaddallunused % force indexing for all unused entries
\end{document}

Unfortunately, in this case xml has been indexed but it hasn't been marked as used (\gls both indexes and marks an entry as used, but \acrlong only indexes), so xml's location list goes wrong (in this case it disappears, but in other cases you can end up with a spurious comma):

Acronyms AUTOSAR AUTomotive Open System ARchitecture. XML Extensible Markup Language.

If you add \gls{xml} anywhere in the document (before \glsaddallunused), the problem will go away, otherwise you need to explicitly mark it as used:

\documentclass{book}

\usepackage[toc, acronym]{glossaries}

\makeglossaries

\newglossaryentry{apple}{name={apple},description={a fruit}}

\input{acronyms.tex}% input somewhere before \begin{document}

\begin{document}

\author{my Name}
\title{Glossary Test}
\maketitle

\newpage
\tableofcontents

\newpage
\printglossary[type=\acronymtype]

\chapter[\glsentrylong{xml}]{\acrlong{xml}}
\glsunset{xml}% mark xml as used

\Gls{apple} or \gls{apple} or \glspl{apple}.

\glsaddallunused
\end{document}

Acronyms AUTOSAR AUTomotive Open System ARchitecture. XML Extensible Markup Language. 5

The default main glossary (containing apple) doesn't appear in the document because \printglossary has only been used with type=\acronymtype.

\documentclass{book}

\usepackage[toc, acronym]{glossaries}

\makeglossaries

\newglossaryentry{apple}{name={apple},description={a fruit}}
\newglossaryentry{pear}{name={pear},description={another fruit}}

\input{acronyms.tex}% input somewhere before \begin{document}

\begin{document}

\author{my Name}
\title{Glossary Test}
\maketitle

\newpage
\tableofcontents

\newpage
\printglossary[type=\acronymtype]% list of acronyms
\printglossary % main glossary

\chapter[\glsentrylong{xml}]{\acrlong{xml}}
\glsunset{xml}% mark xml as used

\Gls{apple} or \gls{apple} or \glspl{apple}.

\glsaddallunused
\end{document}

I've added another entry pear but haven't used it in the document, but \glsaddallunused automatically adds it, so the glossary looks like:

Glossary apple a fruit. 5 pear another fruit.

You can limit \glsaddallunused to a particular sub-set of lists with the optional argument, which should be a comma-separated list of labels identifying the required glossaries:

\glsaddallunused[\acronymtype]

Here's an alternative method using the glossaries-extra extension package. This internally loads glossaries and automatically implements the toc and nopostdot options. (Use postdot or nopostdot=false to make the post-description full stop reappear.) The extension package also provides some commands specifically for use in chapter/section arguments, such as \glsfmtshort and \glsfmtlong.

\documentclass{book}

\usepackage[acronym]{glossaries-extra}

\makeglossaries

\setabbreviationstyle[acronym]{long-short}

\newglossaryentry{apple}{name={apple},description={a fruit}}
\newglossaryentry{pear}{name={pear},description={another fruit}}

\input{acronyms.tex}% input somewhere before \begin{document}

\begin{document}

\author{my Name}
\title{Glossary Test}
\maketitle

\newpage
\tableofcontents

\newpage
\printglossary[type=\acronymtype]% list of acronyms
\printglossary % main glossary

\chapter{\glsfmtlong{xml}}

First use \gls{xml}. Next use \gls{xml}.

\Gls{apple} or \gls{apple} or \glspl{apple}.

\glsaddallunused[\acronymtype] % add all unused entries from the acronym list
\end{document}

Chapter 1 Extensible Markup Language First use Extensible Markup Language (XML). Next use XML. Apple or apple or apples.

Outside of section headings, the short form is obtained with \glsxtrshort (not \acrshort), the long form is obtained with \glsxtrlong (not \acrlong) and the full form (without reference to the first use) is obtained with \glsxtrfull (not \acrfull).

If you don't want long (short) then change the abbreviation style to whatever form you will use most. For example, if you only want the short form except in the chapter heading then use the short style. This way you can use \gls to ensure that the entry is marked as used:

\documentclass{book}

\usepackage[acronym]{glossaries-extra}

\makeglossaries

\setabbreviationstyle[acronym]{short}

\newglossaryentry{apple}{name={apple},description={a fruit}}
\newglossaryentry{pear}{name={pear},description={another fruit}}

\input{acronyms.tex}% input somewhere before \begin{document}

\begin{document}

\author{my Name}
\title{Glossary Test}
\maketitle

\newpage
\tableofcontents

\newpage
\printglossary[type=\acronymtype]% list of acronyms
\printglossary % main glossary

\chapter{\glsfmtlong{xml}}

First use \gls{xml}. Next use \gls{xml}.

\Gls{apple} or \gls{apple} or \glspl{apple}.

\glsaddallunused[\acronymtype] % add all unused entries from the acronym list
\end{document}

For a full list of available abbreviation styles, see sample-abbr-styles.pdf.

Chapter 1 Extensible Markup Language First use XML. Next use XML. Apple or apple or apples.

If you want all defined entries listed, without page numbers, in the order of definition, then you can omit \makeglossaries and \glsaddallunused and replace \printglossary with \printunsrtglossary. (This option is only available with glossaries-extra):

\documentclass{book}

\usepackage[acronym]{glossaries-extra}

\setabbreviationstyle[acronym]{long-short}

\newglossaryentry{apple}{name={apple},description={a fruit}}
\newglossaryentry{pear}{name={pear},description={another fruit}}

\input{acronyms.tex}% input somewhere before \begin{document}

\begin{document}

\author{my Name}
\title{Glossary Test}
\maketitle

\newpage
\tableofcontents

\newpage
\printunsrtglossary[type=\acronymtype]% list of acronyms
\printunsrtglossary % main glossary

\chapter{\glsfmtlong{xml}}

First use \gls{xml}. Next use \gls{xml}.

\Gls{apple} or \gls{apple} or \glspl{apple}.

\end{document}

The document build is now simplified to:

pdflatex myDoc
pdflatex myDoc

or

xelatex myDoc
xelatex myDoc

Acronyms AUTOSAR AUTomotive Open System ARchitecture XML Extensible Markup Language


¹The very first instance requires a rerun of the above because the page numbers will be off due to the missing list of acronyms on the first run. This isn't a problem if the list is at the end of the document or if the page numbering is reset after the list. For example, if you use \frontmatter and \mainmatter:

\begin{document}

\author{my Name}
\title{Glossary Test}
\maketitle

\frontmatter
\tableofcontents

\printglossary[type=\acronymtype]% list of acronyms
\mainmatter
Related Question