lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.53k stars 391 forks source link

syntax highlighting distrupted by apostrophe character (') #2283

Closed alexandreroberts closed 2 years ago

alexandreroberts commented 2 years ago

Description

Using vimtex syntax highlighting, I have found that an apostrophe character in a \footnote or other command (e.g., \emph) disrupts the syntax highlighting, leading vimtex apparently to think that the footnote has ended. This behavior is coupled with the closing brace for a footnote being highlighted in red, as if it were unpaired:

Screen Shot 2021-12-17 at 1 39 11 PM Screen Shot 2021-12-17 at 1 41 13 PM Screen Shot 2021-12-17 at 1 41 20 PM

Unfortunately, I have been unable to isolate what is causing the problem. When I produce very simple .tex and .vim test files, I can't reproduce the behavior. Even opening a simple .tex file with my big, bloated .vimrc doesn't result in the problem. I thought I would post it here, in case anything occurs to you as to what might be causing it and what I should test further -- with apologies that I have not produced the most helpful bug report.

Steps to reproduce

main.tex:

\footnote{For these citations, with complete references, see \cite[72--73]{letrouit1995chronologie}. Stephen's quotation:
\gk{ἓν γὰρ τὸ πᾶν δι’ οὗ τὸ πᾶν καὶ εἰ μὴ τὸ πᾶν ἔχοι τὸ πᾶν οὐδὲν τὸ πᾶν φησιν ὁ πᾶν δυνατὸς} [\alchMsiglum{}~: Letrouit emends this to \gk{πανδύνατος}] \gk{Χίμης}.}

a commentary \emph{On Zosimos's On Action}.

\footnote{Olympiodoros, \emph{On Zosimos's On Action} (a.k.a.\ \emph{De arte sacra}), \caagsec{2}{4}, \S 21--24, ed.\ \cite[140]{viano1995olympiodoros.presocratics}.}

test.vim:

set nocompatible
set mmp=5000

call plug#begin('~/.vim/plugged')
Plug 'lervag/vimtex'
Plug 'ale-cci/aqua-vim'
call plug#end()

hi CursorLine   cterm=NONE ctermbg=0
hi CursorColumn cterm=NONE ctermbg=0
set cursorline! cursorcolumn!

syntax enable
set background=dark
colorscheme aqua-vim

set nu
set numberwidth=3
highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE

au ColorScheme * hi texFootnoteArg cterm=italic
my whole bloated .vimrc file (comments stripped): ```vim set nocompatible let mapleader="," set timeoutlen=250 nnoremap , , filetype plugin on set encoding=utf-8 set history=100 set mouse=a set mmp=5000 map :w !detex \| wc -w autocmd BufEnter * let &titlestring = expand("%:t") . expand("%:h") set title map q vnoremap "+y call plug#begin('~/.vim/plugged') Plug 'tpope/vim-surround' Plug 'justinmk/vim-sneak' Plug 'lervag/vimtex' Plug 'gabrielelana/vim-markdown' Plug 'vim-pandoc/vim-markdownfootnotes', { 'for': 'markdown' } Plug 'mileszs/ack.vim' Plug 'junegunn/goyo.vim' Plug 'folke/zen-mode.nvim' Plug 'scrooloose/nerdcommenter' Plug 'ale-cci/aqua-vim' Plug 'vim-scripts/vis' Plug 'christoomey/vim-titlecase' Plug 'jdhao/better-escape.vim' if has('nvim') || has('patch-8.0.902') Plug 'mhinz/vim-signify' else Plug 'mhinz/vim-signify', { 'branch': 'legacy' } endif Plug 'tpope/vim-fugitive' Plug 'thaerkh/vim-workspace' Plug 'mbbill/undotree' Plug 'SirVer/ultisnips' Plug 'honza/vim-snippets' Plug 'ervandew/supertab' Plug 'Raimondi/delimitMate' Plug 'mreppen/vim-scholar' Plug 'vim-scripts/greplace.vim' call plug#end() hi CursorLine cterm=NONE ctermbg=0 hi CursorColumn cterm=NONE ctermbg=0 set cursorline! cursorcolumn! let g:workspace_persist_undo_history = 0 set undodir=~/.vim/undodir set undofile let macvim_skip_colorscheme = 1 au ColorScheme * hi texFootnoteArg cterm=italic let g:UltiSnipsExpandTrigger="" let g:UltiSnipsJumpForwardTrigger="" let g:UltiSnipsJumpBackwardTrigger="" let g:UltiSnipsSnippetDirectories=["UltiSnips", "mysnippets"] let g:workspace_create_new_tabs = 0 nnoremap b :buffers nnoremap n :bn set updatetime=500 tnoremap jk let g:auto_save = 1 if executable('ag') let g:ackprg = 'ag --vimgrep' endif nnoremap se :Ack set iskeyword+=- augroup my_spelling_colors autocmd! autocmd ColorScheme * hi SpellBad cterm=underline ctermfg=NONE ctermbg=NONE term=Reverse autocmd ColorScheme * hi SpellCap cterm=underline ctermfg=NONE ctermbg=NONE term=Reverse autocmd ColorScheme * hi SpellLocal cterm=underline ctermfg=NONE ctermbg=NONE term=Reverse autocmd ColorScheme * hi SpellRare cterm=underline ctermfg=NONE ctermbg=NONE term=Reverse augroup END let b:myLang=0 let g:myLangList=["nospell","en_us","de_de","fr","pt_br"] function! ToggleSpell() let b:myLang=b:myLang+1 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif if b:myLang==0 setlocal nospell else execute "setlocal spell spelllang=".get(g:myLangList, b:myLang) endif echo "spell checking language:" g:myLangList[b:myLang] endfunction lmap ts :call ToggleSpell() setlocal spell set spelllang=en_us,de,fr inoremap umz[s1z=`zau set spellsuggest=5 autocmd FileType tex nmap e diwi\emph{pi} autocmd FileType tex imap e \emph{}i autocmd FileType tex vmap e di\emph{pi} autocmd FileType markdown nmap e diwi*pi* autocmd FileType markdown imap e **i autocmd FileType markdown vmap e di*pi* autocmd FileType tex nmap f i%% v v v\footnote{}% ^ ^ ^0f}i autocmd FileType tex imap f %% v v v\footnote{}% ^ ^ ^0f}i autocmd FileType tex vmap f di%% v v v\footnote{pi}% ^ ^ ^$ autocmd FileType tex nmap tq diwi\textquote{pi} autocmd FileType tex imap tq \textquote{}i autocmd FileType tex vmap tq di\textquote{pi} autocmd FileType tex nmap pt diwi\parentext{pi} autocmd FileType tex imap pt \parentext{}i autocmd FileType tex vmap pt di\parentext{pi} autocmd FileType tex vmap sc di\textsc{pi} autocmd FileType tex imap sc \textsc{}i autocmd FileType tex vmap sc di\textsc{pi} autocmd FileType tex imap c \cite[]{} autocmd FileType tex vmap c di\cite[pi]{} autocmd FileType tex imap pc \parencite[]{} autocmd FileType tex vmap pc di\parencite[pi]{} autocmd FileType tex imap fc %\footcite[]{}% ^ ^ ^0f]i autocmd FileType tex vmap fc di%\footcite[pi]{}% ^ ^ ^$ filetype plugin on set omnifunc=syntaxcomplete#Complete syntax enable set background=dark colorscheme aqua-vim let g:tex_flavor = 'latex' map lt :VimtexTocOpen map lc :VimtexCompileSS map lv :VimtexView map ls :VimtexStop let g:vimtex_toc_config = { \ 'name' : 'TOC', \ 'layers' : ['include'], \ 'split_width' : 70, \ 'todo_sorted' : 1, \ 'show_help' : 1, \ 'show_numbers' : 1 \} let g:vimtex_view_method = 'skim' let g:vimtex_quickfix_enabled = 0 map lq :let g:vimtex_quickfix_enabled = 0 map lw :let g:vimtex_quickfix_enabled = 1 set nu set numberwidth=3 highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE set ignorecase set smartcase nnoremap i set indentkeys-={ indentkeys-=} set linebreak function! ScreenMovement(movement) if &wrap return "g" . a:movement else return a:movement endif endfunction onoremap j ScreenMovement("j") onoremap k ScreenMovement("k") onoremap 0 ScreenMovement("0") onoremap ^ ScreenMovement("^") onoremap $ ScreenMovement("$") nnoremap j ScreenMovement("j") nnoremap k ScreenMovement("k") nnoremap 0 ScreenMovement("0") nnoremap ^ ScreenMovement("^") nnoremap $ ScreenMovement("$") nnoremap oo ok nnoremap OO Oj nnoremap a ~ nnoremap s 0 nnoremap d $ if !exists('*s:goyo_leave') function! s:goyo_leave() source $MYVIMRC endfunction endif autocmd! User GoyoLeave nested call goyo_leave() ```

Expected behavior

I expect an apostrophe not to affect syntax highlighting at all.

Actual behavior

Instead, it is sometimes being treated as if it were something like an open- or close-brace } {.

The problem goes away entirely if I replace every ' with , but that is not very convenient.

Do you use a latexmkrc file?

Yes (I think)

VimtexInfo

System info
  OS: Mac OS X 10.15.7 (19H1519)
  Vim version: NVIM v0.5.0
  Has clientserver: true
  Servername: /var/folders/92/6c80fs_55hnf_1s2ybgbv5c40000gn/T/nvimYFZtlD/0

VimTeX project: _lists-M-front-matter
  base: _lists-M-front-matter.tex
  root: /Users/robe941/Dropbox/Projects/4-ABOUT-TO-SUBMIT/marcianus-front-matter-Lists-JLAIBS
  tex: /Users/robe941/Dropbox/Projects/4-ABOUT-TO-SUBMIT/marcianus-front-matter-Lists-JLAIBS/_lists-M-front-matter.tex
  main parser: recursive search
  document class: memoir
  packages: amsbsy amsfonts amsgen amsmath amsopn amssymb amstext arabxetex array atbegshi atbegshi-ltx atveryend atveryend-ltx auxhook babel biblatex biblatex-chicago bidi biditools bigintcalc bitset blx-case-expl3 calc caption caption3 chemformula classics csquotes dcolumn delarray endfloat endnotes enumitem epigraph etexcmds etoolbox expl3 fontenc fontspec fontspec-xetex fourier-orns froufrou gensymb geometry gettitlestring graphics graphicx hycolor hyperref ifmtarg iftex ifthen ifvtex import infwarerr intcalc keyval kvdefinekeys kvoptions kvsetkeys l3keys2e latexsym letltxmacro lineno logreq ltxcmds manyfoot memhfixc microtype nameref nccfoots nicefrac paracol parnotes pdfescape pdftexcmds perpage pgf pgfcomp-version-0-65 pgfcomp-version-1-18 pgfcore pgffor pgfkeys pgfmath pgfrcs pgfsys refcount relsize rerunfilecheck stmaryrd stringenc tabularx textcase textcomp tikz trig ulem uniquecounter url varioref wasysym xcolor xfrac xifthen xkeyval xparse xpatch xspace xstring xtemplate zref-abspage zref-base
  source files:
    _lists-M-front-matter.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/define.parameters.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/specific.JLAIBS.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/biblio.JLAIBS.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/bibfixes.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/bibfixes/autocapitalize-volumes-field.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/bibfixes/editorpunct-with-booktitle.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/bibfixes/spurious-comma-after-series.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/bibtweaks/omitpublisher.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/bibtweaks/fullpagerange-firsttimecitation.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/bibtweaks/journal-vol-number-with-slash.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/bibtweaks/edited-by-translated-by-becomes-ed-trans.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/bibtweaks/hereafter.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/general.header.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/general.PACKAGES.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/general.FONTS.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/general.CITE.COMMANDS.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/general.MACROS.mss.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/general.MSS.tex
    ../../../../../alexandre/Dropbox/TeX-Alex-custom-files/general.HYPHENATION.tex
    _outline.tex
    sections-compiled-by-Makefile.tex
    sections/0-intro.tex
    sections/1-TOC.tex
    sections/2-Table-of-Signs.tex
    sections/3-List-of-Authors.tex
    sections/z1-Conclusion.tex
    sections/z2-Acknowledgments.tex
  compiler: latexmk
    engine: -xelatex
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Skim
alexandreroberts commented 2 years ago

Actually, I think I don't use a latexmkrc file. But I suspect that it is not relevant to this particular issue.

lervag commented 2 years ago

Unfortunately, I have been unable to isolate what is causing the problem. When I produce very simple .tex and .vim test files, I can't reproduce the behavior. Even opening a simple .tex file with my big, bloated .vimrc doesn't result in the problem. I thought I would post it here, in case anything occurs to you as to what might be causing it and what I should test further -- with apologies that I have not produced the most helpful bug report.

Does this mean that the minimal tex file and the test.vim file you provided is not sufficient to reproduce the problem? If so, why did you even post that?

I have not seen this issue before and I can't immediately say I understand what the problem is. It would help much if you can provide any reproducible example (even if it is bloated).

alexandreroberts commented 2 years ago

Yes, that's right, sorry for the confusion; I just thought it might be useful to include the test files even though they didn't work. I will now put together as minimal an example as I can.

alexandreroberts commented 2 years ago

OK, I think I've figured it out: it seems to be a bug related to the package chemformula.

Using the files pasted below, I obtain the buggy behavior using nvim -u test-bloated.vim main.tex:

Screen Shot 2021-12-18 at 8 35 23 AM

Using nvim -u test.vim main.tex doesn't produce the obvious syntax highlighting mistake, but it does erroneously label the footnote's close-brace as mismatched:

Screen Shot 2021-12-18 at 8 35 44 AM

main.tex:

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[12pt,article,draft]{memoir}
\usepackage{chemformula}

\begin{document}

\footnote{For these citations, 
see Stephen's quotation.}

Xenocrates was also a philosopher. The \emph{Souda} has two entries under this name, the first for Plato's second successor.

\end{document}

test.vim:

set nocompatible " No vi compatility, this first because it resets some options
set mmp=5000 " Some files need more memory for syntax highlight

call plug#begin('~/.vim/plugged')
Plug 'lervag/vimtex' 
Plug 'ale-cci/aqua-vim'
call plug#end()

" Allow crosshair cursor highlighting.
hi CursorLine   cterm=NONE ctermbg=0
hi CursorColumn cterm=NONE ctermbg=0
"nnoremap <Leader>cu :set cursorline! cursorcolumn!<CR>
set cursorline! cursorcolumn!

" HIGHLIGHTING
syntax enable
set background=dark
"colorscheme afterglow
colorscheme aqua-vim

" LINE NUMBERS
set nu
set numberwidth=3
highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE

au ColorScheme * hi texFootnoteArg cterm=italic
test-bloated.vim: ```vim " BASIC set nocompatible " No vi compatility, this first because it resets some options let mapleader="," " Mapleader: make it , instead of \ set timeoutlen=250 " press comma twice to get old comma functionality nnoremap , , "filetype off filetype plugin on set encoding=utf-8 set history=100 " Keep more history, default is 20 set mouse=a " Allow copy-pasting set mmp=5000 " Some files need more memory for syntax highlight " TEX WORD COUNT (not perfect, just an improvement) " I think it only works for a single file map :w !detex \| wc -w " filename in title/tab autocmd BufEnter * let &titlestring = expand("%:t") . expand("%:h") set title " NO RECORDING map q " COPY/PASTE using Mac Clipboard "vnoremap :w !pbcopy "noremap :r !pbpaste " C-c and C-v - Copy/Paste to global clipboard vnoremap "+y "imap "+gpa " Copy/Paste using Mac shortcuts (Cmd key rather than control): "vnoremap "+x "vnoremap "+y "cnoremap "nnoremap "+gP "cnoremap + "execute 'vnoremap Githubissues.
  • Githubissues is a development platform for aggregating issues.