6

In the following sample, the second link isn't hyperlinked:

\documentclass{article}

\usepackage{amsmath} % Removing this makes the second link work
\usepackage{hyperref}

\begin{document}
  \hyperref[abc-def]{link} % This link works
  \(\textnormal{\hyperref[abc-def]{link}}\) % But not this one
  \label{abc-def} Target
\end{document}

However, removing \usepackage{amsmath} fixes the second link. Why is that? And how can I make the second link work without removing amsmath?

(This is a simplified example from auto-generated XeLaTeX sources, so modifying the code itself is rather inconvenient).

Here is a slightly larger example:

\documentclass{article}

\usepackage{amsmath}
\usepackage{hyperref}

\begin{document}
\hyperref[lbl]{term}
\(\textnormal{\hyperref[lbl]{term}}\)

\newpage
\subsubsection{Abc}
\phantomsection\label{lbl} def
\end{document}
10
  • I'm not sure what you mean: if I change \label{abc-def}Target into \newpage Text\phantomsection\label{abc-def}Target both links point to the intended destination.
    – egreg
    Commented May 22, 2016 at 8:45
  • @egreg Maybe I oversimplified the example then. What I mean is that is that hyperref behaves differently inside of a math block, but only when amsmath is loaded.
    – Clément
    Commented May 22, 2016 at 8:51
  • @Clément \text... commands are completely different if amsmath is loaded (they are a mathchoice so set at 4 different sizes internally so they work in subscripts) Commented May 22, 2016 at 8:52
  • @egreg I can't reproduce your result; I've added a larger example that still shows the issue.
    – Clément
    Commented May 22, 2016 at 8:57
  • @DavidCarlisle: Thanks for the explanation; do you know of a way to make hypertext work in that setting, though? Maybe by saving a copy of the unmodified \text before loading amsmath?
    – Clément
    Commented May 22, 2016 at 8:59

1 Answer 1

6

Update Fixed in Hyperref v6.83p


It appears that the macro code for xetex/dvipdfm(x) only inserts the link in the first choice of a mathchoice (so it works in displaystyle only)

You could use \mbox or a similar construct that forces text size so avoids the mathchoice internally or a possibly better fix is

enter image description here

here I disabled amstext package \iffirstchoice@ test so the macros can not tell that they are being executed four times. this is what you want when adding a hyperref special but it does mean that if you increment a counter, or make an index entry within \textnormal you will get 4 increments or index entries.

\documentclass{article}
\usepackage{amsmath}

\usepackage{hyperref}

\begin{document}

\makeatletter
\let\iffirstchoice@\iftrue
\let\firstchoice@false\relax
\makeatletter

\hyperref[lbl]{1term}
\(\textnormal{\hyperref[lbl]{2term}} x^{\textnormal{\hyperref[lbl]{3term}}}\)

\newpage
\subsubsection{Abc}
\phantomsection\label{lbl} def
\end{document}
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .