153

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 I use macros to generate some of the prose, it has to somehow work with LaTeX. I don't think that such checkers are LaTeX-aware, so 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.

  • 13
    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
  • 2
    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
  • 1
    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
  • 3
    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
  • 1
    latex2html and then upload to grammarly.com. Note that this is a commercial product. A restricted trial period is available which permits free evaluation of the product for non-commercial purposes only for a limited period of time. – niitsuma Nov 9 '15 at 2:19

21 Answers 21

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 :)

  • 7
    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
  • 3
    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
  • 3
    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
  • 14
    It is perfectly polite and recommended to answer your own question. It's even in the help center! – Petr Hudeček Aug 8 '15 at 19:17
  • 4
    LanguageTools is now included in TeXstudio. – nicoguaro Oct 1 '15 at 16:19
20

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 LanguageTool 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 the git repository).

  • It seems that the web app does not work now. – jdhao Jan 20 '18 at 8:38
  • Somehow the irony of a grammar checker printing out the phrase "Captial without preceeding fullstop" at the end of a long day gave me a good chuckle (I think the words are capital and preceding). Nevertheless a good enough tool :) – therealrootuser May 2 '18 at 1:48
  • 2
    @therealrootuser Well, now you know why I needed to write myself a grammar checker. ;) – gmatht May 2 '18 at 5:19
14

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.

  • 4
    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
  • 1
    @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
9

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.

8

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
8

I've just finished writing a new tool for checking spelling and grammar directly on LaTeX files, called TeXtidote:

https://sylvainhalle.github.io/textidote

The program can remove markup from the file and send it to the Language Tool library, which performs a verification of both spelling and grammar in a dozen languages. What is unique to TeXtidote is that it keeps track of the relative position of words between the original and the "clean" text. This means that it can translate the messages from Language Tool back to their proper location directly in your source file. By default, TeXtidote produces an HTML report that shows your original sources, with the errors found by Language Tool highlighted at the correct location:

Screenshot

The tool is free and easy to install (OS-independent, requires Java). I encourage you to give it a try and tell me what you think! (More information about download/install/use can be found on the Readme page of the GitHub repository; click on the "Download" button on the web site to get there.)

  • 1
    It would help to have some integration guidance E.G using TeXworks ((as supplied default OOB with both main distros) that would guide other editor users. In MiKTeX TeXworks it is easy to add in the "Typeset" choices an entry "GrammarChecker" that can run a simple shell script (e.g. grammar.cmd) that in turn can have a line or two (or more) e.g. h:\java\bin\java.exe -jar h:\texidote\textidote.jar --html %1 >report.html and on the second line report.html will automatically open in default browser. P.S I don't see the red mark up whats needed to invoke Language Tool library – user170109 Jan 14 at 2:01
  • My bad omitted the --clean en variables in my script so it calls lang tools (another reason to spoon feed a script template for noobs like me :-) – user170109 Jan 14 at 2:20
  • I'm really digging the Plain Text mode. NOW to see if this could work with ALE and Vim. – Pred Nov 8 at 16:54
6

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

5

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"

  • It is not so good. – jdhao Jan 20 '18 at 9:05
5

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.)

  • 2
    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
5

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.

  • 1
    Note: you can also use language-check (integrating with LanguageTool) and syntastic. – BenC Jul 22 '15 at 7:47
  • I'd recommend against disabling these rules. You may miss a real mistake this way. – varepsilon Dec 16 '16 at 11:47
  • 3
    @varepsilon True, though my experience of it was that without disabling those you get a lot of false positives, and so it becomes more difficult not to miss actual errors. – rth Dec 17 '16 at 12:28
4

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.

4

VIM-BASED SOLUTIONS

INTRODUCTION

LanguageTool is a blessing for the open-source community when it comes to spelling & grammar checking. As a bonus, it is a platform independent Java (.jar) application. Be warned, it is not perfect yet, but it is definitely usable and fills a gap that existed for a very long time. It is being actively developed and I sincerely hope for the day it will be the best tool available ever.

To begin with, any grammar-check solution will inevitably use LanguageTool. It is almost inescapable -- even paid commercial utilities will not give you the flexibility and the integration offered by LanguageTool. Now given this fact, the question simplifies to asking:

How can I use LanguageTool on platform X for documents of type Y?

I will now proceed to answering it for the VIM platform (and latex documents as just a special case). This is a canonical case as far as linux OS is concerned.

Basic Set-up

In summary, as of today in the Feb'17, I find three usable solutions as three plugins. I usually recommend Vundle plugin manager whose simple syntax to include in .vimrc is: (No harm in having all three plugins simultaneously. The subsequent setup of each individual plugin is mentioned in the rest of the write up.)

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'dpelle/vim-LanguageTool'
Plugin 'rhysd/vim-grammarous'
Plugin 'vim-syntastic/syntastic'
call vundle#end()

And then from within vim, issue a pair of commands once-for-all:

:so $MYVIMRC
:VundleInstall

You also need LanguageTool main java (.jar) application installed to ~/LanguageTool/. You may use the following:

>> mkdir -p ~/LanguageTool
>> cd ~/LanguageTool
>> wget https://www.languagetool.org/download/LanguageTool-3.6.zip -O LT.zip
>> unzip LT.zip

The Main Solutions

1. Plugin: vim-LanguageTool

As being the earliest LanguageTool plugin, this has some impressive performance except for some uncomfortable navigation.

There is one caveat to link the LanguageTool application on your desktop. Include the following line in your .vimrc and restart vim (you may :so $MYVIMRC too).

let g:languagetool_jar='~/LanguageTool/languagetool-commandline.jar'

All set, you only have to start the spell/grammar-check-session using command :LanguageToolCheck and end the session using :LanguageToolReset. What you do in between is the key, and you use two commands :lnext :lprevious to navigate among errors. You may remap them in .vimrc for a better comfort for e.g.

nmap gn :lnext<CR>
nmap gp :lprevious<CR>

Actually, you can be slightly smarter and try using those maps only when LanguageToolCheck is active. And nunmap them immediately on issuing LanguageToolReset. (I found aliases LTC and LTR nice, issuing these additional nmap/nunmap'ing commands)

You are also allowed to change color of each type of error (for e.g. green for grammar and red for spelling) using vim commands such as: hi LanguageToolGrammarError guibg=peru guifg=wheat. The full list of types of errors is found in :h LanguageTool.

2. Plugin: vim-grammarous

This is actually a nice alternative to the one above. It automatically installs languagetool java application for itself on its first invocation, hence a much quicker and easier installation to get yourself going.

So directly coming to the usage which is very similar to above except for a couple of more commands. Use :GrammarousCheck to start and :GrammarousReset to end the spell/grammar-check-session. The main tasks are in between and are performed using the small window that opens up explaining the errors in the file. This new window is special and using commands f, n, p, and ? you can navigate.

I personally prefer some of the remaps as below for a more comfortable usage.

let g:grammarous#hooks = {}
function! g:grammarous#hooks.on_check(errs) abort
    nmap <buffer>gn <Plug>(grammarous-move-to-next-error)
    nmap <buffer>gp <Plug>(grammarous-move-to-previous-error)
    nmap <buffer>gr <Plug>(grammarous-move-to-info-window)r
    nmap <buffer>gas f <Plug>(grammarous-move-to-info-window)f
    nmap <buffer>gR <Plug>(grammarous-move-to-info-window)R
endfunction
function! g:grammarous#hooks.on_reset(errs) abort
    nunmap <buffer>gn
    nunmap <buffer>gp
    nunmap <buffer>gr
    nunmap <buffer>gf
    nunmap <buffer>gR
endfunction

This above sample, when present in your .vimrc will create five handy additional normal-mode commands namely gn (next error), gp (previous error), gr (ignore the error), gf (fix automatically with suggested correction), gR (ignore all errors with same rule). These are available only to the current buffer and only when :GrammarousCheck is active, and will disappear as soon as :GrammarousReset is used.

3. Python wrappper: language-check in combination with vim's Syntastic plugin

Note: syntastic should have been installed already during above Basic Set-up step of three plugins.

This is an interesting and simplest solution of all, if you already have the infamous Syntastic plugin on vim and python installed on your linux. All that you have to do is install the python-wrapper language-check using the terminal-command:

>> pip install --upgrade language-check

and add the following two lines to .vimrc.

let g:syntastic_text_checkers = ['language_check']
let g:syntastic_tex_checkers = ["lacheck", "chktex", "text/language_check"]
let g:syntastic_text_language_check_args = '--language=en-GB'
let g:syntastic_tex_language_check_args = '--language=en-GB'

Caveat: By default, this setup checks for spelling everytime a save/write command :w is used and therefore slows it down. You may disable this check-on-write by using the following line in .vimrc. But note that it means that you will check grammar yourself manually.

let g:syntastic_check_on_wq = 0

All set, you can simply use two commands :SyntasticCheck and :SyntasticReset to start and end the session respectively. You don't need any more commands here because of the special interface that already highlights and explains on status bar of what went wrong, as you move your cursor to the specific locations.

If anything troubling, you may first want to verify whether the filetype is properly detected to either tex or text by using the command:

:SyntasticInfo
3

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
3

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

3

I was using TexWorks and had the exact same problem. Upon investigation which platforms were supported by LanguageTool, I discovered TexStudio, which full integrates with LanguateTool and works perfectly. See this page for integration details: http://wiki.languagetool.org/checking-la-tex-with-languagetool#toc4

3

HEVEA is a Latex to HTML translator that does not insert line breaks (unlike detex) and can handle most environments, such as tables, that may include text you also want to grammar-check. Since you are using Ubuntu, you can install the package hevea. Then, you can translate your latex project with the command

hevea document.tex

Since Hevea uses its own parsers and library implementations, it will not understand some Latex environments. In my case, I had to "comment out" all \begin{tabulary}...\end{tabulary} environments by enclosing them with

\begin{latexonly}
\begin{tabulary}
...
\end{tabulary}
\end{latexonly}

The latexonly environment is available after adding \usepackage{hevea} to the preamble of your Latex document and only instructs Hevea to ignore its contents and not affect your usual Latex workflow.

Essentially, this reduces the problem to grammar-checking an html page, document.html.

The good thing about html is that word-processing software, which tend to have state-of-the-art spelling and grammar checking, can flawlessly import html pages. I made good experience using Microsoft Word 2010, which is good at checking English grammar. Aside from many false positives in math expressions, it found several subtle grammar mistakes I had not found after proof-reading my thesis twice. Note that MS Word 2010 runs under Wine environments. Concerning native spell checking on Linux and Ubuntu, you can use LibreOffice.

  • 1
    Welcome to TeX.SX. I think a list of commands/environments to ignore would be a good idea. Would save a lot of adding latexonly environments. – Johannes_B Oct 7 '15 at 9:43
2

As somebody said before, RTextDoc http://jwork.org/rtextdoc/ is a good editor for LaTex source code. It has on-the-fly syntax highlighting of errors (red line) and problems with the grammar (blue lines). See the image shown below:

RTextDoc editor with grammar checks

It's powered by the LanguageTools. In addition to grammar checks, it has many 'bells and whistles' for the usual LaTeX source editing. Note that the grammar checking and syntax highlighting works fine even without activation to the Pro version. It also runs equally well on Windows, Mac and Linux.

1

Check out http://wiki.languagetool.org/checking-la-tex-with-languagetool

You can convert your LaTex file to HTML and check the HTML with the LanguageTool.

1

Here is another solution i found out: Latex Spelling and Grammar Check. Check it out and let me know what you are thinking of it.

  • This is a very low effort answer. This tiny guide could very well fit in the answer instead of just posting a link. Also, using aspell and microsoft word is not revolutionary. – Nichlas H. Jan 2 '18 at 8:59
  • You have a point. Should i delete it and post it as a comment? – chadoulis Jan 2 '18 at 9:00
  • I think you should at least edit your answer to include the names of the tools, if not writing out the whole guide as the answer. Please ignore my comment on it not being revolutionary - noone have made the same suggestion, so it might very well be useful for some. – Nichlas H. Jan 2 '18 at 9:14
0

There are superb grammar checking solutions for Microsoft Word. Open the PDF file using MS Word. This is done in Windows by using right click, then "open with" and select Microsoft Word. The generated Word document may contain a few errors with hyphenated words and footnotes, but it is useful.

MS Word spell checker may be complemented with a popular grammar checking tool such as Grammarly, Language Tool, ProWritingAid.

0

The AbiWord project includes a US English-only grammar checking plugin using "Link Grammar." (For Linux) Current version seems to be 3.02 (from 2016.) I've found it useful, however, I haven't found a way to turn off its detection of certain formatting problems, such as hard returns (from the days of the typewriter, remember, before word wrap?) I suppose running text through something like Sigil or Calibre's epub editor might be able to fix that first. The last time I tried, I may have done something wrong, and it removed ALL spaces, however! That pretty much made the text unreadable.

Edit: Link Grammar Parser January, 2019: link-grammar 5.6.0 released! https://www.abisource.com/projects/link-grammar/

  • Assuming that "Abiword" can perform grammar checking on plain text, how do you propose we do some preprocessing to remove the "tex" commands from the tex file before it can be fed? For example see @Little Bobby Tables 's answer where it is mentioned how to segregate the plain text for use. – GermanShepherd Mar 18 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.