Please consider the following MWE:
\documentclass{article}
\usepackage{hyperref}
\usepackage{xcolor,bookmark}
\usepackage{lipsum}
\begin{document}
\section{Section 1}
\lipsum[1-3]
% hyperref:
\pdfbookmark[2]{Test Bookmark Sect. 1}{TstBookmark1}
\lipsum[4-12]
\section{Section 2}
\lipsum[13-16]
% bookmark:
\bookmark[page=\thepage,rellevel=1,keeplevel,view={XYZ},bold,color=blue]{Test Bookmark Sect. 2}
%
% bookmark with target:
\hypertarget{hereSectII}{}% second arg prints text!
\bookmark[dest=hereSectII,rellevel=1,keeplevel,view={XYZ},bold,color=blue]{Test Bookmark Sect. II}
%
\lipsum[17-20]
\section{Section 3}
Finished.
\end{document}
… which generates output like this (left evince
, right Adobe Reader):
As it can be seen, the target location being focused when the "Test Bookmark Sect. 1":
\pdfbookmark[2]{Test Bookmark Sect. 1}{TstBookmark1}
… is clicked, is between the paragraphs – basically, the target of the bookmark is "here" (so to speak), the location where \pdfbookmark
was placed in the code.
My question is – is there a similar syntax for \bookmark
?
If I specify a page
action, that one links to the top of a page – and otherwise, I have to manually specify a \hypertarget
:
\hypertarget{hereSectII}{}
\bookmark[dest=hereSectII]{Test Bookmark Sect. II}
Compared to this, it seems that \pdfbookmark
inserts both a hypertarget in the document – and the bookmark (which shows in the PDF bookmarks index). Is there a similar syntax for \bookmark
?
Best Answer
The
bookmark
package redefines\pdfbookmark
as a compatibility-feature tohyperref
:In essence,
\pdfbookmark
uses\bookmark
with a specificdest
key-value, and places both a\hyper@anchorstart
and\hyper@anchorend
to match that.The following MWE provides a similar interface as an extension to
\bookmark
that now takes an optional*
. When you use\bookmark[<options>]{<text>}
, things work as before. However,\bookmark*[<options>]{<text>}
overrides any use ofdest
in<options>
in inserts an automated (and incremental) destination: