glossaries: hyperlink only at the first occurrence in every chapter

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}

• 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.) Dec 1, 2017 at 16:39
• @NicolaTalbot thanks, seems this was a left over fragment from other experiments. Dec 4, 2017 at 9:42
• @NicolaTalbot do you see a chance to solve this issue? Jan 4, 2018 at 11:45

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

\documentclass{article}

\usepackage{hyperref}

\usepackage[acronym]{glossaries-extra}

\makeglossaries

\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
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
\Gls{foobar} is linked, but \gls{foobar} is not.
This link is forced on: \gls+{foobar}.

\newpage

\printglossaries
\end{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).

• That looks promising. I'll try one I get that version on CTAN. Jan 5, 2018 at 14:00
• Worked out perfectly! Jan 9, 2018 at 8:36