Glossaries: Hyperlink to First Entry not List of Acronyms
I recommend you upgrade to the latest version of glossaries
(v4.01 at time of writing) and try the following:
\documentclass{report}
\usepackage[colorlinks]{hyperref}
\usepackage[acronym,nowarn,hyperfirst=false]{glossaries}
% Switch off hyperlinks for all uses of \gls etc.
% Hyperlinks will be inserted manually in the custom display style
\setkeys{glslink}{hyper=false}
\renewcommand*{\CustomAcronymFields}{%
name={\the\glsshorttok},%
description={\the\glslongtok},%
}
\renewcommand*{\SetCustomDisplayStyle}[1]{%
\defglsentryfmt[#1]{%
\ifdefempty\glscustomtext
{%
\ifglsused\glslabel
{% subsequent use
% Assuming all acronyms are written in upper case, so
% not bother to check for case changes.
\glsifplural
{% subsequent use, plural
\glshyperlink[\glsentryshortpl{\glslabel}]{\glslabel}%
}%
{% subsequent use, singular
\glshyperlink[\glsentryshort{\glslabel}]{\glslabel}%
}%
}%
{% first use
\glsifplural
{% first use, plural
\glscapscase
{% no case change
\glstarget{\glslabel}{\glsentrylongpl{\glslabel}\glsinsert}%
\space(\glsentryshortpl{\glslabel})%
}%
{% first letter upper case
\glstarget{\glslabel}{\Glsentrylongpl{\glslabel}\glsinsert}%
\space(\glsentryshortpl{\glslabel})%
}%
{% all caps
\glstarget{\glslabel}{\MakeTextUppercase{%
\glsentrylongpl{\glslabel}\glsinsert}}%
\MakeTextUppercase{\space(\glsentryshortpl{\glslabel})}%
}%
}%
{% first use, singular
\glscapscase
{% no case change
\glstarget{\glslabel}{\glsentrylong{\glslabel}\glsinsert}%
\space(\glsentryshort{\glslabel})%
}%
{% first letter upper case
\glstarget{\glslabel}{\Glsentrylong{\glslabel}\glsinsert}%
\space(\glsentryshort{\glslabel})%
}%
{% all caps
\glstarget{\glslabel}{\MakeTextUppercase{%
\glsentrylong{\glslabel}\glsinsert}}%
\MakeTextUppercase{\space(\glsentryshort{\glslabel})}%
}%
}%
}%
}%
{% \glsdisp used
\ifglsused\glslabel
{% subsequent use
\glshyperlink[\glscustomtext]{\glslabel}%
}%
{% first use
\glstarget{\glslabel}{\glscustomtext}%
}%
}%
}%
}
\SetCustomStyle
\newacronym{FEA}{FEA}{Finite Element Analysis}
\begin{document}
First use: \gls{FEA}.
Next use: \gls{FEA}.
\end{document}
I've used the colorlinks
option so you can see where the link is in the result:
The link target is the first use. Be careful not to reset the acronyms (via \glsreset
etc) or you'll end up with multiply defined targets.
Edit: there's a simpler method with the glossaries-extra
extension package:
\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage{glossaries-extra}
\setabbreviationstyle[acronym]{long-short}
\glssetcategoryattribute{acronym}{nohyperfirst}{true}
\renewcommand*{\glsdonohyperlink}[2]{%
{\glsxtrprotectlinks \glsdohypertarget{#1}{#2}}}
\newacronym{FEA}{FEA}{Finite Element Analysis}
\begin{document}
First use: \gls{FEA}.
Next use: \gls{FEA}.
\end{document}
This will create a target when the hyperlink is suppressed. This can cause a problem if you reset the first use flag or if you want to use the starred version \gls*
. A minor modification can keep track of whether the target has been set:
\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage{glossaries-extra}
\setabbreviationstyle[acronym]{long-short}
\glssetcategoryattribute{acronym}{nohyperfirst}{true}
\renewcommand*{\glsdonohyperlink}[2]{%
{\glsxtrprotectlinks
\edef\fieldvalue{\glsxtrusefield{\glslabel}{hastarget}}%
\ifdefstring\fieldvalue{true}
{%
#2%
}%
{%
\gGlsXtrSetField{\glslabel}{hastarget}{true}\glsdohypertarget{#1}{#2}%
}%
}%
}
\newacronym{FEA}{FEA}{Finite Element Analysis}
\begin{document}
First use: \gls{FEA}.
Next use: \gls{FEA}.
No hyperlink: \gls*{FEA}.
Another use: \gls{FEA}.
\end{document}