Latest news 2021-06-05: New blog post: Dickimaw Books Site Account.

glossaries package FAQ

Why does \printglossary use \null when the glossary file is missing? 🔗

When the document build is incomplete (before the associated files have been created by makeindex or xindy), \printglossary will do \null, which creates (empty) content on the page. This can lead to a blank page mid-build. Once the associated files have been created, \printglossary will input the file and not use \null. This shouldn’t normally cause a problem since the PDF is never complete mid-build anyway. (References and citations appear as a double question mark ??, the table of contents, list of floats aren’t present etc.)

The reason for \null is to deal with dictionary-style documents where the document environment simply consists of the glossary. For example:

\documentclass{book}
\usepackage[nonumberlist]{glossaries}
\makeglossaries
\input{definitions}\glsaddall
\begin{document}
\printglossary
\end{document}

Without the \null, there would be no content and the document build would fail. The \null ensures that the PDF file is actually created albeit with a single empty page (with header/footer).

Note that with glossaries-extra, the behaviour of \printglossary is modified to print the chapter/section title and helpful text instead of simply \null. This again ensures that the document contains at least one page but also adds the glossary to the table of contents earlier (which can reduce the total number of LaTeX calls) and provides help to new users who haven’t worked out how to create the associated files.

\printglossary is designed to print content to the page. The fact that it produces different content mid-build shouldn’t be a problem as long as the correct content is present at the end of the build. The only time it causes a problem is when users try to modify the behaviour of \printglossary (through a custom style) so that it doesn’t actually produce any output. This is usually done in an attempt to gather information from the associated file, but there are more efficient ways of gathering this information. The best way is to switch to bib2gls. The location field then provides the formatted location list and the loclist field provides the locations in an internal list that can be iterated over. The group field contains the letter group label, and various resource settings can provide additional information such as child count and sibling count. This is far simpler than trying to write a glossary style that parses the code that makeindex or xindy writes to the glossary files, particularly since they use different commands within the location lists.

See also Is it possible to reference the locations outside of the glossary?

2020-06-29 12:20:58


Permalink: https://www.dickimaw-books.com/faq.php?id=238
Alternative link: https://www.dickimaw-books.com/faq.php?itemlabel=printglosswhynull

Category: glossaries package
Topic: Glossary Formatting