Anybody have a texcount template they would share?

I noticed that the texcount documentation references an option -template="template". I presume this is to enable adding some custom text surrounding the texcount output. My Google-fu has not yielded any examples of what such a template would look like.

I was hoping to combine this with something like fp to make a template that reports a more narrative style summary of my document, to include a calculation of word count according to the publication rules (e.g., text, headers and bibliography + 100 words per figure/table/float).

  • I just use a script and a custom .cfg file. In particular, the script updates the .cfg on the basis of comment lines in documents. Probably not what you had in mind.
    – cfr
    Apr 21, 2015 at 1:16

1 Answer 1


A simple example could be

texcount.pl example.tex -template="Words: {hword} in headers,
   {word} in text, {oword} other places."

which should be all on one line.

An alternative way to specify this template is in the TeX document itself using the %TC instructions. Here's a more elaborate example of this:

%%% Template using new format (version 3 and on)
%TC:template Word count (text+headers+other):
%TC:template  {text}+{headerword}+{otherword} = {sum}\n
%TC:template Element count (head+float+inline+dsmath):
%TC:template  {header}+{float}+{inline}+{displaymath}\n
%TC:template Subcounts{SUB?: {sum}?SUB}

Note that \n indicates line shift which will have to specified explicitly.

You can also specify a template as well as other options in a separate options file, which may sometimes be convenient for big templates. For example, if you make a file with the contents

 # Use as sum count: text words + header words + other words

 # Output template
   \<ul class=count>\n
   \<li class=header>{title}</li>\n
   \<li>Word count: {sum}</li>\n
   \<li>Equations: {inline} inline, {ds} displayed</li>\n
   \{float?<li>Floats: {float}</li>\n?float}
   \{SUB?<li>Subcounts:</li><span class=subcount>\n
   \| <li>{sum} words in {title}</li>\n
   \{file?<li>Number of files in all: {file}</li>?file}\n

you can include it using the -opt= option. This outputs the counts using HTML tags. The SUB section gives subcounts.

These examples, I hope, could make for starting points for experimenting.

  • This is exactly what I needed. Thank you @einar. I'm using (included in my Linux distro) v2.3, but this still ends up being much more simple than what I'd been trying to do.
    – CW Dillon
    Apr 21, 2015 at 15:17
  • Oh! ...and the -sum= option lets me weight counts without having to use fp, too. I get exactly what I need with texcount -sum=1,1,0,0,100,1,100.
    – CW Dillon
    Apr 21, 2015 at 15:27
  • @CWDillon: Nice to hear it was of use. To use names like word and hword instead of index 1 and 2 for text and header words, requires that you upgrade TeXcount to v3.0: this can be done either through the TeX package update or by downloading the texcount perl script and replacing the one you have. The -sum=option, sadly, does not recognise these names and instead uses the 1,1,... format. Apr 21, 2015 at 16:01

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.