# Check if non-empty subsection exists under another section

I'd like to try to make a LaTeX class which enforces a number of (non-empty) sections to exist-- if the user doesn't define them manually, then some default section content will be created.

\begin{document}

\section{Section which requires subsections African swallow'' and European swallow''}

\subsection{African swallow}

The unladen airspeed is \ldots  % The section is defined and has content, so it is okay

% subsection European swallow'' doesn't exist (and therefore is also missing content, of course), so here the compiler adds:
% \subsection{European swallow}
%
% The unladen airspeed is \ldots, although when carrying a coconut it is much less.

\end{document}


It would be even cooler if I could also specify that certain sections must be defined (and are not empty), otherwise the compiler exits with an error.

I hope my question is understandable... I'd be grateful for any tips.

-

I assume that this feature is used for some kind of "to do" markers. If a new section is started, then required parts are specified (comma separated list):

\require{African swallow, European swallow}


And if a part is finished, it is closed with

\done{African swallow}


At the end of the document the missing \dones are reported.

\documentclass{article}

\usepackage{kvsetkeys}
\makeatletter
\newcommand*{\req@list}{}
\newcommand*{\@require}[1]{%
\xdef\req@list{%
\req@list{\detokenize{#1}}%
}%
}
\newcommand*{\require}[1]{%
\comma@parse{#1}\@require
}
\newcommand*{\done}[1]{%
\global\expandafter
\let\csname done@\detokenize{#1}\endcsname\@empty
}
\newcommand*{\check@requirements}{%
\begingroup
\typeout{}%
\typeout{ToDo list}%
\typeout{=========}%
\expandafter
\@tfor\expandafter\x\expandafter:\expandafter=\req@list\do{%
\@ifundefined{done@\x}{%
\typeout{! ToDo: \x}%
}{}%
}%
\typeout{}%
\endgroup
}
\AtEndDocument{\check@requirements}
\makeatother

\begin{document}

\section{Section which requires subsections African swallow'' and European swallow''}
\require{African swallow, European swallow}

\subsection{African swallow}

The unladen airspeed is \ldots  % The section is defined and has content, so it is okay
\done{African swallow}

% subsection European swallow'' doesn't exist (and therefore is also missing content, of course), so here the compiler adds:
% \subsection{European swallow}
%
% The unladen airspeed is \ldots, although when carrying a coconut it is much less.

\end{document}


And the report at the end of the LaTeX run:

ToDo list
=========
! ToDo: European swallow

-