That really is some annoying behavior! I started writing "Oh, just put \pdfbookmark
into the title" until I read the rest of your question. I dug into hyperref.sty
and, eventually, hyperref.pdf
(the version with the documented source) and found out that the whole thing is driven by \Hy@writebookmark
in some way. Note: I don't know what \Hy@writebookmark
actually does, except that it apparently writes a bookmark. Here is the solution I found (in the preamble of the following example code):
\documentclass{article}
\usepackage{hyperref}
\makeatletter
\def\munch#1{}
\newcommand{\bkmk}[4][0]{%
#2#3{\phantomsection%
\Hy@writebookmark%
{}%
{#4}%
{\@currentHref}%
{#1}%
{toc}%
#4}%
}
\makeatother
\begin{document}
\section{Real section}
Stuff and things.
\bkmk[2]\subsection*{Bookmarked as a subsection}
More text.
\end{document}
Compile twice to make sure the bookmarks are in the PDF, and see that the link goes to the right place. What's going on here is that your links are one line off for the same reason as in this question of mine, because \pdfbookmark
(erroneously?) doesn't use \Hy@raisedlink
to place its target above the baseline. Conveniently, \phantomsection
does use this facility, and names the link \@currentHref
, so we just send the bookmark there. If you save (via \edef
) this macro immediately, you can also produce links to the starred section from within the document.
The starting point for this solution was the following much simpler macro that I use to get starred sections into the TOC, which also has the effect (with hyperref) of putting them in the bookmarks with the right link location:
\def\munch#1{}
\newcommand{\toc}[3]{
#1#2{\phantomsection\addcontentsline{toc}{\expandafter\munch\string#1}{#3}#3}
}
Same usage as above (without the optional argument). Since it works, it led me to investigate \addcontentsline
, and so on.
It may sound quite strange, but you have to use exactly the same command as you use to open the external PDF viewer! This is because the code to run the external programs (the function Texmaker::RunCommand
located in texmaker.cpp
, ll.5433-5596 in the sources) checks if the command to be executed is the PDF viewer, and runs the internal viewer instead of the external program if it is activated.
In order to use the internal PDF viewer, you have to select Pdf Viewer->Built-in Viewer
and disable the Embed
checkbox in the Options->Configure Texmaker->Commands
menu. Now you'll be able to launch Texmaker's viewer by using the same command in the Quick Build->User
input field as stated in Commands->Pdf Viewer->External Viewer
.
No program you use in your Quick Build command line must exit with an error, otherwise the execution will be aborted and the viewer won't be shown.
Best Answer
This is not a
pdflatex
issue. You must be using, directly or indirectly, thehyperref
package, which controls the PDF TOC. To have it unfolded, just add this to the preamble of your document: