How to export a document as an empty skeleton with no content?

I have a long and complex document that I want to render as a minimal outline only, without the body of the text. What is the best way to do this?

What I have tried so far is to save a version with titles only, and no other text. This does not work though. The outline gets caught off.

To try and solve the problem, I made a test file like this:

\documentclass{article}

\begin{document}
\section{Foo}
\subsection{bar}
\subsection{bar}
\subsection{bar}
\section{Foo}
\subsection{bar}
\subsection{bar}
\subsection{bar}
[... eight more sections ... ]
\end{document}


The output from this is a two page document, the first page of which is blank. On the second page, the outline appears, but it runs right to the margin until it gets cut off.

Adding a little bit of filler text to each section solves the problem. But without doing that, how can I get the output I would expect?

EDIT: I've edited this to emphasize the specific practical objective I am trying to accomplish, rather than the technical issue of empty sections which is covered by another question.

• That's not the outline, it's the pileup of sections. You want \tableofcontents, most probably, right after \begin{document} – user31729 Mar 21 '15 at 10:54
• If I understand you correctly, the answer you checked, posted by karlkoeller, did not answer your question. Did it? If it did not, please do not check any answer otherwise people get confused. – Symbol 1 Mar 21 '15 at 14:01
• Perhaps it doesn't matter, as long as the question is closed, but it was never a duplicate. – Brian Z Mar 21 '15 at 14:06
• This question may be inappropriate because of duplicate/unclear/or off topic, but we the community should close it correctly. Maybe egreg would find another question of which yours is a duplicate, but just not this one. So please do not confuse people while you are defending yourself. – Symbol 1 Mar 21 '15 at 14:16
• Karlkoeller answered my question. So now this question is closed correctly. I was only trying to clarify, not to confuse. – Brian Z Mar 21 '15 at 16:24

If you want to export the skeleton of your document, without having to extract all sectioning commands, try this way.

Load the tocloft package and, at the end of your document, add the following lines:

\tocloftpagestyle{empty}
\pagestyle{empty}
\renewcommand{\contentsname}{Skeleton}
\renewcommand{\cfttoctitlefont}{\huge\bfseries}
\renewcommand{\cftaftertoctitle}{\vspace*{\baselineskip}}
\setlength{\cftparskip}{\baselineskip}
\cftpagenumbersoff{section}
\cftpagenumbersoff{subsection}
\cftpagenumbersoff{subsubsection}
\renewcommand{\cftsubsecdotsep}{\cftnodots}
\renewcommand{\cftsubsubsecdotsep}{\cftnodots}
\renewcommand{\cftsubsecindent}{0pt}
\renewcommand{\cftsubsubsecindent}{0pt}
\renewcommand{\cftsecfont}{\Large\bfseries}
\renewcommand{\cftsubsecfont}{\large\bfseries}
\renewcommand{\cftsubsubsecfont}{\normalsize\bfseries}
\tableofcontents


In this way, we create a ToC which has the same structure of sectioning titles in the document, but without text.

If you also need a proper ToC in the document, load the shorttoc package and add the following line in your document where you want the ToC:

\shorttoc{Contents}{3}


MWE:

\documentclass{article}

\usepackage{tocloft}
\usepackage{shorttoc}
\usepackage{blindtext}

\begin{document}

\shorttoc{Contents}{3}
\clearpage

\blinddocument
\blinddocument
\blinddocument
\clearpage

\tocloftpagestyle{empty}
\pagestyle{empty}
\renewcommand{\contentsname}{Skeleton}
\renewcommand{\cfttoctitlefont}{\huge\bfseries}
\renewcommand{\cftaftertoctitle}{\vspace*{\baselineskip}}
\setlength{\cftparskip}{\baselineskip}
\cftpagenumbersoff{section}
\cftpagenumbersoff{subsection}
\cftpagenumbersoff{subsubsection}
\renewcommand{\cftsubsecdotsep}{\cftnodots}
\renewcommand{\cftsubsubsecdotsep}{\cftnodots}
\renewcommand{\cftsubsecindent}{0pt}
\renewcommand{\cftsubsubsecindent}{0pt}
\renewcommand{\cftsecfont}{\Large\bfseries}
\renewcommand{\cftsubsecfont}{\large\bfseries}
\renewcommand{\cftsubsubsecfont}{\normalsize\bfseries}
\tableofcontents

\end{document}


Output (proper ToC):

Output (skeleton ToC):

At this point, supposing that your document is called mydoc.tex, to extract the skeleton ToC in a separate pdf file create a new document called skeleton.tex with the following contents:

skeleton.tex

\documentclass{article}

\usepackage{pdfpages}

\begin{document}
\includepdf[pages=11-12]{mydoc.pdf}
\end{document}


The resulting pdf is exactly what you want. Of course you will have to change pages=11-12 to the right range of pages containing the skeleton ToC in your document.

\sections and alike don't allow page breaks after them. So, if you don't have any text following them, you will have them all in one page with an overfull box.

If you only want to see the structure of your document, either use the ToC for that or add the following lines in your preamble:

\usepackage{etoolbox}
\preto{\section}{\leavevmode}


MWE

\documentclass{article}

\usepackage{etoolbox}
\preto{\section}{\leavevmode}

\begin{document}
\section{Foo}
\subsection{bar}
\subsection{bar}
\subsection{bar}
\section{Foo}
\subsection{bar}
\subsection{bar}
\subsection{bar}
\section{Foo}
\subsection{bar}
\subsection{bar}
\subsection{bar}
\section{Foo}
\subsection{bar}
\subsection{bar}
\subsection{bar}
\section{Foo}
\subsection{bar}
\subsection{bar}
\subsection{bar}
\section{Foo}
\subsection{bar}
\subsection{bar}
\subsection{bar}
\section{Foo}
\subsection{bar}
\subsection{bar}
\subsection{bar}
\section{Foo}
\subsection{bar}
\subsection{bar}
\subsection{bar}
\section{Foo}
\subsection{bar}
\subsection{bar}
\subsection{bar}
\end{document}


Output

• Accepted this answer since the output is closer to what I was expecting. I'm wondering though, if I were to add this header in my original document (the one that has text in all the subsections), I'd still have to edit the PDF to get the structure on its own? Or with this approach, is there a way to just export the skeleton on its own? – Brian Z Mar 21 '15 at 13:39
• @BrianZ I've added a solution for having a pdf file containing only the skeleton of your document as if it was the complete document, but without text. – karlkoeller Mar 22 '15 at 6:58

The outline is most probably the ToC (Table of contents), which can be inserted with

\tableofcontents

Make sure to compile twice to see the effect.

The fine control of the ToC can be done with packages such as tocloft or etoc or with rudimentary counters such as tocdepth

\documentclass{article}

\usepackage{blindtext}

\begin{document}
\tableofcontents

\clearpage
\section{Foo}
\subsection{bar}
\blindtext[5]

\subsection{bar}
\subsection{bar}
\section{Foo}
\subsection{bar}
\subsection{bar}
\subsection{bar}

\end{document}


• I hadn't considered this approach, but it does look like I could just turn off the page numbers and dots (tex.stackexchange.com/questions/55465/…) and then export the table of contents from the original document on its own (tex.stackexchange.com/questions/69064/…) to get what I want. – Brian Z Mar 21 '15 at 13:33
• I should have said "extract" rather then "export" I guess. There does not seem to be an easy way just to export the ToC all by itself. – Brian Z Mar 21 '15 at 13:42

Much of the helpful information I learned from asking this question has unfortunately been removed. I'll summarize it here in case any other beginners out there may find it useful.

• Sections, subsections etc. are not really meant to be empty, but adding invisible text with phantom is a way around that.
• Possibly a better approach, instead of creating a "empty" version of the document in the first place, would be to modify and extract the table of contents from the real document.