How to run TeXcount

Setting up TeXcount

TeXcount is a command line tool, and thus does not need to be installed. How to run it may depend a little on your operating system.

If you obtained TeXcount together with LaTeX, e.g. through TeX Live, it may already be set up and made runnable, often simply using the command texcount rather than the script name texcount.pl. If you downloaded TeXcount from the web page, you may want to set it up so it is more convenient to run. The FAQ explains how to set up TeXcount both under Unix/Linux/OSX and Windows.

In all operating systems, you need to have Perl installed, the TeXcount script must either be in the search path or you must give the path to the script file to run it, and the file must be executable (chmod +a texcount on Unix systems, file type .pl must be associated with Perl on Windows). Again, see the FAQ for details on this.

Executing TeXcount

TeXcount is a command line tool. Running it may depend slightly on your operating system: under Unix/Linux/MacOSX it may have been set up to run using the command texcount, whereas under Windows it may be set up to run using either texcount.pl to run the scipt directly, or texcount in case either a batch file texcount.bat or executable texcount.exe has been placed in the search path. For simplicity, I will just write texcount as the command in these explanations.

The syntax for running TeXcount is
texcount [options] file(s)
where [files] is a list of LaTeX files to count.

Basic options

To produce word count for a LaTeX document mydoc.tex, you may run
texcount mydoc.tex
and you should get an overview of the count. If you have several documents you want to count at once, you may add more files. More commonly, however, your document may include subdocuments using \input or \include, and to automatically count these you may add the option -inc. You will then get one count per file pluss a total count. Alternatively, -merge will merge contained subdocuments into the main document.

You should not trust TeXcount to interpret the LaTeX code correctly, and should at least once before you accept the final result investigate the parsing details. This can be done by viewing the verbose output
texcount -v mydoc.tex
containing colour coded markup of how each part of the text was interpreted (for Windows this requires version 3.0). Better visualisation may be obtained by writing the output to a HTML file using option -html
texcount -v -html mydoc.tex > tmp.html
and view this document in a web browser: this is essentially what the online version of TeXcount does.

Further help and documentation

Apart from the basic options required to run TeXcount, there are numerous options and instructions you may use to customise how TeXcount parses the LaTeX code and outputs the resulting counts.

View the Quick Reference Guide for an overview of options and TeXcount instructions, or the full Documentation for more details.

Examples, hints, tricks, and answers to various questions are available in the TeXcount FAQ. If you run into problems, you may also want to view known issues. You may also contact me for questions and suggestions.


Last modified February 12, 2017.