7

Below is a memoir based MWE where we add a few hooks to the TOC and use these to reuse the TOC to mimic a minitoc. This works just fine even with hyperref.

However this does not work with the bookmarks. It only corresponds to the data from the last instance of \tableofcontents, not the combined information.

Anyone able to explain why it does not just combine the information?

\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[
bookmarks=true,
bookmarksnumbered,
colorlinks,
]{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}
7

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.

| improve this answer | |
6

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

| improve this answer | |
  • Thanks I'm accepting jfbus answer because of the explanation – daleif May 25 '18 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.