I need to write section numbers in PDF bookmarks, but only for section (and not for subsections etc.). Desired result:
Now I use bookmark
package, so I can write numbers for every bookmark with numbered option. It is possible, to show numbers only for top-level bookmarks? (Another-leveled items like subsections and deeper must be showed in bookmarks, but without numbers)
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[
open,
openlevel=2,
atend,
numbered
]{bookmark}
\makeatletter
\renewcommand{\Hy@numberline}[1]{#1. }
\makeatother
\begin{document}
\section{Bla bla}
...
\subsection{Lorem}
...
\subsection{ipsum}
..
\section{Bla bla bla}
\end{document}
Best Answer
Option
addtohook
of packagebookmark
allows to change the settings for a bookmark in dependence of some parameters such as the bookmark level. Thus the following would solve the problem:Unhappily option
numbered
is evaluated before the hook in\bookmark
is executed, see the definition of\Hy@writebookmark
in packagebookmark
. Thus the following example changes the effect of optionnumbered
instead: