# How to change the PDFBookmark titles (hyperref)

I am looking to change the title which displays in the PDF bookmark tabs to match the format of how I have my chapters listed.

\documentclass[]{report}
\titleformat{\chapter}[block]
{\normalfont\LARGE\bfseries\centering}{CHAPTER \thechapter}{0em}{:\hspace{2mm}}
\begin{document}

\chapter{THE BEGINNING}
Hello.

\chapter{THE END}
Goodbye.
\end{document}


What i currently have is:

with the option of creating bookmarks of:

What I want my bookmarks to look like is identical to how the chapter title is formatted:

I have found that I can input \pdfbookmark[0]{THE BEGINNING}{name1}, but I would need to remove the bookmarks created by hyperref (which would not be ideal if I have multiple chapters, sections, subsections, etc., and have to input them all manually using this method.)

Will I have to work with changing \chapter{THE BEGINNING} to \chapter{CHAPTER \thechapter: THE BEGINNING}, then worry about removing the chapter number from 'CHAPTER 1: THE BEGINNING' from the title and ToC?

UPDATE:

The best option I found is: How to remove chapter numbering without removing it from tableofcontents

I can use the code

\newcommand{\mychapter}[2]{
\setcounter{chapter}{#1}
\setcounter{section}{0}
\chapter*{#2}


I use TeXMaker, and I like the structure is provides for opening/organizing subfiles (i.e. using \input{...}). To keep this as organized as possible, I resorted to the following:

1. Create .tex file titled Chapter.1.THEBEGINNING

2. This subfile will include \mychapter{1}{CHAPTER \thechapter: THE BEGINNING}

3. My main document will include \input{Chapter.1.THEBEGINNING}

This works well enough...although still looking for better options.

• Maybe Heikos answer to this question will solve your problem: tex.stackexchange.com/questions/115008/…
– DG'
Jan 29, 2014 at 16:46
• Use \hypersetup{bookmarksnumbered} \renewcommand*{\thechapter}{\texorpdfstring{}{CHAPTER }\arabic{chapter}\texorpdfstring{}{:}} Jan 29, 2014 at 17:35
• You may want to update \titleformat, otherwise you'll see : before every \chapter*.
– Werner
Jan 29, 2014 at 18:12
• @Werner I have modified \chapter*{...} to \section*{\LARGE\bfseries\centering...} for this. Jan 29, 2014 at 21:33

This example provides a small modification of Werner's solution. Instead of patching the internal \Hy@writebookmark the redefinition of \numberline is done in the bookmark hook addtohook of package bookmark:

\documentclass{report}

\usepackage{hyperref}
\usepackage{bookmark}
\bookmarksetup{numbered}

\titleformat{\chapter}[block]
{\normalfont\LARGE\bfseries\centering}
{CHAPTER\thechapter: }{0em}{}

\makeatletter
\bookmarksetup{%
\ifnum\toclevel@chapter=\bookmarkget{level}\relax
\renewcommand*{\numberline}[1]{CHAPTER #1: }%
\fi
},
}
\makeatother

\begin{document}

\tableofcontents

\chapter{THE BEGINNING}
Hello.
\section{A section}

\chapter{THE END}
Goodbye.
\end{document}


You can insert a conditional to change the way \numberline functions when dealing with \chapters:

\documentclass{report}
\usepackage{bookmark,etoolbox}
\bookmarksetup{numbered}
\titleformat{\chapter}[block]
{\normalfont\LARGE\bfseries\centering}{CHAPTER \thechapter:\hspace{2mm}}{0em}{}

\makeatletter
\patchcmd{\Hy@writebookmark}% <cmd>
{\let\chapternumberline\Hy@numberline}% <search>
{\ifx\Hy@toclevel\toclevel@chapter\def\numberline##1{CHAPTER ##1: }\fi}% <replace>
{}{}% <success><failure>
\makeatother
\begin{document}

\tableofcontents

\chapter{THE BEGINNING}
Hello.
\section{A section}

\chapter{THE END}
Goodbye.
\end{document}


The default of \numberline (similarly \Hy@numberline used by hyperref is to set the number followed by a space:

\def\numberline#1{#1 }


I've just patched \Hy@writebookmark to correct \numberline when you're dealing with a \chapter using the conditional \ifx\Hy@toclevel\toclevel@chapter. The patch requires etoolbox. It can be updated to provide different prefixes for different sectional units/headings.