LaTeX forum ⇒ MakeIndex, Nomenclature, Glossaries and AcronymsSuperfluous comma in with \glsaddallunused Topic is solved

Information and discussion about MakeIndex - the tool to generate subject indices for LaTeX documents.
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

Superfluous comma in with \glsaddallunused

Postby user49915 » Tue Nov 05, 2019 7:45 pm

Let us save the source
\newcommand{\finiteMap}[1]{\mathopen{\glsuseri{not:finiteMap}}#1\mathclose{\glsuserii{not:finiteMap}}}%%% Finite map, e.g., ⦃ x1↦a1, ... xn↦an ⦄.
\newcommand{\infiniteWordsSet}[1]{#1^{\gls{not:infiniteWordsSymbol}}} %%% Infinite sequences
\newglossary[nlg]{notation}{not}{ntn}{List of symbols}
\newglossaryentry{not:finiteMap}{type=notation, name={\(\{|\dotso|\}\)}, text={\{|\dotso|\}}, sort={finiteMap}, description={A finite map: \(\{| \binding{c_1}{s_1},\,\dotsc,\,\binding{c_n}{s_n}|\}\) is a function that maps \(c_i\) to \(s_i\) for each \(i\).},user1={\{|},user2={|\}}}
\newglossaryentry{not:infiniteWordsSymbol}{type=notation, name={\(\cdot^{\infty}\)}, text={\infty}, sort={*infiniteWordsSymbol}, description={Given an arbitrary set \(Z\), we denote by \(Z^{\infty}\) the set of all infinite words over \(Z\).}}

in mwe.tex and then run
pdflatex mwe && makeindex -s -t mwe.nlg -o mwe.not mwe.ntn

in a loop until the output stabilizes.
Observe the needless comma on the last page of the resulting pdf: "1," in the entry corresponding to finite maps:
mwe.png (215.82 KiB) Viewed 9530 times

The entry corresponding to infinite words works as expected, without a comma.

Any help on how to get rid of the superfluous comma? We do need \glsaddallunused, since in a non-minimal example there are some symbols that are explained only in the list of symbols and intentionally not linked (in my non-minimal example, it would be a halmos symbol and "q.e.d.").

The issue has been reported to Nicola with a reference here.

Recommended reading 2021: •
LaTeX Beginner's Guide LaTeX Cookbook
User avatar
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Superfluous comma in with \glsaddallunused  Topic is solved

Postby nlct » Thu Nov 07, 2019 3:57 pm

\glsaddallunused is designed to iterate over all defined entries and perform \glsadd[format=glsignore]{label} for every entry that hasn't been marked as used.

The \gls command (and its plural and case-changing variants) is intended as the primary way of referencing entries. This has a notion of "first use", which allows it to vary its behaviour on first use. This is most commonly seen in abbreviations but can also be used with other forms of entries.

Commands like \glsuseri are supplementary commands that may be used to reference specific fields without affecting the "first use" flag, so they don't interfere with the behaviour of \gls.

In your MWE, you have only referenced "not:finiteMap" with these supplementary commands so it hasn't been marked as used. This means that \glsaddallunused does \glsadd[format=glsignore]{not:finiteMap} which creates an invisible location in the location list.

The problem here is that makeindex is specifically an indexing application and it requires a location for each indexed item (unless it's a cross-reference or parent of an indexed item). The same applies to xindy. If you want an entry to appear in the glossary it must be indexed but that means it must also have a location. The \glsignore command simply ignores its argument so can be used to create an invisible location. The idea behind \glsaddallunused is to add an invisible location to any entry that hasn't been marked as used in the hope that will be the only number in the location list. That way the location list will appear empty. Unfortunately if it gets added to an entry that has already been indexed (or is indexed after \glsaddallunused) it results in a spurious comma. In your example, the location list actually has two entries: "1" and "" (empty).

The bib2gls application is specifically designed for glossaries-extra and so allows for entries without locations. The iterative commands \glsaddall and \glsaddallunused don't work with bib2gls. Instead you just use the selection=all option which will include all defined entries regardless of whether or not they have been indexed. It also recognises format=glsignore as indicating an "ignored location" which influences selection but doesn't add the ignored location to the list. Thus avoiding the problem.

If you're not able to use bib2gls then there are several workarounds:
  • If you only have a few entries that aren't indexed in the document but must be included in the glossary then you can explicitly add them with \glsadd[format=glsignore]{label} and remove \glsaddallunused.
  • Explicitly unset the first use flag for any entry that you don't intend to reference with \gls (or its variants). For example, put \glsunset{not:finiteMap} at the start of your definition of \finiteMap.
  • Modify the indexing hook so that it automatically marks the entry as having been used. This option is only available with glossaries-extra.sty not for the base glossaries package and will obviously upset the normal behaviour of \gls.

  • Modify the indexing hook to create a list of all the entries that have been indexed and then iterate over all entries and index all entries that aren't in that list. (Again this option is only available with glossaries-extra.sty). For example, add the following to the preamble:

    and the following at the end of the document:

Nicola Talbot

Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

Superfluous comma in with \glsaddallunused

Postby user49915 » Tue Mar 08, 2022 5:39 pm

Thanks, Nicola! What I did in the end was saying \glsaddeach[format=glsignore]{…} instead of \glsaddallunused with the comma-separated list … of entries that are never referenced (hence, do not have page numbers) but still have to be present in the index. (In the given example, the list would have been empty.)

Return to “MakeIndex, Nomenclature, Glossaries and Acronyms”

Who is online

Users browsing this forum: No registered users and 3 guests