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.

I would like a command that takes two arguments: a page number and a block of text. I would like the command to create a PDF hyperlink around the text that will jump to the given page.

I see that the undocumented \hyperpage{} command from the hyperref package will create a link to the given page, however, I don't see how it can be used to make a link for arbitrary text. I took a look at the underlying code in hyperref.sty but I can't really figure it out.

I do realize that I could use \hyperlink{}{}, but that requires I put a \hypertarget{}{} on each of the pages to be linked. In my case, I only know the numerical number of the page to be linked.

share|improve this question
    
I also tried the solutions listed here: tex.stackexchange.com/questions/1021/… but none seemed to apply for my problem. –  ESultanik Aug 16 '10 at 19:45

2 Answers 2

up vote 10 down vote accepted

You could use \hyperlink with the already defined page targets:

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\hyperlink{page.2}{Go to page 2}
\newpage
text on page 2
\end{document}
share|improve this answer
    
Thanks; that worked! I had tried \hyperlink{Page.2}{Go to page 2}, but that caused errors. I guess the "page" is case sensitive. –  ESultanik Aug 16 '10 at 20:42
    
Yes. \hyperpage relies on those anchor names, it uses \hyperlink{page.\the\toks@}{\the\toks@} in hyperref.sty. –  Stefan Kottwitz Aug 16 '10 at 20:51

Not sure it is the same, but you can create a link with something like this.

First you add a label somewhere in the document.

\label{sec:listOfFiles}

And then add the link to that label with.

\ref{sec:listOfFiles} 
\pageref{sec:listOfFiles}

And if you add

\usepackage{hyperref}

it becomes a link you can click on.

share|improve this answer
    
That is not what I want. The "\pageref{}" command typesets the page number of the associated label. I want to have an arbitrary string with a link to a specific page number. For example, I might want to typeset the text "click here to go to page 10" and have that text link to page 10 of the document when clicked from the PDF. Since I don't know a priori how TeX is going to break the pages, I wouldn't know where to put the "\label{}" such that it were guaranteed to be on page 10. –  ESultanik Aug 16 '10 at 20:38
    
ok, a "arbitrary string" is not possible with this method. And you would add the label right next the the thing you need to link to, and then pageref gives you what page that is. But that is also the opposite from what you what. –  Johan Aug 16 '10 at 20:48

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.