texlog.py – A Latex Wordcount Logger in Python

By | February 20, 2015

Log your wordcount in Latex

texlog.py is a simple python script for logging your wordcount in latex. The logging output put is saved as simple comma separated values which you can easily load into plotting software.

Download texlog.py from github

Building on texcount

If you use Latex for writing documents, you may well already be familiar with texcount, a script for counting the number of words in a latex document. You can download it as a stand-alone perl script, although it may also be bundled with your latex distribution, such as Miktex, or latex editor, like Texmaker.

This script is invaluable, particularly when writing large documents, or writing to a strict word limit. I thought it would be cool to be able to keep track of how many words I was writing on a particular document.

To do this I’ve made a python script that keeps a log of the output from the texcount script.

Texlog – a python script for wordcount logging

Texlog, available in a github repository, is a python script that calls texcount, and saves its output as text files that can be plotted in your favour plotting program.

This simple script can easily be edited to work on different files, and set different output files and directories.

If you are using a master file with included files, texlog can also output the word counts of those files separately, as well as the total count for the whole document.

Automated Logging

The most direct usage of the script is just to run it as a standalone python script. New data will be appended to the log files, so you won’t have to worry about over-writing your log file.

You can automate your script using the standard scheduling approach for your software. On linux this will likely by cron, while on windows, you’ll probably want to use the windows task scheduler.

Plotting the Data

The output files are just comma separated values with column headings, so you should have no problem plotting them in your favourite plotting software.

A date and time stamp is automatically included with each log write, so it is easy to build up a time-series of your writing progress.

Feature wish list

For the most part this little script is as I need it for now. If I get time in the future, these are a few things that I might work on:

  • Improved readme
  • Commandline usage
  • Optparser for setting input file, output file, usage options
  • Option for storing other stats e.g. number of chapters, sections, words per section