Automatically count the number of appendices in LaTeX
August 24th, 2009
This guide will show you how to automatically count the number of appendices in your LaTeX document.
First of all you need to place this code in the preamble of your document:
\makeatletter \newcounter{numapp} \newcommand{\numberofapp}{% \immediate\write\@auxout% {\string\setcounter{numapp}{\the\c@chapter}}% } \AtBeginDocument{\AtEndDocument{\numberofapp}} \makeatletter
The script simply counts the number of \chapter’s started since the environment \appendix is called. The number of appendiced will then be placed in the variable \numapp, thus accesible throughout your document using \thenumapp.
Note: The script should run at least twice, before the variable will produce the correct number of appendices.