Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong language passed to grammar checkers 'textidot' and 'vlty' #2190

Closed
cristobaltapia opened this issue Oct 2, 2021 · 18 comments
Closed
Labels

Comments

@cristobaltapia
Copy link

cristobaltapia commented Oct 2, 2021

Description

When trying to use the grammar checkers 'textidot' or 'vlty' an error is displayed, saying that the language is unknown.

Steps to reproduce

I have the following configuration defined:

let g:tex_flavor = 'latex'

let g:vimtex_grammar_vlty = {}
let g:vimtex_grammar_vlty.lt_command = 'languagetool'
let g:vimtex_grammar_vlty.server = 'my'
let g:vimtex_grammar_vlty.show_suggestions = 1
let g:vimtex_grammar_vlty.shell_options =
        \   ' --multi-language'
        \ . ' --packages "*"'
        \ . ' --define ~/vlty/defs.tex'
        \ . ' --replace ~/vlty/repls.txt'
        \ . ' --equation-punctuation display'
        \ . ' --single-letters "i.\,A.\|z.\,B.\|\|"'
        \ . " --lt-options '~--language en-US'"

let g:vimtex_grammar_textidote = {
            \ 'jar': '/opt/textidote/textidote.jar',
            \ 'args': '',
            \}

I define the spell language within the file with a modline:

\documentclass{minimal}
\begin{document}
Hello world!
\end{document}
% vi:spelllang=en_us

Then run e.g.:

compiler textidote | make

Expected behavior

Grammar check

Actual behavior

Errors occur.
Specifically,, textidote throws this error:

:!java -jar '/opt/textidote/textidote.jar' --no-color --output sing
leline --check enUS 'minimal.tex'  2>&1| tee /tmp/nvimIfjg0e/11         
TeXtidote v0.8.2 - A linter for LaTeX documents and others
(C) 2018-2021 Sylvain Hallé - All rights reserved

Unknown language: enUS

and vlty this:

Language 'en' not listed in output of languagetool --list!
Trying 'en' instead.                                                   
Error detected while processing /home/tapia/.vim/plugged/vimtex/compiler/vlty.vim
:
line   90:
:!python3 -m yalafi.shell --lt-command languagetool --server my --encoding utf-8
--language en --disable "WHITESPACE_RULE" --enable "" --disablecategories "" --en
ablecategories "" --documentclass "minimal" --packages ""  --multi-language --pac
kages "*" --define ~/vlty/defs.tex --replace ~/vlty/repls.txt --equation-punctuat
ion display --single-letters "i.\,A.|z.\,B.||" --lt-options '~--language en-US' '
minimal.tex'  2>&1| tee /tmp/nvimIfjg0e/12

*** yalafi.shell: problem:
could not open file "/home/tapia/vlty/repls.txt"

As far as I understand, the correct language in this case should be en_US not enUS nor en-US.

Do you use a latexmkrc file?

no

VimtexInfo

System info
  OS: Arch Linux
  Vim version: NVIM v0.5.1
  Has clientserver: true
  Servername: /tmp/nvimIfjg0e/0

VimTeX project: minimal
  base: minimal.tex
  root: /home/tapia/Documents/latex
  tex: /home/tapia/Documents/latex/minimal.tex
  main parser: current file verified
  document class: minimal
  compiler: latexmk
    engine: -lualatex
    options:
      -verbose
      -shell-escape
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    build_dir: aux-folder
    callback: 0
    continuous: 0
    executable: latexmk
  viewer: Zathura
    xwin id: 0
  qf method: LaTeX logfile
lervag added a commit that referenced this issue Oct 2, 2021
lervag added a commit that referenced this issue Oct 2, 2021
It seems "languagetool --list" only works if a target file is also
specified, e.g. "languagetool --list SOMEFILE".

refer: #2190
@lervag
Copy link
Owner

lervag commented Oct 2, 2021

When trying to use the grammar checkers 'textidot' or 'vlty' an error is displayed, saying that the language is unknown.

textidot

I've fixed a minor bug here, please test again now.

vlty

To be honest, I'm no expert on this particular thing. After installing Yalafi and languagetool, I found it worked well when I removed the .server option and the --define and --replace options.

I'll ping the Yalafi dev to see if he has a comment here: @matze-dd

Perhaps there's been changes to languagetool that breaks something? Or simply that we are not configuring things properly?

@Konfekt: You also did some work on vlty.vim, so perhaps you have some relevant experience that may be helpful here?

@cristobaltapia
Copy link
Author

@lervag thanks for the quick response! I just tested the fix for textidot and now it is working correctly. vlty is also working for me after changing the configuration as you suggest. So all seems to be working now. I guess I should have tried to understand what those two options (--define and --replace) meant before just copying them in my configuration :P

@Konfekt
Copy link
Contributor

Konfekt commented Oct 3, 2021

Unknown language: enUS

is fixed by b0798e5

could not open file "/home/tapia/vlty/repls.txt"

seems to be an issue of vlty itself worked around as suggested by @lervag

Language 'en' not listed in output of languagetool --list!
Trying 'en' instead.

The logic of this check was flawed. Above PR should fix it.

Still, it could be that languagetool --list does not work as expected and should be checked.

@cristobaltapia
Copy link
Author

Still, it could be that languagetool --list does not work as expected and should be checked.

I think this is the problem. The command languagetool --list throws a java error and opens a window with the languagetool GUI:

languagetool --list
java.io.FileNotFoundException: --list (No such file or directory)
	at java.io.FileInputStream.open0(Native Method)
	at java.io.FileInputStream.open(FileInputStream.java:195)
	at java.io.FileInputStream.<init>(FileInputStream.java:138)
	at org.languagetool.gui.Main.loadFile(Main.java:216)
	at org.languagetool.gui.Main.access$2100(Main.java:144)
	at org.languagetool.gui.Main$7.run(Main.java:1204)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

I am using Archlinux and languagetool was installed from the repos.

@lervag
Copy link
Owner

lervag commented Oct 3, 2021

I guess I should have tried to understand what those two options (--define and --replace) meant before just copying them in my configuration :P

Heh, yeah. It's a common mistake :)

Language 'en' not listed in output of languagetool --list!
Trying 'en' instead.

The logic of this check was flawed. Above PR should fix it.

Thanks, I'll look into the PR as soon as possible.

Edit: PR #2191 is merged.

Still, it could be that languagetool --list does not work as expected and should be checked.

I think this is the problem. The command languagetool --list throws a java error and opens a window with the languagetool GUI:

This was already addressed by me in my earlier commit. languagetool --list on itself does not work. However, languagetool --list SOMEFILE works, even if the file argument SOMEFILE does not exist.

@Konfekt
Copy link
Contributor

Konfekt commented Oct 3, 2021

This was already addressed by me in my earlier commit. languagetool --list on itself does not work. However, languagetool --list SOMEFILE works, even if the file argument SOMEFILE does not exist.

This sounds like an issue with the languagetool wrapper script. One would expect it to behave like java -jar languagetool-commandline.jar.

@lervag
Copy link
Owner

lervag commented Oct 3, 2021

I agree, but I'm not personally an avid user of languagetool, so I won't address that myself.

@Konfekt
Copy link
Contributor

Konfekt commented Oct 3, 2021

Oh, well, if languagetool opens a GUI then perhaps it is supposed to do something different from the command-line jar. Perhaps @cristobaltapia could check back with its creator how interchangeable those two commands are.

@cristobaltapia
Copy link
Author

I just made a bit of research and found that the problem with the --list argument has already been reported in the Archlinux bug report system[1]. The issue has been without any activity for a year now. I wrote a comment there to ask if there are any updates on the matter.

[1] https://bugs.archlinux.org/task/68079?project=0&order=id&sort=desc&string=languagetool

@Konfekt
Copy link
Contributor

Konfekt commented Oct 3, 2021

Oh, thank you, @cristobaltapia, and sorry for forgetting that I went down this road a year ago.

@cristobaltapia
Copy link
Author

cristobaltapia commented Oct 3, 2021

No problem @Konfekt ;) At least the workaround is straightforward, so I guess we can live with it until is fixed upstream.

@lervag
Copy link
Owner

lervag commented Oct 3, 2021

It seems to me we can close this issue, then, as there is no clear action to make on the VimTeX side? Or do you want to keep it open in the meantime?

@cristobaltapia
Copy link
Author

I think we can close this. Once there is an update from the side of the languagetool script, then we can either reopen this or create a new issue.

@lervag
Copy link
Owner

lervag commented Oct 4, 2021

Great, thanks!

@junyixu
Copy link

junyixu commented Jan 31, 2022

@cristobaltapia Vimtex is one of the most fantastic vim plugins I've ever seen. But you may have a better experience if using ale which focuses on linter.

Because of lack of specific knowledge for the moment, I can't figure out how to use language tool now languagetool-org/languagetool#6290 (comment).

@lervag
Copy link
Owner

lervag commented Jan 31, 2022

@cristobaltapia Vimtex is one of the most fantastic vim plugins I've ever seen.

<3

But you may have a better experience if using ale which focuses on linter.

Today a lot of people are relying on LSP type plugins for linter backends. E.g., if you use coc.nvim or the neovim built-in lsp stuff, then you probably don't need ALE. See also :help vimtex-af-lsp. I believe ALE is still a valid and good choice, but I just thought it worth mentioning.

Because of lack of specific knowledge for the moment, I can't figure out how to use language tool now languagetool-org/languagetool#6290 (comment).

I'm no expert on languagetool stuff. Did you read the VimTeX docs on the matter, i.e. :help vimtex-grammar-vlty?

@junyixu
Copy link

junyixu commented Feb 1, 2022

Vimtex is undoubtedly the most essential vim plugin for writing latex and a game-changer for me.
@lervag Thank you from the bottom of my heart for your reply and recommendation!

Since there already has been a finished ale_linter, I may change my workflow after the paper deadline 😂 and I don't know how coc and neovim built-in lsp could do that, I mean English grammar checking rather than LaTeX syntax checking. I did read the doc vimtex-grammar-vlty . :compiler vlty and succeed, :make and succeed; :cw and succeed, but which is not the way I want.
This is ALE way using let g:ale_tex_lty_server = 'lt' but only up to 10,000 characters per text

image

ALE is configurable and also asynchronous and will also populate quickfix list, is an enough good "front end for language tool". I have no problem with that.

But the key problem is language tool itself I mentioned above, so my reply may be off-topic although I want to discuss how to make language tool behave as it does on https://languagetool.org/ or how to find out more grammar mistakes when I use vim since Grammarly has no API for that as far as I'm concerned

@lervag
Copy link
Owner

lervag commented Feb 1, 2022

Vimtex is undoubtedly the most essential vim plugin for writing latex and a game-changer for me. @lervag Thank you from the bottom of my heart for your reply and recommendation!

Glad to hear it! :)

But the key problem is language tool itself I mentioned above, so my reply may be off-topic although I want to discuss how to make language tool behave as it does on https://languagetool.org/ or how to find out more grammar mistakes when I use vim since Grammarly has no API for that as far as I'm concerned

Ah, yes, it's off topic. And I'm sorry to say I can't help with this. I don't use these things that much myself. Note, though, that perhaps you would find the LTeX language server useful? It relies on languagetool as well and I've heard good things of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants