I am using TeXCount to perform a word count. I am using %TC:macro \macroname n (http://app.uio.no/ifi/texcount/faq.html#newmacro) to treat macros differently (for example I have a 'to-do' macro). Can I count the contents of these macros and put this count in a custom category for HTML output? Their other option ("count text as other text") puts the count in the same category as captions, etc. which is undesired.


\todo{Insert some text here.}

Given a 'to-do' macro todo which simply colours the enclosed text in red, I seek a TeXCount command like %TC:macro \todo [my_category] which counts the number of words enclosed in \todo and associates it with my_category. It should produce something like the following.

File: mwe.tex
Encoding: ascii
Words in text: 0
Words in headers: 0
Words outside text (captions, etc.): 0
Number of headers: 0
Number of floats/tables/figures: 0
Number of math inlines: 0
Number of math displayed: 0
Number of words in my_category: 4
  text+headers+captions (#headers/#floats/#inlines/#displayed/#my_category)
0+0+0 (0/0/0/0/4) _top_

I appreciate that this may not be possible.


  • 2
    Thank you for your question and welcome to the TeX.SX! Could you please edit your post and add fully compilable (minimum working) example (MWE)? It would be a fine starting point for the solvers.
    – Malipivo
    Apr 14, 2014 at 10:04
  • I do something not entirely unlike this. In my case, I remove some extra text and count the number of occurrences of a particular kind of macro created in the preamble. It would be straightforward to adapt this to get a word count of specific parts of the text. The way I do it involves creating a temporary file and feeding that to texcount. Essentially you would create two such files and give counts for each. I use a script which wraps texcount and does all this automatically. The details depend on your code and OS, though. But that's the basic strategy.
    – cfr
    Apr 14, 2014 at 10:31

1 Answer 1


Assuming you have a recent version of TeXcount (version 3), you can add more counters and use these to count words.

%TC:newcounter mine My words
%TC:macro \mytext [mine]
Text inside \mytext{my macro} now gets counted separately.

The syntax of newcounter is

%TC:newcounter _name_ _description_

where the description may consist of several words (i.e. may contain space) and will be used as as the counter description in the summary.

I guess the TeXcount FAQ could do with an update...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.