[Tex/LaTex] Wrong PDF bookmark for Bibliography chapter

bookmarks

I cannot set up correct PDF bookmark for Bibliography chapter in the backmatter.

The page number in TOC is correct, however the PDF bookmark consistently points to the last section in the mainmatter.

\documentclass{book}

\usepackage{bookmark}

\begin{document}
\pdfbookmark{\contentsname}{Contents}
\tableofcontents\cleardoublepage
\pagenumbering{arabic}

\begin{mainmatter}
    \chapter{Chapter A}
    \section{Section a}
\end{mainmatter}

\begin{backmatter}
    \addcontentsline{toc}{chapter}{Bibliography}
    \begin{thebibliography}{9}
    \end{thebibliography}
\end{backmatter}

\end{document}

Best Answer

Package tocbibind can be used to include the chapter titles of the table of contents and the bibliography to the table of contents and the bookmarks:

\documentclass{book}
\usepackage{tocbibind}
\usepackage{bookmark}

\begin{document}

\frontmatter
\tableofcontents

\mainmatter
\chapter{Chapter A}
\section{Section a}

\backmatter
\begin{thebibliography}{9}
\end{thebibliography}

\end{document}

Remarks:

  • \mainmatter, \backmatter are commands rather than environments in class book.