# How to find out how many chapters are in a part?

Is there some counter that holds the number of \chapter that are in a \part? Or do I need to define and run my own counter?

-

No such counter exists, as far as I know. However, a running count of the number of chapters within a part can easily be done (see below).

Accessing the total number of chapters within a part at any point of the document (e.g. at the very beginning of a the part in question) is a little trickier. That would probably require running a first pass, retrieving information on the number of chapters from the auxiliary files, processing it, and running a second pass. I don't know how to do that.

\documentclass{book}

\newcounter{totalch}

\let\oldpart\part
\renewcommand{\part}{\setcounter{totalch}{0}\oldpart}

\let\oldchapter\chapter

\begin{document}

\part{foo}
\chapter{one}
\chapter{two}
\chapter{three}
\thetotalch    %returns 3, here

\part{bar}
\chapter{four}
\chapter{five}
\thetotalch    %returns 2, here

\end{document}

-
Thank you very much. :) –  Foo Bar Apr 22 '13 at 16:13