I am writing a proposal for which it is required to give the number of words of the main section in the proposal itself. I found this answer on how I can get a word count on a LaTeX document:
Is there any way to do a correct word count of a LaTeX document?
But this is only for entire documents. I was wondering if it is possible to get a word count in a LaTeX document of a section/part of text and actually return this in the text as well.
I am open to suggestions with Sweave. One thing I could think of is to write the entire section in a Sweave block in an R character string. Then simply get the word count from that and return the string. This would however include all LaTeX codes used and not only intended words. Another solution I thought of was to extend this R code to wrap the string in an empty document, compile that and use tools available to get a wordcount from that, then return it. This seems like it could work but I am hoping there is a simpler solution.
Best Answer
You can use
texcount
to count the words. It automatically produces subcounts for the sections.Here's a new macro that calls
texcount
, extracts the subcount for the current section, and then inserts the word count into the document. It requireswrite18
to be enabled, andtexcount
must be in your path (or you have to include the full path to the executable in the macro).