[Tex/LaTex] Errors when using glossaries package

glossaries

I am compiling a .tex file with TeXmaker, but it's still generating errors.
In fact, I use the glossaries package but when I add a newglossaryentry, the compilation ends with errors.
This is my code:

\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}

\author{sk001}
\title{My title}

\usepackage[style=long, nonumberlist, toc, xindy, nowarn, nomain, section=chapter]{glossaries}

\makeglossaries

\newglossaryentry{iai}{%
name={IAI},%
description={Institut Africain d'Informatique}%
type=\newacronym
}

\begin{document}
\titlepage

\newpage

L'Institut Africain d'Informatique(\gls{iai}) est un établissement d'enseignement supérieur.

\printglossary


\end{document}

This is the displayed error in the log:

! Missing \endcsname inserted.
<to be read again>
\glsdefaulttype
l.50 }
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
! Package glossaries Error: Glossary type '\glsdefaulttype ' has not been defin
ed.
See the glossaries package documentation for explanation.
Type H <return> for immediate help.
...
l.50 }
You need to define a new glossary type, before making entries in it
! Missing \endcsname inserted.
<to be read again>
\glsdefaulttype
l.50 }
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.

Best Answer

As others have pointed out the problem comes from using nomain (which prevents the main glossary from being created) but you haven't provided an alternative glossary (via package options such as acronym or explicitly using \newglossary).

It looks like you actually want the acronym option with \newacronym rather than \newglossaryentry. Like this:

\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}

\author{sk001}
\title{My title}

\usepackage[style=long,nonumberlist,toc,xindy,acronym,nomain]{glossaries}

\makeglossaries

\newacronym{iai}{IAI}{Institut Africain d'Informatique}

\begin{document}

L'\gls{iai} est un établissement d'enseignement supérieur.
Next use: \gls{iai}.

\printglossary[type=\acronymtype]

\end{document}

Note that since you're not using the main glossary, you need to specify the glossary in the optional argument of \printglossary. Alternatively you can just use \printglossaries, like this:

\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}

\author{sk001}
\title{My title}

\usepackage[style=long,nonumberlist,toc,xindy,acronym,nomain]{glossaries}

\makeglossaries

\newacronym{iai}{IAI}{Institut Africain d'Informatique}

\begin{document}

L'\gls{iai} est un établissement d'enseignement supérieur.
Next use: \gls{iai}.

\printglossaries

\end{document}

Or, with at least version 4.0, you can use \printacronyms, which is the same as \printglossary[type=acronym].

Both the above examples produce:

Image of result

Other notes:

  1. You don't need section=chapter in the package option as that's the default for classes that define \chapter
  2. If you're just starting out with glossaries, I don't recommend using nowarn as it will suppress warnings that occur with some common new user mistakes. If you read those warnings, it may save you having to come back for more help.

Other resources:

Related Question