I can use \settocdepth
to change the depth of the ToC min-document.
This works as expected in the MWE below when I comment out the \include
statement.
However, when the \settocdepth
command is followed by an include statement which includes a file containing the different \chapter
and \section
statements, the toc file ends up in the wrong order.
My MWE is the following:
\documentclass{memoir}
\begin{document}
\frontmatter
\settocdepth{chapter}
\tableofcontents*
\chapter{Preface}
\chapter{Introduction}
\section{Section 1}
\section{Section 2}
\section{Section 3}
\mainmatter
\settocdepth{section}
\include{first-chapter}
%\chapter{First chapter}
%\section{A section}
%\section{Another section}
\chapter{Second chapter}
\section{A section}
\section{Another section}
\end{document}
The ToC file:
\changetocdepth {0}
\contentsline {chapter}{Preface}{iii}{}%
\contentsline {chapter}{Introduction}{v}{}%
\contentsline {section}{Section 1}{v}{}%
\contentsline {section}{Section 2}{v}{}%
\contentsline {section}{Section 3}{v}{}%
\contentsline {chapter}{\chapternumberline {1}First chapter}{1}{}%
\contentsline {section}{\numberline {1.1}A section}{1}{}%
\contentsline {section}{\numberline {1.2}Another section}{1}{}%
\changetocdepth {1}
\contentsline {chapter}{\chapternumberline {2}Second chapter}{3}{}%
\contentsline {section}{\numberline {2.1}A section}{3}{}%
\contentsline {section}{\numberline {2.2}Another section}{3}{}%
You can see that \changetocdepth
is only added after the contentsline
s from the included file.
How can I fix this? What am I doing wrong?
\settocdepth
command belongs intisde the included file containing the chapter contents. Especially should I decide to change the order of the chapters, I would have to remember moving that command around as well.