Komascript: remove (sub)-section from TOC

I'm working on a document where I want to exclude several (sub)sections on different toc-depths from being listed inside the TOC.

Example:

Chapter 1
Section 1.1
Subsection 1.1.1 << remove
Subsection 1.1.2 << remove

Section 1.2
Section 1.3 << remove
Section 1.4


Excluding these sections via tocdepth isn't possible for me. So my idea was to have modified \chapter*, \section*, \subsection* ... commands that generate the headings (including the formatting and numbering) as usual but don't list the entries inside the TOC.

Is there a way to get this to work?

• You can change tocdepth locally with tocvsec2: ctan.org/pkg/tocvsec2 Oct 16 '17 at 16:40
• Short answer (because of missing MWE): If you use an empty string for the ToC-entry it automatically will not be added. You can do this using the optional argument of the (sub)section command. Oct 16 '17 at 16:48

You can use the extended optional argument of the sectioning commands. KOMA-Script will automatically omit empty ToC entries. To switch on the parsing for the extended optional argument, you have to use one of the following options:

• headings=optiontotocandhead: Use the not extended optional argument for both the ToC and the running head
• headings=optiontotoc: Use the not extended optional argument for the ToC only but the mandatory argument for the running head
• headings=optiontohead: Use the not extended optional argument for the running head, but the mandatory argument for the ToC

So you can either use:

\documentclass[
% for sectioning commands
]{scrbook}

\setcounter{tocdepth}{\subsectiontocdepth}% generally show part, chapter,
% section and subsection in the ToC

\usepackage{lipsum}

\begin{document}
\tableofcontents
\chapter{Chapter 1}
\lipsum[1]
\section{Section 1.1}
\lipsum[2]
\subsection[tocentry={}]{Subsection 1.1.1}% no ToC entry
\lipsum[3]
\subsection[tocentry={}]{Subsection 1.1.2}% no ToC entry
\lipsum[4]
\section{Section 1.2}
\lipsum[5]
\section[tocentry={}]{Section 1.3}% no ToC entry
\lipsum[6]
\section{Section 1.4}
\lipsum[7]
\subsection{Subsection 1.5}
\lipsum[8]
\end{document}


or

\documentclass[
headings=optiontotoc% switch on extended optional argument parsing
% for sectioning commands and restrict it to the ToC
]{scrbook}

\setcounter{tocdepth}{\subsectiontocdepth}% generally show part, chapter,
% section and subsection in the ToC

\usepackage{lipsum}

\begin{document}
\tableofcontents
\chapter{Chapter 1}
\lipsum[1]
\section{Section 1.1}
\lipsum[2]
\subsection[]{Subsection 1.1.1}% no ToC entry
\lipsum[3]
\subsection[]{Subsection 1.1.2}% no ToC entry
\lipsum[4]
\section{Section 1.2}
\lipsum[5]
\section[]{Section 1.3}% no ToC entry
\lipsum[6]
\section{Section 1.4}
\lipsum[7]
\subsection{Subsection 1.5}
\lipsum[8]
\end{document}


to get

Don't do it.

Is there a way to get this to work?