1

Is there any way to prevent hyperref from underlining:

1) glossary entries linked with \gls

2) footnote marks of the \footnote

3) footnote marks set with \footref from the footmisc package?

MWE for testing (you will need to compile it twice).

\documentclass[a4paper, 12pt]{article}
\usepackage{hyperref}
\usepackage{glossaries}
\usepackage{footmisc}

\hypersetup{
    pdfborderstyle={/S/U/W 0.5},%
}

\newglossaryentry{foo}{name=foo, description=bar}

\begin{document}

This document uses the most advanced \gls{foo} technology.

There is also a footnote\footnote{\label{fn}This is the footnote}. 
It can be referenced multiple times.\footref{fn}

\end{document}
  • What about normal \ref commands and other internal document links. Should they loose the underlining too? – Ulrike Fischer May 16 at 12:57
  • @UlrikeFischer We definitely have some places where underlining is still needed; for example, \ref links linking to other chapters, and some links to a particular appendix. I suppose we could define some kind of "\underlinedRef" command which would underline those and search&replace manually, but that is not preferable. – Konstantin Kotenko May 16 at 13:06
  • 1
    Then it is not something that can be done at the hyperref level. This commands share the same internal command and so the same default settings. You will have to modify \gls and \footref etc to locally reset the style. – Ulrike Fischer May 16 at 13:09
1

As Ulrike Fischer mentioned: you have to modify \gls and all other commands that need modified links to locally reset the hyperlink style.

To do this you can use the xpatch package to add a \hypersetup command at the start of the commands to be modified, and another \hypersetup command at the end of these commands.

However, this does not always work, for example \gls is not a complete command that processes its arguments, but instead it calls the internal glossaries command \@gls to process the arguments. Simplified: \gls is rewritten to \initialstuff\@gls, which means that \gls{abc} is executed as \initialstuff\@gls{abc}. So if you append \hypersetup to \gls it instead becomes something like \initialstuff\@gls\hypersetup{}, which means that \gls{abc} will be executed as \initialstuff\@gls\hypersetup{}{abc}, which does not work. The obvious solution here is to patch \@gls instead. Similarly, to append something to \footnote you need to patch \@footnotetext.

MWE:

\documentclass[a4paper, 12pt]{article}
\usepackage{hyperref}
\usepackage{glossaries}
\usepackage{footmisc}
\usepackage[nameinlink]{cleveref} % for demonstration purposes
\usepackage{xpatch}

\makeatletter
\xpretocmd{\gls}{\hypersetup{hidelinks}}{}{}
\xapptocmd{\@gls}{\hypersetup{pdfborderstyle={/S/U/W 0.5}}}{}{}
\xpretocmd{\footnote}{\hypersetup{hidelinks}}{}{}
\xapptocmd{\@footnotetext}{\hypersetup{pdfborderstyle={/S/U/W 0.5}}}{}{}
\xpretocmd{\footref}{\hypersetup{hidelinks}}{}{}
\xapptocmd{\footref}{\hypersetup{pdfborderstyle={/S/U/W 0.5}}}{}{}
\makeatother

\hypersetup{
    pdfborderstyle={/S/U/W 0.5},%
}

\newglossaryentry{foo}{name=foo, description=bar}

\begin{document}

\section{First section}
\label{sec:first}

This document (See \Cref{sec:first}) uses the most advanced \gls{foo} technology. See again \Cref{sec:first}.

There is also a footnote\footnote{\label{fn}This is the footnote}. 
It can be referenced multiple times.\footref{fn} See \Cref{sec:first} for the third time.

\end{document}

Result:

enter image description here

  • Works like a charm, thanks! (Heads-up for future readers: You probably also want to add \xpretocmd{\glspl}{\hypersetup{hidelinks}}{}{} as well.) – Konstantin Kotenko May 16 at 14:37

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.