# Excluding parts but keeping everything in TOC

I have a document where I use \includeonly to only compile parts of it at a time. However I would still like the Table of Contents to display everything. Is this possible?

• Yes, compile twice with all \includes enabled and then say \nofiles in the preamble, using \includeonly at will. This way, the toc won't be regenerated and is frozen to the full state. – user31729 Oct 31 '15 at 13:07

Using \nofiles will freeze (any!) generation of .toc etc. files:

Compile twice first with %\includeonly and then add \nofiles and remove the % in front of \includeonly to include the relevant parts at will.

\documentclass{book}

\begin{filecontents}{mychapter1.tex}
\chapter{First}
\section{First}
\subsection{First}
\end{filecontents}

\begin{filecontents}{mychapter2.tex}
\chapter{Second}
\section{Second}
\subsection{Second}
\end{filecontents}

\includeonly{mychapter1}

\nofiles

\begin{document}
\tableofcontents
\include{mychapter1}

\include{mychapter2}

\end{document}