154

What's the best strategy for spell checking LaTeX documents?

1
  • 2
    This question is noticeably lacking in Windows-specific answers. (For those of us using Windows-native editors rather than emacs, vi.) I suspect if I ask a Windows-specific question, it will be merged here... ?
    – Mohan
    Commented Sep 29, 2012 at 23:45

18 Answers 18

77

It sort of depends on the system you're working on.

I'm using GNU/Linux and here aspell does a good job. For instance, to check test.tex in Danish, I would do like this from the terminal:

aspell -c -t test.tex -d da

The option -c tells aspell to check the file, -t puts it in TeX mode, and -d gives the base name of the main dictionary to use. On Ubuntu/Debian, this can be installed using:

sudo aptitude install aspell

Aspell is also available as a Windows executable. It can but run from the command line or from any good text-editor (i.e. one that supports macros to run external programs).

7
  • 14
    You can also use the --mode=tex or -t options to put aspell into tex mode, which ignores the spelling of standard tex commands. If you have defined additional tex commands these can be added to or removed from the ignore list using --add-tex-command=<list>, --rem-tex-command=<list>.
    – ihuston
    Commented Jul 26, 2010 at 20:57
  • 2
    Hunspell also has a TeX/LaTeX mode, -t, if one is using a language aspell does not support. Commented Aug 29, 2010 at 8:30
  • I use this to do a spellcheck in Swedish "aspell --lang=sv --mode=tex -c my_file.tex"
    – Johan
    Commented Aug 29, 2010 at 11:48
  • 4
    for those who, like me, are struggling with the --add-tex-command option: if you want to ignore \\citep and citet citation commands, just use it's -add-tex-command "citep op" --add-tex-command "citet op" (op stands for "ignore the optional parameter as well, use "Op" if you do not want to ignore it)
    – Ansa211
    Commented Jun 27, 2019 at 13:40
  • 1
    @Ansa211 Your reading of the manual is incorrect, "op" means skip over an optional parameter and check the next parameter. You can use a whole variation of o, O, p and P. For more detail see aspell.net/man-html/The-Options.html#TeX_002fLaTeX-Filter Commented Nov 25, 2022 at 17:45
36

Spell-checking can commonly be handled by your text editor. I'm not sure what the windows LaTeX editors have, but it's common to use vi or emacs in linux, and the editor's spell checking is pretty sufficient. Also, because these editors are syntax-aware, your spell-checking can be as well.

4
  • 5
    I personally use M-x flyspell-mode with AucTeX in Emacs which checks spelling as you type. Commented Jul 26, 2010 at 19:37
  • As another example, if you use TextMate on Mac OS X to edit your Latex documents, you can use its spell-checking features. Seems to work fairly well. Commented Jul 26, 2010 at 20:25
  • 4
    Personally use the new set :spell in Vim 7, and Automatic Spell Checking available in all system languages in Kile.
    – EricR
    Commented Aug 4, 2010 at 15:52
  • I'd point out that every dedicated TeX editor I know of has a spell checker: this applies to all platforms. It's such an obvious requirement that editors would not really succeed without it.
    – Joseph Wright
    Commented Aug 29, 2010 at 8:22
7

There's a reasonable on-line spell-checker at Micro Spell.

0
7

You might want to have a look at the spelling package. Though not yet matured, it already works reasonably well. The spelling package requires the LuaTeX engine. Main features of the package are:

  • Text is extracted during typesetting and written to a file that can be checked by your favourite spell-checker application.
  • Spelling errors can be highlighted in PDF output.

(The maintainer of the spelling package.)

7

Old question but I figured I'd throw in my two cents. An approach that I use, following a careful read-through to make sure that I catch as much as I can, is to first convert the latex document to RTF (using the latex2rtf package), and then open it up in Word. The figures tend to be ignored, however the wording and grammar at least can be handled by Word's excellent spelling and grammar checker.

6

I use a mac and I have cocoaspell, which works for the whole computer. As I use Aquamacs, I then enable flyspell (spell check on the fly), and it is all done!

6
detex doc.tex | spell
3
  • Hi, I would like to know, where should I write this command in order to let latex check my spelling? I have tried to write it after \begin{document}, but it doesn´t work. Should I create a new tex file and give this command?
    – Vivian
    Commented Nov 30, 2016 at 13:41
  • detex is a command line program. It needs to be installed on your system, and you need to run it in a terminal at a command prompt.
    – mankoff
    Commented Nov 30, 2016 at 19:28
  • Try aspell or ispell. May need to be installed with 3rd party package manager.
    – mankoff
    Commented Mar 9, 2017 at 19:32
6

As other users have advised, aspell is a good tool to use for this problem.

However, rather than configuring aspell's behaviour at the command line with --add-tex-command=<list>, --rem-tex-command=<list>, etc. I'd recommend creating project-level tex_conf and my_spelling files. These files are easier to manage and curate for larger projects and can also be version controlled (hopefully with the rest of your project files) and distributed with your content.

Typically, in my projects I would provision a simple shell script (check_spellings.sh):

#! /bin/bash

aspell -c -t *.tex --conf=./tex_conf --add-extra-dicts=./my_spelling

In this example I'm checking all files in the executed directory with a .tex file extension. I also have a file tex_conf and my_spelling in the same directory as my .tex files. (You may organise your project as you see fit so long as you adjust the paths to tex_conf, my_spelling, and the targeted .tex files in check_spellings.sh)

tex_conf is the place to add and remove tex commands for checking. An example tex_conf may contain:

add-tex-command cref p
add-tex-command captionsetup op
add-tex-command begin pop
add-tex-command frac pp

From the aspell documentation:

A ’p’ skips over a parameter while a ’P’ doesn’t. Similarly an ’o’ will skip over an optional parameter while an ’O’ doesn’t. The first letter on the list will apply to the first parameter, the second letter will apply to the second parameter etc

An example my_spelling may look like:

personal_ws-1.1 en 1
AIC
Akaike
autocorrelation
HMC
Stanislaw
1
  • Good summary. Is there any equivalent of add-tex-environment to help us ignore arguments of environments?
    – Stewart
    Commented Oct 23, 2023 at 14:27
5

It depends not only on the packages suggested but also on the language that you are using and on the front-end you edit your text. If you are a Windows user, I recommend WinEdt which is a paid front-end for LaTeX. It has dictionaries for many languages and underlines in red the words which are written incorrectly. A right click on an underlined word shows alternatives for it. If you write in different languages, you can also combine different dictionaries.

Example of Winedt spell checking

If you problem is hyphenation, however, remember to configure MiKTeX and your document for the language considered. There may be problems still, but you can correct them manually with \hyphenation.

5

I have good experiences with the spell checker of TeXStudio, but I guess there are many other editors with good LaTeX compatible spell checkers. You find a good list in this question.

A second option that some of my colleagues practice is to copy'n'paste the pdf output to Word. This may sound cumbersome and probably is, but the time you will/should take to proof read your document will exceed the time amount for the copy and paste by order of magnitudes.

1
  • It is time consuming way to paste in word, but it worth because the office 2013 can check some grammar errors not only the spells.
    – Tawei
    Commented Sep 26, 2013 at 2:13
5

The check_spelling command from my R package TeXCheckR is designed to enhance the features in hunspell.

Synopsis:

library(TeXCheckR)
check_spelling("file-to-check.tex")

Features:

  • Ignores the contents of commands which don't print, for example the contents of \labels and cite commands, which hunspell spuriously raises as possible spelling errors. You can also add commands whose contents will be ignored.
  • The ability to add words to the dictionary on a document-by-document basis, by adding % add_to_dictionary: stackexchange to the preamble.

  • The ability to fail on certain words, to maintain consistency % stop_if_present: organize

  • The ability to detect acronyms and add them automatically to the dictionary, so the following will pass.

    The Quebec Xylophone Enterprise Foundation (QXEF) is fictional.

  • Author names in the bibliography are automatically added (with a note).

  • Valid English contractions are not considered spelling errors.

  • The contents of \input and \include files are checked recursively.

Due to an oversight, I check against the en_GB dictionary and don't provide the user to select a dictionary. In the next version, I'll allow any hunspell dictionary. (It's trivial to update this: just don't want to pester CRAN.)

1
  • 1
    Consistently ignored in the requests and answers regarding spell checkers is the fact that spell checking is not enough. Syntax checking (and good proofreading) is also necessary. Evidence: a correctly spelled, but quite erroneous notice posted on a (physical, not electronic) Stanford bulletin board some years ago: "The semester will being on September 4." Commented Aug 8, 2019 at 16:21
4

As it hasn't been mentioned, note also Texmaker:

test.png

Cross-platform (on Linux I use 4.1.1 as it is the last static build available for download, otherwise my OS is too old), apparently it has it's own spell-check dictionaries (program directory contains e.g. en_GB.aff, en_GB.dic - not sure if these use aspell or standalone engine); comments are skipped (I like), commands are skipped (I like), filecontents with bibliography entries are skipped (surprised at this, like), math is skipped (like) -- though some packages/arguments are still checked/underlined, and \cite arguments too (see Make spellchecker ignore contents of certain commands in TexMaker). In any case, this looks quite good to me...

3

Although this is an old question, here is what I have found to work well if you have access to Word. It is similar to the suggestion of espais. pdflatex the document and then open the PDF in Word (which Word 2013 can do).

When proof-reading a document what I am looking for are not just spelling mistakes but more broadly typos; for example repeated words (e.g., "the the"). Word is actually quite good at catching these mistakes.

The only minor problem I have found is that certain types of formatting can confuse Word's conversion from PDF. For instance watermarks caused problems (but in my case they were easy to turn off).

3

Can't comment on the text editor question:

I made good experiences using the LTeX extension in vscode. It also checks for grammar. And I tested: It works equally well on Windows and Linux.

Other spell checking extensions also support LaTeX. As pointed out above by @machinaut, every decent text editor should.

2
  • 1
    +1 nice answer, I have edited your question to add a link to the LTeX documentation, hope this is fine
    – JamesT
    Commented Apr 7, 2023 at 7:50
  • Sure is, thank you. I though most people would search thorugh vscode anyway, but good idea, in case the extension disappears for some reason.
    – Paul Smith
    Commented Apr 7, 2023 at 7:53
2

It seems that the best tool on the market is GNU aspell and it supports TeX. However, it's very difficult to configure it right. I made my own texsc tool to simplify the usage of aspell. You just do this and your LaTeX documents will be checked:

gem install texsc
texsc --ignore=citet,citep,verbatim book.tex chapter1.tex chapter2.tex

You can also specify your own additional vocabulary:

texsc --pws=vocab.pws book.tex

More info in this blog post of mine.

3
  • Is it possible to use GNU Aspell for LaTeX on Windows? If so, how could I be doing this?
    – lucenalex
    Commented Aug 23, 2020 at 11:12
  • @lucenalex I believe it's possible. Try it out and if something doesn't work, submit a ticket here, I will try to help.
    – yegor256
    Commented Nov 1, 2020 at 8:49
  • @lucenalex not sure if you've been helped with this, but I have it working. I downloaded the WSL: docs.microsoft.com/en-us/windows/wsl/install-win10 Commented Feb 13, 2021 at 16:13
2

In case you are using VS Code, you can install the LTeX – LanguageTool grammar/spell checkin which calls LanguageTool behind the scenes.

As standalone UI there is TeXtidote available.

1
  • there is also the Code Spell Checker extension that uses cSpell under the hood.
    – Foad
    Commented Jul 12 at 8:48
2

I usually arrange my LaTeX documents into multiple chapters and sections, sometimes in a directory tree. For a global spellcheck, I use a command like

find . -name "*.tex" -exec hunspell -t -d en_US -l {} \; | sort -n | uniq -c

This works directly in unix-like environments, but could be arranged to work under any OS.

1

Following up on machinaut's answer... In vim version 7+, you can enable spell check by entering (in command mode)

:set spell spelllang=en_us

To turn it off

:set nospell

For additional documentation, search for the spell.txt file. On my Mac (OSX 10.15.7), it is located at /usr/share/vim/vim81//doc/spell.txt. Look in /usr/share/vim//vim81/spell for available languages.

It looks like you can get additional languages from here. Look at Christian Brabandt's answer for further details on installation of new languages.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .