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 am adding entries to bookmarks and I want one entry to point to a specific page. However, I don't want to provide it's number, because it may change depending on contents modification before that page. The command to add an entry using the bookmark package is:

\bookmark[page=X,level=0]

where X is the page number. How can I determine at compile time the current page number to replace X with it? I've tried using \thepage in X's place but it didn't work. In the package documentation I found out there are named actions to PrevPage, NextPage, FirstPage and LastPage but there is no CurrentPage. How to fix this?

Thanks.

share|improve this question

4 Answers 4

up vote 13 down vote accepted

Set a target on the page:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{bookmark}
\begin{document}
\bookmark[dest=mypage]{go to my page!}


page 1\newpage page 2 \newpage my page \hypertarget{mypage}{}
\newpage next page

\end{document}
share|improve this answer
    
@Ulrike Thanks!!! They should add one example of use of hypertarget in the documentation! –  Weslei Feb 24 '11 at 17:46
1  
There is an example. And in my version line 23 says \hypertarget{fig}{}. –  Ulrike Fischer Feb 24 '11 at 17:55
    
@Ulrike Sorry, I didn't figure it out when I read that example... –  Weslei Feb 24 '11 at 17:57
2  
Wouldn't this jump directly to the position of the hypertarget and not to the page in general, i.e. make a difference in the zoom level, etc.? –  Martin Scharrer Feb 24 '11 at 18:43
    
@Martin Yes, but as every bookmark node jumps direct to the section title and not to the beggining of the page, I thought it was reasonable to let this way here too. –  Weslei Feb 24 '11 at 18:46

Here a solution how to add bookmarks to the current page using absolute page numbers provided by the zref package(s).

I actually needed this now for my thesis myself. There I want a PDF bookmark on e.g. the bibliography page (really the page, not the headline etc.).

Definition:

\usepackage{zref-user}
\usepackage{zref-abspage}
\makeatletter
\newcommand{\pagebookmark}[3][]{%
    \zlabel{#2}%
    \bookmark[page=\zref@extractdefault{#2}{abspage}{1},#1]{#3}%
}
\makeatother

Usage:

\pagebookmark[<options>]{<page label>}{<bookmark text>}

Example:

My bibLaTeX bibliography is printed and bookmarked using the following code:

\clearpage
\pagebookmark[level=0]{bibpage}{\bibname}%
\printbibliography

The \clearpage ensures that the correct page is bookmarked.

share|improve this answer
1  
If the page counter is never reset you can also use \bookmark[page=\value{page}]{...} direct after a \clearpage where page should have the correct value. This worked for me well for the frontmatter, but not after page got reset for the mainmatter. Also \bookmark[page=\numexpr\value{abspage}+1\relax] (zref-abspage package) works well after a \clearpage but the above solution is much more secure. –  Martin Scharrer Jun 16 '11 at 11:35

With the pageslts package, it is possible to say

\bookmark[page=\theCurrentPage,level=0]{Hi!}

even if \pagenumbering{roman}\addtocounter{page}{42} was used.

share|improve this answer

You can get page numbers using refcount package.

\usepackage{refcount}
\label{thispage}
\newpage
page=\getpagerefnumber{thispage}
share|improve this answer
1  
This won't work for the mentioned case in the question. If the page number is in roman it will return the roman page number, and what is needed for the bookmark is the real page number of the document, for instance, it should use the number 3 even if the third page of the document is in frontmatter using roman page numbering - iii or similar. –  Weslei Feb 24 '11 at 18:54

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.