Python Training by Dan Bader

Spell-checking LaTeX documents with aspell

LaTeX is a great way to create beautiful documents. But its embedded markup makes it difficult to check LaTeX documents for spelling errors. This article explains how to setup and use a program called aspell to spell check your LaTeX documents.

Aspell in action

LaTeX and spell-checking

I love LaTeX. It’s a document markup language from the early 1980’s that is great at producing beautifully typeset PDF documents. Sadly, documents written in LaTeX markup can be difficult to spell check with automated tools. Although many editors support spell-checking LaTeX documents directly, for example LyX1, it’s still useful to have a universal way to spell check any LaTeX document. A little program called aspell is just that.

What is aspell?

aspell is a command-line based spell checker. It spell checks ordinary plain text files but it can also handle TeX and LaTeX input files. If spell-checking LaTeX files, aspell ignores the markup. This means that valid LaTeX commands such as \textbf will not be marked as spelling errors.

The easiest way to set up aspell on Mac OS X2 is to use the Homebrew package manager. To install aspell from Homebrew’s repository run the following command:

brew install aspell --lang=en

Aspell requires dictionary files to work. Luckily these can also be installed easily via Homebrew. You choose which dictionaries to install with the --lang argument. It’s also possible to install multiple languages at once like this: --lang=en,de,es.

How to use aspell?

To spell check a single LaTeX (.tex) file you issue the following command:

aspell --lang=en --mode=tex check file.tex

Once you’ve started aspell it shows you a text-based interface. There you can browse any found spelling errors and fix them in-place. You control the interface using various single letter keyboard shortcuts listed at the bottom of the screen. To exit aspell press the x key.

You can also teach aspell new words by pressing the a key. This adds the currently selected word to your personal dictionary. Aspell stores your personal dictionary at ~/.aspell.en.pws3. The dictionary is a simple plaintext file that you can edit with any text editor. I frequently edit my aspell dictionary file because I’m sometimes too eager with pressing a.

By default aspell also checks comments in the LaTeX source file. If you don’t want to spell check comments use the --dont-tex-check-comments switch.

To spell check multiple files at once use the following command. It runs aspell on all .tex files in the current directory:

find . -name "*.tex" -exec aspell --lang=en --mode=tex check "{}" \;

More information

You can find more information on how to use aspell in the official aspell manual. Additionally, Huiying Wu and Chris Rennie, and this wikibook provide information about spell-checking LaTeX documents.


  1. Of course Emacs, vi, and many others can do this too. But my current favorite editor on OS X, TextMate 2, has somewhat broken spell-checking support. 

  2. I’ve tested this with Mountain Lion but it should also work with older versions of OS X. 

  3. For other languages the filename will be different, for example ~/.aspell.de.pws for German. 

<strong><em>Improve Your Python</em></strong> with a fresh 🐍 <strong>Python Trick</strong> 💌 every couple of days

Improve Your Python with a fresh 🐍 Python Trick 💌 every couple of days

🔒 No spam ever. Unsubscribe any time.

This article was filed under: productivity.

Related Articles:
5 Thoughts on Mastering Python

5 Thoughts on Mastering Python
A free email class for Python developers:
» Click here to get the first lesson

Latest Articles:

📦🐍 Which frameworks and libraries are the most important to know to be considered an effective Python dev? Here’s how you go from “writing scripts” to “building applications” with Python, master the tools of the trade for Dependency Management, and become an expert at picking quality Python libraries: » Click here to learn more

← Browse All Articles