30

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).

Thorsten
  • 12,872

2 Answers2

37

This can be done with hyperref, like this

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

See the LaTeX/Hyperlinks wiki for more examples.

chl
  • 8,890
5

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.