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 need to link a text to a page (by page number). I do not want to use labels, but simply to specify the text and the page number. Can I do that with hyperref?

share|improve this question
3  
I can't see any advantage of non-using /label and \ref/\pageref combination because this allows you to edit your file without care of such references. And what "text" do you mean? Text on referred page or caption of the reference? –  Crowley May 30 '11 at 8:01
    
@Crowley: I think "text" refers to the link text. So instead of "The details will be discussed on p. [[5]]", Raphink wants something like "[[The details]] are discussed at a later point.", where the part between [[ ]] is the link. –  Jake May 30 '11 at 8:19
    
@Crowley: in general no, indeed. But in this particular case, I'm post-processing an index to replace page numbers with text, and I want the text to link to the page number I'm replacing. –  ℝaphink May 30 '11 at 8:22
add comment

1 Answer 1

up vote 19 down vote accepted

You can link to any page using the implicit page anchor page.<number> as long the pageanchor option is active (which is the default anyway). Using labels is still more correct and recommended.

Note that this makes the link jump to the upper left corner of the page where the page anchor is automatically inserted. The zoom level is not changed, so if you have a large zoom factor before than you might not see the full page.

\documentclass{article}

\usepackage[pageanchor]{hyperref}
\usepackage{lipsum}

\begin{document}
\hyperlink{page.5}{On page 5}

\lipsum[1-50]

\end{document}

Note that the page number is the "number" given by \thepage. If you have a frontmatter with roman numbers then the page link might be page.I, page.II and page.5 should be the logical, not physical page 5.

Using the bookmark package you can also create a PDF bookmark (the ToC like structure displayed by the PDF reader) which points directly to the absolute page (starting with 1 for the very first page of the document). Using this link the full page is always displayed disregarding the existing zoom level.

\bookmark[page=5]{Absolute page 5}%  useful option: level=<number>

There seems to be no macro to add such a page link into the text. \hyperlink doesn't support any options. I posted a message at comp.text.tex asking about this. The author of hyperref is active there.

Furthermore, the zref package with its abspage module is useful if you want to get the absolute page numbers of stuff (i.e. label them using \zlabel).


Supplement:

After a short discussion with the hyperref author I came up with this patch to make all page anchors to be displayed in full page mode, i.e. the zoom level is changed to make the whole page fit on the screen. I very much prefer this for page links.

\makeatletter
\let\orig@Hy@EveryPageAnchor\Hy@EveryPageAnchor
\def\Hy@EveryPageAnchor{%
    \begingroup
    \hypersetup{pdfview=Fit}%
    \orig@Hy@EveryPageAnchor
    \endgroup
}
\makeatother 
share|improve this answer
    
Thank you, exactly what I wanted! –  ℝaphink May 30 '11 at 8:25
    
just saw the patch. This is very nice. Not sure it'll be useful in my case since my main goal is to get the PDF printed as a book :-) –  ℝaphink Aug 26 '11 at 10:06
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.