# Additional short TOC in scrbook

Nevertheless I want to use it in scrbook but then the detailed TOC is not printed. Does someone know an implementation that works with pdfpages?

\documentclass{scrbook}
\begin{document}
{\renewcommand*{\contentsname}{Short Contents}
\setcounter{tocdepth}{0}
\tableofcontents
}
\tableofcontents

\chapter{Intro}
\section{Sub A}
\section{Sub B}
\end{document}


### Comment

The use of the package pdfpages (with addtotoc=...) seems to be incompatible with etoc, which itself could serve as a solution.

You could use KOMA-Script package scrwfile:

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage{scrwfile}
\TOCclone[Short Contents]{toc}{stoc}
\begin{document}
\listofstoc
\tableofcontents
\chapter{Intro}
\section{Sub A}
\section{Sub B}
\end{document}


Another possibility is patching \addtocentrydefault to write all ToC entries in a new file with the extension .stoc.

\documentclass{scrbook}
\usepackage[english]{babel}
\BeforeStartingTOC[stoc]{\value{tocdepth}=0}
\usepackage{xpatch}
{}{\PatchFailed}

\begin{document}
\listoftoc[Short Contents]{stoc}
\tableofcontents
\chapter{Intro}
\section{Sub A}
\section{Sub B}
\end{document}


If the TOC should get an entry in the "Short Contents" add the following lines to the preamble of the examples above:

\BeforeStartingTOC[toc]{%
}


Use the technique from this post. As you want it to work with babel you have to take care of babel commands.

It seems that including babel will also break the grouping of tocdepth, so you might need to \setcounter{tocdepth}{2} before issuing your second \tableofcontents.

\documentclass{scrbook}
\usepackage[english]{babel}
\begin{document}
{
\makeatletter
\renewcommand*{\contentsname}{Short Contents}
\setcounter{tocdepth}{0}
\expandafter\def\csname @starttoc\endcsname#1{\InputIfFileExists{\jobname.#1}{}{}}\tableofcontents
\makeatother
}
\tableofcontents

\chapter{Intro}
\section{Sub A}
\section{Sub B}
\end{document}

• This solution seems incompatible with the package babel. Try with \usepackage[english]{babel}. – strpeter Dec 30 '18 at 13:03
• @strpeter No, it is not. You only have to take care of the obvious babel commands. – TeXnician Dec 30 '18 at 13:12
• True it works! Great thank you. Could you explain a bit more in depth what the following command does? \expandafter\def\csname @starttoc\endcsname#1{\InputIfFileExists{\jobname.#1}{}{}} – strpeter Dec 30 '18 at 13:30
• @strpeter \@starttoc is the core piece of \tableofcontents and it is simply redefined to input the toc file if it exists. As it is now in a makeatletter context one would not even need the expandafter-csname magic here… – TeXnician Dec 30 '18 at 14:16
• @strpeter A much better explanation and workaround is given in Schweinbacke's answer. – TeXnician Dec 30 '18 at 14:23

To read the toc-file twice, you have to avoid to open it to write before the second reading. LaTeX's kernel macro \@starttoc, which is used by \tableoofcontents, usually also opens the file for writing. Loading scrwfile as shown in esdd's answer already avoids opening files for writing when \@starttoc is used. Also local redefinition of \@starttoc as show in TeXnician's answer can be used to avoid the opening for writing. Another suggestion would be to deactivate LaTeX's opening of auxiliary files for writing, e.g.:

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage{scrwfile}
\usepackage{mwe}% provides \Blinddocument
\makeatletter
\newcommand*{\shorttableofcontents}{%
\begingroup
\value{tocdepth}=\z@ % set tocdepth locally to zero
\@fileswfalse % deactivate opening of auxiliary files
\listoftoc[Short Contents]{\ext@toc}%
\endgroup
}
\makeatother
\begin{document}
\shorttableofcontents% must be before \tableofcontents
\tableofcontents
\Blinddocument
\end{document}


Here KOMA-Script's \listoftoc is used to show the short version of the ToC. See the manual for more information.

However this suggestion would fail, if \shorttableofcontents would be used after \tableofcontents! And you cannot add extra entries to the short table of contents, that are not shown in the normal table of contents. If you need such things, esdd's answer would be the better suggestion.

However you could use another KOMA-Script macro to clone the main ToC:

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage{scrwfile}
\usepackage{mwe}% provides \Blinddocument
\DeclareNewTOC[%
listname={Short Contents},
]{stoc}
\makeatletter
}
\makeatother
\BeforeStartingTOC[stoc]{\value{tocdepth}=0\relax}
\let\shorttableofcontents\listofstocs
\begin{document}
\shorttableofcontents
\tableofcontents
\Blinddocument
\end{document}


KOMA-Script uses \addtocentrydefault to generate the ToC entries of all headings. But this does not work, if a package generates ToC entries without using \addtocentryefault e.g. using \addcontentsline directly.

Instead of redefining \addtocentrydefault you can try to patch it as shown in esdd's second suggestion.

ah sorry, posted this before seeing your pdfpages comment. Maybe this should be topic of another question if there is incompatibility with etoc? (a mwe showing the problem would be helpful)

\documentclass{scrbook}
\usepackage{etoc}
\begin{document}
{\renewcommand*{\contentsname}{Short Contents}
\etocsetnexttocdepth{chapter}
\tableofcontents
}
\tableofcontents

\chapter{Intro}
\section{Sub A}
\section{Sub B}
\end{document}