# how to determine when rerunning makeglossaries?

As for indices, also for glossaries latex creates a raw index/glossary, then an external sorting tool, makeindex or makeglossaries is run and another latex run includes the sorted index/glossary into tex. The problem is, that not only latex must be rerun to obtain correct results, but also sometimes makeindex.

For indices, the package imakeidx seems to provide a solution, which includes sorting into the latex run so no explicit run of makeindex is required. Question: how can this be used for glossaries also???

Thank you for help!!!

• The glossaries package has an automake option which automatically runs makeindex. – Nicola Talbot Nov 7 '16 at 16:04
• Hey, thank you Nicola. I finally found something in the documentation. – user2609605 Dec 5 '16 at 9:30
• You write that it probably does not work for xindy. Why that? Somewhere you write this is a last resort as makeindex is run after each latex run. How can i find out whether I have to rerun latex after the makeindex run?? – user2609605 Dec 5 '16 at 9:40

The automake package option uses the shell escape to generate the external files. This is analogous to imakeidx's automatic feature.

You write that it probably does not work for xindy. Why that?

The automake option can work with xindy if you have the unrestricted shell escape on, but not if the restricted mode is on (which is usually the default for most TeX distributions). makeindex is considered a trusted application and may be run through the shell escape in restricted mode, but xindy isn't on the trusted list so it requires the unrestricted shell escape. (This also applies to imakeidx with xindy.)

If you look at the texmf.cnf file, you should find the following comment:

% we'd like to allow:
% dvips - but external commands can be executed, need at least -R1.
% epspdf, ps2pdf, pstopdf - need to respect openout_any,
%   and gs -dSAFER must be used and check for shell injection with filenames.
% pygmentize - but is the filter feature insecure?
% ps4pdf - but it calls an unrestricted latex.
% rpdfcrop - maybe ok, but let's get experience with repstopdf first.
% texindy,xindy - but is the module feature insecure?


So xindy has been considered for inclusion on the trusted list, but there's a security query which has prevented its addition.

The other problem is that you must make sure you set the language and code page exactly as required by xindy. The makeglossaries script maps known babel language labels to the appropriate label expected by xindy. For example if you have

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[xindy]{glossaries}


Then makeglossaries picks up the language label ngerman from the .aux file, but knows that it needs to map this to -L german. The makeglossaries script can pick up the uft8 encoding, but it will additionally add din5007 since no codepage has been specified in the document that includes din5007 or duden or braille. The automake option doesn't have this level of sophistication and will simply try -L ngerman -C utf8, which won't work.

So if you want the above ngerman example to work with automake, it must be written as:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[automake,xindy={language=german,codepage={din5007-utf8}}]{glossaries}

\makeglossaries

\newglossaryentry{foo}{name=foo,description={an example}}

\begin{document}
\gls{foo}.

\printglossaries

\end{document}


If run in restricted mode this doesn't create the glossary file and the log file contains:

runsystem(xindy -I xindy -L german -M test -C din5007-utf8 -t test.glg
-o test.gls test.glo)...disabled (restricted).


(where the document was called test.tex.) The shell escape must be enabled:

pdflatex -shell-escape test


The automake option is considered a last resort because it lacks the sophistication of the makeglossaries script:

• the LaTeX code doesn't map babel language labels to xindy labels;

• the LaTeX code doesn't know about special cases for particular languages (such as the requirement of the german module to include one of din5007, duden or braille);

• the makeglossaries script analyses the transcript files if something goes wrong and will try to give a more intelligible message since some of the messages (especially from xindy) are quite cryptic;

• the makeglossaries script can correct some problems. In particular it detects makeindex's "multiple encaps" warning and will try to fix the problem.

These kinds of tasks are far easier and far more efficient to do with a scripting language, such as Perl, than attempting it with TeX.

How can i find out whether I have to rerun latex after the makeindex run??

You will always need to run LaTeX after makeindex as it's makeindex that creates the files read by \printglossary (or \printglossaries). This is the same as for imakeidx.

You may need an extra makeindex/xindy run if the page numbers change between builds. For example, the inclusion of a table of contents where the page numbering isn't reset at the start of the front matter, can cause the indexed page numbers to change. This problem also occurs with imakeidx.

Another case that requires the glossary files to be rebuilt is if an entry is only referenced by another entry in the glossary. The most common case is when the see key is used.

For example:

\documentclass{article}

\usepackage{glossaries}

\makeglossaries

\newglossaryentry{foo}{name=foo,description={an example}}
\newglossaryentry{bar}{name=bar,description={another
example},see={foo}}

\begin{document}
\gls{bar}.

\printglossaries

\end{document}


The steps latex, makeindex, latex only include the bar entry

since the foo entry can't be indexed until it's processed when the glossary file is read. This means that another makeindex and latex run are required.

Alternatively, if you use the extension package glossaries-extra, it will search for the see key of all used entries at the end of the document and automatically index them if they haven't been used.

\documentclass{article}

\usepackage{glossaries-extra}

\makeglossaries

\newglossaryentry{foo}{name=foo,description={an example}}
\newglossaryentry{bar}{name=bar,description={another
example},see={foo}}

\begin{document}
\gls{bar}.

\printglossaries

\end{document}


This means that only latex, makeindex and latex are required.