I edit big documents, so it is useful for me to open the last page after compilation. Normally, the first page is opened, but by using hyperref, I can configure it to open any page at start.
\usepackage[pdftex,pdfstartpage=1]{hyperref}
But there is no variable lastpage. Can this be done in some other ways?
Best Answer
A package such as
zref-totpages
that counts the absolute number of pages helps. The critical part is the timing:Update: In the first run,
\ztotpages
is not yet known and has value0
causing an error with pdfTeX:page number must be positive
. (hyperref
6.83o will add some validation for the value ofpdfstartpage
.)Timing:
\zref-totpages
.\AtBeginDocument
for settingpdfstartpage
.hyperref
that\AtBeginDocument
for usingpdfstartpage
.\begin{document}
reads the.aux
file.⇒
\zreftotpages
is valid.\AtBeginDocument
is executed, first with\hypersetup
to setpdfstartpage
.hyperref
usespdfstartpage
to set the starting page.The last page is known at the end of the document,
hyperref
usespdfstartpage
earlier (TeX does not execute\special
after the last DVI output page), thus two LaTeX runs are needed.Remark: Package
lastpage
does not help here, because the page number of the last page can be different from the number of absolute pages, especially if there are resettings of the page counter (\frontmatter
,\mainmatter
, ...).Named action
LastPage
In a comment to the question Stephan Lehmke noted a named action
LastPage
. Packagehyperref
does not directly support this for the open action. Buthyperref
's open action specification can be disabled by an empty start page and the named action can be added manually, e.g. for pdfTeX: