The bookmark package

Replaces the bookmark code of hyperref: the PDF outline is correct after one run, and \bookmarksetup sets its style, numbering and open levels.

Loading the package

\usepackage{bookmark}

hyperref writes the bookmarks into an .out file and reads them in the next run, so the outline in the PDF viewer lags one run behind. bookmark writes them into the PDF in the same run.

The package also adds settings that hyperref does not have: bold, italic or coloured bookmarks, the level up to which the outline is open when the PDF is opened, and bookmarks to any page or to a web address.

bookmark loads hyperref if that has not happened yet. To pass options to hyperref, load hyperref first.

Main commands

\bookmarksetup{numbered}Puts the section numbers in front of the bookmark texts.
\bookmarksetup{open, openlevel=1}Opens the outline down to the given level when the PDF is opened.
\bookmarksetup{bold, color=blue}Style of the following bookmarks; color needs xcolor.
\pdfbookmark[1]{Contents}{toc}A bookmark at the current position, here for the table of contents; the number is the level and the last argument a unique name.
\bookmark[page=1, level=0]{Cover}A bookmark that points to a page number.
\bookmarksetup{startatroot}Puts the next bookmark on the top level, for example the first heading after the last \part.

Complete example

\documentclass{article}
\usepackage{hyperref}
\usepackage{bookmark}
\bookmarksetup{numbered, open, openlevel=1}
\begin{document}
\pdfbookmark[1]{Contents}{toc}
\tableofcontents

\section{Introduction}
\subsection{Background}
Text of the subsection.

\bookmarksetup{bold}
\section{Results}
The bookmark of this section is bold.
\end{document}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023.

Pitfalls

Related pages