1

I would like to cross-reference glossary entries within the glossary, but I don't want page numbers to appear for those cross-references. Right now, I have:

\documentclass{report}
\usepackage{hyperref}
\usepackage[xindy]{glossaries}\makeglossaries

\newglossaryentry{LaTeX}{
  name=LaTeX,
  description={A typesetting engine for producing beautiful \glspl{document}}
}
\newglossaryentry{document}{
  name=document,
  description={A file that contains a bunch of text}
}

\begin{document}

This is a sentence about \gls{LaTeX} and \glspl{document}.
\glsaddall
\clearpage
\printglossary

\end{document}

The entry for "document" says it is referenced on pages 1 and 2, but I only want it to show the reference from page 1. However, I would like to keep the hyperref link to the "document" entry from the "LaTeX" entry.

2 Answers 2

1

Use \glshyperlink[document]{document} in glossary description in place of \glsps.

\documentclass{report}
\usepackage{hyperref}
\usepackage[xindy]{glossaries}\makeglossaries

\newglossaryentry{LaTeX}{
  name=LaTeX,
  description={A typesetting engine for producing beautiful \glshyperlink{document}{document}}
}
\newglossaryentry{document}{
  name=document,
  description={A file that contains a bunch of text}
}

\begin{document}

This is a sentence about \gls{LaTeX} and \glspl{document}.
\glsaddall
\clearpage
\printglossary

\end{document}
2
  • Ah, sorry! I was actually using hyperref to get links with the cross-references, which I was hoping to be able to retain, but then I forgot that was relevant and removed hyperref from the MWE! Commented Mar 11 at 14:33
  • @A.R. OK. I updated my answer accordingly.
    – jlab
    Commented Mar 11 at 15:10
0

Based on jlab's answer, and further examination of the glossaries package, I was able to add the following segment to my preamble to address the problem by redefining the \gls family of commands only within the evaluation of the \printglossary command. (If you are using a different command to print your glossary, e.g. \printglossaries, that command name should be substituted in the \AddToHook calls.

\makeatletter
\AddToHook{cmd/printglossary/before}{%
    % SAVE THE ORIGINAL DEFINITIONS
    \let\o@gls\gls%
    \let\o@Gls\Gls%
    \let\o@glspl\glspl%
    \let\o@Glspl\Glspl%
    %
    % NEW DEFINITIONS THAT DON'T PRODUCE PAGE ENTRIES
    \renewcommand*\gls[1]{\glshyperlink[\glsentryname{#1}\@empty]{#1}}%
    \renewcommand*\Gls[1]{\glshyperlink[\Glsentryname{#1}\@empty]{#1}}%
    \renewcommand*\glspl[1]{\glshyperlink[\glsentryplural{#1}\@empty]{#1}}%
    \renewcommand*\Glspl[1]{\glshyperlink[\Glsentryplural{#1}\@empty]{#1}}%
}
\AddToHook{cmd/printglossary/after}{%
    % RESTORE ORIGINAL DEFINITIONS AFTER GLOSSARY
    \let\gls\o@gls%
    \let\Gls\o@Gls%
    \let\glspl\o@glspl%
    \let\Glspl\o@Glspl%
}
\makeatother

If the glossary is at the end of the document, this can be simplified, as we don't need to restore the original behaviors:

\makeatletter
\AddToHook{cmd/printglossary/before}{%
    \renewcommand*\gls[1]{\glshyperlink[\glsentryname{#1}\@empty]{#1}}%
    \renewcommand*\Gls[1]{\glshyperlink[\Glsentryname{#1}\@empty]{#1}}%
    \renewcommand*\glspl[1]{\glshyperlink[\glsentryplural{#1}\@empty]{#1}}%
    \renewcommand*\Glspl[1]{\glshyperlink[\Glsentryplural{#1}\@empty]{#1}}%
}
\makeatother
1
  • I also ended up doing the same for the table of contents and list of figures, which I also didn't want showing up in the glossary. Commented Mar 11 at 17:43

You must log in to answer this question.

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