MakeIndex, Nomenclature, Glossaries and Acronymsglossaries automake option does not work with \clearpage at end of document

Information and discussion about MakeIndex - the tool to generate subject indices for LaTeX documents.
Post Reply
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

glossaries automake option does not work with \clearpage at end of document

Post by Ijon Tichy »

There seem to be an issue with glossaries automake option but the bug tracker seem to be down. So I use this page to at least document the issue.

glossaries uses

Code: Select all

\AtEndDocument{\@gls@doautomake}
to initialize the automake and

Code: Select all

\newcommand*{\@gls@automake}[1]{%
   \ifglossaryexists{#1}
   {%
     \@closegls{#1}%
     \ifdefstring{\glsorder}{letter}%
      {\def\@gls@order{-l }}%
      {\let\@gls@order\@empty}%
     \edef\@gls@dothiswrite{\noexpand\write18{makeindex \@gls@order
       -s \istfilename\space
       -t \jobname.\csuse{@glotype@#1@log}
       -o \jobname.\csuse{@glotype@#1@in}
       \jobname.\csuse{@glotype@#1@out}}%
     }%
     \@gls@dothiswrite
   }%
   {%
     \GlossariesWarning{Can't make glossary `#1', it doesn't exist}%
   }%
 }
(in case of usage of makeindex, the xindy case is similar) to do the execution of makeindex.

But \write is delayed until the next shipout. If TeX has nothing to shipout any more, the \write is never done and so the makeindex execution(s) are missing.

This happen, if someone has a \newpage or \clearpage at the very end of the document. Such \clearpage are sometimes the result of a \include or of the usage of a package. Because of this it would be better not to use \write18 but \immediate\write18 and much better to use \ShellEscape of package shellesc (because this works with luatex too). But to do so, it must be after the final \clearpage. Best solution for this would be to replace \AtEndDocument by \BeforeClosingMainAux or \AfterClosingMainAux (package scrlfile) or \AfterLastShipout (package atveryend).

MWE with the issue:

Code: Select all

\documentclass{article}
\usepackage[acronym,automake]{glossaries} % make a separate list of acronyms
\makeglossaries
\longnewglossaryentry{par}{name={par}}%
{%
  A long description with a paragraph break.

  This is the next paragraph.
}
\newglossaryentry{sample}{name={sample},
description={a sample entry}}
\setacronymstyle{long-short}
\newacronym[\glsshortpluralkey=cas,\glslongpluralkey=contrived
acronyms]{aca}{aca}{a contrived acronym}
\begin{document}

A \gls{sample} entry and \gls{aca}. Second use: \gls{aca}.

Plurals: \glspl{sample}. Reset acronym\glsreset{aca}.
First use: \glspl{aca}. Second use: \glspl{aca}.

\glsresetall
First letter upper case: \Gls{sample}. First use: \Gls{aca}.
Subsequent use: \Gls{aca}.
\glsresetall
Plurals: \Glspl{sample}. First use: \Glspl{aca}. Next: \Glspl{aca}.

If you want paragraph breaks in the description use
\verb|\longnewglossaryentry|, as with entry \gls{par}.

Title case a particular field:
\glslink{sample}{\glsentrytitlecase{sample}{desc}}.

\printglossaries

\clearpage
\end{document}
And here a fixed version using scrlfile (you can do almost the same using atveryend):

Code: Select all

\documentclass{article}
\usepackage[acronym,automake]{glossaries} % make a separate list of acronyms
\makeglossaries
\usepackage{scrlfile}
\usepackage{shellesc}
\makeatletter
% Deactivation of the \AtEndDocument{\@gls@doautomake}.
\let\orig@gls@doautomake\@gls@doautomake
\let\@gls@doautomake\relax
% Acitivation of \@gls@doautomake at the very end.
\BeforeClosingMainAux{\orig@gls@doautomake}% Do it after the last \clearpage.
% immediate actions
\renewcommand*{\@gls@automake}[1]{%
  \ifglossaryexists{#1}
  {%
    \immediate\@closegls{#1}% CHANGED
    \ifdefstring{\glsorder}{letter}%
      {\def\@gls@order{-l }}%
      {\let\@gls@order\@empty}%
      \edef\@gls@dothiswrite{\noexpand\ShellEscape% CHANGED
        {makeindex \@gls@order
       -s \istfilename\space
       -t \jobname.\csuse{@glotype@#1@log}
       -o \jobname.\csuse{@glotype@#1@in}
       \jobname.\csuse{@glotype@#1@out}}%
      }%
    \@gls@dothiswrite% CHANGED
  }%
  {%
    \GlossariesWarning{Can't make glossary `#1', it doesn't exist}%
  }%
}
\makeatother
\longnewglossaryentry{par}{name={par}}%
{%
  A long description with a paragraph break.

  This is the next paragraph.
}
\newglossaryentry{sample}{name={sample},
description={a sample entry}}
\setacronymstyle{long-short}
\newacronym[\glsshortpluralkey=cas,\glslongpluralkey=contrived
acronyms]{aca}{aca}{a contrived acronym}
\begin{document}

A \gls{sample} entry and \gls{aca}. Second use: \gls{aca}.

Plurals: \glspl{sample}. Reset acronym\glsreset{aca}.
First use: \glspl{aca}. Second use: \glspl{aca}.

\glsresetall
First letter upper case: \Gls{sample}. First use: \Gls{aca}.
Subsequent use: \Gls{aca}.
\glsresetall
Plurals: \Glspl{sample}. First use: \Glspl{aca}. Next: \Glspl{aca}.

If you want paragraph breaks in the description use
\verb|\longnewglossaryentry|, as with entry \gls{par}.

Title case a particular field:
\glslink{sample}{\glsentrytitlecase{sample}{desc}}.

\printglossaries

\clearpage

\end{document}
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

glossaries automake option does not work with \clearpage at end of document

Post by Johannes_B »

Thank you Tichy,

I left the package author a private message.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

glossaries automake option does not work with \clearpage at end of document

Post by nlct »

If you have at least v4.42 you can use the automake=immediate package option, which will use the shell escape at the start of \makeglossaries before the glossary files are opened.

Regards
Nicola Talbot
Post Reply