Is it possible to omit a single specific subsection from the table of contents, while keeping it numbered as usual within the main body, and keeping other subsections listed?

(I am using the amsart class.)

-
Why would you want to do that? Just curious... – vonbrand Mar 2 '13 at 1:17

The following code provides the an \addsubsection macro that works similar to \subsection (starred version, optional argument) that uses the \qrr@gobblenexttocentry macro to suppress the content that gets written to the .toc file.

When the hyperref package is used this line consists of five parameters, hence the \ifcsname check.

This won’t work if between the to-be-hidden subsection and its predecessor is not a single character. (But why would one do this?)

## Code

\documentclass{amsart}

%\usepackage{hyperref}% works with or without hyperref

\makeatletter
\ifcsname phantomsection\endcsname
\newcommand*{\qrr@gobblenexttocentry}[5]{}
\else
\newcommand*{\qrr@gobblenexttocentry}[4]{}
\fi
\subsection}
\makeatother

\usepackage{lipsum}
\begin{document}
\tableofcontents
\section{section name}
\lipsum[1]
\subsection{I'm here.}
\lipsum[1]
\lipsum[1]
\subsection{I'm there.}
\lipsum[1]
\end{document}


## Output

-

In the following code, whatever is put between \ignorethis...\endignorethis is ignored, and \TOCstop with \TOCstart simply write these two commands into the .toc file.

\documentclass{article}

\protected\def\ignorethis#1\endignorethis{}
\let\endignorethis\relax

\begin{document}

\tableofcontents

\section{FOO}
\subsection{BAR}
\TOCstop
\subsection{BAZ}
\TOCstart
\subsection{BAR}

\end{document}

-