Reusing TOC vs bookmarks

When the toc file is executed by the first \tableofcontents the BREAK is configured to do \setcounter{tocdepth}{-10}. But hyperref obeys the then current value of tocdepth to decide what goes to the bookmarks. So the main matter sectioning does not make it to the bookmarks.

The second table of contents contains a BREAK which sets the tocdepth to 3. So the appendices sectioning coming next end up in the bookmarks.

See also 11.1. The hyperref option bookmarksdepth in etoc manual.

When modifying the counter tocdepth for the purposes of multiple uses of \tableofcontents or \localtableofcontents, one should be aware that package hyperref by default takes into account the current value of the tocdepth counter to decide whether the pdf file will contain a bookmark corresponding to sectioning commands encountered in the source file. Thus, one typically needs to reset tocdepth to its previous value after having temporarily modified it for a given table of contents.

Or, there is the bookmarksdepth=n option of package hyperref, with n the desired document bookmarks maximal depth, which can be numeric or the name of a level known to hyperref. This documentation previously passed bookmarksdepth=3 as option to hyperref, so even if tocdepth was left to 1 by inadvertance after printing a certain table of contents this did not modify the bookmark tree of the pdf file. Now that \etocsetnexttocdepth has been added to the package, we have used it systematically and there was no need for bookmarksdepth=3 anymore.


You can set bookmarksdepth individually, then it will work:

\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[
bookmarks=true,
bookmarksnumbered,
colorlinks,
bookmarksdepth=10 %<-------
]{hyperref}

\begin{document}

\frontmatter

% disable TOC part after BREAK
\cftinsertcode{BREAK}{\setcounter{tocdepth}{-10}}

\tableofcontents*

\mainmatter

\chapter{Mainmatter chapter}

\section{Mainmatter section}

\subsection{Mainmatter subsection}


\appendix

\appendixpage

\cftinserthook{toc}{BREAK}

% disable before BREAK
\setcounter{tocdepth}{-10}
% enable after break
\cftinsertcode{BREAK}{\setcounter{tocdepth}{3}}

\renewcommand\contentsname{Appendices overview}
\tableofcontents*

\clearpage

\chapter{Appendix chapter}

\section{Appendix section}

\subsection{Appendix subsection}

\end{document}

enter image description here