Go to the first, previous, next, last section, table of contents.

How can I spell-check TeX or *roff documents?

If you want to spell-check TeX or *roff documents with Ispell, you need to arrange for a filter program that understands how to strip TeX or *roff formatting commands to be run. In the TeX distribution, there are several different programs named `detex', all with incompatible options, and a very old pair of programs named `detex' and `delatex', which should probably be avoided. The most useful one for Ispell is `detex' by Daniel Trinkle. A more recent version is available via FTP:


  /arthur.cs.purdue.edu:pub/trinkle/detex-2.3.tar.Z

Raphael Cerf <cerf@clipper.ens.fr> recently released a program for this named `xetal':


  /spi.ens.fr:pub/unix/tex/

There is a program that comes with Unix named `deroff' for stripping formatting commands from *roff files.

Here is an example of code you can put in a .emacs file to use these programs:

  ;; Based on suggestions by David G. Grubbs <dgg@ksr.com> and Paul Palmer
  ;; <palmerp@math.orst.edu>.
  ;; Assuming the use of detex 2.3 by Daniel Trinkle:
  ;; -w means one word per line.
  ;; -n means don't expand \input or \include commands.
  ;; -l means force LaTeX mode.
  (require 'ispell) ; for the make-variable-buffer-local statements
  (setq plain-TeX-mode-hook
        (function
         (lambda ()
           (setq ispell-filter-hook "detex")
           (setq ispell-filter-hook-args '("-nw")))))
  (setq LaTeX-mode-hook
        (function
         (lambda ()
           (setq ispell-filter-hook "detex")
           (setq ispell-filter-hook-args '("-lnw")))))
  (setq nroff-mode-hook
        (function
         (lambda ()
           (setq ispell-filter-hook "deroff")
           (setq ispell-filter-hook-args '("-w")))))

You will have to adjust the arguments for programs other than Trinkle's detex or for other versions of deroff. Experiment running the command from the shell to find the correct options. If you don't have a filter that knows how to output one word per line, you must pipe its output through another filter to break up the output.


Go to the first, previous, next, last section, table of contents.