4

When using the glossaries package to generate a glossary the page list for each entry gets very long when the \gls{} command is used in many places, e.g.

Page list example I want to be able to suppress the page list (keeping the link in the text to the glossary) and leave only specified link entries, e.g. like the one in bold, which is nicely achieved with

 \gls[format=hyperbf]{label}

So something similar to, e.g.

 \gls[format=pagelistinclude]{label}

such that this appear in the page list, while just \gls{label} does not.

How can I make this?

1
  • Just use \gls{rhubarb} only with those instances that you DO want to show up in glossary, and simply type rhubarb where you don't. – Michael Palmer Dec 30 '16 at 16:13
2

The glossaries-extra provides an extra key noindex that can be used in the optional argument of commands like \gls that suppresses the indexing for that use, so you can use \gls{label} to index as normal and \gls[noindex]{label} to suppress the indexing. However, where you more often want to suppress the indexing, you may find it easier to switch off the default indexing, which can be done with:

\GlsXtrSetDefaultGlsOpts{noindex}

and then you just need to switch it on using \gls[noindex=false]{label} where you actually want to index the entry. For example:

\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage{glossaries-extra}

\makeglossaries

\GlsXtrSetDefaultGlsOpts{noindex}

\newglossaryentry{sample}{name={sample},description={an example}}

\begin{document}
This is a sample document.
The \gls{sample} entry is used on this page but isn't indexed.

\newpage
The \gls[noindex=false]{sample} entry is used on this page and is indexed.

\newpage
The \gls{sample} entry is used on this page but isn't indexed.

\newpage
\printglossaries

\end{document}

You may prefer to set up a modifier character to provide a shorthand version. Choose a character, say, > and set it as the modifier:

\GlsXtrSetAltModifier{>}{noindex=false}

Now \gls>{label} is equivalent to \gls[noindex=false]{label}.

\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage{glossaries-extra}

\makeglossaries

\GlsXtrSetDefaultGlsOpts{noindex}
\GlsXtrSetAltModifier{>}{noindex=false}

\newglossaryentry{sample}{name={sample},description={an example}}

\begin{document}
This is a sample document.
The \gls{sample} entry is used on this page but isn't indexed.

\newpage
The \gls>{sample} entry is used on this page and is indexed.

\newpage
The \gls{sample} entry is used on this page but isn't indexed.

\newpage
\printglossaries

\end{document}
0
0

Use a dummy counter (that produces no text) for the entries where you don't want the page numbers.

\newcounter{dummy}
\renewcommand\thedummy{}

This one gets the bold reference in the glossary:
\gls[format=hyperbf]{term}
\newpage

This one will get a link to the glossary, but no page number in the glossary: 
\gls[counter=dummy]{term}

You can even make the counter=dummy the default, by giving an extra optional argument to \newglossary, like in

\newglossary[slg]{symbol}{sot}{stn}{Symbols}[dummy]

or giving it as a package option:

\usepackage[counter=dummy,...]{glossaries}

But then you have at add the counter=page option for those entries that must have the page number registered.

\gls[format=hyperbf,counter=page]{term}

The \usepackage option might not be the best choice if you have more than one glossary, like a nomenclature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.