14
Nov

Partial LaTeX Word Count + TextMate

Long time no post, sorry! Here’s just a quick one.

I’ve been working on some essays and reports for uni in LaTeX, and the criteria for the work is usually that it is within a certain word limit, discounting titles, appendices, references etc. So I thought the easiest way to do this would be to have the main content, the bit that actually counts towards the word limit, in a separate file and include it. I then needed a good way of counting the words in this, and Googling lead me to a solution which converted the rendered PDF into ASCII and counted that, which is fine, but doesn’t work for partial LaTeX documents, i.e. ones without document tags etc. So I came across detex, which works pretty damned well. The only issue I’ve found with it so far is that it doesn’t filter keywords within braces, so for example, with \begin{itemize} it strips the \begin{}, but not the itemize, so this obviously adds to your word count. It’s a minor issue though, and one I’ll happily live with. You can then just pipe the output of that into “wc” to get the word count (and various other bits of info).

If you happen to be using TextMate, here’s a nice little command which will do it for you:

detex "$TM_DIRECTORY"/"$TM_FILENAME" | wc -w

I’ve added the “-w” option to just give me the word count, but obviously you can change this to get the other data wc will give you.

Enjoy!

Comments ( 0 )

    Leave A Comment

    Your email address will not be published. Required fields are marked *