# Is there a simple way to obtain the statistic data of the document being typeset?

I want to put the statistic data of my book in a certain page right after the title page but before "This book is presented to my kittens..." page.

The statistic data includes:

1. The total number of words used from chapter 0 to appendixes.
2. The total number of sentences used from chapter 0 to appendixes.
3. The total number of characters used from chapter 0 to appendixes.
4. The total number of pages from chapter 0 to appendixes.
-
Why?........... –  Matthew Leingang Dec 26 '10 at 2:17
Because the number of pages does not reflect the density of words used in the book. By knowing the density of words, the reader can make a rough prediction of the time needed to read the book. –  xport Dec 26 '10 at 2:23
nltk.org –  Yiannis Lazarides Dec 26 '10 at 2:57
If you have math in the book, this complicates the count; I suggest you throw in the number of inline and displayed equations as well. Counting words in the source is of course not so easy with macros interfering, though if they could all be expanded you could just count the number of spaces (ignoring repeats, outside math) and add 1. Sentences would be harder to detect, since you have to ignore abbreviations; this seems like a good candidate for an NLTK like Yiannis suggests. –  Ryan Reich Dec 26 '10 at 8:14
For word counts see also this post. –  Hendrik Vogt Dec 28 '10 at 12:13

There is a useful LaTeX word count Perl script to count words and the number of formulas. The seems to be an alpha version of it that also counts letters. Create a separate master file for texcount that only includes the main text. You could probably get a good estimate of the number of sentences by counting the number of `.`, `?` and `!` in your TeX files. Counting the number of pages should be easy (the book class starts numbering pages from `\mainmatter`).
Personally, I'd go with something simple like `pdftotext` and then just use `wc` (or any standard utility) to get approximate answers. If you need exact answers, it's going to be significantly harder (and unlikely to be worth your trouble).