# Suppress text (space) output when using \glsadd{}

I'm using the glossaries (or glossaries-extra) and am trying to add terms to the glossary silently. That is, inside my document, I occasionally want to add a term to the glossary without it appearing in the text output at the point where I use the command.

I tried glsadd{<key>}. This fulfills both criteria. But annoyingly it produces a space, when written on empty lines. Is there a package-option to prevent this or another command?

Any help would be appreciated. The following is minimal example which demonstrates the issues sufficiently.

\documentclass[a4paper]{scrbook}
\usepackage{glossaries} % problem exists under glossaries-extra too

\newglossaryentry{term}{sort={0}, name={Term}, description={Something.}}
\newglossaryentry{here}{sort={1}, name={Here}, description={Something.}}
\newglossaryentry{is}{sort={2}, name={Is}, description={Something.}}
\newglossaryentry{more}{sort={3}, name={More}, description={Something.}}
\newglossaryentry{proof}{sort={4}, name={Proof}, description={Something.}}

\makeglossaries

\def\silentcmd#1{\setcounter{page}{#1}}

\begin{document}
\setlength{\parskip}{1\baselineskip}
\setlength{\parindent}{0em}

Here is a sentence I want to to add a term \glsadd{term} silently and that works. But then consider writing a command on an empty line.

Between me and the last paragraph is nothing.

\silentcmd{5}

Between me and the last paragraph is a silent command.

Between me and the last paragraph is a glsadd-command.

For clarity, between me and the last paragraph are 3 glsadd-commands.
Is there another command to glsadd to properly silently add terms to the glossary? If not\ldots why??!
\end{document}


glossaries keeps track of on which pages the glossary entries are used. In order to this, the page on which this happens needs to be well defined, i.e. \glsadd has to be part of a line of text. This is why glossaries adds an empty \mbox to the document using \@gls@adjustmode when you call \glsadd in vertical mode.

You should decide to which paragraph every \glsadd belongs, then you won't have this problem and glossaries will record reasonable page numbers. For example

This is a paragraph with some entries at the end.

This is a paragraph with other entries at the beginning and something between sentences.

If you don't care about page numbers (and are using the nonumberlist option), you can remove the feature with
\makeatletter