3

I am using glossaries-extra.

How can the hyperlink be suppressed after the first use of an acronym or glossary entry in every chapter (or section) without changing the first use flag? I have found this solution, which does not work with acronyms and this one, which provides a kind of hacky and ugly hotfix and another solution that doesn't work with sections or chapters. I don't want to reset the first use flag in every section/chapter to avoid repeating acronym explanations.

Is there a solution that is not a hack?

MWE:

\documentclass{article}

\usepackage{hyperref}

\usepackage[acronym]{glossaries-extra}
\RestoreAcronyms

\newacronym{ex}{EX}{example}
\newglossaryentry{foobar}
{
    name={foobar},
    description={The FOOBAR blaa},
}

\makeglossaries

\begin{document}

\section{First section}

I explain \gls{ex} completely. But the second one here is short and has no more hyperlink: \gls{ex}.
Moreover, this is hyperlinked: \gls{foobar}, but this one is not: \gls{foobar}.

\section{Second section}

This \gls{ex} is short and with a hyperlink and this one is short and without a link: \gls{ex}.
\Gls{foobar} is linked, but \gls{foobar} is not.

\newpage

\printglossaries
\end{document}
  • 1
    Aside: Don't use both \RestoreAcronyms and \setabbreviationstyle. Either use \RestoreAcronyms and use the base glossaries \setacronymstyle or use \setabbreviationstyle and don't use \RestoreAcronyms. (\RestoreAcronyms changes \newacronym back to the way it works with the base glossaries package rather than using glossaries-extra's new abbreviation mechanism.) – Nicola Talbot Dec 1 '17 at 16:39
  • @NicolaTalbot thanks, seems this was a left over fragment from other experiments. – languitar Dec 4 '17 at 9:42
  • @NicolaTalbot do you see a chance to solve this issue? – languitar Jan 4 '18 at 11:45
6
+50

With glossaries-extra v1.26 (2018-01-05)¹ you can do:

\documentclass{article}

\usepackage{hyperref}

\usepackage[acronym]{glossaries-extra}

\makeglossaries

\GlsXtrEnableLinkCounting[section]{general,acronym}

% disable hyperlink if link count is greater than 1:
\renewcommand*{\glslinkpresetkeys}{%
 \ifnum\GlsXtrLinkCounterValue{\glslabel}>1
  \setkeys{glslink}{hyper=false}%
 \fi
}

\setabbreviationstyle[acronym]{long-short}

\newacronym{ex}{EX}{example}
\newglossaryentry{foobar}
{
    name={foobar},
    description={The FOOBAR blaa},
}

\begin{document}

\section{First section}

I explain \gls{ex} completely. But the second one here is short and
has no more hyperlink: \gls{ex}.
Moreover, this is hyperlinked: \gls{foobar}, but this one is not:
\gls{foobar}.

\section{Second section}

This \gls{ex} is short and with a hyperlink and this one is short
and without a link: \gls{ex}.
\Gls{foobar} is linked, but \gls{foobar} is not.
This link is forced on: \gls+{foobar}.

\newpage

\printglossaries
\end{document}

image of document

This new link² counting method is independent of the first use flag so it won't interfere with abbreviations. The optional argument of \GlsXtrEnableLinkCounting is the name of the master counter (section in this case).


¹I've only just uploaded this version to CTAN, so allow a few days for it to reach the distributions.

²The term "link" refers to the underlying internal command \@gls@link that's used by commands like \gls and \glstext rather than to \hyperlink (which may or may not be used by \@gls@link).

| improve this answer | |
  • That looks promising. I'll try one I get that version on CTAN. – languitar Jan 5 '18 at 14:00
  • Worked out perfectly! – languitar Jan 9 '18 at 8:36

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.