# Can I configure texcount to double-count text in certain mandatory arguments?

Is it possible to configure texcount to double-count the contents of non-optional arguments for certain macros?

Consider the following example:

\documentclass{article}
\begin{document}
\autocite[e.g.][4]{key-1,key-2}
\autocites[e.g.][5]{key-1,key-2}[and][89]{key-3}
\end{document}


This will not compile, of course, but it works as a minimal example for texcount which does not care whether it compiles or not.

My texcount.cfg includes the following rules:

%TC:macro \autocite [1]
%TC:macro \autocites [1,1]


Running the minimal document above through texcount yields output which includes the following:

\documentclass{article} [0]
\begin{document} [0]
\autocite[e.g.][4]{key-1,key-2} [2]
\autocites[e.g.][5]{key-1,key-2}[and][89]{key-3} [5]
\end{document} [5]

Total
Sum count: 5
Words in text: 5
Words outside text (captions, etc.): 0
Number of floats/tables/figures: 0
Number of math inlines: 0
Number of math displayed: 0
Files: 2


For my purposes, this is a significant improvement over the default which would not count my citations at all. Nonetheless, it still underestimates the count. An accurate count would be (approximately) 16 words rather than 5, including 10 from double-counting each key:

• each use of a <key> produces an author-year label and there are 5 of these, for a total of 10 words

I realise that it is impossible for texcount to know I'm using author-year labels. But can I tell it to double-count each word in the non-optional arguments?

The answer is partially no, and partially yes.

You cannot specify that words in a particular macro should be counted twice. However, you can achieve much the same affect by using the -sum=... option together with a particular (or new) counter.

You can use the -sum=... option on the command line (but not as a %TC instruction within the document) to provide a total count. This adds the different counters together to give a total count, and it is possible to specify which counters are included (weight 1) or excluded (weight 0) so that e.g. -sum=1,0,1 which will include the words in the text (first counter) and in other places like captions (third counter), but not in headers (second counter). However, the weights can be any integer, so -sum=1,1,2 will count all words, but with words in other places counted twice.

Next, you can define a new counter for the particular purpose of double counting. This takes the form %TC:newcounter name Description. E.g.

%TC:newcounter double Double count
%TC:macro \autocite [option:text,option:ignore,double]
\autocite[e.g.][4]{key-1,key-2}


This will not double count the double words, but it will count them separately.

Initially there are 7 counters, and so the double counter will be number 8, so to count all words with double words counted doubly, you could run TeXcount with the option -sum=1,1,1,0,0,0,0,2. However, in order for TeXcount to accept more than 7 weight, you'd have to change the line in sub option_sum (at line 1012 the latest version) from

 } elsif ($arg=~/^(\d+(\.\d*)?(,\d+(\.\d*)?){0,6})$/) {


to

 } elsif ($arg=~/^(\d+(\.\d*)?(,\d+(\.\d*)?)*)$/) {


in which case you will have to make sure you don't add more weights than there are counters or TeXcount will likely fail.

• I'm getting Warning: Option value 1,1,1,0,0,1,1,2 not valid, ignoring option. when I try this. I assume this is because the option has to be passed before texcount has read the configuration file. It seems happy enough if I remove the ,2. (I tested the default value if using -sum as I was already using -sum.) Is there a way to tell it about the new counter before it needs to know how to sum it? (Am I making sense?) – cfr Jan 5 '16 at 23:16
• @cfr: You're right. I missed that there's actually a check to ensure no more than seven weights are provided. Will explain in the original answer how to fix this in the script. – Einar Rødland Jan 6 '16 at 22:42