# avoid page numbers in minitoc if tocloft is loaded

Below is a MWE which shows page numbers in the minitoc as soon as I uncomment the line loading the tocloft package. How to prevent this in addition to setting \mtcsetpagenumbers{minitoc}{off}?

\documentclass{book}

%\usepackage[titles]{tocloft}
%\makeatletter
%\def\l@subsubsection#1#2{{\let\numberline\@gobble{\sffamily\small #1~[#2]}}}
%\makeatother

\usepackage{minitoc} % Mini-ToCs with loose line spacing
\setcounter{minitocdepth}{2}
\mtcsettitle{minitoc}{} % for empty title
\mtcsetpagenumbers{minitoc}{off} % turn off page numbering in minitocs

\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}

\begin{document}
\dominitoc
\tableofcontents
{\let\clearpage\relax \chapter{Chapter title}}
\minitoc
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\end{document}


Additionally, if I uncomment the context around \def\l@subsubsection#1#2 (to achieve a compact TOC similar to that one in the microtype manual; line was copied from there) the minitoc shows the subsubsection even if minitocdepth=2.

• I've fixed the description. I meant tocloft. But anyway, I don't understand how your suggestion should help. I need both the tocloft and minitoc package but as soon as tocloft is loaded it disables some functionality of minitoc (hiding page numbers). – Mathias Walter Sep 16 '18 at 18:38

It appears that minitoc defers when tocloft is loaded first, and tocloft changes \l@section etc. when loaded after.

BTW, \l@subsection is supposed to check \value{tocdepth} and your (commented out) replacement didn't.

\documentclass{book}

\usepackage{minitoc} % Mini-ToCs with loose line spacing
\setcounter{minitocdepth}{2}
\mtcsettitle{minitoc}{} % for empty title
\mtcsetpagenumbers{minitoc}{off} % turn off page numbering in minitocs

\makeatletter
\let\normal@section=\l@section
\let\normal@subsection=\l@subsection
\makeatother

\usepackage[titles]{tocloft}

\makeatletter
\let\l@section=\normal@section
\let\l@subsection=\normal@subsection
\makeatother

\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}

\begin{document}

\dominitoc
\tableofcontents
{\let\clearpage\relax \chapter{Chapter title}}
\minitoc
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\end{document}

• It works, great. I also changed \l@subsubsection to \def\l@subsubsection#1#2{{\ifnum\c@tocdepth>2 \let\numberline\@gobble{\sffamily\small #1~[#2]} \fi}}. Is there any way to ensure a line break, if the subsubsection is the last entry in the toc? With my definition, no line break is introduced and the first chapter title is printed right after Subsubsection [1] without a new line in between. – Mathias Walter Sep 17 '18 at 5:37
• Just put a \par inside the \fi. That is what \@dottedtocline does. – John Kormylo Sep 17 '18 at 13:22
• With \par it works like expected. Unfortunately, I found a big drawback of your solution above. Any font change of TOC-entries, i. e. with \renewcommand{\cftsecfont}{\normalfont\sffamily} does not work anymore, because it gets reseted in the line \let\l@section=\normal@section. If I place the renew command after this line, it does not work either. How to solve this? – Mathias Walter Sep 18 '18 at 15:30
• The whole point was to prevent tocloft from changing the \l@subsection. Personally, I avoid tocloft and just change \l@secttion etc. directly. You can use the etoolkit to replace \normalfont in \l@subsection, etc. Or try \meaning\l@subsection to see what minitoc has one. – John Kormylo Sep 18 '18 at 17:47