Skip to content

Integrating LaTeX3 syntax  #1798

@Rmano

Description

@Rmano

This ticket is related to #1781 about adopting a syntax highlighter specific to vimtex.

Since February 2020 (more or less) the LaTeX3 programming layer (expl3) has been incorporated in the default LaTeX format (at least for pdflatex, lualatex and xelatex). It is used more and more and, for people that are programming packages, it is quite the layer to use nowadays.

Syntax highlight of expl3 code snippets is quite awful:

image

There is a plugin available at https://github.com/wtsnjp/vim-expl3 that makes things quite better:

image

But it has the problems that:

  • it has to be switched manually (set ft=expl3)
  • it acts on the whole file, and the highlighting of the "normal" part of the document is better handled with the existing highlighter.

The expl3 syntax should be enabled only:

  1. locally, for code enclosed in \ExplSyntaxOn and \ExplSyntaxOff;
  2. for the whole buffer, if the file starts with \ProvideExplPackage, \ProvideExplClass,\ProvideExplFile.

A quick-and-dirty stopgap solution I use now is having in my .vimrc:

"
" latex3 syntax highlight fix
"
nnoremap <leader>3 :syn match texStatement "\\[a-zA-Z_:@]\+"<CR>
nnoremap <leader>2 :syn match texStatement "\\[a-zA-Z@]\+"<CR>

and manually switching when needed, but at this point doing the same with the @wtsnjp package is quite better.

"
nnoremap <leader>3 :set ft=expl3<CR>
nnoremap <leader>2 :set ft=tex<CR>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions