3

I'm trying to achieve the effect from this existing question: \gls should produce hyperlinks, but without the distracting frames, while all other links behave as usual.

The answer to that question was to change the border color to white. However, this tends to obscure punctuation marks around the reference. I therefore tried to set pdfborder to zeros, but that seemed to have no effect.

After some trial and error, I ended up with this MWE:

\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{glossaries}

\newacronym{foo}{foo}{foobar}
\makenoidxglossaries

\defglsentryfmt[\glsdefaulttype]{\hypersetup{linkbordercolor=green,pdfborder=0 0 0.1}\glshyperlink[\glsgenentryfmt]{\glslabel}}

\begin{document}
    \section{\label{x}Foo}

    In Section~\ref{x} we saw that \gls{foo}.

    \printnoidxglossaries
\end{document}

result of above input

Note how there are actually two borders, one affected by my settings, one unaffected. You can also see that the period is almost completely obscured, so a white border is undesirable. Where does this second hyperlink come from and how do I influence its appearance?

1

The format specified with \defglsentryfmt indicates the text that's used inside the hyperlink for commands like \gls. Since \defglsentryfmt has been redefined to use \glshyperlink, which inserts a hyperlink, this causes the nested hyperlinks.

It's actually better to simply redefine the command used to generate the hyperlinks. Internally, this is \@glslink but \glsenablehyper assigns this to the value of \glsdohyperlink, so you just need to redefine \glsdohyperlink and then use \glsenablehyper. Like this:

\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{glossaries}

\newacronym{foo}{foo}{foobar}
\makenoidxglossaries

\renewcommand*{\glsdohyperlink}[2]{%
 {\hypersetup{linkbordercolor=green}\hyperlink{#1}{#2}}}

\glsenablehyper

\begin{document}
    \section{\label{x}Foo}

    In Section~\ref{x} we saw that \gls{foo}.

    \printnoidxglossaries
\end{document}

This produces

image of document

| improve this answer | |
  • Thanks! Of course, the effect I was after was to disable the border, but that was easy enough. Bonus points for avoiding \makeatletter :-) – wrtlprnft Feb 29 '16 at 14:14
  • @wrtlprnft Have you tried hidelinks? (Instead of changing the border colour.) – Nicola Talbot Mar 1 '16 at 12:59
  • I've seen that it exists, but it didn't help with my problem at the time. From the package source, one of the things this option actually does is set the border thickness to 0. – wrtlprnft Mar 3 '16 at 20:43

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.