jameswfrost.co.uk

home about archive

LaTeX Word Count in TextMate

April 30 2008

LaTeX Bundle Icon

As I’m currently writing my dissertation (using LaTeX, written with the wonderful TextMate), I was looking for a way to do a proper word count of my document. The LaTeX version of the document contains a lot of markup, so to simply do a normal wordcount on that would give a rather inflated value. I scoured the internet and found a solution using the tool ps2ascii to convert the PDF version of the document to text (the PDF version being devoid of the tex markup), and piping that into wc. However, the version available for download doesn’t suppress any errors that ps2ascii might throw up, so I’ve made a minor modification to fix that. The command amounts to (roughly):

    ps2ascii "$TM_DIRECTORY"/"$BASENAME".pdf 2>/dev/null | wc -w

You can grab the updated TextMate command from http://sucs.org/~frosty/Word%20Count.tmCommand.
Double-click the downloaded file to install it.

Simply hit Ctrl+Shift+N to bring up the word count as a tooltip (it may take a little while if your file is big). Also note that the script relies on you having already generated a PDF of a your tex file. Let me know if you have any problems!

blog comments powered by Disqus