[Tex/LaTex] Contents in PDF bookmarks

bookmarkshyperrefkoma-scripttable of contents

I am using KOMA-Script (scrreprt) and hyperref.

The PDF bookmarks are generated nicely from the table of contents, but I would like an extra Contents bookmark to point to the table of contents itself (without including an entry in the table of contents) – like the KOMA manual itself.

(Also list of figures and list of tables if I include them)

What is the best way to do this?

I could add a \pdfbookmark manually but I'm not sure how to get it to point correctly to the start of the section – if I do it after it will be on the wrong page (multipage toc), if I do before it will be the page before (since \tableofcontents does \cleardoublepage?). I guess I have to redefine \tableofcontents somehow.

Best Answer

The following code should create a correct ToC bookmark for both scrreprt and scrbook:

\makeatletter
\usepackage{etoolbox}
\pretocmd{\tableofcontents}{%
  \if@openright\cleardoublepage\else\clearpage\fi
  \pdfbookmark[0]{\contentsname}{toc}%
}{}{}%
\makeatother