2

Consider the following document:

\documentclass{article}
\usepackage{glossaries-extra}
\newglossary[nlg]{notation}{not}{ntn}{Notation}
\makeglossaries
\newglossaryentry{symb:c}{type=notation,name=$c$, description=the speed of light}
\newglossaryentry{symb:m}{name=$m$, description=mass}

\begin{document}
Referencing my glossary items: \gls{symb:c},  \gls{symb:m}.
\newpage
Referencing my glossary items again: \gls{symb:c},  \gls{symb:m}.

\noindent\rule{\textwidth}{0.4pt}

\printglossaries
\end{document}

(and never mind things like acronyms.)

I want the "Notation" glossary to only show the first page on which a term was referenced; but I want the general glossary (or other glossaries) not to be affected. So, I can't just use indexonlyfirst as a package option.

What do I do instead?

5
  • I believe you will increase your chances of a reply if you add an MWE to your question that people can use for testing possible solutions.
    – schtandard
    Jan 19, 2022 at 12:20
  • @schtandard: But I don't really have an MWE to show. It's not like I have a document that's broken. I'm asking about feature availability...
    – einpoklum
    Jan 19, 2022 at 17:33
  • Sure, but none of us has a document where we could plug in that feature and see if it's working. If anyone wanted to answer your question they'd first have to construct such a document, which is work. If you provide one containing everything that is needed (e.g. two glossaries containing entries that allow you to see if indexonlyfirst is in effect) but nothing more (so it isn't confusing and unnecessarily long), that makes an answerer's job much easier.
    – schtandard
    Jan 19, 2022 at 18:44
  • @schtandard: I was assuming there may be some known mechanism for this. But I see your point.
    – einpoklum
    Jan 19, 2022 at 18:45
  • 1
    @schtandard: Added an example.
    – einpoklum
    Jan 28, 2022 at 15:10

1 Answer 1

2

You can use the category attribute indexonlyfirst (not to be confused with the package option of the same name).

\documentclass{article}

\usepackage{glossaries-extra}

\newglossary[nlg]{notation}{not}{ntn}{Notation}
\glssetcategoryattribute{notation}{indexonlyfirst}{true}

\newglossaryentry{symb:c}{type=notation, category=notation, name=$c$, description=the speed of light}
\newglossaryentry{symb:m}{name=$m$, description=mass}

\makeglossaries

\begin{document}

Referencing my glossary items: \gls{symb:c}, \gls{symb:m}.

\newpage

Referencing my glossary items again: \gls{symb:c}, \gls{symb:m}.

\printglossaries

\end{document}

If you use a wrapper macro for defining the notation entries (or all of the other ones), you can set the category in the definition of that wrapper macro (the built-in wrappers like \newabbreviation already do that) and just have to set the category attribute for the correct category.

If you do define the entries for all of your glossaries directly with \newglossaryentry, you can set the category for all of them using \glsforeachincategory after the definitions. (This feels clumsy, but I could not find any more elegant way to do it.)

\documentclass{article}

\usepackage{glossaries-extra}

\newglossary[nlg]{notation}{not}{ntn}{Notation}
\glssetcategoryattribute{notation}{indexonlyfirst}{true}

\newglossaryentry{symb:c}{type=notation, name=$c$, description=the speed of light}
\newglossaryentry{symb:m}{name=$m$, description=mass}

\makeatletter
  \glsforeachincategory[notation]{general}{\@temp@glsry}{\@temp@label}{%
    \glsxtrsetcategory{\@temp@label}{notation}%
  }
\makeatother

\makeglossaries

\begin{document}

Referencing my glossary items: \gls{symb:c}, \gls{symb:m}.

\newpage

Referencing my glossary items again: \gls{symb:c}, \gls{symb:m}.

\printglossaries

\end{document}
2
  • 1. I don't quite understand your use of \glsforeachincategory. Doesn't it require the items it iterates to already be in that category? 2. Is what you're saying essentially that I'm going to have disjoint sets of categories for different glossaries, so that I can "capture" glossaries using the set of categories encompassing their entries? And if that's the case - what if the glossaries are not disjoint?
    – einpoklum
    Jan 29, 2022 at 10:33
  • 1
    1. Yes, I iterate over all entries in the notation glossary that have the (default) category general and set their category to notation. 2. Yes. If the categories are not disjoint, this approach won't work. Defining a glossary style that only displays the first page (rather than only indexing the first page) may be the way to go then.
    – schtandard
    Jan 29, 2022 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .