5

I want to add a glossary to my document. On this website: Glossaries I found an example and tried it on my machine:

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

As a result I got 2 pages, with the second page, where the actual glossary should appear, being empty.
However, these 2 files have been created:

  • myDoc.glsdefs
  • myDoc.glo

I also compiled my document several times.

When compiling the very same example on Sharelatex.com (an online Latex compiler), everything worked as intended (the second page wasn't empty).

  • Did you run makeglossaries or directly the indexing program (xindy/makeindex)? – Johannes_B Jun 19 '15 at 18:01
  • @Johannes_B: I executed \makeglossaries at the beginning of my document (as can be seen in this example). In Texmaker I also have makeindex %.idx as Makeindex command, but I'm not sure, whether it's being executed. – user1170330 Jun 19 '15 at 18:08
  • There is a bit more behind it, that would call makeindex to generate an index, not a glossary (or related). Please have a look at [Glossaries, Nomenclature, Lists of Symbols and Acronyms ](latex-community.org/know-how/…). There is a section describing the use of makeindex. Alternatively, look at Biblatex with Biber: Configuring my editor to avoid undefined citations, the procedure is the same with makeglossaries. – Johannes_B Jun 19 '15 at 18:14
  • 1
    @user1170330: No, you normally need to run the program makeglossaries as well – user31729 Jun 19 '15 at 19:05
5

(As an aside, I don't understand why the file myDoc.glsdefs was created from the document you provided as this file is only created if \newglossaryentry is used inside the document environment. This file is certainly not created when I tried the example. Make sure that you keep all \newglossaryentry commands in the preamble or you can have them in a separate file and load it using \loadglsentries.)

However, as others have mentioned in the comments, it's necessary to run another application after LaTeX has created your PDF file. This step is required to create the glossary file which is then input the next time you LaTeX (build/compile/typeset) your document. So the steps are:

  1. Run (pdf)LaTeX to create myDoc.pdf
  2. Run the indexing application to create myDoc.gls
  3. Run (pdf)LaTeX to create myDoc.pdf which should now include the glossary.

Step 2 is the place where many people get stuck. There are two indexing applications: makeindex and xindy. All TeX distributions should have makeindex installed. This is a pre-compiled application so it doesn't need anything extra to run it, but it's hard-coded for the English alphabet and doesn't support UTF-8. The other indexing application, xindy, is much more flexible and has rules for different languages, but it's a Perl script, which means that you need to have Perl installed to run it.

In your document you just have

\usepackage{glossaries}

\makeglossaries

This means that the default makeindex application is assumed, and the glossaries package will create the files myDoc.glo and myDoc.ist, which can be read by the makeindex application.

If instead you have

\usepackage[xindy]{glossaries}

\makeglossaries

then glossaries will create the files myDoc.glo and myDoc.xdy, which can be read by xindy.

It can be a bit of a nuisance trying to remember whether to use makeindex or xindy and what options to pass to the appropriate application, so glossaries comes with a Perl script called makeglossaries which will read the myDoc.aux file and will run makeindex or xindy for you. (Don't confuse the external makeglossaries script with the \makeglossaries command in your document.) If you use a command prompt then you can build your document using the following application calls:

pdflatex myDoc
makeglossaries myDoc
pdflatex myDoc

The reason your example worked fine when you used ShareLaTeX was because ShareLaTeX detected that you needed to run makeglossaries and did that for you behind the scenes.

If you don't have Perl installed then you can't use the makeglossaries script, but you can use a simplified Lua script that's now also provided with the glossaries package. This script is bundled with the file name makeglossaries-lite.lua but you may find that your TeX distribution provides it with a different name. For example, TeX Live on Unix-like systems create a symbolic link makeglossaries-lite which omits the .lua extension. In this case the build process is:

pdflatex myDoc
makeglossaries-lite myDoc
pdflatex myDoc

Alternatively you can run makeindex directly:

pdflatex myDoc
makeindex -s myDoc.ist -t myDoc.glg -o myDoc.gls myDoc.glo
pdflatex myDoc

If you don't use a terminal or command prompt, that is, you just click on a button or menu item to build your PDF, then how you run the indexing application depends on the text editor that you are using (for example, TeXWorks, TeXnicCenter, WinEdt). Each editor has a different way of adding a new tool, so the instructions will be different, but most will have an example in the manual that you might be able to modify. I have an example of how to add makeglossaries to TeXWorks in Building Your Document . On this site there's:

If all else fails, there are two fallback methods. If you have at least version 4.08 of the glossaries package you can add the automake package option:

\usepackage[automake]{glossaries}

This requires the \write18 mode to be enabled, but now you just need to run (pdf)LaTeX twice:

pdflatex myDoc
pdflatex myDoc

This will run makeindex for you. Since the shell escape is a security risk, the default mode is usually restricted to only allowing trusted applications to run. The trusted list usually includes makeindex but doesn't include xindy. Some systems may completely disable the shell escape, in which case the automake option won't work for either makeindex or xindy. Search the .log file for instances of runsystem to find out if the application was allowed to run.

The other fallback method will slow the document build as it will use TeX to sort and collate the glossary entries instead of using the more efficient makeindex or xindy applications. In this case you need to replace

\makeglossaries

with

\makenoidxglossaries

and replace

\printglossaries

with

\printnoidxglossaries

(Or replace \printglossary with \printnoidxglossary.) For example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{glossaries}

\makenoidxglossaries

\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

\printnoidxglossaries

\end{document}

The glossaries-extra extension package provides another method that doesn't require an external application, but with this method the glossary lists all defined entries in the order of definition:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{glossaries-extra}

\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

\printunsrtglossaries

\end{document}

The build method is now simply:

pdflatex myDoc

A comparison of all the different methods is given in section 1.1 Indexing Options in the glossaries user manual.

Finally, if you need to call external applications, such as makeglossaries, makeindex or bibtex, you might want to look at one of the automation tools, such as arara, which will run all the required applications for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.