<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to HowTo_PartToC</title><link>https://sourceforge.net/p/koma-script/wiki-en/HowTo_PartToC/</link><description>Recent changes to HowTo_PartToC</description><atom:link href="https://sourceforge.net/p/koma-script/wiki-en/HowTo_PartToC/feed" rel="self"/><language>en</language><lastBuildDate>Tue, 30 Jun 2026 14:56:56 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/koma-script/wiki-en/HowTo_PartToC/feed" rel="self" type="application/rss+xml"/><item><title>HowTo_PartToC modified by Markus Kohm</title><link>https://sourceforge.net/p/koma-script/wiki-en/HowTo_PartToC/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="h-how-to-create-a-custom-table-of-contents-for-parts-part"&gt;How to create a custom table of contents for parts (&lt;code&gt;\part&lt;/code&gt;)&lt;/h1&gt;
&lt;p&gt;The standard approach for part-specific tables of contents would be to use the &lt;a href="https://www.ctan.org/pkg/minitoc" rel="nofollow"&gt;&lt;code&gt;minitoc&lt;/code&gt;&lt;/a&gt; package. However, there are a few hurdles to overcome when using it with KOMA-Script, and there is no guarantee that this package will work flawlessly with KOMA-Script classes, nor that the KOMA-Script classes will continue to function properly after loading this package. However, the classes themselves, in conjunction with the &lt;code&gt;tocbasic&lt;/code&gt; package they use, already provide everything necessary for partial tables of contents, for example at the &lt;code&gt;\part&lt;/code&gt; level.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note: The solution shown below works best with LuaLaTeX. If you use PDFLaTeX or XeLaTeX—which is no longer recommended for LaTeX—you may easily encounter error messages due to too many &lt;code&gt;\newwrite&lt;/code&gt; commands.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;First, we define a command that can switch between different tables of contents. The extension for the helper file is &lt;code&gt;.toc&amp;lt;addition&amp;gt;&lt;/code&gt;, where &lt;code&gt;&amp;lt;addition&amp;gt;&lt;/code&gt; can be specified using the command’s optional argument. If the argument is not provided, the command reverts to the main table of contents. It might look something like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\NewDocumentCommand&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\switchcontents&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;o&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\IfValueT&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;#1&lt;span class="nb"&gt;}&lt;/span&gt;
  &lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\edef\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;toc#1&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% define new toc extension&lt;/span&gt;
  &lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\edef\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;toc&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% switch back to main ToC&lt;/span&gt;
  &lt;span class="nb"&gt;}&lt;/span&gt;
  &lt;span class="c"&gt;% If you do not want bookmarks for the following \chapter etc. remove&lt;/span&gt;
  &lt;span class="c"&gt;% the next three lines.&lt;/span&gt;
  &lt;span class="k"&gt;\scr@ifundefinedorrelax&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;hypersetup&lt;span class="nb"&gt;}{}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\edef\reserved@a&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\noexpand\hypersetup&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;bookmarkstype=&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}}&lt;/span&gt;&lt;span class="k"&gt;\reserved@a&lt;/span&gt;
  &lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="c"&gt;% Reserve the toc extension&lt;/span&gt;
  &lt;span class="k"&gt;\Ifattoclist&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}{}{&lt;/span&gt;&lt;span class="k"&gt;\addtotoclist&lt;/span&gt;&lt;span class="na"&gt;[toc]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The specific features of KOMA-Script used here are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The KOMA-Script classes do not write directly to the file with the &lt;code&gt;toc&lt;/code&gt; extension. Instead, the extension of the auxiliary file for the table of contents is defined via the &lt;code&gt;\ext@toc&lt;/code&gt; macro, which is set to &lt;code&gt;toc&lt;/code&gt; by default.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;tocbasic&lt;/code&gt; package maintains a list of known extensions for auxiliary files. With &lt;code&gt;\Ifattoclist&lt;/code&gt;, you can check whether an extension is already in use, and with &lt;code&gt;\addtotoclist&lt;/code&gt;, you can add an extension to the list of used extensions.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Next, we define a command to switch to a partial table of contents. If the partial table of contents was not yet known at the time of the switch, it should also be printed. The default value for the &lt;code&gt;&amp;lt;addition&amp;gt;&lt;/code&gt; here is the value of the &lt;code&gt;part&lt;/code&gt; counter:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\newcommand*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\partcontents&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;[1][&lt;span class="k"&gt;\thepart&lt;/span&gt;]&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\Ifattoclist&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;toc#1&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\switchcontents&lt;/span&gt;&lt;span class="na"&gt;[#1]&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\switchcontents&lt;/span&gt;&lt;span class="na"&gt;[#1]&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\listoftoc&lt;/span&gt;&lt;span class="na"&gt;[Contents of this Part]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% show contents only for new extensions&lt;/span&gt;
  &lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;So now we simply need to insert &lt;code&gt;\partcontents&lt;/code&gt; after a &lt;code&gt;\part{…}&lt;/code&gt; that is to have a sub-table of contents. For unnumbered parts, a unique &lt;code&gt;&amp;lt;suffix&amp;gt;&lt;/code&gt; should be specified as an optional argument.&lt;/p&gt;
&lt;p&gt;However, it would of course be desirable if we had the option to include the chapters, sections, etc., of a part that has its own sub-table of contents in the main table of contents as well. To do this, we slightly modify &lt;code&gt;\switchcontents&lt;/code&gt;:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\newif\ifparttocinmaintoc&lt;/span&gt;
&lt;span class="k"&gt;\NewDocumentCommand&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\switchcontents&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;o&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\IfValueTF&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;#1&lt;span class="nb"&gt;}&lt;/span&gt;
  &lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\addtocontents&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="k"&gt;\protect\ifparttocinmaintoc\protect\InputIfFileExists&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\jobname&lt;/span&gt;.toc#1&lt;span class="nb"&gt;}{}{}&lt;/span&gt;&lt;span class="k"&gt;\protect\fi&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% conditionally load the part ToC into the main ToC&lt;/span&gt;
    &lt;span class="k"&gt;\edef\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;toc#1&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% define new toc extension&lt;/span&gt;
  &lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\edef\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;toc&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% switch back to main ToC&lt;/span&gt;
  &lt;span class="nb"&gt;}&lt;/span&gt;
  &lt;span class="c"&gt;% If you do not want bookmarks for the following \chapter etc. remove&lt;/span&gt;
  &lt;span class="c"&gt;% the next three lines.&lt;/span&gt;
  &lt;span class="k"&gt;\scr@ifundefinedorrelax&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;hypersetup&lt;span class="nb"&gt;}{}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\edef\reserved@a&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\noexpand\hypersetup&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;bookmarkstype=&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}}&lt;/span&gt;&lt;span class="k"&gt;\reserved@a&lt;/span&gt;
  &lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="c"&gt;% Reserve the toc extension&lt;/span&gt;
  &lt;span class="k"&gt;\Ifattoclist&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}{}{&lt;/span&gt;&lt;span class="k"&gt;\addtotoclist&lt;/span&gt;&lt;span class="na"&gt;[toc]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now we can use &lt;code&gt;\parttocinmaintoctrue&lt;/code&gt; &lt;em&gt;before&lt;/em&gt; &lt;code&gt;\tableofcontents&lt;/code&gt; to ensure that all sub-tables of contents also appear in the main table of contents.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note: The above extension using &lt;code&gt;\ifparttocinmaintoc&lt;/code&gt; only works if &lt;code&gt;\tableofcontents&lt;/code&gt; appears &lt;em&gt;before&lt;/em&gt; the first &lt;code&gt;\partcontents&lt;/code&gt;. If it appears after &lt;code&gt;\partcontents&lt;/code&gt;, the sub-tables of contents are already open for writing but still empty by the time they are read by &lt;code&gt;\tableofcontents&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It would also be nice if the switch to the main table of contents occurred automatically with every &lt;code&gt;\part&lt;/code&gt;. One option for this is the KOMA-Script-specific DoHook &lt;code&gt;heading/preinit/part&lt;/code&gt;, which is executed very early in the &lt;code&gt;\part&lt;/code&gt; command:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\AddtoDoHook&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;heading/preinit/part&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="k"&gt;\switchcontents\@gobble&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You can achieve something similar for &lt;code&gt;appendix&lt;/code&gt; using the hook &lt;code&gt;\KOMAClassName/appendix&lt;/code&gt;:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\AddToHook&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\KOMAClassName&lt;/span&gt;/appendix&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="k"&gt;\switchcontents&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Suppose we have a document with four parts, and only Parts II and IV are to have their own table of contents. In that case, the code might look something like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\documentclass&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;scrreprt&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;hyperref&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;mwe&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\newif\ifparttocinmaintoc&lt;/span&gt;
&lt;span class="k"&gt;\makeatletter&lt;/span&gt;
&lt;span class="k"&gt;\NewDocumentCommand&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\switchcontents&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;o&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\IfValueTF&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;#1&lt;span class="nb"&gt;}&lt;/span&gt;
  &lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\addtocontents&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="k"&gt;\protect\ifparttocinmaintoc\protect\InputIfFileExists&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\jobname&lt;/span&gt;.toc#1&lt;span class="nb"&gt;}{}{}&lt;/span&gt;&lt;span class="k"&gt;\protect\fi&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% conditionally load the part ToC into the main ToC&lt;/span&gt;
    &lt;span class="k"&gt;\edef\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;toc#1&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% define new toc extension&lt;/span&gt;
  &lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\edef\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;toc&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% switch back to main ToC&lt;/span&gt;
  &lt;span class="nb"&gt;}&lt;/span&gt;
  &lt;span class="c"&gt;% If you do not want bookmarks for the following \chapter etc. remove&lt;/span&gt;
  &lt;span class="c"&gt;% the next three lines.&lt;/span&gt;
  &lt;span class="k"&gt;\scr@ifundefinedorrelax&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;hypersetup&lt;span class="nb"&gt;}{}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\edef\reserved@a&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\noexpand\hypersetup&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;bookmarkstype=&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}}&lt;/span&gt;&lt;span class="k"&gt;\reserved@a&lt;/span&gt;
  &lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="c"&gt;% Reserve the toc extension&lt;/span&gt;
  &lt;span class="k"&gt;\Ifattoclist&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}{}{&lt;/span&gt;&lt;span class="k"&gt;\addtotoclist&lt;/span&gt;&lt;span class="na"&gt;[toc]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\newcommand*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\partcontents&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;[1][&lt;span class="k"&gt;\thepart&lt;/span&gt;]&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\Ifattoclist&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;toc#1&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\switchcontents&lt;/span&gt;&lt;span class="na"&gt;[#1]&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\switchcontents&lt;/span&gt;&lt;span class="na"&gt;[#1]&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\listoftoc&lt;/span&gt;&lt;span class="na"&gt;[Contents of this Part]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% show contents only for new extensions&lt;/span&gt;
  &lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\AddtoDoHook&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;heading/preinit/part&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="k"&gt;\switchcontents\@gobble&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% automatic switch back to main ToC at next \part&lt;/span&gt;
&lt;span class="k"&gt;\AddToHook&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\KOMAClassName&lt;/span&gt;/appendix&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="k"&gt;\switchcontents&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% automatic switch back to main ToC at \appendix&lt;/span&gt;
&lt;span class="k"&gt;\makeatother&lt;/span&gt;
&lt;span class="k"&gt;\parttocinmaintoctrue&lt;/span&gt;&lt;span class="c"&gt;% show the contents of the part ToC also in the main ToC&lt;/span&gt;
&lt;span class="c"&gt;%\parttocinmaintocfalse% don't show the contents of the part ToC in the main ToC&lt;/span&gt;

&lt;span class="k"&gt;\begin&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;document&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\tableofcontents&lt;/span&gt;
&lt;span class="k"&gt;\part&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;First Part&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\blinddocument&lt;/span&gt;

&lt;span class="k"&gt;\part&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;Second Part&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\partcontents&lt;/span&gt;&lt;span class="c"&gt;% use \jobname.toc\thepart as new toc file and show the contents&lt;/span&gt;
&lt;span class="k"&gt;\blinddocument&lt;/span&gt;

&lt;span class="k"&gt;\part&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;Third Part&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\blinddocument&lt;/span&gt;

&lt;span class="k"&gt;\part&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;Fourth Part&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\partcontents&lt;/span&gt;&lt;span class="c"&gt;% use \jobname.toc\thepart as new toc file and show the contents&lt;/span&gt;
&lt;span class="k"&gt;\blinddocument&lt;/span&gt;

&lt;span class="k"&gt;\appendix&lt;/span&gt;
&lt;span class="k"&gt;\blinddocument&lt;/span&gt;
&lt;span class="k"&gt;\end&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;document&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Before you ask: Yes, you can also adapt this for use with &lt;code&gt;\chapter&lt;/code&gt; instead of &lt;code&gt;\part&lt;/code&gt;:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\newcommand*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chaptercontents&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;[1][&lt;span class="k"&gt;\thechapter&lt;/span&gt;]&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\Ifattoclist&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;toc#1&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\switchcontents&lt;/span&gt;&lt;span class="na"&gt;[#1]&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\switchcontents&lt;/span&gt;&lt;span class="na"&gt;[#1]&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\setuptoc&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;leveldown&lt;span class="nb"&gt;}{&lt;/span&gt;toc#1&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% the chapter toc is a section not a chapter&lt;/span&gt;
    &lt;span class="k"&gt;\listoftoc&lt;/span&gt;&lt;span class="na"&gt;[Contents of this Chapter]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\ext@toc&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% show contents only for new extensions&lt;/span&gt;
  &lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\AddtoDoHook&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;heading/preinit/chapter&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="k"&gt;\switchcontents\@gobble&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% automatic switch back to main ToC at next chapter&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If the document also uses parts, the DoHook &lt;code&gt;heading/preinit/part&lt;/code&gt; must be retained. Otherwise, it can be omitted.&lt;/p&gt;
&lt;p&gt;Using both &lt;code&gt;\parttoc&lt;/code&gt; and &lt;code&gt;\chaptertoc&lt;/code&gt; does not work this way. To do so, you would also need to know, in &lt;code&gt;heading/preinit/chapter&lt;/code&gt;, whether to call &lt;code&gt;\switchcontents&lt;/code&gt; or &lt;code&gt;\switchcontents[\thepart]&lt;/code&gt;. While this is a manageable task, you should avoid using too many tables of contents.&lt;/p&gt;
&lt;p&gt;Using different &lt;code&gt;tocdepth&lt;/code&gt; settings for the main table of contents and sub-tables of contents is also possible (simply insert the appropriate counter settings in the right places). But I don’t want to get too far ahead of myself here regarding a future package or extension for KOMA-Script.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Markus Kohm</dc:creator><pubDate>Tue, 30 Jun 2026 14:56:56 -0000</pubDate><guid>https://sourceforge.netca0b0b707656d83d841508844150426fbabaf58f</guid></item></channel></rss>