Thu 02 June 2016

Checking your LaTeX sources for spelling errors with Hunspell

Posted by ankur in Research (219 words, approximately a 1 minute read)

I usually use Vim and a Makefile when writing LaTeX documents. Even though Vim does permit you to check your spellings, it's always nice to run the entire text through a standalone spell checker before passing your documents on to others.

The workflow is quite simple. Once you've written your text, you commit your changes, and then you can use one of either Aspell or Hunspell to check your text for spelling errors. Both provide an interactive interface that makes them easy to use.

On Fedora, you can install them using dnf:

sudo dnf install aspell hunspell

You'll also need to make sure you have the language files installed:

sudo dnf install aspell-en hunspell-en

Then, to check all your .tex files, you can use something like this:

find . -name "*.tex" -exec aspell --lang=en --mode=tex check "{}" \; # Aspell
find . -name "*.tex" -exec hunspell -t -i utf-8 '{}' \; # Hunspell

I looked around a bit, and decided to use Hunspell. It's used by LibreOffice, Firefox, and other applications. I commit my work first and then run the above command which opens a window like this:

Hunspell screenshot

Once you've gone through it and made your changes, you can then use git diff --word-diff to review your changes. If you'd like to undo some of them, use git add -i and so on:

Git diff screenshot

That's it! Happy writing!