Is it possible to configure texcount not to ignore text in optional arguments for certain macros?

Consider the following example:


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]

Sum count: 5
Words in text: 5
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
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 6 in pre- and post-notes:

  • the optional arguments are produced as part of the citations and total 6 words

Can I tell texcount to count the words in the optional arguments?


Assuming you're running version 3 of TeXcount, you can specify parsing rules for optional arguments.

You can also use more intuitive names for the rules rather than the numerical codes.

In you case, you can use the following parsing rules:

%TC:macro \autocite [option:text,option:ignore,text]
%TC:macro \autocites [option:text,option:ignore,text,option:text,option:ignore,text]

The optional rules, specified on the format option:rule apply if an optional argument is provided to the macro, otherwise it is skipped.

The available parsing rules are (copied from section 5.1 of the documentation):

  • Text: (key: text, word, wd, w formerly 1) Count as text (i.e. count words).
  • Header text: (key: headertext, headerword, hword, hwd, hw formerly 2) Count as header text.
  • Other text: (key: otherword, other, oword, owd, ow formerly 3) Count as float/caption text.
  • Displaymath: (key: displaymath, dsmath, dmath, ds formerly 7) Count as displayed math formulae.
  • Inline math: (key: inlinemath, inline, imath, eq formerly 6) Count as inlined math formulae.
  • To header: (key: header, heading, head formerly 4) Count header, then count text as headertext (transition state).
  • To float: (key: float, table, figure formerly 5) Count float, then parse contents as isfloat (transition state).
  • Preamble: (key: formerly -9) Parse as preamble, i.e. ignore text but look for preambleinclude macros.
  • Ignore: (key: ignore formerly 0) Ignore text, i.e. do not count, but will still parse the code.
  • Float: (key: isfloat formerly -1) Float contents, ignore text but look for floatinclude macros.
  • Strong exclude: (key: xx formerly -2) Strong ignore which ignore environments, e.g. to use in macro definitions where \begin–\end need not be balanced.
  • Stronger exclude: (key: xxx formerly -3) Stronger ignore, handles macros as isolated tokens without handling their parameters, to use with macro definitions like \newcommand and \def.
  • Exclude all: (key: xall formerly -4) Ignore all, including unbalanced braces (e.g. used by %TC:ignore and the verbatim environment). This rule may be used for environment contents, but not for macro or environment parameters or options since the exclusion causes { and [ to be ignored.
  • Thank you! May I suggest that you indicate in the output from texcount --help that documentation is available via texdoc? Because this is something I use at the command line rather than loading it as a package, I looked for a man page or info entry and it did not occur to me to try texdoc. Maybe this is just me being idiotic, but I would have been glad of a helpful hint for idiots! – cfr Jan 5 '16 at 22:13
  • I even tried reading the script itself to look for commented clues. I realise now that I responded in all the ways I respond when searching for information on CLI tools and none of the ways I respond when trying to look for information on TeX stuff. – cfr Jan 5 '16 at 22:15
  • @cfr: Good point! I though I had cited the web site, which is probably the best place for the latest documentation, but realise I hadn't. Will add it to the help text. – Einar Rødland Jan 5 '16 at 22:21
  • I'd still add texdoc. People aren't always connected, whereas they are likely to have access to the PDF as part of their TeX installations. The help does cite the web site. However, it doesn't say anything about documentation being there. – cfr Jan 5 '16 at 22:25
  • @cfr: Will add reference to texdoc texcount as well. I was actually not aware of the texdoc command, but that's quite useful. – Einar Rødland Jan 5 '16 at 22:33

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.