LaTeX forum ⇒ 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.
User avatar
Ijon Tichy
Posts: 1
Joined: Mon Dec 24, 2018 10:12 am

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

Postby Ijon Tichy » Mon Dec 24, 2018 11:35 am

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
  1. \AtEndDocument{\@gls@doautomake}
to initialize the automake and
  1. \newcommand*{\@gls@automake}[1]{%
  2. \ifglossaryexists{#1}
  3. {%
  4. \@closegls{#1}%
  5. \ifdefstring{\glsorder}{letter}%
  6. {\def\@gls@order{-l }}%
  7. {\let\@gls@order\@empty}%
  8. \edef\@gls@dothiswrite{\noexpand\write18{makeindex \@gls@order
  9. -s \istfilename\space
  10. -t \jobname.\csuse{@glotype@#1@log}
  11. -o \jobname.\csuse{@glotype@#1@in}
  12. \jobname.\csuse{@glotype@#1@out}}%
  13. }%
  14. \@gls@dothiswrite
  15. }%
  16. {%
  17. \GlossariesWarning{Can't make glossary `#1', it doesn't exist}%
  18. }%
  19. }
(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:
  1. \documentclass{article}
  2. \usepackage[acronym,automake]{glossaries} % make a separate list of acronyms
  3. \makeglossaries
  4. \longnewglossaryentry{par}{name={par}}%
  5. {%
  6. A long description with a paragraph break.
  7.  
  8. This is the next paragraph.
  9. }
  10. \newglossaryentry{sample}{name={sample},
  11. description={a sample entry}}
  12. \setacronymstyle{long-short}
  13. \newacronym[\glsshortpluralkey=cas,\glslongpluralkey=contrived
  14. acronyms]{aca}{aca}{a contrived acronym}
  15. \begin{document}
  16.  
  17. A \gls{sample} entry and \gls{aca}. Second use: \gls{aca}.
  18.  
  19. Plurals: \glspl{sample}. Reset acronym\glsreset{aca}.
  20. First use: \glspl{aca}. Second use: \glspl{aca}.
  21.  
  22. \glsresetall
  23. First letter upper case: \Gls{sample}. First use: \Gls{aca}.
  24. Subsequent use: \Gls{aca}.
  25. \glsresetall
  26. Plurals: \Glspl{sample}. First use: \Glspl{aca}. Next: \Glspl{aca}.
  27.  
  28. If you want paragraph breaks in the description use
  29. \verb|\longnewglossaryentry|, as with entry \gls{par}.
  30.  
  31. Title case a particular field:
  32. \glslink{sample}{\glsentrytitlecase{sample}{desc}}.
  33.  
  34. \printglossaries
  35.  
  36. \clearpage
  37. \end{document}

And here a fixed version using scrlfile (you can do almost the same using atveryend):
  1. \documentclass{article}
  2. \usepackage[acronym,automake]{glossaries} % make a separate list of acronyms
  3. \makeglossaries
  4. \usepackage{scrlfile}
  5. \usepackage{shellesc}
  6. \makeatletter
  7. % Deactivation of the \AtEndDocument{\@gls@doautomake}.
  8. \let\orig@gls@doautomake\@gls@doautomake
  9. \let\@gls@doautomake\relax
  10. % Acitivation of \@gls@doautomake at the very end.
  11. \BeforeClosingMainAux{\orig@gls@doautomake}% Do it after the last \clearpage.
  12. % immediate actions
  13. \renewcommand*{\@gls@automake}[1]{%
  14. \ifglossaryexists{#1}
  15. {%
  16. \immediate\@closegls{#1}% CHANGED
  17. \ifdefstring{\glsorder}{letter}%
  18. {\def\@gls@order{-l }}%
  19. {\let\@gls@order\@empty}%
  20. \edef\@gls@dothiswrite{\noexpand\ShellEscape% CHANGED
  21. {makeindex \@gls@order
  22. -s \istfilename\space
  23. -t \jobname.\csuse{@glotype@#1@log}
  24. -o \jobname.\csuse{@glotype@#1@in}
  25. \jobname.\csuse{@glotype@#1@out}}%
  26. }%
  27. \@gls@dothiswrite% CHANGED
  28. }%
  29. {%
  30. \GlossariesWarning{Can't make glossary `#1', it doesn't exist}%
  31. }%
  32. }
  33. \makeatother
  34. \longnewglossaryentry{par}{name={par}}%
  35. {%
  36. A long description with a paragraph break.
  37.  
  38. This is the next paragraph.
  39. }
  40. \newglossaryentry{sample}{name={sample},
  41. description={a sample entry}}
  42. \setacronymstyle{long-short}
  43. \newacronym[\glsshortpluralkey=cas,\glslongpluralkey=contrived
  44. acronyms]{aca}{aca}{a contrived acronym}
  45. \begin{document}
  46.  
  47. A \gls{sample} entry and \gls{aca}. Second use: \gls{aca}.
  48.  
  49. Plurals: \glspl{sample}. Reset acronym\glsreset{aca}.
  50. First use: \glspl{aca}. Second use: \glspl{aca}.
  51.  
  52. \glsresetall
  53. First letter upper case: \Gls{sample}. First use: \Gls{aca}.
  54. Subsequent use: \Gls{aca}.
  55. \glsresetall
  56. Plurals: \Glspl{sample}. First use: \Glspl{aca}. Next: \Glspl{aca}.
  57.  
  58. If you want paragraph breaks in the description use
  59. \verb|\longnewglossaryentry|, as with entry \gls{par}.
  60.  
  61. Title case a particular field:
  62. \glslink{sample}{\glsentrytitlecase{sample}{desc}}.
  63.  
  64. \printglossaries
  65.  
  66. \clearpage
  67.  
  68. \end{document}

User avatar
Johannes_B
Site Moderator
Posts: 3933
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Mon Dec 24, 2018 1:41 pm

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.


Return to “MakeIndex, Nomenclature, Glossaries and Acronyms”

Who is online

Users browsing this forum: No registered users and 2 guests