ExistingProgram3883 · 2022-02-03 12:39
Hi there,
has anybody integrated one of the [emacs-grammarly-packages](https://github.com/emacs-grammarly) (e.g. in the form of [`flycheck`ing](https://github.com/emacs-grammarly/flycheck-grammarly)) into `LaTeX-mode`? I'm looking for a setup which allows me to write LaTeX and benefit from grammarly-checks.
Thanks in advance for pointing me to some resources or sharing your configs!
jmite · 2022-02-03 14:44
I've never seen grammarly integration for LaTeX, but I have seen a few LanguageTool things.
* [lsp-ltex](https://github.com/emacs-languagetool/lsp-ltex). This is based on ltex-ls, which is a language server for grammar-checking LaTeX using LanguageTool. The setup is a bit tricky, and there are definitely some bugs and missing features, but when it's set up it's pretty smooth.
* [Textidote](https://github.com/sylvainhalle/textidote) is also based on languageTool. It doesn't use LSP, but it can generate nice browseable HTML to look at all of the errors. It's not emacs-specific, but there's a snippet in the README of how to integrate it with flycheck.
You could possibly rig something on your own with Textidote, running `textidote --clean` removes the markup from your file and replaces math with X, so you can pass that to grammarly. The hard part is then relating it back to the original source locations. I think it would at least preserve which line the error was on.
ExistingProgram3883 · 2022-02-03 17:51
Thanks for your reply. I will have a look at LanguageTool.
ExistingProgram3883 · 2022-02-03 17:54
In the meantime, I tried the `flycheck`-based mode with the following config:
```elisp
(use-package flycheck-grammarly
:ensure t
:after flycheck
:config
(setq flycheck-grammarly-check-time 0.8)
(add-to-list 'flycheck-checkers 'grammarly))
```
It works quite well, but is rather slow.
Any opinions on, whether the `lsp-grammarly` will be faster?
sylvain_soliman · 2022-02-04 19:16
If you go the LanguageTool route, I'd recommend `yalafi` over `textidote`:
```lisp
(after! flycheck
(flycheck-define-checker tex-yalafi
"A LaTeX grammar/spelling checker using languagetool and yalafi.
See https://github.com/matze-dd/YaLafi"
:modes (latex-mode plain-tex-mode)
:command ("python3" "-m" "yalafi.shell" "--lt-command" "languagetool"
"--language" (eval (if ispell-current-dictionary (substring ispell-current-dictionary 0 2) "en"))
source)
:error-patterns ((warning line-start "=== " (file-name) " ===\n"
(one-or-more digit) ".) Line " line ", column " column
", Rule ID: " (id (one-or-more (any "A-Z_")) (optional "[" (one-or-more digit)"]")) "\n"
"Message: " (message) line-end))
:enabled (lambda () (and
(flycheck-python-find-module 'tex-yalafi "yalafi.shell")
(executable-find "languagetool")))
:verify (lambda (_) (flycheck-python-verify-module 'tex-yalafi "yalafi.shell")))
(add-to-list 'flycheck-checkers 'tex-yalafi t))
```