How to count words in LaTeX files?

I am a big LaTeX fan, mostly thanks to my friend Cedric who introduced me to it ;) And I don’t regret it at all; there is simply no better way to create long, beautiful PDF documents, particularly during these times of dissertation writing! I’m in my last step towards the Master’s degree I’ve been working on for the last two years, and creating documents is an important part of that.

LaTeX works for me, because:

  1. It’s cross-platform (and I need that for my project!);
  2. It’s text based (I can edit the files with any decent editor; personally I use and TexShop and sometimes TextMate);
  3. I can generate PDF, plain text, RTF, and much more from the same source;
  4. I can split my documents in several others and work separately in each;
  5. I can generate meaningful diffs using Subversion (to see what I’ve changed in every revision);
  6. I can manage the bibliography for my papers easily (using the awesome BibDesk tool);
  7. I don’t have to cope with a buggy text editor that crashes every so often!
  8. I can generate gorgeous, absolutely beautiful documents. Easily.

For my last document, the dissertation, I have a numeric limit in the number of words (~ 10K to 15K words) and I need to count the number of words in the documents I generate. Since I’m not using Word, nor KOffice nor OpenOffice, this simple requirement becomes more complex to fulfill. But working in a Unix environment has its benefits; first I found this solution:

$ detex file.tex | wc -w

This command provides a first approach to the problem; however, it just strips off the LaTeX commands, even those that generate content in the final document. For example, if you have a macro that puts in bold the name of your project, those words will not appear in the final calculation even if they do appear in the final document. Clearly not acceptable. Googling a bit more, I found what I was looking for:

$ ps2ascii file.pdf | wc -w

In this case we’re working on the final PDF document, and of course the final result is much, much more interesting.

Happy typesetting!

Install MySQL_python in Leopard

I wanted to make my Django blog engine work on Leopard using MySQL as a database engine. I had a hard time making it work, partially because of my lack of knowledge of Python, partially because I am using MAMP instead of a “/usr/local/mysql”-like MySQL installation, partially because of Leopard itself.

The problem is, basically, that if you try to do the “easy_install MySQL_python” thing, it won’t work in Leopard (the compilation of the native code fails). Here’s how I made it work, following the instructions in this post in the MySQL forums, and doing some tweaking manually. Continue reading

Updating RubyGems and Rails in Leopard

If you just installed Leopard and the developer tools, you’ll find out that Ruby on Rails is there, ready to be used. But of course, it’s Rails 1.2.3, which is fine, but it turns out that last Friday Rails went 2.0. Not only that, but RubyGems was updated to 0.9.5 lately too… and you’re dying to have everything up and running on your system.

So how to proceed? Follow these instructions:

  1. Open Terminal.app
  2. $ sudo gem update --system
  3. $ sudo gem install rails
  4. $ sudo gem update

If you just do “gem update”, then the current Rails installation will be broken. You must do ‘gem install rails” (which seems odd, because it was already installed, after all). The thing is that since you’ve updated RubyGems with the command 2) above, then you need to re-install Rails. I haven’t tried with other gems, but it could be the same situation for them.

Update, 2007-12-19: Here’s another solution for this problem!

Installing Xubuntu 7.10 on a G3 iBook

Just a small post, pointing to the one and only solution to a known bug, that (incredibly) shipped with the public release of the PowerPC version of the latest Ubuntu distribution: 7.10 or “Gutsy Gibbon”. When installing that OS on a PowerPC G3 iBook (like mine), during the boot sequence the computer “freezes” (that is, the scrollbar stops running and the whole boot stops) and then you get a “BusyBox” screen, which is, needless to say, kind of a bummer.

The problem is that /dev/hda3 is not available (that is, your IDE internal hard disk) and of course, Xubuntu does not know what to do in that case. Kind of incredible, huh?

Well, the solution for that problem was in this answer of the Ubuntu Forums. Just follow the instructions there and you’ll succeed. Now I have a nice Xubuntu install in my good old and faithful G3 iBook (in double boot with Mac OS X “Jaguar”).

Little terminal trick

If you have to delete a folder which contains locked files, the Mac OS X Finder won’t let you (because the “locked” flag is used precisely for that!). If you want to remove such folder (typically folders coming from a Subversion checkout have this problem) run these commands:


sudo chflags -R nouchg to_destroy/
sudo rm -r to_destroy/

Where “to_destroy” is the name of the folder that you want to get rid of. As always, be careful! There is no confirmation dialog whatsoever! You’ve been warned.

How to make in X11 so that the focused window follows the mouse?

Another long title.

Just a quick one, not to forget: in Apple’s X11, if you want to have the focus follow the current window, just type the following at the terminal window:

defaults write com.apple.x11 wm_ffm -bool true

Restart X11 and that’s it! This is particularly useful in apps like Gimpshop that have several open windows simultaneously (for the palettes, the layers, and the images themselves).