# Add preliminary elements to the ToC

Assume I have finished two sections of my book so far, yet I want to display my preliminary ToC with all parts and chapters (but with no page number) as a preview like this:

I  First Part              1

1  First Chapter           3
1.1  First Section .... 3
1.2  Second Section ... 5
1.3  Third Section ....
2  Second Chapter
2.1  First Section ....
2.2  Second Section ...
2.3  Third Section ....

II Second Part

3  Third Chapter
1.1  First Section ....
1.2  Second Section ...
1.3  Third Section ....
4  Fourth Chapter
2.1  First Section ....
2.2  Second Section ...
2.3  Third Section ....


How can I include these pseudo-parts/chapters/sections etc. without having empty parts/chapters/sections in the document.

• Well, you could use \addcontentsline{toc}{part}{theverysophisticatedtitle} etc, but this is tedious and won't update the corresponding numbers. Should the titles be 'correct' already or are dummy titles sufficient? – user31729 Nov 3 '14 at 15:59
• I would like to use the proper names to have a draft of the final ToC. – Christian Ivicevic Nov 3 '14 at 16:02
• I would nevertheless suggest a cleaner solution with empty chapters etc, doing nothing, perhaps with a boolean state variable – user31729 Nov 3 '14 at 16:57
• Are you referring to a possibility of trailing empty chapters etc which can be omitted from the final output - at least as the content is concerned? I was actually thinking about using \includepdf to just grab the first part - i wasn't sure though whether hyperref links would break or not. – Christian Ivicevic Nov 3 '14 at 17:04
• No, hacking the structure command codes to do basically nothing (apart from adding a toc entry) if a certain boolean state is true or false. You could place the change of the state to that position in your document which divides it to written/unwritten content ... Perhaps I have some time this evening – user31729 Nov 3 '14 at 17:06

Note See the GhostChapters version at the bottom

The preliminary entries can be added by faking \addtocontents and omitting the 2nd argument to the original \contentsline{} command, thus removing the page number.

In lack of a MWE this works for book, scrbook and memoir classes so far only.

\documentclass{book}

\usepackage{etoolbox}%

\refstepcounter{#1}%
}%

\AtEndDocument{%

\addfakecontent{chapter}{Even another chapter of another part}%

\addfakecontent{chapter}{Some chapter of the final part}
\addfakecontent{section}{A section of a final part}

}

\usepackage{blindtext}

\begin{document}

\tableofcontents

\part{First}

\chapter{Some chapter content}

\blindtext

\end{document}


## Ghostchapter - version

This version uses the concept of ghost chapters (i.e. \parts, \chapters etc.) By using \EnableGhostChapters at 'any' arbitrary position in the document the following structure commands are disabled, but add an entry to ToC. It works for scrbook, memoir down to subparagraph, and up to subsubsection for book class -- I did not figure out why it fails for paragraph and subparagraph for the book class... (weird definition?)

The ghost chapters are displayed with darkgray color in the ToC.

Use \DisableGhostChapters to switch back to normal behaviour.

The macros \EnablePagesInToc and \DisablePagesInToc enable/disable the display of the page number in the ToC

Note: Although I used \patchcmd ... it's not a patch, it's a hack ;-)

It does not work correctly for \include{} but with \input{}

\documentclass{book}

\usepackage{xcolor}%
\usepackage{etoolbox}%

\newcommand{\preliminarycontentscolor}{darkgray}

\newbool{UsePagesInToc}

\newbool{GhostChapters}

\newcommand{\EnablePagesInToc}{%
\clearpage
\setbool{UsePagesInToc}{true}%
}%

\newcommand{\DisablePagesInToc}{%
\setbool{UsePagesInToc}{false}%
}%

\newcommand{\EnableGhostChapters}{%
\DisablePagesInToc%
\setbool{GhostChapters}{true}%
}%

\newcommand{\DisableGhostChapters}{%
\EnablePagesInToc%
\setbool{GhostChapters}{false}%
}%

\setcounter{tocdepth}{5}

\setcounter{secnumdepth}{5}

\makeatletter

\ifbool{UsePagesInToc}{%
}{%
}%
}%

\makeatletter

\patchcmd{\@part}{%
\markboth{}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\bfseries \partname\nobreakspace\thepart%
\par
\vskip 20\p@
\fi
\Huge \bfseries #2\par}%
\@endpart%
}{%
\ifbool{GhostChapters}{\thispagestyle{empty}}{%
\markboth{}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\bfseries \partname\nobreakspace\thepart%
\par
\vskip 20\p@
\fi
\Huge \bfseries #2\par}%
\@endpart%
}%
}{\typeout{part structure successfully patched}}{\typeout{part structure patching failed}}

\patchcmd{\@chapter}{\chaptermark{#1}%
\if@twocolumn
\else
\fi}{% Patch
\ifbool{GhostChapters}{\thispagestyle{empty}}{%
\chaptermark{#1}%
\if@twocolumn
\else
\fi}
}{\typeout{chapter structure successfully patched}}{\typeout{chapter structure patching failed}}

\patchcmd{\@sect}{%
\ifdim \@tempskipa>\z@
\begingroup
#6{%
\@hangfrom{\hskip #3\relax\@svsec}%
\interlinepenalty \@M #8\@@par}%
\endgroup
\csname #1mark\endcsname{#7}%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}%
\else
\def\@svsechd{%
#6{\hskip #3\relax
\@svsec #8}%
\csname #1mark\endcsname{#7}%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}}%
\fi
\@xsect{#5}}{%
\ifbool{GhostChapters}{%
\ifdim \@tempskipa>\z@
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}
\else
\def\@svsechd{%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}}%
\fi%
\@xsect{#5}%
}{%
\ifdim \@tempskipa>\z@
\begingroup
#6{%
\@hangfrom{\hskip #3\relax\@svsec}%
\interlinepenalty \@M #8\@@par}%
\endgroup
\csname #1mark\endcsname{#7}%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}%
\else
\def\@svsechd{%
#6{\hskip #3\relax
\@svsec #8}%
\csname #1mark\endcsname{#7}%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}}%
\fi
\@xsect{#5}
}%
}{\typeout{section structures successfully patched}}{\typeout{section structures patching failed}}

\AtBeginDocument{%
\DisableGhostChapters%
\EnablePagesInToc%
}%

\AtEndDocument{%
\phantom{some output}
}%

\makeatother
\usepackage{blindtext}

\begin{document}
\DisableGhostChapters
\tableofcontents

\part{First}

\chapter{First of first part}

\section{First section of first chapter}

\subsection{First subsection}

\subsubsection{First subsubsection}
\paragraph{First paragraph}

\subparagraph{First subparagraph}

\blindtext

\chapter{Second chapter}

\EnableGhostChapters

\part{OtherOne}

\chapter{New Chapter}

\section{Section of another chapter}%

\chapter{Another chapter}

\chapter{Yet another chapter of another part}

\section{First section of another chapter}

\subsection{First subsection}

\subsubsection{First subsubsection}
\paragraph{First paragraph}

\subparagraph{First subparagraph}

\EnablePagesInToc
\DisableGhostChapters

\chapter{You will see me!}

\part{And some visible part}

\EnableGhostChapters%
\DisablePagesInToc%
\chapter{With an invisible chapter}

\end{document}


• Unfortunately this does not work with my current source files, yet with your MWE it does - I will have to find out what's interfering, thank you so far. Meanwhile, do you know how to specifically remove the page numbers from the fake content? Otherwise I would have to live with it having them. – Christian Ivicevic Nov 3 '14 at 16:25
• @ChristianIvicevic: I am working to remove them... I know, that there is a caveat... It would be nice to know which class and packages you are using – user31729 Nov 3 '14 at 16:26
• Actually I fixed the issue as I was using input rather than include for my chapters and your code is now working as intended. Just the page numbers and we're good to go! Concerning packages I am just using book with the usual ams packages, etoolbox, some tikz packages, but nothing too fancy so far (except fancyhdr ;-) ). – Christian Ivicevic Nov 3 '14 at 16:30
• I was actually wrong! When using \include{Chapter1} your code does not work if all structural elements are in the second file. Adding a \chapter{Foo} after the include yields the expected result with the fake entries. Any ideas why this is happening? – Christian Ivicevic Nov 3 '14 at 16:37
• @ChristianIvicevic: I just tested it with some \include{...} and \input{...} -- it works – user31729 Nov 3 '14 at 16:46