Home > hyperref > glossaries package: hyperlink only on first use of acronym

# glossaries package: hyperlink only on first use of acronym

April 15Hits:1

By default, the glossaries package creates a link to the glossary for each occurrence of an entry (e.g. each time I use \gls{entry}). With the links visualized (e.g. using hyperref colorlinks). This becomes really cluttered if an entry is used many times.

I would rather prefer that only the first occurrence of an entry is hyperlinked. Is this possible?

While you can manually renounce the hyperlink by using \glsentrytext{entry}, or \glsentryname{entry}, or \gls*{entry} instead of \gls{entry}, this is cumbersome, as one would have to track the place of the first usage oneself.

An automatic approach is to patch \@[email protected]:

\documentclass[a4paper,10pt]{article}

\usepackage{glossaries}

\usepackage{etoolbox}
\makeatletter
%% patch first occurence of "\@[email protected][#1]{#2}{\@[email protected]}", as this is the one for \glsused{#2}
\patchcmd{\@[email protected]}
{\@[email protected][#1]{#2}{\@[email protected]}}
{\@[email protected][#1,hyper=false]{#2}{\@[email protected]}}
{}{}
\makeatother

\makeglossaries
\newglossaryentry{pear}{
name=pear,
description={an oddly shaped fruit}
}

\begin{document}
\gls{pear}, \gls{pear}, \gls{pear}, \gls{pear}.

\printglossaries
\end{document}



If you also use upper case variants \Gls and \GLS, the respective internal macros \@[email protected] and \@[email protected] need similar patching:

\patchcmd{\@[email protected]}
{\@[email protected][#1]{#2}}
{\@[email protected][#1,hyper=false]{#2}}
{}{}

\patchcmd{\@[email protected]}
{\@[email protected][#1]{#2}{\MakeUppercase{\@[email protected]}}}
{\@[email protected][#1,hyper=false]{#2}{\MakeUppercase{\@[email protected]}}}
{}{}



There's a hook \glslinkcheckfirsthyperhook that gets used by commands like \gls. It's original purpose was to assist with the opposite (don't hyperlink on first use) but it also can be used in this situation:

\documentclass{article}

\usepackage{glossaries}

\makeglossaries

\ifglsused{\glslabel}%
{%
}%
{}%
}

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

\begin{document}

First use: \gls{sample}, \gls{sample2}.

Next use: \gls{sample}, \gls{sample2}.

\printglossaries

\end{document}



This produces:

## Related Articles

• ### glossaries package: hyperlink only on first use of acronym April 15

By default, the glossaries package creates a link to the glossary for each occurrence of an entry (e.g. each time I use \gls{entry}). With the links visualized (e.g. using hyperref colorlinks). This becomes really cluttered if an entry is used many t

• ### Weird bug (header) when using the glossaries package and KOMA's automarkJune 16

I'm using \usepackage[automark]{scrpage2} in my preable together with the glossaries package. Whenever I use an acronym within a \section{...} command, I get a header like the one pictured below. Any ideas how to prevent this? I'm using LuaLaTeX btw.

• ### Capitalization with glossaries packageNovember 3

I have the following minimal example in which the \Gls command of the glossaries package does not seem to work. %% % listgloss.text % Minimal file to test functionality and use of glossaries package % % Compile as % % pdflatex listgloss % makeglossar

• ### pdflatexmk doesn't run makeglossaries for glossaries package (TeXShop, OSX) August 6

Is there a way to make Latexmk invoke makeglossaries (part of the glossaries package)? Specifically I want to use latexmk to compile a LaTeX document that uses the glossaries package to produce a glossary. Currently I'm using this rather clumsy seque

• ### Using the glossaries package in other languages.November 28

I have just started using the glossaries package, and as I'm writing my documents in icelandic I run into a certain problem. The glossaries package assumes the words are in two forms, singular or plural, but for icelandic the same word can easily tak

• ### Glossaries package and pagenumberingDecember 18

I am using the glossaries package to maintain an Acronyms list and a Glossary. My problem is that the Acronyms list is too big. Currently it is occupying 2 pages. The first page is numbered as vi, which is how I want it. However, the second page is n

• ### How to make a reverse dictionary via glossaries package?April 6

From http://www.latex-community.org/forum/viewtopic.php?f=51&t=12595 I want to compile an new English terms on my proffesional field collections. It's much like a dictionary but in reverse sort of words for learning convenience, e.g. ... romance ...

• ### Change style of printing acronyms with glossaries packageJune 29

I'm using the glossaries package to define my acronyms and print them out. I'm using this style: \newglossarystyle{super3colleft}{% \renewenvironment{theglossary}% {\tablehead{}\tabletail{}% \begin{supertabular}{@{}>{\bfseries}lp{\glsdescwidth}p{\gls

• ### Glossaries package and acronyms with an &August 1

I'm using glossaries package and have one entry that has an & in between: %\newacronym{CK}{CK}{Chidamber \& Kemerer} \newglossaryentry{CK}{type =\acronymtype, name={CK}, description={Chidamber \& Kemerer}, text={CK}, first={Chidamber \& Ke

• ### Can't compile LaTeX document when glossaries package is used (fatal error) August 2

I just followed the instructions for setting up TeXnicCenter to work with the glossaries package as described at latex-community.org. I am trying to create a list of acronyms, however, I will not be using them in text. My document looks like this: \d

• ### Problems with glossaries package 'see' attributeAugust 26

I'm using the glossaries package to define a glossary (who would have thought of that). Yesterday I came across the feature to be able to use see={other glossary entry, another one, etc.} which I like very much. But using this feature something funny

• ### Using the glossaries package for English acronyms in German documentsOctober 12

This is a repost of the original message I posted to comp.text.tex in August, which is still unanswered there. I'm sorry for reposting, but I want to spread this to a wider readership. I found couple of similar questions (along with helpful answers)

• ### Glossaries package: ignore \newacronym if acronym has been defined beforeMay 24

I have a document consisting of multiple tex files, one per chapter, I am using the glossaries package to create list of acronyms. Ideally I want to define acronyms as close to where they are used, i.e. in the chapter tex files, in order to make the

• ### Latex decides to ignore see attribute to \newglossaryentry when using enabling nonumberlist on glossaries packageAugust 24

The weirdest thing happened to me today: I was looking for a way to link from an abbreviation to a glossary entry and found this answer. When emulating it in my code, it did not work - pdflatex would ignore the see attribute. Fiddling around, I disco

• ### Glossaries package and hyphenated (dashed) acronym fail to break across linesDecember 18

With respect to using the glossaries package, if I have an acronym with a long hyphenated word, it often result in sentences that runs into margins. For example: \newacronym[sort=WH]{WH}{Wh}{Wiener-Hammerstein} results in: I have also tried \newacron

• ### How to configure TexStudio editor to use glossaries package with makeglossaries and xindy or how to configure TexStudio to use arara?June 12

Xindy is an efficient indexing tool, it is an external perl-based application that ships readily with TexLive distribution but not with MikTeX, for the latter one you need to install it manually, this thread can be of help. For configuration of xindy

• ### Avoiding double dots in glossaries packageJune 17

I would like to incorporate the suggested solution by Herbert, that can be found HERE, within certain glossary records. Consider the following example: \documentclass[a4paper]{book} \usepackage{glossaries} \makeglossaries \makeatletter \newcommand{\f

• ### Glossaries package: small caps in body and normal caps in the acronym listJuly 29

I want a list of acornyms to be printed in normal caps. However, I want small cpas acronyms in the body text. I use glossaries package as the follwoing example. Would you please help? \documentclass[a4paper]{report} \usepackage[style=long, toc, small

• ### list of symbols with glossaries package: space between symbol and descriptionAugust 25

I am using the glossaries package to make a list of symbols. Is there a simple way to manipulate the space between the symbol and the description? \documentclass{scrreprt} \usepackage{glossaries} \usepackage{glossary-mcols} \newglossary[slg]{symbolsl

• ### How to update glossaries package on Ubuntu 12.10?September 14

My texlive version is \$ tex -version TeX 3.1415926 (TeX Live 2012/Debian) kpathsea version 6.1.0 Copyright 2012 D.E. Knuth. There is NO warranty. Redistribution of this software is covered by the terms of both the TeX copyright and the Lesser GNU Gen