# Overwrite pdfbookmarks created by \addcontentsline

I want a bookmark called "Frontmatter" at level=0 and bookmarks for "Preface", "Acknowledgements" and "Contents" at level=1.

My problem is that \addcontentsline{toc}{chapter}{<x>} automatically creates bookmarks at chapter level (level=0) and I don't how to overwrite them with bookmarks at level=1. The lines I commented out in the below MWE indicate the structure of the bookmarks I would like to have. The bookmark package seems not be provide a solution either, hence I didn't load it in the MWE.

\documentclass{book}

\usepackage{lipsum}
\usepackage{hyperref}

\begin{document}

\frontmatter

%\pdfbookmark[0]{Frontmatter}{frontmatter}
\chapter*{Preface}
%\pdfbookmark[1]{Preface}{preface}
\lipsum[1]

\chapter*{Acknowledgements}
%\pdfbookmark[1]{Acknowledgements}{acknowledgements}
Thanks to everyone for everything.

\cleardoublepage
\pdfbookmark[0]{Contents}{toc}
%\pdfbookmark[1]{Contents}{toc}
\tableofcontents

\mainmatter

\chapter{Lipsum 2}
\lipsum[2]

\end{document}

-

Also in this case package bookmark can help. The bookmark "Frontmatter" can be added at part level and at \mainmatter the bookmark hierarchy is restarted using option startatroot.

\documentclass{book}

\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{bookmark}

\begin{document}

\frontmatter

\pdfbookmark[-1]{Frontmatter}{frontmatter}
\chapter*{Preface}
\lipsum[1]

\chapter*{Acknowledgements}
Thanks to everyone for everything.

\cleardoublepage
\pdfbookmark[0]{Contents}{toc}
\tableofcontents

\bookmarksetup{startatroot}
\mainmatter

\chapter{Lipsum 2}
\lipsum[2]

\end{document}


An alternative solution would be the redefinition of \toclevel@chapter to 1 and resetting after the frontmatter.

-
Why is this solution better than mine (it got a positive vote mine didn't)? No, I am not whining, I just want to know so that I can improve my LaTeX style! ;-) –  lpdbw Aug 10 '12 at 14:24

Solution: Use bookmark package and then \bookmarksetup{depth=-1} for the frontmatter and \bookmarksetup{depth=4} for the mainmatter.

\documentclass{book}

\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{bookmark}

\begin{document}

\bookmarksetup{depth=-1}

\frontmatter

\pdfbookmark[0]{Frontmatter}{frontmatter}
\chapter*{Preface}
\pdfbookmark[1]{Preface}{preface}
\lipsum[1]

\chapter*{Acknowledgements}
\pdfbookmark[1]{Acknowledgements}{acknowledgements}
Thanks to everyone for everything.

\cleardoublepage
\pdfbookmark[1]{Contents}{toc}
\tableofcontents

\bookmarksetup{depth=4}

\mainmatter

\chapter{Lipsum 2}
\lipsum[2]

\end{document}

-