I want to have the "Contents" section appear as a PDF bookmark.
I have found this question, and the following generally works:
\makeatletter
\usepackage{etoolbox}
\pretocmd{\tableofcontents}{%
\if@openright\cleardoublepage\else\clearpage\fi
\pdfbookmark[0]{\contentsname}{toc}%
}{}{}%
\makeatother
But now I have a new problem. It also adds a bookmark for "List of Listings". I have the following sequence:
\tableofcontents
\listoffigures
\listoftables
\lstlistoflistings
I want only the first item (\tableofcontents
) to appear as PDF bookmark. Interestingly, the list-of-figures and list-of-tables do not get bookmarks, which is great. But unfortunately the list-of-listings seems implemented differently and does appear. How can I make the list-of-listings go away again from my PDF bookmarks?
I already have this customisation, perhaps it can be further adjusted?
\renewcommand\lstlistlistingname{List of Listings}
Or I could "undo" the \pretocmd
before \lstlistoflistings
?
Best Answer
Instead of using
\pretocmd
, simply prepend that stuff to\tableofcontents
directly. That way, the list of listings is not affected. So: