If you don't mind changing the insides of minitoc
a little you can do this. I'm not sure this answer is a particularly good one because
- The
minitoc
documentation mentions that the package has been substantially reworked at least once, so there's a lot of reason to doubt this solution will work with older versions of the package. (And of course, if future versions change how minitoc
's \PTC@test
command is used, it might not with those either.)
- The
\skipcontents
and \readcontents
commands I'm about to define don't quite work as intuitively as I think they ought. (E.g., the caveat at the end of this answer)
Consequently, a better idea may be to just switch and use etoc
. If you're absolutely set on minitoc
, though, here is a sort-of answer.
Since minitoc reads through the .toc
file and picks out relevant commands like \contentsline
and puts them in their own partial toc (.ptc) files. You can (sort of) get what you want by redefining the command \PTC@test
, which minitoc uses to test for relevance, so that it also tests whether you've told it to ignore \contentsline
s. You can then add commands to the .toc
file which don't do anything, but which minitoc
recognizes as switching the relevance of \contentsline
on or off.
\documentclass[a4paper,oneside]{scrbook}
\usepackage{minitoc}
\newif\ifignorecontents
\newcommand\skipcontents{\addtocontents{toc}{\protect\ignorecontentstrue}}
\newcommand\readcontents{\addtocontents{toc}{\protect\ignorecontentsfalse}}
\makeatletter
%Mostly copied from minitoc documentation p.357, ll.4257-4271
\long\def\PTC@test#1#2#3#4#5#6\PTC@{%
\ifx#1\ignorecontentstrue \ignorecontentstrue\else
\ifx#1\ignorecontentsfalse \ignorecontentsfalse\else
\ifx#1\contentsline
\ifignorecontents\else
\let\mtc@string\string
\PTC@contentsline{#2}{#3}{#4}{#5}%
\let\mtc@string\relax
\fi
\else\ifx#1\@input
\edef\PTC@list{\PTC@list#2\relax}%
\else\ifx#1\partend
\immediate\closeout\tf@mtc
\immediate\openout\tf@mtc=\jobname.mtc
\else\ifx#1\partbegin
\addtocounter{ptc}{-1}%
\fi\fi\fi\fi\fi\fi
\ifeof\@inputcheck\expandafter\PTC@toc
\else\expandafter\PTC@read\fi}%
\makeatother
\begin{document}
And then around the chapter you don't want
\chapter{Chapter 3}
\skipcontents %exclude from part's toc
\chapter{Chapter 4}
\readcontents %start including again
\chapter{Chapter 5}
But if you have something like
\chapter{Chapter 3}
\section{3.1}
\section{3.2}
\skipcontents
\section{3.3}
\chapter{Chapter 4}
\section{4.1}
\section{4.2}
\readcontents
\section{4.3}
you'll get a line for section 4.3 under chapter 3 in the partial toc.
\settocdepth{part}
bevor the chapter 4 I got that result, because it changes the depth of the toc at a specific point in a document. So in theory shouldn't it be possible to write a macro doing the exact same thing, but just for parttoc instead of toc? Unfortunately I have no experience with that.