# Ignoring asterisks * in the whole document

When using * to remove headlines from the toc, there might be times when you would like to see all the headlines in the toc -- including the removed ones. But you would like to see the headlines just temporarily to check what is in your document and what is not there without changing all the *-ed headlines to non-*-headlines (and back afterwards).

My question: Is there a command or something to ignore the *-ing globally in the whole document, that can be switched on and off at any time?

-
some classes do include the starred headers in the toc, for example amsbook, amsart and amsproc. this, of course, results in the problem of how to omit (some or all of) them if they're not wanted there. but that's a different question. –  barbara beeton Aug 10 '12 at 14:47

You can include the following patch in your document preamble and active it using the \ifshowallintoc conditional:

\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox

\newif\ifshowallintoc
%\showallintoctrue% Comment/uncomment to include all/not in ToC

\makeatletter
\ifshowallintoc
\patchcmd{\@startsection}% <cmd>
{\@ifstar}% <search>
{\xdef\@@section@level{#1}\xdef\@@section@level@num{#2}\@ifstar}% <replace>
{}{}% <success><failure>
\patchcmd{\@ssect}% <cmd>
{\@xsect}% <search>
\ifnum \@@section@level@num>\c@secnumdepth \else
\protect\numberline{}%
\fi%
#5}\@xsect}% <replace>
{}{}% <success><failure>
\fi
\makeatother
\begin{document}
\tableofcontents
\section{A section}
\subsection{A subsection}
\subsection*{Another subsection}
\subsection{A subsection}
\section*{Another section}
\section{A section}
\subsection*{Another subsection}
\end{document}


Uncommenting \showallintoctrue (since the default is \showallintocfalse) reveals:

The motivation behind the solution is to store information previously lost when using the starred version of a sectional unit. This information is then written to the ToC file upon the condition being true or false. The main macros modified with the patch (provided by etoolbox's \patchcmd) are \@startsection and \@ssect.

Note that this solution is heavily dependent on the document class you're using. It may require a completely different patch if you're not using one of the standard document classes, or even using one that supports \chapter- and \part-level commands, like book and report.

-
Thank you very much! Basically, it works. But there are two questions remaining: 1. Is it possible to define a single solution like this that can be used in every class? 2. As you see in your shared outcome (more precise, in the second) there is the headline "Contents" twice. Could one be removed? –  Philip Aug 11 '12 at 8:58
@Philip: 1) It would be possible to adapt the current solution to work for other document classes, but something that is general would be difficult. Why? Different document classes handle their sectional units differently; either in structure, or the collection of information. What document class do you use? 2) The "second" Contents is the 'Table of Contents' heading included in the ToC. This is because of the fact that the ToC (in article) is set as a \section*. It is possible to remove this "duplication". Then again, you're just toggling this removal anyway, so it's temporary, right? –  Werner Aug 11 '12 at 13:37
1) Usually, I use the book or the article class. 2) I see. And yes, I would use it just temporary. –  Philip Aug 14 '12 at 21:56