# How to insert a page break in a minitoc but not in toc?

I would like to insert a page break in a minitoc of a chapter between two subsections but I don't want it in the global toc at the beginning of the document.

Any idea how I could achieve this ?

Here is a MWE :

\documentclass{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{minitoc}

\usepackage{xr-hyper}
\usepackage{varioref}
\usepackage{hyperref}
\usepackage{cleveref}

\setsecnumdepth{subsection} % numbering of subsection if memoir document
\setcounter{tocdepth}{1}
\setcounter{minitocdepth}{2}

\dominitoc

\begin{document}

\tableofcontents

\chapter{1}
\minitoc

\section{1a}
Hello
\subsection{1aa}
blabla

% PAGE BREAK HERE%
\subsection{1ab}
blabla
\section{1b}

\end{document}


Solutions I tried

• \addtocontents{toc}{\protect\pagebreak} but it adds a pagebreak to the toc and not in the minitoc
• \addcontentsline{toc}{subsection}{\protect\pagebreak} that almost does what I am looking for but adds a line of dot and a page number in the minitoc.
• \cftaddtitleline{toc}{subsection}{\protect\pagebreak}{} that gets rid of the page number but not the line dots. I could not find how to get rid of the dots for a specific entry...

An easy way of managing the ToC entries is to highjack one that you'll probably never use. That way the process behind the scenes remains the same, especially when dealing with minitoc. So, below I take over how starparagraphs (stemming from \paragraph*) is handled:

\documentclass{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{minitoc,etoolbox}

\usepackage{xr-hyper}
\usepackage{varioref}
\usepackage{hyperref}
\usepackage{cleveref}

\setsecnumdepth{subsection} % numbering of subsection if memoir document
\setcounter{tocdepth}{1}
\setcounter{minitocdepth}{2}

}
\newif\ifmaintoc% Used to see whether we're setting \tableofcontents or \minitoc
\AtBeginDocument{%
\let\oldtableofcontents\tableofcontents
\RenewDocumentCommand{\tableofcontents}{ s }{%
\maintoctrue% In the main ToC
\IfBooleanTF{#1}
{\oldtableofcontents*}
{\oldtableofcontents}%
\maintocfalse% Outside of the main ToC
}%
}
\let\oldcontentsline\contentsline
\renewcommand{\contentsline}[4]{%
\ifnum\pdfstrcmp{#1}{starparagraph}=0% If we're processing a starparagraph
\ifmaintoc\else% In the main ToC, do nothing, otherwise
#2% Set it as-is
\fi
\else% We're not processing a starparagraph, so execute the regular \contentsline process
\oldcontentsline{#1}{#2}{#3}{#4}%
\fi
}

\dominitoc

\begin{document}

\tableofcontents

\chapter{1}
\minitoc

\section{1a}
Hello
\subsection{1aa}
blabla

\subsection{1ab}
blabla
\section{1b}

\end{document}


The approach is to write whatever you want to the regular (main) ToC under the guise of being a startparagraph. Then, process starparagraph entries in an as-is way, rather than setting them in the usual ToC manner (with a clickable hyperlink, a leader and page number). Since the ToC-related hyperlinking is broken into parts (to capture the destination of the link and set it across the sectional unit title), it's easier to condition at the start of \contentsline whether we're dealing with a starparagraph or not. Then, within the true branch, we condition on whether we're in the main ToC or not, just to make sure we completely ignore the entry in the former case, but set it as-is in the latter.

Here is the default (main) ToC:

And here is the mini-ToC for Chapter 1, broken in two:

If you're not running a current/up-to-date LaTeX, you may have to add \usepackage{xparse} to your preamble before being able to use \RenewDocumentCommand.

• Thank for your extremely didactic answer. The MWE works fine but in my document I have this weird compilation error No room for a new \write. Any idea from where it could come ? I suspect a compatibility issue... – nlair Mar 17 at 22:18
• Each chapter is in a separate subfile (I use \documentclass[main.tex]{subfiles}). I do not get the error when I compile the chapter separately, only when i compile the whole document... – nlair Mar 17 at 22:22
• I cannot reproduce the error in a MWE but as soon as I withdraw my \listoftodos in my main the error disappears. If you have any idea about this weird behavior I wuold be interested ! Thanks again for your previous help ! – nlair Mar 17 at 22:32
• @nlair: \listoftodos is from the todo package and surely writes content to a "list of" that is similar to the ToC. I fiddle around with the ToC in my code, so that could cause an issue. – Werner Mar 17 at 23:08