5

I'm using nvim and LaTeX together, and for the most part it's been great. However, nvim appears to be incorrectly highlighting underscores that appear in filenames I include as part of the subfiles package (https://www.sharelatex.com/learn/Multi-file_LaTeX_projects#The_subfiles_package). At first I thought this was syntastic's fault, but I've verified that disabling syntastic does not solve the issue.

Here's what the highlights look like:

incorrect highlights in nvim

I think vim thinks that the underscores are an illegal character in this context, however the report compiles just fine.

Any suggestions on turning this behavior off? Maybe just in this context if possible?

1
  • 1
    Syntastic has nothing to do with syntax highlighting.
    – lcd047
    Commented Aug 19, 2018 at 6:16

2 Answers 2

6

This is happening because the syntax file for LaTeX does not recognize \subfile{ as a command which takes a file name. You can customize this as follows.

In your config directory (.vim, .config/nvim, etc), create the directory structure /after/syntax/. Create a file called tex.vim with the following contents:

syn match texInputFile "\\subfile\s*\(\[.*\]\)\={.\{-}}"
     \ contains=texStatement,texInputCurlies,texInputFileOpt

Then reload vim. This instructs vim to treat the pattern \subfile{name} as containing a file name, similar to \input{}

1
  • Note the plugin vimtex has added this to its after/syntax/tex.vim file. So installing the plugin vimtex should also fix the issue.
    – Hotschke
    Commented Sep 5, 2018 at 15:28
4

If you want to turn off this behavior in general, add following to your vimrc

let g:tex_no_error=1

The documentation found under :h g:tex_no_error: is

                    *tex-error* *g:tex_no_error*
 Tex: Excessive Error Highlighting?

The <tex.vim> supports lexical error checking of various sorts.  Thus,
although the error checking is ofttimes very useful, it can indicate
errors where none actually are.  If this proves to be a problem for you,
you may put in your <.vimrc> the following statement: >
    let g:tex_no_error=1
and all error checking by <syntax/tex.vim> will be suppressed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.