Is it safe to redefine \@starttoc?

I'm using tocloft and would like to produce a two-column table of contents. While it's easy to just wrap the whole toc in a multicol-environment, I don't like the look of that, because the title gets wrapped into that as well, which makes the second column start above the title.

As tocloft redefines \tableofcontents using \AtBeginDocument, I thought instead of overwriting that definition at a later point I might just redefine \@starttoc to produce what I want, like this:

\documentclass{scrbook}
\usepackage{multicol}
\usepackage{tocloft}
\makeatletter
% tocloft redefines \tableofcontents \AtBeginDocument
% As I don't want the title to be part of the two column layout,
% it seems easiest to just add the multicols to \@starttoc.
\let\@starttocorg\@starttoc
\def\@starttoc#1{%
\begin{multicols*}{2}%
\@starttocorg{#1}%
\end{multicols*}}%
\makeatother
\begin{document}
\tableofcontents
\part{part}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\part{part}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\part{part}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\end{document}


Which produces:

But as I don't know what \@starttoc does internally, I'm not sure if it's safe to do that. Are there any implications I don't see? (I suppose I could also re-phrase the question as Can it really be that easy?)

• You can look how \@starttoc is defined using \show\@starttoc. From my point of view, it looks save. Using a KOMA-class you don't need to use tocloft and should use tocbasic, imho. Sep 11 '17 at 11:52
• @Skillmon Thanks for the tobasic hint, I'll have a look at that ... Sep 11 '17 at 11:58

Each of the KOMA-Script classes scrartcl, scrreprt and scrbook load and use package tocbasic for the ToC and the Lists. tocbasic uses \tocbasic@starttoc based on \@starttoc. \tocbasic@starttoc and \@starttoc both are internal commands and should not be redefined by users. But tocbasic provides two hooks to execute code before (\BeforeStartingTOC) and after (\AfterStartingTOC) @starttoc.

Note that \BeforeStartingTOC and \AfterStartingTOC are at the same group level (inside the same group), so you can use:

\BeforeStartingTOC[toc]{\begin{multicols}{2}}
\AfterStartingTOC[toc]{\end{multicols}}


Code:

\documentclass{scrbook}
\usepackage{multicol}

\BeforeStartingTOC[toc]{\begin{multicols}{2}}
\AfterStartingTOC[toc]{\end{multicols}}

\begin{document}
\tableofcontents

\part{part}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\part{part}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\end{document}


Or with the starred version of multicols:

\BeforeStartingTOC[toc]{\begin{multicols*}{2}}
\AfterStartingTOC[toc]{\end{multicols*}}


Needs at least two LaTeX runs.

\documentclass{scrbook}
\usepackage{multicol}
\begin{document}
\tableofcontents

\part{part}
[...]


Or for the star version of multicols (no balanced columns)

\AfterTOCHead[toc]{\raggedcolumns\begin{multicols}{2}}

• What's the advantage of this (honestly interested, as I don't see any problem with redefining \@starttoc)? Sep 11 '17 at 12:33
• You could also use \AfterStartingTOC[toc]{\end{multicols}}. @Skillmon \AfterTOCHead and \AfterStartingTOC are official and documented hooks provided by package tocbasic. So there is really no need to redefine an internal command.
– esdd
Sep 11 '17 at 13:16
• I would probably use this. But while this works for multicols, when I try to use the starred version \AfterTOCHead[toc]{\begin{multicols*}{2}} \AfterStartingTOC[toc]{\end{multicols*}} I get an error: !LaTeX Error: \begin{multicols} on input line 680 ended by \end{multicols*}. Sep 12 '17 at 7:24
• @esdd: \AfterStartingTOC is misleading. It should better be named as \AtEndTOC
– user2478
Sep 12 '17 at 7:55
• Use \raggedcolumns (see edited answer) then it should behave like the star version
– user2478
Sep 12 '17 at 8:28