This is a quick solution with the cntperchap package (I am quite familar with its author ;-))
The key is to register counters which should be tracked on a per chapter base, here it is the section counter.
Then use the \GetStoredCounterValue[chapter number]{section} macro to get the number of sections in the relevant chapter. This does not print the number itself, it is stored in the cps@@tempstoragecounter counter macro...
I should change/document this in the next release of cntperchap package, probably during the next days.
Some notes
- The
cntperchap package needs two (pdf)LaTeX runs to store the correct values
- Basically any
LaTeX counter be tracked this way, however, the page counter is a little bit tricky due to the shipout mechanism.
\documentclass{book}
\usepackage{cntperchap}
\RegisterCounters{section} % Register the counters which should be watched
\makeatletter
\newcommand{\currentchaptertitle}[1]{%
\GetStoredCounterValue[#1]{section}
\ifnumgreater{\value{cps@@tempcounterstorage}}{0}{%
A chapter with \number\value{cps@@tempcounterstorage} sections
}{%
A chapter without any sections
}
}
\makeatother
\begin{document}
\chapter{\currentchaptertitle{1}}
\section{First}
\section{Second}
\chapter{\currentchaptertitle{2}}
\end{document}
