SublimeText / LaTeXTools

LaTeX plugin for Sublime Text
https://latextools.readthedocs.io/
2.01k stars 366 forks source link

Feature request: integration with Language​Tool for grammar checking #855

Open jdumas opened 8 years ago

jdumas commented 8 years ago

Hi,

There is already an existing plugin for checking grammatical errors with LanguageTool in Sublime. However, it doesn't appear to work well with LaTeX files, and by default it sends queries on a remote public server. There is a page on the LanguageTool wiki that explains how to check LaTeX files with LanguageTool, but it is all a bit cumbersome. I was wondering if it would be possible to provide a better integration between LanguageTool with LaTeXTools? I know that TeXStudio propose to check the grammar of its documents with it.

This is related to feature request #664 for academic writing checks.

r-stein commented 8 years ago

This is a very interesting idea and tool. The problem is to convert the LaTeX document in to plaintext/html while preserving line numbers and in the best case also columns. Otherwise we cannot link the problems with the text positions.

The syntax and scope selector system of Sublime Text might be helpful in dividing text and latex commands, but it is still complicated.

jdumas commented 8 years ago

It looks like this is what TeXStudio is doing. They have their own LaTeX parser, and seem to remap the analyzed content to the original LaTeX lines.

Not sure how much work it is to do the same in Python with Sublime Text though.

r-stein commented 8 years ago

Yes, writing a LaTeX parser would pretty much work, but fortunatly Sublime Text has already a syntax parser and we can query the results.

My first approach would be to query all text regions, concanate them, and just send this to LanguageTool while preserving a mapping from the lines/columns to the regions. If you want to see how we can detect text regions you can open your ST console via `ctrl+`` and paste to hightlight them:

reg = view.find_by_selector("- (comment, constant, variable, punctuation, keyword, entity.name, meta.environment.math, meta.group.brace, meta.group.bracket, support.function)"); view.add_regions("normal_text", reg, scope="comment", flags=sublime.DRAW_NO_FILL)

afterwards paste to remove the highlight:

view.erase_regions("normal_text")

This is the first approach for the selector and can still increase, but already does a decent job.

evandrocoan commented 6 years ago

I would suggest using https://github.com/pkubowicz/opendetex to convert the document to plain text file, so LanguageTool knows how to deals with it. This also should convert all macros expansions, and my texts are filled with them. So, if I do not convert them, the results would be incomplete as the macros would be omitted.

I just do not know how to link back the plain text file with the latex files and lines. If there is no direct way by opendetex, them we would have to build a approximate one by parsing the plain text file and searching back from where they come on the latex files.