1

I have the following situation:
I have a set structure of a document with numbered sections and subsections.
Some of the sections are allowed to be empty. I would like to hide the empty ones from the resulting pdf as well as the table of contents.
At the same time, the numbering of the sections WITH content should work as if the empty sections where there!
A small example, the following numbering is not just allowed, but expected:

1 Intro
1.1 Topics presented
1.3 Other notes

with 1.2 missing, because I have nothing to say there. To help me work on the document, it would be best id the \section{name} for 1.2 could still be in the document, though:

\section{Intro}  
\subsection{Topics presented}  
\subsection{Nothing to say}  
\subsection{Other notes}

How can I best archive this?

5
  • Can't you simply do \stepcounter{subsection}? Nov 6 '17 at 13:28
  • 1
    What is the reason of jumping over some sections and increasing the numbers,but omitting the content?
    – user31729
    Nov 6 '17 at 13:44
  • Reason is, in short: bureaucracy. There is a template, with numbering that has to be used EXACTLY THAT WAY for submission of the document. The \stepcounter would take care of the numbering, but would make the document harder to work on; seeing the intended FULL structure makes things a whole lot less annoying.
    – Layna
    Nov 6 '17 at 13:53
  • 1
    It is rather difficult to check if there is someting "in" a subsection as you don't have environments. So imho you will have to markup the empty one and write \missing\subsection{nothing to say} or something similar. Nov 6 '17 at 13:59
  • 1
    You could use \subsection*{1.2 Nothing to say}\stepcounter{subsection}. The first command prints the heading without creating a hyperref link in pdftex and an entry in the toc, the second advances the internal subsection counter so that the next non-starred subsection continues at 1.3.
    – Lupino
    Nov 6 '17 at 16:19
1

A possible solution with a command named \hiddensubsection that hides its content if the conditional \ifshowsubsection evaluates to 'false' and increases the relevant counter.

Say \showsubsectiontrue in order to show the subsection, this can done \subsection-wise with

\showsubsectiontrue
\hiddensubsection{Foo}{Foobar}
\showsubsectionfalse

The full code:

\documentclass{article}
\usepackage{blindtext}
\usepackage{hyperref}

\newif\ifshowsubsection% Initially false

% Say \showsubsectiontrue in order to show the subsection

\newcommand{\hiddensubsection}[2]{%
  \ifshowsubsection
  \subsection{#1}
  #2%
  \else
  \refstepcounter{subsection}% allow for \label 
  \fi
}
\begin{document}
\tableofcontents

\section{First section}

\subsection{Foo subsection}

\subsection{Foobar subsection}

\hiddensubsection{You won't see this}{\blindtext}

\subsection{Yet another foobar subsection}

\end{document}
1
  • Thanks a lot, that does exactly what I needed! Writing this will be so much easier now :)
    – Layna
    Nov 7 '17 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.