[Tex/LaTex] Glossaries: suppress pages when using glsaddall

glossaries

I would like to generate an index of notation using the glossaries-package such that certain page numbers are suppressed.

It is easy to define some standard notation and include it in the index using \glsaddall.
But this adds the page numbers to the index, which is what I want to avoid.

Adding nonumberlist to the definition of an entry suppresses the page number. (nonumberlist also exists as package option, but not as option to \glsaddall.) But this has to be done for each entry and would also suppress future references.

Here is my question: How can I suppress all page numbers generated by \glsaddall? In other words: \glsaddall ensures that all notation not referenced by \gls appears in the index, but without having a page number. All entries generated by \gls add page numbers.

Here is a good example:

\documentclass{article}

\usepackage{amsfonts}
\newcommand*{\Z}{\mathbb{Z}}
\newcommand*{\Q}{\mathbb{Q}}

% glossaries-user.pdf (v3.03):
% If you use hyperref and glossaries, you must load hyperref first.
\usepackage{hyperref}
\usepackage[
  style=long3colheader,
  hyperfirst=false
  ]{glossaries}

\newglossaryentry{integers}{name=\ensuremath{\Z},
  description={the ring of integers}, sort=!}
\newglossaryentry{rationals}{name=\ensuremath{\Q},
  description={the field of rational numbers}, sort=!, nonumberlist}

\newglossaryentry{vector-space}{name=\ensuremath{V},
  description={a vector space}, sort=V}

\makeglossaries

\begin{document}

\glsaddall

A vector space \gls{vector-space} \ldots

\printglossaries

\end{document}

The output is the following. The pages for Z and Q should not appear. (The page for Q is suppressed manually.)

Output

(This question is related but not equal to glossaries: including an entry without page location.)

Best Answer

Here is an approach that works with only a minor restriction: Instead of issuing \gladdall in the beginning, we issue a \glsaddallunused right before we do \printglossaries. This new command \glsaddallunused will write all entries that have not been used up to this point to the glossaries, with suppressed page numbers. For the suppression we will use lockstep's answer that you linked to.

If we were to write all entries with \glsaddall to the auxiliary glossary file, we would have a hard time to teach makeindex which page numbers to suppress, and how to sort and compress that correctly. In my approach, we only have entries with all page numbers shown (those explicitly referenced), and entries with completely suppressed page list.

\documentclass{article}

\usepackage{amsfonts}
\newcommand*{\Z}{\mathbb{Z}}
\newcommand*{\Q}{\mathbb{Q}}

\usepackage{lipsum} % to have some dummy text, and therefore larger page numbers
\usepackage[colorlinks]{hyperref}
\usepackage[
  style=long3colheader,
  hyperfirst=false
  ]{glossaries}

\newcommand*{\glsgobblenumber}[1]{}
% \renewcommand*{\glsgobblenumber}[1]{#1}% uncomment for testing

\makeatletter
%% lockstep's code
\newcommand*{\glsaddnp}[2][]{%
  \glsdoifexists{#2}%
  {%
%     \def\@glsnumberformat{glsnumberformat}% DELETED
    \def\@glsnumberformat{glsgobblenumber}% NEW
    \edef\@gls@counter{\csname glo@#2@counter\endcsname}%
    \setkeys{glossadd}{#1}%
    \@gls@saveentrycounter
    \@do@wrglossary{#2}%
  }%
}
%% new code; modified \glsaddall
\newcommand{\glsaddallunused}[1][]{%
  \edef\@glo@type{\@glo@types}%
  \setkeys{glossadd}{#1}%
  \forallglsentries[\@glo@type]{\@glo@entry}{%
    \ifglsused{\@glo@entry}{}{%
     \glsaddnp[#1]{\@glo@entry}}}%
}
\makeatother


\newglossaryentry{integers}{name=\ensuremath{\Z},
  description={the ring of integers}, sort=Z}

\newglossaryentry{rationals}{name=\ensuremath{\Q},
  description={the field of rational numbers}, sort=Q, nonumberlist}

\newglossaryentry{vector-space}{name=\ensuremath{V},
  description={a vector space}, sort=V}

\makeglossaries

\begin{document}
A vector space \gls{vector-space} \ldots
\lipsum[1-10]

\glsaddallunused
\printglossaries
\end{document}

sample output