Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

This can be done with hyperref, like this

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

See the LaTeX/Hyperlinks wiki for more examples.

share|improve this answer
    
Thanks for the answer! –  Peteris Krumins May 1 '11 at 10:30
add comment

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.

share|improve this answer
    
an alternative is package varioref –  pmav99 May 1 '11 at 9:47
    
Thanks, I prefer hyperref! –  Peteris Krumins May 1 '11 at 10:30
    
Whatever suits you mate! –  pmav99 May 1 '11 at 16:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.