# Grammar-checking tool for use with LaTeX?

I am looking for a grammar-checking tool, i.e., something that checks for mistakes such as "two dog" or "a books". It has to work on Linux (Ubuntu). Also, since that I use macros to generate some of the prose, it has to somehow work with LaTeX. I don't believe that such checkers are LaTeX-aware, to it has to work with some compilation product of LaTeX: DVI or PDF.

If you suggest a grammar checker that checks plain text, please explain how to you extract the text. catdvi does a nice job, but it leaves some garbage, like page numbers.

-
TextLint is not a grammar checker, but might still be of interest. It's a writing style checker, meaning it will recognize things like passive voice, repetitions, useless words... –  Damien Pollet Dec 2 '10 at 0:06
A good alarm: I have to think twice before I move to Latex. Since I am second language speaker to English,I found the grammar suggestions in MS word so helpful. I like the fonts and the flexibility Latex offers, and I was thinking to migrate to it(I am writing my mater thesis, by the way). May be I have to stick with MS Word... Thanks –  user3856 Feb 26 '11 at 22:11
obbsss I wrote "mater" in place of "master". Well, Andrew Roberts could be right " it(Ms word) corrects the common typos that we all make. However, the problem in my opinion is that it means we don't learn from our mistakes, e.g., you will continue to type 'teh' instead of 'the' because Word will sort it out for you" hahahhaa –  user3856 Feb 26 '11 at 22:24
Since this is asked in 2010, I wonder if there is any update. Could OP consider remove the check mark to encourage more answers? The current answer is still unsatisfactory, leading me to always write in MS Word first then do formatting in Latex. –  Heisenberg Jul 11 '14 at 20:02
@Anh I'm still unaware of a good solution other than hacking the LaTeX code into plain text and then running this or the other grammar checker on it, so AFAIK the answer is still valid. If you have a specific situation you're facing, or have other language tools in mind, I think you should post a new question. –  Little Bobby Tables Jul 13 '14 at 6:51

(It's not too polite to answer your-own questions, but this is what I ended up with.)

LanguageTool is a very nice standalone, Java-based grammar checker. However, it works on plain text. Therefore, I needed to convert my LaTeX document to as plain as possible text document - Not a simple task. I managed to do it using the following trick:

1. I arranged for all floats to hold their positions using the floats package and the H option. This is required so that captions won't break the paragraphs when transforming to plain text.
2. I removed line numbers using the nopageno package.
3. I used a sed script to do some more fine-tuning, like adding periods to section names and description labels. I don't publish the script here, since that it is really specific to my-own style and conventions.
4. After this preprocessing, I compiled to DVI and ran catdvi -s.
5. I used another simple sed script to get rid of empty lines and page breaks. The final result is a reasonable textual conversion of the LaTeX document, which LanguageTool can work on.

There are still some leftover annoyances, like inlined program listings, which the grammar checker can't understand, but all together I got a decent automated proof-checking from it :)

-
You can transform your TeX document to plain text using detex on the command line. This doesn’t work perfectly but probably well enough for your purpose. –  Konrad Rudolph Dec 5 '10 at 15:08
I tried detex. It just leaves out the macros, which is not the same thing as rendering the document to plain text after macro expansion –  Little Bobby Tables Dec 5 '10 at 17:25
I have a LaTeX-to-HTML conversion set up using tex4ht. Copying the converted HTML from the browser to the LanguageTool online spell checker worked fine for me. –  krlmlr Jul 14 '12 at 1:36
It is perfectly polite and recommended to answer your own question. It's even in the help center! –  Petr Hudeček Aug 8 at 19:17

I don't believe there are good grammar checkers, but Word's is better than most — provided, that is, you tell it to switch off broken features like checking for passive constructions.

You can load your Latex file into Word as a plain text file and look for the highlights that indicates that its grammar checker is concerned about some construction (typically green dotted underlining).

With a bit of macrology, you can get a good approximation to indicating to Word which bits are English (or whatever) and indicate the Latex markup as not-a-language. This makes running the grammar/spell checkers more pleasant to use.

Postscript — I had not noticed the tag: various flavours of Word can be run under Wine. In the absence of competition, this might be the best Linux solution, although it can't be the best free software solution.

-
Rather than loading your .tex files as text, you could try and convert it into HTML, and loading the result through Word that way. Unfortunately that means you have to try and find a good LaTeX to HTML converter, which is something I can't find... –  jevon Sep 29 '11 at 2:06
And another option is available if your build process creates .ps (PostScript) files; you can use ps2ascii to translate the TeX'd output into text and play with it from there, but unfortunately this includes headers, footers and hyphenation. –  jevon Sep 29 '11 at 2:08
@jevon: convert it into HTML Sure, I give a script to do this at tex.stackexchange.com/questions/16367/… which has problems (it doesn't tell Word which is text and macros). ps2ascii - These conversions are more trouble than they are worth, and in particular, the round trip loses most Tex formatting. –  Charles Stewart Sep 29 '11 at 5:47
If I'm not mistaken, doesn't that script only convert TeX into HTML-highlighted TeX, and doesn't actually compile it? e.g. \textbf{} won't become bold text in the generated HTML. I since wrote a basic script in PHP to actually compile TeX into HTML, I might release it later. –  jevon Oct 7 '11 at 5:11
@jevon: The HTML-highlighting does appropriately display things like italics, bold and so on, and also gives section heads or subscripts in larger or smaller fonts. I don't think compiling the Tex is actually desirable at the editing stage, because of the problem of translating changes to the output back to the Tex source; if you really do want to do this, tex4ht gives a good framework for this. –  Charles Stewart Oct 7 '11 at 19:12

I wrote a grammar checker for checking TeX documents called LyX-GC. It can also be used online as a web app.

It can use LanguageTool as a back-end. The main advantages over just using LanguageTool directly are that (1) it filters the TeX to avoid false positives from LanguateTool trying to interpret TeX commands as English and (2) it has hundreds of is own rules, including TeX-specific rules. For example, it knows that "See \ref{lem:foo}." should really be "See Lemma \ref{lem:foo}". (Also, if you use LyX, LyX-GC obviously has the advantage of being able to integrate with LyX)

LyX-GC only really supports English (though there is experimental French support in git).

-
Welcome to TeX.SX! –  Papiro Aug 18 '13 at 9:16

There are two old Unix tools for checking grammar. They are called style and diction. Check out the link:

http://dsl.org/cookbook/cookbook_15.html#SEC220

I personally have never used them.

However I am of a belief that the best way to check your punctuation and grammar is to have somebody else proofread your paper for you.

-

The TeXworks editor has integrated spell-check and it works on Linux too.

I think it uses the same spell-checker as OpenOffice, so it should be able to check the mentioned mistakes.

-
You can elaborate a little on this. For example, you can compile your documents (use draft mode) and start a spell check in the pdf-view. Then you can copy and paste the output as a pure text into a grammar checker. Of course, it is not possibility to automatically correct the misspellings and wrong grammar with a mouse click. You have to correct the language manually in the TeX source (not a big issue, in my opnion). –  Sveinung May 20 '12 at 7:18

I've been thinking about this lately as well. The question How to perform advanced spell checking of latex documents? suggests a tool called After the Deadline which looks quite interesting. Haven't tried it though so I can't tell you how to use it or if it's any good.

EDIT: Don't know if I'm doing something wrong, but I've been testing their web service and it's not too impressive. It reports no errors on these sentences: "I have two dog. I read a books"

-

Have you checked out stylecheck? I found it to be reasonably good, though I'm not sure what it does with macros....

-

I add Queequeg to the list, although it is far from perfect, too. It is a simple command-line tool aimed exactly at finding concordance errors in English. It works with LaTeX sources out of the box.

Unlike After the Deadline, it errs on the side of false positives, and sometimes there are a lot of them. It correctly reports the concordance errors on the example sentence "I have two dog; I read a books" suggested in another answer.

(Small tip for those who wish to try it: there is an error in the installation instructions, you should replace make dict WORDNET=/src/wordnet/dict with make dict WORDNETDICT=/src/wordnet/dict.)

-
Oh, the irony: I just ran it on my own answer here above and I found that I had forgotten the "s" in "reports". :) –  Federico Poloni May 20 '12 at 9:07

You can use SCaVis editor to edit Latex files. It has LaTeX tools (to insert math characters), content management (shows Latex sections on the left panel), LaTeX syntax highlighting and spell checking based on OpenOffice dictionaries

-
It's unfortunate that there's no mention of it supporting LaTeX syntax on the main page (only other programming environments). It's only hidden in the section on Writing Jython/Python script in the SCaVis IDE, where it is just as inconspicuous. –  Werner Oct 4 '13 at 20:02

When opening LaTeX files with vim text editor, it is possible to use a plugin that integrates LanguageTool grammar checker. Since, it does not explicitly support the LaTeX syntax, some elements will be detected as syntax errors.

However, the number of these false positives can be significantly reduced if the most common errors due to LaTeX syntax are ignored. This can be achieved, adding, for instance, the following line to ~/.vimrc,

let g:languagetool_disable_rules='WHITESPACE_RULE,EN_QUOTES,' \ . 'COMMA_PARENTHESIS_WHITESPACE,CURRENCY,EN_UNPAIRED_BRACKETS'

While not perfect, this approach allows for the LaTeX document to be checked, without the hassle of converting it to a plain text format.

-
Note: you can also use language-check (integrating with LanguageTool) and syntastic. –  BenC Jul 22 at 7:47

It's also an option to spell-check the output, i.e. the PDF file. It's a bit indirect, but at least you won't have problems with the LaTeX specific syntax.

Adobe Acrobat has a spell-check if I'm not mistaken, but not everybody has access to it of course.

-

Yes, you can use grammar and style checking using the RTextDoc LaTeX editor.

-