Make the arrow of \xrightarrow an hyperlink

I order not to loose the reader of a big document with a lot of new notations, I make each of the notations I introduce an hyperlink to the place it is defined, so at any time, the reader can refer to the definition (in particular when notations are overloaded).

One of the notation I use is a labeled arrow using \xrightarrow from amsmath [1], and I'd like the arrow to be an hyperlink to its definition, but not the label (for external reasons, mainly the label itself should sometimes be a reference to elsewhere).

Of course, embedding the whole \xrightarrow in a \hyperlink{...} also makes the label a link, which I do not want (see the example below, I use colorlinks=true to emphasize which part is a link and which is not).

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{hyperref}
\hypersetup{
}

\newtheorem{definition}{Definition}

\begin{document}

\begin{definition}[\hypertarget{Arrow}{Arrow}]
Here I define $$A\xrightarrow{\text{\rm long label}} B$$.
\end{definition}

$A \hyperlink{Arrow}{\xrightarrow{\textrm{long label}}} B$

\end{document}


Looking at other questions about \xrightarrow (e.g. here), it seems to be doable by (worst case) redefining the command, but I'm not comfortable enough with amsmath to do it. Also, I checked the hyperref manual for a command to exclude some text from a label (to do something like hyperlink{Arrow}{\xrightarrow{\exclude{\text{long label}}}}, but I couldn't find such command.

Remarks: The question is about unlinking the label, not just removing the color (which was added in the MWE to clarify the problem, but won't be turned on in the end).

[1] The context is that I define the transitions of a labeled transition system (for computer scientists).

• do you actually need the label unlinked, or just uncoloured (which is easier) – David Carlisle Aug 11 at 9:51
• unrelated but I'd use \textrm here not \text so you get a consistent font not italic in the definition. – David Carlisle Aug 11 at 9:52
• @DavidCarlisle I need the label unlinked (color will be disabled anyway in the end, I put it here just for emphasize). For the label, this was just to illustrate (in practice, labels are also math, not text), but I'll edit that :-) – Bromind Aug 11 at 9:58
• links in pdf are really just rectangular regions somewhat separate from but overlayed over the text so actually there isn't a lot of difference between having the text linked or not linked, it just makes the link rectangle a bit taller – David Carlisle Aug 11 at 10:11
• Yes, I read @Ulrike answer below which also explains that. My understanding of links was wrong, so thank both of you. – Bromind Aug 11 at 10:29

Links doesn't link "content". They only add a rectangle annotation box. The content is only relevant to decide how large the box should be. So if you want a smaller link area you need to hide the content that should not contribute to the box. E.g.

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{hyperref}
\hypersetup{
}

\newtheorem{definition}{Definition}

\begin{document}

\begin{definition}[\hypertarget{Arrow}{Arrow}]
Here I define $$A\xrightarrow{\text{long label}} B$$.
\end{definition}

$A \xrightarrow{\text{long label}} \llap{\hyperlink{Arrow}{\hphantom{\xrightarrow{\text{long label}}}\rule{0pt}{4pt}}\kern2pt} B$

\end{document}


The main problem is that it is rather difficult to add this without disturbing the math spacing.

• Oh, thanks! I actually though that links where linking content, and that the default red box of hyperref was an intentionnally bigger area to ease clicking on the links. Now you mentionned it, I indeed noticed that even with colorlinks=true, the linking area is a rectangle (typically, in the white upper right/left corners). I really appreciate this kind of answers which not only gives what one need, but also corrects the fallacies one has for a long time. – Bromind Aug 11 at 10:27