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

Additional compiler vlty #1714

Closed
wants to merge 10 commits into from
11 changes: 11 additions & 0 deletions autoload/vimtex.vim
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ function! vimtex#init_options() abort " {{{1

call s:init_option('vimtex_format_enabled', 0)

call s:init_option('vimtex_grammar_vlty', {
\ 'lt_directory': '~/lib/LanguageTool',
\ 'lt_disable': 'WHITESPACE_RULE',
\ 'lt_enable': '',
\ 'lt_disablecategories': '',
\ 'lt_enablecategories': '',
\ 'server': 'no',
\ 'shell_options': '',
\ 'show_suggestions': 0,
\})

call s:init_option('vimtex_imaps_enabled', 1)
call s:init_option('vimtex_imaps_disabled', [])
call s:init_option('vimtex_imaps_list', [
Expand Down
75 changes: 75 additions & 0 deletions compiler/vlty.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
if exists('current_compiler') | finish | endif
let current_compiler = 'vlty'

" Older Vim always used :setlocal
if exists(':CompilerSet') != 2
command -nargs=* CompilerSet setlocal <args>
endif

let s:cpo_save = &cpo
set cpo&vim

let s:vlty = g:vimtex_grammar_vlty

function! s:installation_error(msg)
call vimtex#log#error(
\ [a:msg, 'Please see ":help vimtex-grammar-vlty" for more details.'])
endfunction

if !executable('python')
call s:installation_error('vlty compiler requires Python')
finish
endif

call system('python -c "import yalafi"')
if v:shell_error != 0
call s:installation_error('vlty compiler requires the Python module YaLafi')
finish
endif

if s:vlty.server !=# 'lt'
if !executable('java')
call s:installation_error('vlty compiler requires java')
finish
endif

if !filereadable(fnamemodify(s:vlty.lt_directory
\ . '/languagetool-commandline.jar', ':p'))
call s:installation_error('vlty compiler - lt_directory path not valid')
finish
endif
endif

let s:vimtex = get(b:, 'vimtex', {'documentclass': '', 'packages': {}})
let s:documentclass = s:vimtex.documentclass
let s:packages = join(keys(s:vimtex.packages), ',')
let s:language = matchstr(&spelllang, '\v^\a\a([-_]\a\a)?')
let s:language = substitute(s:language, '_', '-', '')

let &l:makeprg =
\ 'python -m yalafi.shell'
\ . ' --lt-directory ' . s:vlty.lt_directory
\ . (s:vlty.server ==# 'no'
\ ? ''
\ : ' --server ' . s:vlty.server)
\ . ' --language ' . s:language
\ . ' --disable "' . s:vlty.lt_disable . '"'
\ . ' --enable "' . s:vlty.lt_enable . '"'
\ . ' --disablecategories "' . s:vlty.lt_disablecategories . '"'
\ . ' --enablecategories "' . s:vlty.lt_enablecategories . '"'
\ . ' --documentclass "' . s:documentclass . '"'
\ . ' --packages "' . s:packages . '"'
\ . ' ' . s:vlty.shell_options
\ . ' %:S'
silent CompilerSet makeprg

let &l:errorformat = '%I=== %f ===,%C%*\d.) Line %l\, column %v\, Rule ID:%.%#,'
if s:vlty.show_suggestions == 0
let &l:errorformat .= '%ZMessage: %m,%-G%.%#'
else
let &l:errorformat .= '%CMessage: %m,%Z%m,%-G%.%#'
endif
silent CompilerSet errorformat

let &cpo = s:cpo_save
unlet s:cpo_save
112 changes: 97 additions & 15 deletions doc/vimtex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ CONTENTS *vimtex-contents*
Arara |vimtex-arara|
Syntax Checking (Linting) |vimtex-lint|
Grammar Checking |vimtex-grammar|
vlty |vimtex-grammar-vlty|
View |vimtex-view|
Synctex |vimtex-synctex|
Forward search |vimtex-synctex-forward-search|
Expand Down Expand Up @@ -1641,6 +1642,54 @@ OPTIONS *vimtex-options*

Default value: 0

*g:vimtex_grammar_vlty*
This option is used to configure the `vlty` grammar checker. It is a dictionary
with the following keys (see |vimtex-grammar-vlty| for more details):

lt_directory~
Path to the `LanguageTool` software.

lt_disable~
lt_enable~
lt_disablecategories~
lt_enablecategories~
Options for `LanguageTool` that control application of rules and rule
categories. For more info, see:
http://wiki.languagetool.org/command-line-options

server~
Specify whether an HTTP server should be used. This may be faster for
short texts. Possible values are:

`no` Do not use a server.
`my` Use a local `LanguageTool` server. If not yet running, it is started.
`lt` Contact the Web server provided by `LanguageTool`. In this case,
no local installation is necessary. Please see the following page
for conditions and restrictions:
http://wiki.languagetool.org/public-http-api

shell_options~
Pass additional options to `YaLafi`, e.g., `--equation-punctuation displ`;
for more info, see:
https://github.com/matze-dd/YaLafi

show_suggestions~
If set to 1, then `LanguageTool's` replacement suggestions are included
in the |quickfix| or |location-list| messages.

Default: >

let g:vimtex_grammar_vlty = {
\ 'lt_directory': '~/lib/LanguageTool',
\ 'lt_disable': 'WHITESPACE_RULE',
\ 'lt_enable': '',
\ 'lt_disablecategories': '',
\ 'lt_enablecategories': '',
\ 'server': 'no',
\ 'shell_options': '',
\ 'show_suggestions': 0,
\}

*g:vimtex_imaps_enabled*
Use this option to disable/enable the insert mode mappings.

Expand Down Expand Up @@ -4038,25 +4087,58 @@ Finally, for more full-fledged linting in Vim, see the plug-ins mentioned in
==============================================================================
GRAMMAR CHECKING *vimtex-grammar*

|vimtex| provides grammar checking for TeX files through two compilers:
`style-check` [1] and `textidote` [2]. These may be activated with the
|:compiler| command, see |compiler-select|. A selected compiler may then be
used e.g. with |:make| or |:lmake|. See |vimtex-lint| above for some tips on
how to use this feature.
|vimtex| provides grammar checking for TeX files through the |compiler-select|
feature in Vim for a few selected checkers. They may be activated with the
|:compiler| command. A selected compiler may then be used e.g. with |:make| or
|:lmake|. The language of the Tex file is determined by |'spelllang'|. As an
example, one may do the following to use the |location-list| with a given
checker: >

A common workflow is to utilize the |location-list| with |:lmake|:
:compiler {checker}|lmake

See also |vimtex-lint| above for some tips on how to use this feature. The
following is a list of the available checkers:

style-check~
http://www.cs.umd.edu/~nspring/software/style-check-readme.html

textidote~
https://sylvainhalle.github.io/textidote/
To use `textidote`, the path to its jar file `textidote.jar` must be
indicated in the option |g:vimtex_textidote_jar|.

vlty~
See more details here: |vimtex-grammar-vlty|
>
------------------------------------------------------------------------------
VLTY *vimtex-grammar-vlty*

The `vlty` compiler uses the Python package `YaLafi` [1] for extracting the
plain text and combines this with the proofreading software `LanguageTool` [2].

In order to use `vlty`, you need local installations of both components. An
archive of `LanguageTool` can be downloaded from [3]. After uncompressing at
a suitable place, the path to it is specified as shown below. `YaLafi` itself
can be installed with: >

pip install --user yalafi

Configuration is controlled by the Vim dictionary |g:vimtex_grammar_vlty|.
As a minimal example, one could write in |vimrc|: >

let g:vimtex_grammar_vlty = {'lt_directory': 'path/to/LanguageTool'}
set spelllang=en_gb

- To check the currently open TeX file with `style-check`, run
`:compiler style|lmake`
- To check the currently open TeX file with `textidote`, run
`:compiler textidote|lmake`
The given directory has to contain the `LanguageTool` software, including for
instance the file `languagetool-server.jar`. A separated `:compiler vlty` will
raise an error message, if some component cannot be found.

The language of the Tex file is determined by |'spelllang'|. Be aware that to
use `textidote`, the path to its jar file `textidote.jar` must be indicated in
the option |g:vimtex_textidote_jar|.
Note: Spell checking with `LanguageTool` is only enabled if a country code is
specified in |'spelllang'|.

[1] http://www.cs.umd.edu/~nspring/software/style-check-readme.html
[2] https://sylvainhalle.github.io/textidote/
[1] https://github.com/matze-dd/YaLafi
[2] https://www.languagetool.org
[3] https://www.languagetool.org/download

==============================================================================
VIEW *vimtex-view*
Expand Down