So I am writing a programming book and I have a code example in it that I have labeled \label{ex11}. How can I later in the document make a link to it using custom text?

For example, I am writing somewhere later in the book, "As I mentioned in the first one-liner, ...".

Here I want the text "the first one-liner" to be linked to \label{ex11}. So that when I click that text, the document jumps to the label. Any ideas how to do that?

If this was HTML, I'd just do <a href="ex11">the first one-liner</a> (just to give you a better understanding about what I want to do).


This can be done with hyperref, like this

\hyperref[ex11]{the first one-liner}

See the LaTeX/Hyperlinks wiki for more examples.


As I mentioned in the first one-liner, \ref{ex11}".

With package fancyref you can use \vref instead for results like as seen in Example 12 on the following page which is possible with as seen in Example~\vref{ex11}

With hyperref all references are converted into links. And with \href[options]{URL}{text} you can link it with a specific text.

  • an alternative is package varioref – pmav99 May 1 '11 at 9:47
  • Whatever suits you mate! – pmav99 May 1 '11 at 16:11

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.