13/03/2014

LaTeX wordcount

I found out that I need one of these in my thesis recently and thought I would probably be a major PITA. However I then found TeXcount, and then found that it was included in my install by default. So typing
"texcount thesis.tex" at a command line gave me a load of interesting output.

A bit more playing and Googling showed me that I could run it during compile to automatically update in the document. I was using "\write18" anyway to pull images from other folders so this was no problem. In order to include the wordcount in the document I made a new command to do this. Mine is slightly simpler than in that link as I only need a total, so here it is:

% command to count words in document
\newcommand\wordcount{
\immediate\write18{texcount -inc -sum -0 -template={SUM} thesis.tex > count.txt}

(\input{count.txt}words)}

with that in my preamble I can then call \wordcount where I want it inserted in my document - easy.

Some more detail on the texcount options I'm using:
-inc includes all the "\include" files and "\input" files that I call in my thesis
-sum calculates the sum of all the words (including headers, captions, body text, etc)
-0 only prints the output, not all the details (although I'm not sure if it's necessary with the -template option)
-template={SUM} prints the output without any details of errors in the calculates

The output gets piped to a text file and then read back in again.

I should really find time to investigate the errors it's giving me and decide if there are any parts of the text that I don't want to count, but that can wait for now...

No comments:

Post a Comment