Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.)

share|improve this question
3  
Why would you want to do that? Just curious... –  vonbrand Mar 2 '13 at 1:17
add comment

2 Answers

up vote 4 down vote accepted

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?)

Reference

Code

\documentclass{amsart}

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

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

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

Output

enter image description here

share|improve this answer
add comment

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
\def\TOCstop{\addtocontents{toc}{\ignorethis}}
\def\TOCstart{\addtocontents{toc}{\endignorethis}}

\begin{document}

\tableofcontents

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

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.