Remove chapter from ToC

\documentclass{mwrep}
\begin{document}
\tableofcontents
\chapter{c1}
\chapter{c2}
\chapter*{c3}
\chapter*{c4}
\section*{s}
\chapter{c5}
\end{document}

I know chapter* removes a chapter from numbering. How can I remove it also from ToC? I want to remove c4 but not c3.

-

1 Answer

To remove from the ToC all the entries associated with \chapter* you need to redefine the \chapter@toc command implemented in mwrep.cls; the following example code includes the necessary redefinition:

\documentclass{mwrep}

\makeatletter
\renewcommand*\chapter@toc{%
\ifHeadingNumbered\typeout{\@chapapp\space\thechapter.}
\addcontentsline{toc}{chapter}{%
\ifHeadingNumbered
\protect\numberline{\mw@seccntformat{\HeadingNumber}}%
\fi
\HeadingTOCText}\fi%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
}
\makeatother

\begin{document}
\tableofcontents
\chapter{c1}
\chapter{c2}
\chapter*{c3}
\end{document}

To remove from the ToC only a particular entry associated with \chapter* you could 1) use the tocvsec2 package:

\documentclass{mwrep}
\usepackage{tocvsec2}

\begin{document}
\tableofcontents
\chapter{c1}
\chapter{c2}
\chapter*{c3}
\settocdepth{part}
\chapter*{c4}
\settocdepth{section}
\end{document}

or 2) Use \addtocontents to appropriately change the value of the tocdepth counter:

\documentclass{mwrep}

\begin{document}
\tableofcontents
\chapter{c1}
\chapter{c2}
\chapter*{c3}
\addtocontents{toc}{\setcounter{tocdepth}{-1}}
\chapter*{c4}
\addtocontents{toc}{\setcounter{tocdepth}{2}}
\end{document}
-
And this makes every chapter* excluded? This is not what I want. I corrected my question because it was misleading. –  Ichibann Jul 27 '11 at 22:49
@Ichibann: Yes. I've updated my answer to provide a solution for the new requirement. –  Gonzalo Medina Jul 27 '11 at 23:00
Your secont way does not work (in example as in my edited question). First works without problems. –  Ichibann Jul 27 '11 at 23:54
@Ichibann: what exactly doesn't work? In your new edit what do you want to remove from the ToC? –  Gonzalo Medina Jul 28 '11 at 0:28
@GonzaloMedina Solution 2) makes the ToC disappear completely. Solution 1) works great. –  stanwise Sep 13 '12 at 15:23