When working on LaTeX documents in TextMate, the default word count feature isn’t too helpful, as it also includes all of the LaTeX control sequences in the count. There are plenty of suggestions out there, but this is one I came up with, which works the same way as the default word count facility (Ctrl-Shift-N):
#!/usr/bin/env ruby -wKU def pretty(number) number.to_s.gsub(/\d{1,3}(?=\d{3}+(?!\d))/, '\0,') end counts = `detex -l | wc -lwc`.scan(/\d+/) counts[0] = counts[0].to_i + 1 # increase one to the line count %w[ line word byte ].each do |unit| cnt = counts.shift plural = cnt.to_i != 1 ? 's' : '' printf("%11.11s %s%s\n", pretty(cnt), unit, plural) end
This is just a copy of the default statistics action from the Text bundle, but with the ‘detex’ utility added into the pipeline to remove all LaTeX control sequences.
Put this in a new command in the LaTeX bundle, with ‘Selected Text’ for input, and ‘Show as Tool Tip’ for output. I assigned Ctrl-Shift-N as the key equivalent.
Related posts
- Inserting vector graphics in Office documents Sometimes I have the misfortune of having to write conference...
- Align comments in Textmate A Textmate command script to align comments in a block...
- Using Quicksilver with iTunes I tend to play a fair bit of music while...
- Textmate: ‘git diff’ in FileMerge I found myself wanting to pick through some changes I...



One Comment
Amazing – thanks! Worked perfectly :) A much better solution than ps2ascii. Perhaps you might want to create a bundle for easier installation?
J