4

I know what I am trying to do could sound contrived. However, I am just writing my thesis. I am the beginning of the work, so I started writing down my table of contents, so as to provide a scaffolding for my work.

Now, while I would like to have my table of contents fully displayed, there are tons of titles and subtitles under it without any content, and that's irritating indeed.

Can I make that huge bunch of titles and subtitles disappear, without deleting those from the table of contents? I tried wrapping them inside an \iffalse - \fi couple, but while indeed they were no longer displayed, they also disappeared from my table of contents.

What should I do? I don't care if the trick is dirty, it's just to have everything more tidy while I am still developing my contents.

1

2 Answers 2

4

I propose a \TODO prefix to the command for a chapter/section/subsection that has no contents yet:

\documentclass[a4paper]{book}

\usepackage{xparse}% for easier management of optional arguments

\ExplSyntaxOn
\NewDocumentCommand{\TODO}{msom}
 {
  \IfBooleanF{#1}% do nothing if it's starred
   {
    \cs_if_eq:NNT #1 \chapter { \cleardoublepage\mbox{} }
    \refstepcounter{\cs_to_str:N #1}
    \IfNoValueTF{#3}
     {
      \addcontentsline{toc}{\cs_to_str:N #1}{\protect\numberline{\use:c{the\cs_to_str:N #1}}#4}
     }
     {
      \addcontentsline{toc}{\cs_to_str:N #1}{\protect\numberline{\use:c{the\cs_to_str:N #1}}#3}
     }
   }
  \cs_if_eq:NNF #1 \chapter { \mbox{} }% allow page breaks after sections
 }
\ExplSyntaxOff

\begin{document}

\frontmatter

\tableofcontents

\mainmatter

\chapter{Introduction}

This has contents, which will be completed according
to the results in section~\ref{sec:procr}.

\chapter{Main thing}

\section{Whatever}

This has contents.

\TODO\section{Procrastination}\label{sec:procr}

\TODO\section[Short title for this one]
  {This section has a very very long title}

\TODO\chapter{Developments}

\end{document}

When you start writing contents, just remove the \TODO prefix.

enter image description here

2
  • Very interesting approach...I'm learning something new today! I noticed that the third chapter (Developments) won't appear in the TOC unless there is some text after it. Could you explain why that is?
    – Guho
    Commented Oct 16, 2015 at 22:09
  • @Guho Because I forgot to force some text in the page. ;-) Thanks for noting.
    – egreg
    Commented Oct 16, 2015 at 22:13
1

Not knowing the specifics of your setup makes it difficult to answer conclusively. A (relatively) generic approach that wouldn't require diving into each sectioning command would be to first establish a switch, indicating if the heading should be shown (set to true below):

\newif\ifshowheadings \showheadingstrue

With that, a "wrapper" command could be defined to evaluate each of the headings, showing it if \showheadingstrue and not if \showheadingsfalse:

\def\showheadings#1{\ifshowheadings#1\else\relax\fi}

Each of the sections would then be placed as the argument to this command, for example:

\showheadings{\chapter{Test}}
\showheadings{\section{Subsection Test}}

When the document is run with \showheadingstrue, all of the headings will be included in the TOC, with the appropriate \contentsline commands written to the toc file. Depending on the class, the \tableofcontents command could be replicated with:

\chapter*{Contents}
\input{\jobname.toc}

Therefore, to divorce the actual TOC from the displayed TOC, you could change \jobname to an alternative name (e.g., schematictoc). Wrapping this change into a command might look like:

\def\switchedtableofcontents{\ifshowheadings\tableofcontents\else\chapter*{Contents}\input{schematictoc.toc}\fi}

Accordingly, an approach would be to layout your thesis as you have detailed with \showheadingstrue. Process your document, resulting in the toc file corresponding to the layout. Then, change the name of the toc file to schematictoc.toc and set \showheadingsfalse. Thereafter, any changes to the document would not be reflected in the displayed TOC.

Put together:

\documentclass{report}
\newif\ifshowheadings \showheadingstrue
\def\showheadings#1{\ifshowheadings#1\else\relax\fi}
\def\switchedtableofcontents{\ifshowheadings\tableofcontents\else\chapter*{Contents}\input{schematictoc.toc}\fi}
\begin{document}


\switchedtableofcontents

\showheadings{\chapter{Test}}
\showheadings{\section{Subsection Test}}
\showheadings{\chapter{Test}}
\showheadings{\section{Subsection Test}}
\showheadings{\chapter{Test}}
\showheadings{\section{Subsection Test}}
\showheadings{\chapter{Test}}
\showheadings{\section{Subsection Test}}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .