In a generic way, how can I change the format of bookmarks generated automatically by hyperref (or bookmark)?

By generic, I mean the ability the customize the bookmark format for part, chapter, section, etc. without having to modify the document TeX. Ideally it will be contained in a class wrapper.

Bookmark format ideas:

  • Unnumbered parts, numbered chapters, unnumbered sections/subsections (but they all are numbered - not@star).
  • Part format: "Part <#>: " or ", Part <#>"
  • Move number to after the title


\part{Test Part}
\chapter{Test Chapter}
\section{Test Section}
\part{Test Part}
\chapter{Test Chapter}
\section{Test Section}

Here's the index output (evince) marked up with what I would like to do. Perhaps rewriting a bookmark/hyperref command would do?

sample output

  • Do you want this change to be global, or just for \parts and \chapters?
    – Werner
    May 8, 2013 at 7:04
  • Updated question to (hopefully) clarify. Looking for a global solution that is configurable for each heading type.
    – h0tw1r3
    May 8, 2013 at 15:01

1 Answer 1


The following provides the functionality to swap titles and numbers in the bookmarks:

enter image description here

\documentclass{scrbook}% http://ctan.org/pkg/KOMA-script
% \usepackage{hyperref}% http://ctan.org/pkg/hyperref
\usepackage[numbered]{bookmark}% http://ctan.org/pkg/bookmark
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox

% Argument patching inside a macro: https://tex.stackexchange.com/q/113147/5764
% Swap num/title in bookmarks
  % \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
  \patchcmd{\Hy@writebookmark}{\bookmark}{\let\numberline\@gobble\edef\BKM@reversetitle{#2\ #1}\bookmark}{}{}%
\newcommand{\reverttitlenumswap}{\let\Hy@writebookmark\store@Hy@writebookmark}% Revert num/title swap in bookmarks
% Section-specific swapping of num/title in bookmarks


\parttitlenumswap% Swap \part num/title in bookmarks
\sectiontitlenumswap% Swap \section num/title in bookmarks

\part{Test Part}
\chapter{Test Chapter}
\section{Test Section}

\part{Test Part}
\chapter{Test Chapter}
\section{Test Section}


The above MWE provides \reversetitlenum that acts as a switch. After calling this macro, all subsequent sectional units will have a swapped number/title in the bookmarks. \reverttitlenum is a switch that reverts back to the default presentation.

Separate macros for each sectional unit (\part, \chapter and \section, although other can also be defined as needed) is also provided to selectively activate the swapping of bookmark constructions.

The main approach to this solution is to hack into \Hy@writebookmark - the macro that is finally called to construct the bookmark (from bookmark.dtx):


It takes 5 arguments of which the first 2 are the most important from a visual/end user perspective. #1 contains the sectional unit number <num> (although it is never used), while #2 contains a ToC-like entry of the form \protect\numberline{<num>}<title>. The default is to only use #2. The suggested patch in \reversetitlenumswap uses both, printing it as #2\ #1 while also temporarily deactivating the macro \numberline. The patch is inserted just above the \bookmark entry, while also updating the use of only #2 (resulting in two separate patches).

It is not necessary to load hyperref. bookmark loads hyperref and uses some of its code. See Which package should I load first: hyperref or bookmark?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .