Skip to content

Respect file encoding with vlty gramma check #1829

@petRUShka

Description

@petRUShka

Issue
Suppose we have tex-file in non utf-8 encoding and want to check grammar. vimtex together with vlty don't respect fileencoding so I get an error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 340: invalid start byte

minimal.vim

set nocompatible
let &runtimepath  = '~/.vim/bundle/vimtex,' . &runtimepath
let &runtimepath .= ',~/.vim/bundle/vimtex/after'
filetype plugin indent on
syntax enable

let g:vimtex_grammar_vlty = {}
let g:vimtex_grammar_vlty.lt_directory = '/usr/share/java/languagetool/'
let g:vimtex_grammar_vlty.lt_command = 'languagetool'
let g:vimtex_grammar_vlty.encoding = 'cp866'

if has('nvim')
    let g:vimtex_compiler_progname = 'nvr'
endif

au Filetype tex
            \ set spell |
            \ set spelllang=ru,en

minimal.tex

  \documentclass{article}
  \usepackage[cp866]{inputenc}
  \usepackage[russian]{babel}

  \begin{document}
  \selectlanguage{russian}

  Случайный текст на русском

  \end{document}

don't forget to convert file to cp866 encoding

iconv -t cp866 test.tex > test_cp866.tex

Commands/Input
Setup vim and text_cp866.tex like above. Run vim on test_cp866.tex and execute:

:compiler vlty
:make

Observed Behaviour

:!python3 -m yalafi.shell --lt-directory /usr/share/java/languagetool/ --language ru --disable "WHITESPACE_RULE" --enable "" --disablecategories "" --enablecat
egories "" --documentclass "" --packages "amsthm,babel,enumerate,inputenc"  'test_cp866.tex'  2>&1| tee /tmp/vijaI15/129
=== test.tex
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.8/site-packages/yalafi/shell/__main__.py", line 3, in <module>
    from . import shell
  File "/usr/lib/python3.8/site-packages/yalafi/shell/shell.py", line 351, in <module>
    gentext.generate_text_report(proofreader.run_proofreader, sys.stdout)
  File "/usr/lib/python3.8/site-packages/yalafi/shell/gentext.py", line 89, in generate_text_report
    (tex, plain, charmap, matches) = run_proofreader(file)
  File "/usr/lib/python3.8/site-packages/yalafi/shell/proofreader.py", line 47, in run_proofreader
    tex = f.read()
  File "/usr/lib/python3.8/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x91 in position 132: invalid start byte   

Expected Behaviour

But yalafi.shell has an option --encoding which works well. So it is sufficient to check on fileencoding vim setting and send its value to yalafi via --encoding option. And\or accept

  let g:vimtex_grammar_vlty.encoding = 'cp866'

Output from VimtexInfo

System info
  OS: Arch Linux
  Vim version: VIM 8.2 (1-1704)
  Has clientserver: true
  Servername: VIM1

vimtex project: vimtex_test
  base: test_cp866.tex
  root: /home/user/vimtex_test
  tex: /home/user/vimtex_test/quintic_sextic_sqrt_periodic_maik.tex
  out: /home/user/vimtex_test/build//test_cp866.pdf
  log: /home/user/vimtex_test/build//test_cp866.log
  aux: /home/user/vimtex_test/build//test_cp866.aux
  fls: /home/user/vimtex_test/build//test_cp866.fls
  main parser: current file verified
  compiler: latexmk
    configuration: 
      continuous: 1
      callback: 1
      build_dir: build/
      latexmk options:
        -verbose
        -file-line-error
        -synctex=1
        -interaction=nonstopmode
      latexmk engine: -pdf
  viewer: Zathura
    xwin id: 98566145
    process: 
      pid: -
      cmd: zathura -x "/usr/bin/vim --servername VIM1 --remote-expr \"vimtex#view#reverse_goto(%{line}, '%{input}')\"" --synctex-forward 1:1:'/home/user/vimtex_test/test_cp866.tex'  '/home/user/vimtex_test/build//test_cp866.pdf' >/dev/null 2>&1 &
  qf: LaTeX logfile
    config: 
      overfull: 1
      general: 1
      packages: 
        biblatex: 1
        babel: 1
        default: 1
        hyperref: 1
        natbib: 1
        scrreprt: 1
        fixltx2e: 1
        titlesec: 1
      default: 1
      underfull: 1
  document class: 
  packages:
    amsbsy
    amsfonts
    amsgen
    amsmath
    amsopn
    amssymb
    amstext
    amsthm
    array
    babel
    bm
    calc
    caption2
    caption3
    enumerate
    epstopdf-base
    eufrak
    extsizes
    fontenc
    graphics
    graphicx
    ifthen
    inputenc
    keyval
    longtable
    mathtext
    natbib
    revsymb
    trig
    url

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions