15

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.)

One
  • 1,485

4 Answers4

8

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

mafp
  • 19,096
  • More complicated than I hoped, but a perfect answer. \glsaddallunused is absolutely acceptable. Thank you! – One May 26 '13 at 21:03
  • @Thomas You are welcome. It is indeed not so simple, but this is due to the limitations of makeindex. And if you put all this code into its own package, say myglos.sty, and load that with \usepackage{myglos}, your main file will look clean again ;-) – mafp May 26 '13 at 21:38
5

Here's an alternative that doesn't use internal commands:

\documentclass{article}

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

\usepackage{hyperref}
\usepackage[
  style=long3colheader,
  hyperfirst=false
  ]{glossaries}

\newcommand{\ignore}[1]{}

\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}

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

\printglossaries


\forallglsentries{\thislabel}%
{%
  \ifglsused{\thislabel}{}{\glsadd[format=ignore]{\thislabel}}%
}

\end{document}

Result:

Image of glossary

Nicola Talbot
  • 41,153
  • I want it to be in this form: http://imgur.com/j3bVshQ Also in the example with the glossaries the text appears before the glossary? Shoudln't it be the other way around? – Bob1990 Apr 29 '16 at 08:20
  • @Bob1990 It depends entirely on the document whether the glossary goes at the front or back. Just move \printglossaries (or \printglossary) to where you want it to appear. There are 100 different predefined glossary styles, which can all be adjusted. Have a look at the glossaries styles gallery to see which best suits your requirement. – Nicola Talbot Apr 29 '16 at 09:18
  • Ok but is it possible to change the name from Glossary to Acronyms? – Bob1990 Apr 29 '16 at 09:49
  • @Bob1990 \printglossary[title=Acronyms] instead of \printglossaries or add package option acronyms. – Nicola Talbot Apr 29 '16 at 10:55
2

The command \glsaddallunused suggested by @mafp has been added to glossaries package.

So the example can be reduced to:

\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}

\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}
user45786
  • 183
0

The above answers did not work for me. All still produced an empty page when i used \glsaddall \printglossary[title=Glossar, toctitle=Glossar] with the package \usepackage[acronym, toc, section=section]{glossaries}.

What did work however is \usepackage[acronym, toc,section=chapter]{glossaries-extra} with \printunsrtglossary

Z3R0
  • 1
  • Can you please extend your answer to a full answer with complete example as shown in the other answers. Currently it is IMHO more or less only a comment to other answers. – cabohah Oct 09 '23 at 10:05
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. – Community Oct 09 '23 at 10:35