# Remove prepended numbers in minitoc

I would like to omit the Chapter number in the minitoc printings. For example, in the below mwe I would like the minitoc in Chapter two to print "1 Test 1" instead of "2.1 Test 1".

\documentclass{book}
\usepackage{minitoc}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\setcounter{minitocdepth}{\value{tocdepth}}

\begin{document}
\dominitoc
\tableofcontents

\chapter{Chapter title}
\minitoc

\section{Test 1}

\chapter{Chapter two}
\minitoc

\section{Test 1}
hello

\subsection{Test 1 subsection}

\section{Test 2}
hello
\subsection{Test 2 subsection}

\subsection{Test 2 subsection}
hello

\subsubsection{Subsubsection}
hello
\end{document}

• you can add \makeatletter \def\numberline#1{\def\mt{#1}\hb@xt@\@tempdima{\expandafter\@gobbletwo\mt\hfil}} \makeatother after \tableofcontents. – touhami Jan 18 '17 at 23:26

Every entry in the mtcX files is of the form

{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {1.1}Test 1}{\reset@font\mtcSfont 3}}


where \mtc@string is defined to be \relax. We can overload it to modify (locally) the meaning of \numberline to gobble up to and including the first period.

\documentclass{book}
\usepackage{minitoc}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\setcounter{minitocdepth}{\value{tocdepth}}

\makeatletter
\let\xumtc@numberline\numberline
\protected\def\mtc@string{\let\numberline\xumtc@gobble@numberline}
\def\xumtc@gobble@numberline#1{\xumtc@gobble@@numberline#1\@nil}
\def\xumtc@gobble@@numberline#1.#2\@nil{\xumtc@numberline{#2}}
\makeatother

\begin{document}
\dominitoc
\tableofcontents

\chapter{Chapter title}
\minitoc

\section{Test 1}

\chapter{Chapter two}
\minitoc

\section{Test 1}
hello

\subsection{Test 1 subsection}

\section{Test 2}
hello
\subsection{Test 2 subsection}

\subsection{Test 2 subsection}
hello

\subsubsection{Subsubsection}
hello
\end{document}


A higher level patch that takes care of possible lacking periods (we might have \numberline{} for unnumbered sections that are included in the minitoc nonetheless):

\documentclass{book}
\usepackage{minitoc}
\usepackage{expl3}

\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\setcounter{minitocdepth}{\value{tocdepth}}

\ExplSyntaxOn
\cs_new_protected:Nn \xumtc_string:
{
% locally change \numberline to gobble up to and including the first period
\cs_set_eq:NN \numberline \xumtc_gobble_numberline:n
}
% the 'external' name
\cs_set_eq:cN { mtc@string } \xumtc_string:
% save the old meaning of \numberline
\cs_set_eq:NN \xumtc_numberline:n \numberline
% define a variant that first expands the argument
\cs_generate_variant:Nn \xumtc_numberline:n { x }
% allocate a variable
\seq_new:N \l__xumtc_numberline_seq
% the main macro
\cs_new_protected:Nn \xumtc_gobble_numberline:n
{
% split the argument at periods
\seq_set_split:Nnn \l__xumtc_numberline_seq { . } { #1 }
% discard the first item
\seq_pop_left:NN \l__xumtc_numberline_seq \l_tmpa_tl
% yield the remaining items with a period between them
\xumtc_numberline:x { \seq_use:Nn \l__xumtc_numberline_seq { . } }
}
\ExplSyntaxOff

\begin{document}
\dominitoc
\tableofcontents

\chapter{Chapter title}
\minitoc

\section{Test 1}

\chapter{Chapter two}
\minitoc

\section{Test 1}
hello

\subsection{Test 1 subsection}

\section{Test 2}
hello
\subsection{Test 2 subsection}

\subsection{Test 2 subsection}
hello

\subsubsection{Subsubsection}
hello
\end{document}

• … assuming that the argument of \numberline contains at least one period (I was working on exactly the same solution, but I saw the question too late… ;-) Why don’t you use xparse? – GuM Jan 18 '17 at 23:52
• @GustavoMezzetti It does, in this case, because only levels from sections down are listed. It's just a hack, maybe I can think to a higher level solution. ;-) – egreg Jan 18 '17 at 23:55
• I know it does in this case, but I don’t expect anything less than a highest level solution from you… ;-) – GuM Jan 18 '17 at 23:58
• May I suggest \def\xumtc@gobble@numberline#1{\xumtc@gobble@@numberline#1\@nil.#1\@nil\@@nil} and \def\xumtc@gobble@@numberline#1.#2\@nil#3\@@nil{\xumtc@numberline{#2}}? – GuM Jan 19 '17 at 0:13
• @GustavoMezzetti Your wish is my command – egreg Jan 19 '17 at 0:13