From 0dc1fd2db79986467e6661f812ad430911a2b592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 18 Oct 2020 10:34:35 +0200 Subject: [PATCH 01/99] wip: remove old style after/tex.vim --- README.md | 3 +- after/syntax/tex.vim | 9 -- autoload/vimtex/options.vim | 1 - autoload/vimtex/syntax.vim | 34 ----- autoload/vimtex/syntax/after.vim | 136 ------------------ autoload/vimtex/syntax/core.vim | 26 ---- autoload/vimtex/syntax/misc.vim | 18 --- autoload/vimtex/syntax/p/asymptote.vim | 2 - autoload/vimtex/syntax/p/beamer.vim | 2 - autoload/vimtex/syntax/p/dot2texi.vim | 1 - autoload/vimtex/syntax/p/gnuplottex.vim | 1 - autoload/vimtex/syntax/p/luacode.vim | 1 - autoload/vimtex/syntax/p/markdown.vim | 1 - autoload/vimtex/syntax/p/minted.vim | 2 - autoload/vimtex/syntax/p/pythontex.vim | 1 - autoload/vimtex/syntax/p/tabularx.vim | 2 - autoload/vimtex/syntax/p/tikz.vim | 3 - autoload/vimtex/syntax/p/wiki.vim | 1 - autoload/vimtex/syntax/packages.vim | 7 +- doc/vimtex.txt | 30 ++-- syntax/tex.vim | 27 +++- test/tests/test-syntax/test-alpha.vim | 19 --- test/tests/test-syntax/test-ieeetrantools.vim | 3 - 23 files changed, 48 insertions(+), 282 deletions(-) delete mode 100644 after/syntax/tex.vim delete mode 100644 autoload/vimtex/syntax/after.vim delete mode 100644 test/tests/test-syntax/test-alpha.vim diff --git a/README.md b/README.md index 9b677d4b23..187440957a 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,8 @@ disabled if desired. - Context menu on citations (e.g. `\cite{...}`) mapped to `` - Improved folding (`:h 'foldexpr'`) - Improved indentation (`:h 'indentexpr'`) -- Improved syntax highlighting +- Syntax highlighting + - A consistent core syntax specification - Highlight matching delimiters - Support for `biblatex`/`natbib` package - Support for `cleveref` package diff --git a/after/syntax/tex.vim b/after/syntax/tex.vim deleted file mode 100644 index 94b85d868f..0000000000 --- a/after/syntax/tex.vim +++ /dev/null @@ -1,9 +0,0 @@ -" vimtex - LaTeX plugin for Vim -" -" Maintainer: Karl Yngve Lervåg -" Email: karl.yngve@gmail.com -" - -if !get(g:, 'vimtex_syntax_alpha') - call vimtex#syntax#init_post() -endif diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index 8f4be01fff..4f7badc109 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -261,7 +261,6 @@ function! vimtex#options#init() abort " {{{1 call s:init_option('vimtex_subfile_start_local', 0) - call s:init_option('vimtex_syntax_alpha', $VIMTEX_ALPHA) call s:init_option('vimtex_syntax_config', { \ 'conceal': get(g:, 'tex_conceal', 'abdmgsS'), \ 'conceal_set_super': diff --git a/autoload/vimtex/syntax.vim b/autoload/vimtex/syntax.vim index 2a6ce158d7..48c81238d5 100644 --- a/autoload/vimtex/syntax.vim +++ b/autoload/vimtex/syntax.vim @@ -4,40 +4,6 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#init() abort " {{{1 - " This script is a fork of version 119 (dated 2020-06-29) of the syntax script - " "tex.vim" created and maintained by Charles E. Campbell [0]. - " - " [0]: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_TEX - - if exists('b:current_syntax') - return - elseif !get(g:, 'vimtex_syntax_alpha') - source $VIMRUNTIME/syntax/tex.vim - return - endif - - call vimtex#syntax#core#init() -endfunction - - " }}}1 -function! vimtex#syntax#init_post() abort " {{{1 - if !get(g:, 'vimtex_syntax_enabled', 1) | return | endif - - " The following ensures that syntax addons are not loaded until after the - " filetype plugin has been sourced. See e.g. #1428 for more info. - if exists('b:vimtex') - call vimtex#syntax#after#load() - else - augroup vimtex_syntax - autocmd! - autocmd User VimtexEventInitPost call vimtex#syntax#after#load() - augroup END - endif -endfunction - -" }}}1 - function! vimtex#syntax#stack(...) abort " {{{1 let l:pos = a:0 > 0 ? [a:1, a:2] : [line('.'), col('.')] if mode() ==# 'i' diff --git a/autoload/vimtex/syntax/after.vim b/autoload/vimtex/syntax/after.vim deleted file mode 100644 index 1d7a83320d..0000000000 --- a/autoload/vimtex/syntax/after.vim +++ /dev/null @@ -1,136 +0,0 @@ -" vimtex - LaTeX plugin for Vim -" -" Maintainer: Karl Yngve Lervåg -" Email: karl.yngve@gmail.com -" - -function! vimtex#syntax#after#load() abort " {{{1 - if s:is_loaded() | return | endif - - " Initialize project cache (used e.g. for the minted package) - if !has_key(b:vimtex, 'syntax') - let b:vimtex.syntax = {} - endif - - " Initialize b:vimtex_syntax - let b:vimtex_syntax = {} - - " Reset included syntaxes (necessary e.g. when doing :e) - call vimtex#syntax#misc#include_reset() - - " Set some better defaults - syntax spell toplevel - syntax sync maxlines=500 - - " Load some general syntax improvements - call vimtex#syntax#after#general() - - " Load syntax for documentclass and packages - call vimtex#syntax#packages#init() - - " Hack to make it possible to determine if vimtex syntax was loaded - syntax match texVimtexLoaded 'dummyVimtexLoadedText' contained -endfunction - -" }}}1 -function! vimtex#syntax#after#general() abort " {{{1 - if !exists('b:vimtex_syntax') | return | endif - - " I don't see why we can't match Math zones in the MatchNMGroup - if !exists('g:tex_no_math') - syntax cluster texMatchNMGroup add=@texMathZones - endif - - " Todo elements - syntax match texStatement '\\todo\w*' contains=texTodo - syntax match texTodo '\\todo\w*' - - " Fix strange mistake in main syntax file where \usepackage is added to the - " texInputFile group - syntax match texDocType /\\usepackage\>/ - \ nextgroup=texBeginEndName,texDocTypeArgs - - " Improve support for italic and bold fonts - " Note: This essentially fixes a couple of bugs in the main syntax script - if get(g:, 'tex_fast', 'b') =~# 'b' - let l:spell = get(g:, 'tex_nospell') ? '' : ',@Spell' - if empty(l:spell) - syntax cluster texMatchGroup add=texBoldStyle,texBoldItalStyle,texItalStyle,texItalBoldStyle - syntax cluster texMatchNMGroup add=texBoldStyle,texBoldItalStyle,texItalStyle,texItalBoldStyle - syntax cluster texStyleGroup add=texBoldStyle,texBoldItalStyle,texItalStyle,texItalBoldStyle - endif - - let l:conceal = get(g:, 'tex_conceal', 'b') =~# 'b' ? 'concealends' : '' - if empty(l:conceal) - let l:matrix = [ - \ ['texBoldStyle', 'texBoldGroup', ['textbf']], - \ ['texBoldItalStyle', 'texItalGroup', ['textit']], - \ ['texItalStyle', 'texItalGroup', ['textit']], - \ ['texItalBoldStyle', 'texBoldGroup', ['textbf']], - \ ['texEmphStyle', 'texItalGroup', ['emph']], - \ ['texEmphStyle', 'texBoldGroup', ['texts[cfl]', 'textup', 'texttt']], - \] - else - let l:matrix = empty(l:spell) - \ ? [['texEmphStyle', 'texBoldGroup', ['texts[cfl]', 'textup', 'texttt']]] - \ : [] - endif - - for [l:style, l:group, l:commands] in l:matrix - for l:cmd in l:commands - execute 'syntax region' l:style 'matchgroup=texTypeStyle' - \ 'start="\\' . l:cmd . '\s*{" end="}"' - \ l:conceal - \ 'contains=@' . l:group . l:spell - endfor - endfor - endif - - " Allow arguments in newenvironments - syntax region texEnvName contained matchgroup=Delimiter - \ start="{"rs=s+1 end="}" - \ nextgroup=texEnvBgn,texEnvArgs contained skipwhite skipnl - syntax region texEnvArgs contained matchgroup=Delimiter - \ start="\["rs=s+1 end="]" - \ nextgroup=texEnvBgn,texEnvArgs skipwhite skipnl - syntax cluster texEnvGroup add=texDefParm,texNewEnv,texComment - - " Add support for \renewenvironment and \renewcommand - syntax match texNewEnv "\\renewenvironment\>" - \ nextgroup=texEnvName skipwhite skipnl - syntax match texNewCmd "\\renewcommand\>" - \ nextgroup=texCmdName skipwhite skipnl - - " Match nested DefParms - syntax match texDefParmNested contained "##\+\d\+" - highlight def link texDefParmNested Identifier - syntax cluster texEnvGroup add=texDefParmNested - syntax cluster texCmdGroup add=texDefParmNested - - " Do not check URLs and acronyms in comments - " Source: https://github.com/lervag/vimtex/issues/562 - syntax match texCommentURL "\w\+:\/\/[^[:space:]]\+" - \ contains=@NoSpell containedin=texComment contained - syntax match texCommentAcronym '\v<(\u|\d){3,}s?>' - \ contains=@NoSpell containedin=texComment contained - highlight def link texCommentURL Comment - highlight def link texCommentAcronym Comment - - " Add nospell for commands per configuration - syntax region texVimtexNoSpell matchgroup=Delimiter - \ start='{' end='}' - \ contained contains=@NoSpell - for l:macro in g:vimtex_syntax_nospell_commands - execute 'syntax match texStatement /\\' . l:macro . '/' - \ 'nextgroup=texVimtexNospell' - endfor -endfunction - -" }}}1 - -function! s:is_loaded() abort " {{{1 - let l:result = vimtex#util#command('syntax') - return !empty(filter(l:result, 'v:val =~# "texVimtexLoaded"')) -endfunction - -" }}}1 diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index c9c14db2d2..5b2f03ecc5 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -408,32 +408,6 @@ function! vimtex#syntax#core#init() abort " {{{1 call s:init_highlights(l:cfg) let b:current_syntax = 'tex' - - if exists('b:vimtex') - call vimtex#syntax#core#load() - else - augroup vimtex_syntax - autocmd! - autocmd User VimtexEventInitPost call vimtex#syntax#core#load() - augroup END - endif -endfunction - -" }}}1 -function! vimtex#syntax#core#load() abort " {{{1 - " Initialize b:vimtex_syntax - let b:vimtex_syntax = {} - - " Initialize project cache (used e.g. for the minted package) - if !has_key(b:vimtex, 'syntax') - let b:vimtex.syntax = {} - endif - - " Reset included syntaxes (necessary e.g. when doing :e) - call vimtex#syntax#misc#include_reset() - - " Load syntax for documentclass and packages - call vimtex#syntax#packages#init() endfunction " }}}1 diff --git a/autoload/vimtex/syntax/misc.vim b/autoload/vimtex/syntax/misc.vim index b7e632dc8d..bc7ed82b6b 100644 --- a/autoload/vimtex/syntax/misc.vim +++ b/autoload/vimtex/syntax/misc.vim @@ -4,24 +4,6 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#misc#add_to_section_clusters(group) abort " {{{1 - if get(g:, 'vimtex_syntax_alpha') | return | endif - - for l:cluster in [ - \ 'texPartGroup', - \ 'texChapterGroup', - \ 'texSectionGroup', - \ 'texSubSectionGroup', - \ 'texSubSubSectionGroup', - \ 'texParaGroup', - \] - execute printf('syntax cluster %s add=%s', l:cluster, a:group) - endfor - - execute printf('syntax cluster texVimtexGlobal add=%s', a:group) -endfunction - -" }}}1 function! vimtex#syntax#misc#include(name) abort " {{{1 let l:inc_name = 'vimtex_nested_' . a:name diff --git a/autoload/vimtex/syntax/p/asymptote.vim b/autoload/vimtex/syntax/p/asymptote.vim index 25f2f95303..d54cb03d27 100644 --- a/autoload/vimtex/syntax/p/asymptote.vim +++ b/autoload/vimtex/syntax/p/asymptote.vim @@ -8,8 +8,6 @@ function! vimtex#syntax#p#asymptote#load() abort " {{{1 if has_key(b:vimtex_syntax, 'asymptote') | return | endif let b:vimtex_syntax.asymptote = 1 - call vimtex#syntax#misc#add_to_section_clusters('texZoneAsymptote') - if !empty(vimtex#syntax#misc#include('asy')) syntax region texZoneAsymptote \ start='\\begin{asy\z(def\)\?}'rs=s diff --git a/autoload/vimtex/syntax/p/beamer.vim b/autoload/vimtex/syntax/p/beamer.vim index 84ed5a3dc8..69fae16917 100644 --- a/autoload/vimtex/syntax/p/beamer.vim +++ b/autoload/vimtex/syntax/p/beamer.vim @@ -18,8 +18,6 @@ function! vimtex#syntax#p#beamer#load() abort " {{{1 \ '\\includegraphics<[^>]*>\(\[.\{-}\]\)\=\s*{.\{-}}' \ contains=texStatement,texBeamerOpt,texInputCurlies,texInputFileOpt - call vimtex#syntax#misc#add_to_section_clusters('texStatementBeamer') - highlight link texStatementBeamer texStatement highlight link texBeamerOpt Identifier highlight link texBeamerDelimiter Delimiter diff --git a/autoload/vimtex/syntax/p/dot2texi.vim b/autoload/vimtex/syntax/p/dot2texi.vim index 46285f41e1..c9255546a4 100644 --- a/autoload/vimtex/syntax/p/dot2texi.vim +++ b/autoload/vimtex/syntax/p/dot2texi.vim @@ -9,7 +9,6 @@ function! vimtex#syntax#p#dot2texi#load() abort " {{{1 let b:vimtex_syntax.dot2texi = 1 call vimtex#syntax#misc#include('dot') - call vimtex#syntax#misc#add_to_section_clusters('texZoneDot') syntax region texZoneDot \ start="\\begin{dot2tex}"rs=s \ end="\\end{dot2tex}"re=e diff --git a/autoload/vimtex/syntax/p/gnuplottex.vim b/autoload/vimtex/syntax/p/gnuplottex.vim index c035bc6bbe..c325f21480 100644 --- a/autoload/vimtex/syntax/p/gnuplottex.vim +++ b/autoload/vimtex/syntax/p/gnuplottex.vim @@ -9,7 +9,6 @@ function! vimtex#syntax#p#gnuplottex#load() abort " {{{1 let b:vimtex_syntax.gnuplottex = 1 call vimtex#syntax#misc#include('gnuplot') - call vimtex#syntax#misc#add_to_section_clusters('texZoneGnuplot') syntax region texZoneGnuplot \ start='\\begin{gnuplot}\(\_s*\[\_[\]]\{-}\]\)\?'rs=s \ end='\\end{gnuplot}'re=e diff --git a/autoload/vimtex/syntax/p/luacode.vim b/autoload/vimtex/syntax/p/luacode.vim index 0a3d96b7cc..5211268492 100644 --- a/autoload/vimtex/syntax/p/luacode.vim +++ b/autoload/vimtex/syntax/p/luacode.vim @@ -9,7 +9,6 @@ function! vimtex#syntax#p#luacode#load() abort " {{{1 let b:vimtex_syntax.luacode = 1 call vimtex#syntax#misc#include('lua') - call vimtex#syntax#misc#add_to_section_clusters('texZoneLua') syntax region texZoneLua \ start='\\begin{luacode\*\?}'rs=s \ end='\\end{luacode\*\?}'re=e diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index f558dc6b9b..8db9af5012 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -8,7 +8,6 @@ function! vimtex#syntax#p#markdown#load() abort " {{{1 if has_key(b:vimtex_syntax, 'markdown') | return | endif let b:vimtex_syntax.markdown = 1 - call vimtex#syntax#misc#add_to_section_clusters('texZoneMarkdown') call vimtex#syntax#misc#include('markdown') " Don't quite know why this is necessary, but it is diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index 954c64b996..f9e9763187 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -43,7 +43,6 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 syntax match texStatement '\\newmint\%(ed\|inline\)\?' nextgroup=texMintedName,texMintedNameOpt " Match "unknown" environments - call vimtex#syntax#misc#add_to_section_clusters('texZoneMinted') syntax region texZoneMinted \ start="\\begin{minted}\%(\_s*\[\_[^\]]\{-}\]\)\?\_s*{\w\+}"rs=s \ end="\\end{minted}"re=e @@ -72,7 +71,6 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 let l:group_main = 'texZone' . l:name let l:group_arg = 'texArg' . l:name let l:group_arg_zone = 'texArgZone' . l:name - call vimtex#syntax#misc#add_to_section_clusters(l:group_main) if empty(l:cluster) let l:transparent = '' diff --git a/autoload/vimtex/syntax/p/pythontex.vim b/autoload/vimtex/syntax/p/pythontex.vim index a2ca94f7f2..3080b8ffaf 100644 --- a/autoload/vimtex/syntax/p/pythontex.vim +++ b/autoload/vimtex/syntax/p/pythontex.vim @@ -18,7 +18,6 @@ function! vimtex#syntax#p#pythontex#load() abort " {{{1 \ start='\z([#@]\)' end='\z1' \ contained contains=@vimtex_nested_python - call vimtex#syntax#misc#add_to_section_clusters('texZonePythontex') syntax region texZonePythontex \ start='\\begin{pyblock}'rs=s \ end='\\end{pyblock}'re=e diff --git a/autoload/vimtex/syntax/p/tabularx.vim b/autoload/vimtex/syntax/p/tabularx.vim index b82ffca846..f5647d5d9f 100644 --- a/autoload/vimtex/syntax/p/tabularx.vim +++ b/autoload/vimtex/syntax/p/tabularx.vim @@ -8,8 +8,6 @@ function! vimtex#syntax#p#tabularx#load() abort " {{{1 if has_key(b:vimtex_syntax, 'tabularx') | return | endif let b:vimtex_syntax.tabularx = 1 - call vimtex#syntax#misc#add_to_section_clusters('texTabular') - syntax match texTabular '\\begin{tabular}\_[^{]\{-}\ze{' \ contains=texBeginEnd \ nextgroup=texTabularArg diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index cc12907f02..929a830ad7 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -8,9 +8,6 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 if has_key(b:vimtex_syntax, 'tikz') | return | endif let b:vimtex_syntax.tikz = 1 - call vimtex#syntax#misc#add_to_section_clusters('texTikzSet') - call vimtex#syntax#misc#add_to_section_clusters('texTikzpicture') - " Define clusters syntax cluster texTikz contains=texTikzEnv,texBeginEnd,texStatement,texTikzSemicolon,texComment,@texVimtexGlobal syntax cluster texTikzOS contains=texTikzOptsCurly,texTikzEqual,texMathZoneX,texTypeSize,texStatement,texLength,texComment diff --git a/autoload/vimtex/syntax/p/wiki.vim b/autoload/vimtex/syntax/p/wiki.vim index 1c6abdc2c7..de759807d0 100644 --- a/autoload/vimtex/syntax/p/wiki.vim +++ b/autoload/vimtex/syntax/p/wiki.vim @@ -8,7 +8,6 @@ function! vimtex#syntax#p#wiki#load() abort " {{{1 if has_key(b:vimtex_syntax, 'wiki') | return | endif let b:vimtex_syntax.wiki = 1 - call vimtex#syntax#misc#add_to_section_clusters('texZoneWiki') call vimtex#syntax#misc#include('markdown') syntax region texZoneWiki diff --git a/autoload/vimtex/syntax/packages.vim b/autoload/vimtex/syntax/packages.vim index 4cdf9db736..2acc565b82 100644 --- a/autoload/vimtex/syntax/packages.vim +++ b/autoload/vimtex/syntax/packages.vim @@ -5,7 +5,12 @@ " function! vimtex#syntax#packages#init() abort " {{{1 - if !exists('b:vimtex_syntax') | return | endif + if !exists('b:vimtex') || !exists('b:vimtex_syntax') | return | endif + + " Initialize project cache (used e.g. for the minted package) + if !has_key(b:vimtex, 'syntax') + let b:vimtex.syntax = {} + endif try call vimtex#syntax#p#{b:vimtex.documentclass}#load() diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 9d6f910fd5..0a13b5402a 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -109,16 +109,16 @@ the plugin. ------------------------------------------------------------------------------ COMMENT ON INTERNAL TEX PLUGIN *vimtex-comment-internal* -Vim ships with some LaTeX support out of the box. In particular, it provides +Vim ships with LaTeX support out of the box. In particular, it provides pretty good syntax highlighting (|ft-tex-syntax|), indentation (see the source file $VIMRUNTIME/indent/tex.vim for the documentation), and some sensible options (|ft-tex-plugin|). -When |vimtex| is active, it will be used as the main |ftplugin|. It will -define the same set of sensible settings as the internal plugin. However, -|vimtex| does not provide its own syntax, instead it adds a few minor -improvements to |ft-tex-syntax|, see |vimtex-syntax|. |vimtex| also provides its -own indentation plugin, see |vimtex-indent|. +When |vimtex| is active, it will by default be used as the main |ftplugin|, +syntax plugin (|vimtex-syntax|) and indent plugin (|vimtex-indent|). It will +define the same set of sensible settings as the internal plugin (and much +more, of course). Various features may be disabled by the user, see the +`g:vimtex_*_enabled` style of configuration options in |vimtex-options|. *vimtex-tex-flavor* |ft-tex-plugin| supports both plain TeX, ConTeXt, and LaTeX files. This means @@ -196,7 +196,8 @@ FEATURE OVERVIEW *vimtex-features* - Context menu on citations (e.g. `\cite{...}`) mapped to `` - Folding - Indentation -- Improved syntax highlighting +- Syntax highlighting + - A consistent core syntax specification - Highlight matching delimiters - Support for `biblatex`/`natbib` package - Support for `cleveref` package @@ -293,7 +294,6 @@ vimtex, but that are instead better provided by other plugins. * Linting and syntax checking |vimtex-nf-linting| * Snippets/Templates |vimtex-nf-snippets| -* Syntax highlighting |vimtex-nf-syntax| * Tag navigation |vimtex-nf-tag-nav| * Manipulate surrounding cmds/delims/envs |vimtex-nf-surround| * Enhanced matching and higlighting of delimiters |vimtex-nf-enhanced-matchparen| @@ -326,10 +326,6 @@ Snippets/Templates~ Snippets and/or templates are provided by for instance `neosnippet` and `UltiSnips`. See |vimtex-neosnippet| and |vimtex-UltiSnips| for more info. -Syntax highlighting~ - *vimtex-nf-syntax* - See |vimtex-comment-internal|. - Tag navigation~ *vimtex-nf-tag-nav* One may navigate by tags with the |CTRL-]| mapping, e.g. from @@ -1992,7 +1988,7 @@ OPTIONS *vimtex-options* Default value: 0. *g:vimtex_syntax_enabled* - Use this option to disable/enable |vimtex| improved syntax highlighting. + Use this option to disable/enable syntax highlighting as provided by vimtex. Default value: 1. @@ -3628,9 +3624,9 @@ Associated settings: ============================================================================== SYNTAX HIGHLIGHTING *vimtex-syntax* -Vim ships with syntax highlighting for LaTeX documents out of the box, please -see |ft-tex-syntax|. |vimtex| therefore does not provide its own syntax -highlighting. However, |vimtex| does add some minor improvements: +|vimtex| provides a core syntax plugin that should generally work well out of +the box. It includes package specific syntax highlighting for a lot of +different packages, e.g.: - Support for `biblatex` and `natbib` package - Support for `cleveref` package @@ -3638,6 +3634,8 @@ highlighting. However, |vimtex| does add some minor improvements: - Nested syntax highlighting for `dot2tex`, `lualatex`, `gnuplottex`, `asymptote`, `pythontex`, `listings`, and `minted` +See also |vimtex-comment-internal| on the internal syntax plugin shipped with Vim. + *vimtex-syntax-packages* The syntax improvements for a specific package is loaded if that package is detected in the current document, see |vimtex-package-detection|. This diff --git a/syntax/tex.vim b/syntax/tex.vim index a6abd4076a..3ceb008494 100644 --- a/syntax/tex.vim +++ b/syntax/tex.vim @@ -3,5 +3,30 @@ " Maintainer: Karl Yngve Lervåg " Email: karl.yngve@gmail.com " +" +" This script is a fork of version 119 (dated 2020-06-29) of the syntax script +" "tex.vim" created and maintained by Charles E. Campbell [0]. +" +" [0]: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_TEX + +if !get(g:, 'vimtex_syntax_enabled', 1) | finish | endif +if exists('b:current_syntax') | finish | endif + +" Load core syntax (does not depend on vimtex state) +call vimtex#syntax#core#init() + + +" Initialize buffer local syntax state +let b:vimtex_syntax = {} +call vimtex#syntax#misc#include_reset() + -call vimtex#syntax#init() +" Load package specific syntax (may depend on vimtex state) +if exists('b:vimtex') + call vimtex#syntax#packages#init() +else + augroup vimtex_syntax + autocmd! + autocmd User VimtexEventInitPost ++once call vimtex#syntax#packages#init() + augroup END +endif diff --git a/test/tests/test-syntax/test-alpha.vim b/test/tests/test-syntax/test-alpha.vim deleted file mode 100644 index 2f93d32f68..0000000000 --- a/test/tests/test-syntax/test-alpha.vim +++ /dev/null @@ -1,19 +0,0 @@ -source common.vim - -let &rtp = '.,' . &rtp -let g:vimtex_fold_enabled = 1 -let g:vimtex_syntax_alpha = 1 - -silent edit test-large.tex - -syntax sync fromstart - -if empty($INMAKE) | finish | endif - -call vimtex#test#assert_equal(len(keys(b:vimtex_syntax)), 20) - -" PythonTeX inside tikzpictures (#1563) -call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 243, 11)) -call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 248, 11)) - -quit! diff --git a/test/tests/test-syntax/test-ieeetrantools.vim b/test/tests/test-syntax/test-ieeetrantools.vim index 1a335f2755..81eb5d0273 100644 --- a/test/tests/test-syntax/test-ieeetrantools.vim +++ b/test/tests/test-syntax/test-ieeetrantools.vim @@ -7,9 +7,6 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texMathZoneIEEEeqnA', 8, 1)) call vimtex#test#assert(vimtex#syntax#in('texMathZoneIEEEeqnA', 13, 1)) -if !get(g:, 'vimtex_syntax_alpha') - call vimtex#test#assert(vimtex#syntax#in('texDocZone', 20, 1)) -endif call vimtex#test#assert(vimtex#syntax#in('texMathZoneC', 24, 1)) call vimtex#test#assert(vimtex#syntax#in('texMathZoneIEEEeqnB', 31, 1)) From 4c1bbc9b92e0f59b1ac85776705dd42552abbe4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 19 Oct 2020 00:16:51 +0200 Subject: [PATCH 02/99] wip: simplify and rename clusters and some groups --- autoload/vimtex/syntax/core.vim | 132 +++++++++------------ autoload/vimtex/syntax/p/array.vim | 2 +- autoload/vimtex/syntax/p/asymptote.vim | 6 +- autoload/vimtex/syntax/p/biblatex.vim | 20 ++-- autoload/vimtex/syntax/p/cleveref.vim | 10 +- autoload/vimtex/syntax/p/dot2texi.vim | 2 +- autoload/vimtex/syntax/p/gnuplottex.vim | 2 +- autoload/vimtex/syntax/p/hyperref.vim | 6 +- autoload/vimtex/syntax/p/ieeetrantools.vim | 12 +- autoload/vimtex/syntax/p/listings.vim | 10 +- autoload/vimtex/syntax/p/luacode.vim | 6 +- autoload/vimtex/syntax/p/markdown.vim | 2 +- autoload/vimtex/syntax/p/minted.vim | 18 +-- autoload/vimtex/syntax/p/moreverb.vim | 12 +- autoload/vimtex/syntax/p/pythontex.vim | 4 +- autoload/vimtex/syntax/p/varioref.vim | 8 +- autoload/vimtex/syntax/p/wiki.vim | 2 +- test/tests/test-syntax/test-markdown.vim | 2 +- test/tests/test-syntax/test-minted.vim | 4 +- test/tests/test-syntax/test-wiki.vim | 2 +- 20 files changed, 122 insertions(+), 140 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 5b2f03ecc5..bd29e2c3c5 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -19,36 +19,22 @@ function! vimtex#syntax#core#init() abort " {{{1 let l:cfg.is_style_document = \ index(['sty', 'cls', 'clo', 'dtx', 'ltx'], l:cfg.ext) >= 0 - " {{{2 Define clusters - - syntax cluster texClusterNewCmd contains=texCmdBody,texComment,texDefParm,texDelimiter,texDocType,texInput,texLength,texLigature,texMathDelim,texMathOper,texNewCmd,texNewEnv,texRefZone,texSection,texBeginEnd,texBeginEndName,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,@texMathZones,texErrorMath,texDefParmNested - syntax cluster texClusterNewEnv contains=texMatcher,texMathDelim,texSpecialChar,texStatement,texDefParm,texNewEnv,texComment,texDefParmNested - - syntax cluster texClusterMathText contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texInputFile,texLength,texLigature,texMatcher,texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ,texNewCmd,texNewEnv,texOnlyMath,texOption,texParen,texRefZone,texSection,texBeginEnd,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texBoldStyle,texItalStyle,texEmphStyle - - syntax cluster texClusterSty contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texBoldStyle,texBoldItalStyle,texItalStyle,texItalBoldStyle,texZone,texInputFile,texOption,texStatementSty,texMatcherSty,@Spell - syntax cluster texClusterBold contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texInputFile,texLength,texLigature,texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ,texNewCmd,texNewEnv,texOnlyMath,texOption,texParen,texRefZone,texSection,texBeginEnd,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texBoldStyle,texBoldItalStyle,texMatcher - syntax cluster texClusterItal contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texInputFile,texLength,texLigature,texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ,texNewCmd,texNewEnv,texOnlyMath,texOption,texParen,texRefZone,texSection,texBeginEnd,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texItalStyle,texEmphStyle,texItalBoldStyle,texMatcher - - syntax cluster texRefGroup contains=texMatcher,texComment,texDelimiter - - syntax cluster texMatchGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texMatcher,texNewCmd,texNewEnv,texOnlyMath,texParen,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texBoldStyle,texBoldItalStyle,texItalStyle,texItalBoldStyle,texZone,texInputFile,texOption,@Spell,@texMathZones - - syntax cluster texMathZones contains=texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ - syntax cluster texMathMatchGroup contains=@texMathZones,texComment,texDefCmd,texDelimiter,texDocType,texInput,texLength,texLigature,texMathDelim,texMathMatcher,texMathOper,texNewCmd,texNewEnv,texRefZone,texSection,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,texErrorMath,texGreek,texSuperscript,texSubscript,texMathSymbol - syntax cluster texMathZoneGroup contains=texComment,texDelimiter,texLength,texMathDelim,texMathMatcher,texMathOper,texMathSymbol,texMathText,texRefZone,texSpecialChar,texStatement,texTypeSize,texTypeStyle,texErrorMath,@NoSpell,texGreek,texSuperscript,texSubscript,texMathSymbol + " Define clusters + syntax cluster texClusterBold contains=TOP,texItalStyle,texItalBoldStyle,texEmphStyle + syntax cluster texClusterItal contains=TOP,texBoldStyle,texBoldItalStyle syntax cluster texClusterComment contains=texTodo,@Spell - - " }}}2 + syntax cluster texClusterMath contains=texComment,texDelimiter,texErrorMath,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texRegionRef,texSpecialChar,texStatement,texSubscript,texSuperscript,texTypeSize,texTypeStyle,@NoSpell + syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texDelimiter,texDocType,texErrorMath,texGreek,texInput,texLength,texLigature,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texNewCmd,texNewEnv,texRegion,texRegionRef,texSection,texSpecialChar,texStatement,texString,texSubscript,texSuperscript,texTypeSize,texTypeStyle + syntax cluster texClusterRef contains=texComment,texDelimiter,texMatcher " {{{2 Primitives " Delimiters - syntax region texMatcher matchgroup=Delimiter start="{" skip="\%(\\\\\)*\\}" end="}" transparent contains=@texMatchGroup,texError - syntax region texMatcher matchgroup=Delimiter start="\[" end="]" transparent contains=@texMatchGroup,texError,@NoSpell - syntax region texMathMatcher matchgroup=Delimiter start="{" skip="\%(\\\\\)*\\}" end="}" contained contains=@texMathMatchGroup - syntax region texParen start="(" end=")" transparent contains=@texMatchGroup,@Spell + syntax region texMatcher matchgroup=Delimiter start="{" skip="\%(\\\\\)*\\}" end="}" transparent contains=TOP + syntax region texMatcher matchgroup=Delimiter start="\[" end="]" transparent contains=TOP,@NoSpell + syntax region texMatcherMath matchgroup=Delimiter start="{" skip="\%(\\\\\)*\\}" end="}" contained contains=@texClusterMathMatch + syntax region texParen start="(" end=")" transparent contains=TOP,@Spell syntax match texDelimiter "&" @@ -82,7 +68,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " Environments syntax match texBeginEnd "\v\\%(begin|end)>" nextgroup=texBeginEndName syntax region texBeginEndName matchgroup=Delimiter start="{" end="}" contained contains=texComment nextgroup=texBeginEndModifier - syntax region texBeginEndModifier matchgroup=Delimiter start="\[" end="]" contained contains=texComment,@texMathZones,@NoSpell + syntax region texBeginEndModifier matchgroup=Delimiter start="\[" end="]" contained contains=texComment,@NoSpell " Some common, specific LaTeX commands " TODO: This should be updated! @@ -154,14 +140,14 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texTypeStyle "\\textmd\>" syntax match texTypeStyle "\\textrm\>" - syntax region texBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" end="}" contains=@texClusterBold,@Spell - syntax region texBoldItalStyle matchgroup=texTypeStyle start="\\textit\s*{" end="}" contains=@texClusterItal,@Spell - syntax region texItalStyle matchgroup=texTypeStyle start="\\textit\s*{" end="}" contains=@texClusterItal,@Spell - syntax region texItalBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" end="}" contains=@texClusterBold,@Spell - syntax region texEmphStyle matchgroup=texTypeStyle start="\\emph\s*{" end="}" contains=@texClusterItal,@Spell - syntax region texEmphStyle matchgroup=texTypeStyle start="\\texts[cfl]\s*{" end="}" contains=@texClusterBold,@Spell - syntax region texEmphStyle matchgroup=texTypeStyle start="\\textup\s*{" end="}" contains=@texClusterBold,@Spell - syntax region texEmphStyle matchgroup=texTypeStyle start="\\texttt\s*{" end="}" contains=@texClusterBold,@Spell + syntax region texBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" end="}" contains=@texClusterBold + syntax region texBoldItalStyle matchgroup=texTypeStyle start="\\textit\s*{" end="}" contains=@texClusterItal + syntax region texItalStyle matchgroup=texTypeStyle start="\\textit\s*{" end="}" contains=@texClusterItal + syntax region texItalBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" end="}" contains=@texClusterBold + syntax region texEmphStyle matchgroup=texTypeStyle start="\\emph\s*{" end="}" contains=@texClusterItal + syntax region texEmphStyle matchgroup=texTypeStyle start="\\texts[cfl]\s*{" end="}" contains=@texClusterBold + syntax region texEmphStyle matchgroup=texTypeStyle start="\\textup\s*{" end="}" contains=@texClusterBold + syntax region texEmphStyle matchgroup=texTypeStyle start="\\texttt\s*{" end="}" contains=@texClusterBold syntax match texTypeStyle "\\mathbb\>" syntax match texTypeStyle "\\mathbf\>" @@ -220,7 +206,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texMathOper "[_^=]" contained " Text Inside Math Zones - syntax region texMathText matchgroup=texStatement start="\\\(\(inter\)\?text\|mbox\)\s*{" end="}" contains=@texClusterMathText,@Spell + syntax region texMathText matchgroup=texStatement start="\\\(\(inter\)\?text\|mbox\)\s*{" end="}" contains=TOP,@Spell " Math environments call vimtex#syntax#core#new_math_zone('A', 'displaymath', 1) @@ -229,17 +215,17 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_math_zone('D', 'math', 1) " Inline Math Zones - syntax region texMathZoneZ matchgroup=texStatement start="\\ensuremath\s*{" matchgroup=texStatement end="}" contains=@texMathZoneGroup + syntax region texMathZoneZ matchgroup=texStatement start="\\ensuremath\s*{" matchgroup=texStatement end="}" contains=@texClusterMath if l:cfg.conceal =~# 'd' && &encoding ==# 'utf-8' - syntax region texMathZoneV matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" concealends contains=@texMathZoneGroup keepend - syntax region texMathZoneW matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" concealends contains=@texMathZoneGroup keepend - syntax region texMathZoneX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" concealends contains=@texMathZoneGroup - syntax region texMathZoneY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" concealends contains=@texMathZoneGroup keepend + syntax region texMathZoneV matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" concealends contains=@texClusterMath keepend + syntax region texMathZoneW matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" concealends contains=@texClusterMath keepend + syntax region texMathZoneX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" concealends contains=@texClusterMath + syntax region texMathZoneY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" concealends contains=@texClusterMath keepend else - syntax region texMathZoneV matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" contains=@texMathZoneGroup keepend - syntax region texMathZoneW matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" contains=@texMathZoneGroup keepend - syntax region texMathZoneX matchgroup=Delimiter start="\$" skip="\%(\\\\\)*\\\$" matchgroup=Delimiter end="\$" contains=@texMathZoneGroup - syntax region texMathZoneY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" contains=@texMathZoneGroup keepend + syntax region texMathZoneV matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" contains=@texClusterMath keepend + syntax region texMathZoneW matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" contains=@texClusterMath keepend + syntax region texMathZoneX matchgroup=Delimiter start="\$" skip="\%(\\\\\)*\\\$" matchgroup=Delimiter end="\$" contains=@texClusterMath + syntax region texMathZoneY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" contains=@texClusterMath keepend endif " Math delimiters: \left... and \right... @@ -275,36 +261,35 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texSpecialChar "\\[SP@]\ze\A" endif syntax match texSpecialChar "\\\\" - syntax match texOnlyMath "[_^]" + syntax match texOnlyMath "[_^]" contained syntax match texSpecialChar "\^\^[0-9a-f]\{2}\|\^\^\S" " {{{2 Specific commands/environments " Verbatim - syntax region texZone start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}" - syntax region texZone start="\\verb\*\?\z([^\ta-zA-Z]\)" end="\z1" + syntax region texRegionVerb start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}" + syntax region texRegionVerb start="\\verb\*\?\z([^\ta-zA-Z]\)" end="\z1" if l:cfg.is_style_document - syntax region texZone start="\\verb\*\?\z([^\ta-zA-Z@]\)" end="\z1" + syntax region texRegionVerb start="\\verb\*\?\z([^\ta-zA-Z@]\)" end="\z1" endif " Tex Reference Zones - syntax region texZone matchgroup=texStatement start="@samp{" end="}" contains=@texRefGroup - syntax region texRefZone matchgroup=texStatement start="\\nocite{" end="}" contains=@texRefGroup - syntax region texRefZone matchgroup=texStatement start="\\bibliography{" end="}" contains=@texRefGroup - syntax region texRefZone matchgroup=texStatement start="\\label{" end="}" contains=@texRefGroup - syntax region texRefZone matchgroup=texStatement start="\\\(page\|eq\)ref{" end="}" contains=@texRefGroup - syntax region texRefZone matchgroup=texStatement start="\\v\?ref{" end="}" contains=@texRefGroup - syntax region texRefOption contained matchgroup=Delimiter start='\[' end=']' contains=@texRefGroup,texRefZone nextgroup=texRefOption,texCite - syntax region texCite contained matchgroup=Delimiter start='{' end='}' contains=@texRefGroup,texRefZone,texCite - syntax match texRefZone '\\cite\%([tp]\*\?\)\?\>' nextgroup=texRefOption,texCite + syntax match texRegionRef '\\cite\%([tp]\*\?\)\?\>' nextgroup=texRefOption,texRefCite + syntax region texRegionRef matchgroup=texStatement start="\\nocite{" end="}" contains=@texClusterRef + syntax region texRegionRef matchgroup=texStatement start="\\bibliography{" end="}" contains=@texClusterRef + syntax region texRegionRef matchgroup=texStatement start="\\label{" end="}" contains=@texClusterRef + syntax region texRegionRef matchgroup=texStatement start="\\\(page\|eq\)ref{" end="}" contains=@texClusterRef + syntax region texRegionRef matchgroup=texStatement start="\\v\?ref{" end="}" contains=@texClusterRef + syntax region texRefOption matchgroup=Delimiter start='\[' end=']' contains=@texClusterRef,texRegionRef nextgroup=texRefOption,texRefCite contained + syntax region texRefCite matchgroup=Delimiter start='{' end='}' contains=@texClusterRef,texRegionRef,texRefCite contained " \makeatletter ... \makeatother sections " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do " In short: allow @ in multicharacter macro name - syntax region texGroupSty matchgroup=texStatement start='\\makeatletter' end='\\makeatother' contains=@texClusterSty syntax match texStatementSty "\\[a-zA-Z@]\+" contained - syntax region texMatcherSty matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=@texClusterSty,texError contained - syntax region texMatcherSty matchgroup=Delimiter start="\[" end="]" contains=@texClusterSty,texError contained + syntax region texRegionSty matchgroup=texStatement start='\\makeatletter' end='\\makeatother' contains=TOP,texStatementSty + syntax region texMatcherSty matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=TOP,texStatementSty contained + syntax region texMatcherSty matchgroup=Delimiter start="\[" end="]" contains=TOP,texStatementSty contained " }}}2 @@ -313,11 +298,12 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texNewCmd "\\newcommand\>" nextgroup=texCmdName skipwhite skipnl syntax region texCmdName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texCmdArgs,texCmdBody skipwhite skipnl syntax region texCmdArgs contained matchgroup=Delimiter start="\["rs=s+1 end="]" nextgroup=texCmdBody skipwhite skipnl - syntax region texCmdBody contained matchgroup=Delimiter start="{"rs=s+1 skip="\\\\\|\\[{}]" matchgroup=Delimiter end="}" contains=@texClusterNewCmd + syntax region texCmdBody contained matchgroup=Delimiter start="{"rs=s+1 skip="\\\\\|\\[{}]" matchgroup=Delimiter end="}" contains=TOP + syntax match texNewEnv "\\newenvironment\>" nextgroup=texEnvName skipwhite skipnl syntax region texEnvName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texEnvBgn skipwhite skipnl - syntax region texEnvBgn contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texEnvEnd skipwhite skipnl contains=@texClusterNewEnv - syntax region texEnvEnd contained matchgroup=Delimiter start="{"rs=s+1 end="}" skipwhite skipnl contains=@texClusterNewEnv + syntax region texEnvBgn contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texEnvEnd skipwhite skipnl contains=TOP + syntax region texEnvEnd contained matchgroup=Delimiter start="{"rs=s+1 end="}" skipwhite skipnl contains=TOP " Allow arguments in newenvironments syntax region texEnvName contained matchgroup=Delimiter @@ -419,22 +405,20 @@ function! vimtex#syntax#core#new_math_zone(sfx, mathzone, starred) abort " {{{1 execute 'syntax match texBadMath /\\end\s*{\s*' . a:mathzone . '\*\?\s*}/' let grp = 'texMathZone' . a:sfx - execute 'syntax cluster texMathZones add=' . grp execute 'syntax region ' . grp \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\s*}''' \ . ' end=''\\end\s*{\s*' . a:mathzone . '\s*}''' - \ . ' keepend contains=@texMathZoneGroup' - execute 'highlight def link '.grp.' texMath' + \ . ' keepend contains=@texClusterMath' + execute 'highlight def link ' . grp . ' texMath' if !a:starred | return | endif let grp .= 'S' - execute 'syntax cluster texMathZones add=' . grp execute 'syntax region ' . grp \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\*\s*}''' \ . ' end=''\\end\s*{\s*' . a:mathzone . '\*\s*}''' - \ . ' keepend contains=@texMathZoneGroup' - execute 'highlight def link '.grp.' texMath' + \ . ' keepend contains=@texClusterMath' + execute 'highlight def link ' . grp . ' texMath' endfunction " }}}1 @@ -455,7 +439,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight texBoldItalStyle gui=bold,italic cterm=bold,italic highlight texItalBoldStyle gui=bold,italic cterm=bold,italic highlight def link texEmphStyle texItalStyle - highlight def link texCite texRefZone + highlight def link texRefCite texRegionRef highlight def link texDefCmd texDef highlight def link texDefName texDef highlight def link texDocType texCmdName @@ -466,7 +450,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texMathDelimSet1 texMathDelim highlight def link texMathDelimSet2 texMathDelim highlight def link texMathDelimKey texMathDelim - highlight def link texMathMatcher texMath + highlight def link texMatcherMath texMath highlight def link texAccent texStatement highlight def link texGreek texStatement highlight def link texSuperscript texStatement @@ -503,7 +487,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texNewCmd Statement highlight def link texNewEnv Statement highlight def link texOption Number - highlight def link texRefZone Special + highlight def link texRegionRef Special highlight def link texSection PreCondit highlight def link texSpaceCodeChar Special highlight def link texSpecialChar SpecialChar @@ -511,7 +495,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texString String highlight def link texTodo Todo highlight def link texType Type - highlight def link texZone PreCondit + highlight def link texRegion PreCondit " New highlight def link texCommentURL Comment @@ -938,8 +922,8 @@ endfunction " }}}1 function! s:match_conceal_super_sub(cfg) " {{{1 - syntax region texSuperscript matchgroup=Delimiter start='\^{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSuperscripts,texStatement,texSubscript,texSuperscript,texMathMatcher - syntax region texSubscript matchgroup=Delimiter start='_{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSubscripts,texStatement,texSubscript,texSuperscript,texMathMatcher + syntax region texSuperscript matchgroup=Delimiter start='\^{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSuperscripts,texStatement,texSubscript,texSuperscript,texMatcherMath + syntax region texSubscript matchgroup=Delimiter start='_{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSubscripts,texStatement,texSubscript,texSuperscript,texMatcherMath for [l:from, l:to] in filter(copy(s:map_super), \ {_, x -> x[0][0] ==# '\' || x[0] =~# a:cfg.conceal_set_super}) diff --git a/autoload/vimtex/syntax/p/array.vim b/autoload/vimtex/syntax/p/array.vim index 76090dd73d..cced938f7e 100644 --- a/autoload/vimtex/syntax/p/array.vim +++ b/autoload/vimtex/syntax/p/array.vim @@ -27,7 +27,7 @@ function! vimtex#syntax#p#array#load() abort " {{{1 \ 'skip="\%(\\\\\)*\\\$"' \ 'end="\$"' \ 'end="%stopzone\>"' - \ 'contains=@texMathZoneGroup' + \ 'contains=@texClusterMath' \ (l:concealed ? 'concealends' : '') endfunction diff --git a/autoload/vimtex/syntax/p/asymptote.vim b/autoload/vimtex/syntax/p/asymptote.vim index d54cb03d27..a88afdfe61 100644 --- a/autoload/vimtex/syntax/p/asymptote.vim +++ b/autoload/vimtex/syntax/p/asymptote.vim @@ -9,19 +9,19 @@ function! vimtex#syntax#p#asymptote#load() abort " {{{1 let b:vimtex_syntax.asymptote = 1 if !empty(vimtex#syntax#misc#include('asy')) - syntax region texZoneAsymptote + syntax region texRegionAsymptote \ start='\\begin{asy\z(def\)\?}'rs=s \ end='\\end{asy\z1}'re=e \ keepend \ transparent \ contains=texBeginEnd,@vimtex_nested_asy else - syntax region texZoneAsymptote + syntax region texRegionAsymptote \ start='\\begin{asy\z(def\)\?}'rs=s \ end='\\end{asy\z1}'re=e \ keepend \ contains=texBeginEnd - highlight def link texZoneAsymptote texZone + highlight def link texRegionAsymptote texRegion endif endfunction diff --git a/autoload/vimtex/syntax/p/biblatex.vim b/autoload/vimtex/syntax/p/biblatex.vim index f96ad55fea..2eec747479 100644 --- a/autoload/vimtex/syntax/p/biblatex.vim +++ b/autoload/vimtex/syntax/p/biblatex.vim @@ -28,7 +28,7 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 \] execute 'syntax match texStatement' \ '/\v\\' . l:pattern . '\ze\s*%(\[|\{)/' - \ 'nextgroup=texRefOption,texCite' + \ 'nextgroup=texRefOption,texRefCite' endfor for l:pattern in [ @@ -44,7 +44,7 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 \] execute 'syntax match texStatement' \ '/\v\\' . l:pattern . '\ze\s*%(\[|\{)/' - \ 'nextgroup=texRefOptions,texCites' + \ 'nextgroup=texRefOptions,texRefCites' endfor for l:pattern in [ @@ -59,22 +59,22 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 syntax region texRefOptions contained matchgroup=Delimiter \ start='\[' end=']' - \ contains=@texRefGroup,texRefZone - \ nextgroup=texRefOptions,texCites + \ contains=@texClusterRef,texRegionRef + \ nextgroup=texRefOptions,texRefCites - syntax region texCites contained matchgroup=Delimiter + syntax region texRefCites contained matchgroup=Delimiter \ start='{' end='}' - \ contains=@texRefGroup,texRefZone,texCites - \ nextgroup=texRefOptions,texCites + \ contains=@texClusterRef,texRegionRef,texRefCites + \ nextgroup=texRefOptions,texRefCites syntax region texQuoteLang contained matchgroup=Delimiter \ start='{' end='}' \ transparent - \ contains=@texMatchGroup - \ nextgroup=texRefOption,texCite + \ contains=@texClusterMG + \ nextgroup=texRefOption,texRefCite highlight def link texRefOptions texRefOption - highlight def link texCites texCite + highlight def link texRefCites texRefCite endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/cleveref.vim b/autoload/vimtex/syntax/p/cleveref.vim index d547b6a1fe..55b1b68450 100644 --- a/autoload/vimtex/syntax/p/cleveref.vim +++ b/autoload/vimtex/syntax/p/cleveref.vim @@ -23,17 +23,17 @@ function! vimtex#syntax#p#cleveref#load() abort " {{{1 syntax region texCRefZone contained matchgroup=Delimiter \ start="{" end="}" - \ contains=@texRefGroup,texRefZone + \ contains=@texClusterRef,texRegionRef syntax region texCRefZoneRange contained matchgroup=Delimiter \ start="{" end="}" - \ contains=@texRefGroup,texRefZone + \ contains=@texClusterRef,texRegionRef \ nextgroup=texCRefZone skipwhite skipnl syntax region texCRefLabelOpts contained matchgroup=Delimiter \ start='\[' end=']' - \ contains=@texRefGroup,texRefZone + \ contains=@texClusterRef,texRegionRef - highlight link texCRefZone texRefZone - highlight link texCRefZoneRange texRefZone + highlight link texCRefZone texRegionRef + highlight link texCRefZoneRange texRegionRef highlight link texCRefLabelOpts texCmdArgs endfunction diff --git a/autoload/vimtex/syntax/p/dot2texi.vim b/autoload/vimtex/syntax/p/dot2texi.vim index c9255546a4..8f0bd9acfb 100644 --- a/autoload/vimtex/syntax/p/dot2texi.vim +++ b/autoload/vimtex/syntax/p/dot2texi.vim @@ -9,7 +9,7 @@ function! vimtex#syntax#p#dot2texi#load() abort " {{{1 let b:vimtex_syntax.dot2texi = 1 call vimtex#syntax#misc#include('dot') - syntax region texZoneDot + syntax region texRegionDot \ start="\\begin{dot2tex}"rs=s \ end="\\end{dot2tex}"re=e \ keepend diff --git a/autoload/vimtex/syntax/p/gnuplottex.vim b/autoload/vimtex/syntax/p/gnuplottex.vim index c325f21480..8e22f6c3ea 100644 --- a/autoload/vimtex/syntax/p/gnuplottex.vim +++ b/autoload/vimtex/syntax/p/gnuplottex.vim @@ -9,7 +9,7 @@ function! vimtex#syntax#p#gnuplottex#load() abort " {{{1 let b:vimtex_syntax.gnuplottex = 1 call vimtex#syntax#misc#include('gnuplot') - syntax region texZoneGnuplot + syntax region texRegionGnuplot \ start='\\begin{gnuplot}\(\_s*\[\_[\]]\{-}\]\)\?'rs=s \ end='\\end{gnuplot}'re=e \ keepend diff --git a/autoload/vimtex/syntax/p/hyperref.vim b/autoload/vimtex/syntax/p/hyperref.vim index 6f97d64f1c..f15cf361da 100644 --- a/autoload/vimtex/syntax/p/hyperref.vim +++ b/autoload/vimtex/syntax/p/hyperref.vim @@ -22,14 +22,14 @@ function! vimtex#syntax#p#hyperref#load() abort " {{{1 syntax match texStatement '\\hyperref\>' nextgroup=texHyperref syntax match texStatement '\\autoref\>' nextgroup=texHyperref syntax region texHyperref matchgroup=Delimiter start='\[' end='\]' contained - \ contains=@texRefGroup,texRefZone + \ contains=@texClusterRef,texRegionRef syntax region texHyperref matchgroup=Delimiter start='{' end='}' contained - \ contains=@texRefGroup,texRefZone + \ contains=@texClusterRef,texRegionRef highlight link texUrl Function highlight link texUrlVerb texUrl highlight link texHref texUrl - highlight link texHyperref texRefZone + highlight link texHyperref texRegionRef endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/ieeetrantools.vim b/autoload/vimtex/syntax/p/ieeetrantools.vim index 2a0bd4d950..4ab16dc716 100644 --- a/autoload/vimtex/syntax/p/ieeetrantools.vim +++ b/autoload/vimtex/syntax/p/ieeetrantools.vim @@ -17,20 +17,18 @@ endfunction " }}}1 function! s:new_math_zone(sfx, mathzone) abort " {{{1 - if get(g:, 'tex_fast', 'M') !~# 'M' | return | endif + " This needs to be slightly different than vimtex#syntax#core#new_math_zone + " to handle options for the environment. - let foldcmd = get(g:, 'tex_fold_enabled') ? ' fold' : '' + execute 'syntax match texBadMath ''\\end\s*{\s*' . a:mathzone . '\*\?\s*}''' let grp = 'texMathZone' . a:sfx - execute 'syntax cluster texMathZones add=' . grp execute 'syntax region ' . grp \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\z(\*\?\)\s*}' \ . '\(\[.\{-}\]\)\?{\w*}''' \ . ' end=''\\end\s*{\s*' . a:mathzone . '\z1\s*}''' - \ . foldcmd . ' keepend contains=@texMathZoneGroup' - execute 'highlight def link '.grp.' texMath' - - execute 'syntax match texBadMath ''\\end\s*{\s*' . a:mathzone . '\*\?\s*}''' + \ . ' keepend contains=@texClusterMath' + execute 'highlight def link ' . grp . ' texMath' endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index e608aa5223..9ac9f8c14a 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -12,11 +12,11 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 syntax match texInputFile \ "\\lstinputlisting\s*\(\[.\{-}\]\)\={.\{-}}" \ contains=texStatement,texInputCurlies,texInputFileOpt - syntax match texZone "\\lstinline\s*\(\[.\{-}\]\)\={.\{-}}" + syntax match texRegion "\\lstinline\s*\(\[.\{-}\]\)\={.\{-}}" " Set all listings environments to listings - syntax cluster texFoldGroup add=texZoneListings - syntax region texZoneListings + syntax cluster texFoldGroup add=texRegionListings + syntax region texRegionListings \ start="\\begin{lstlisting}\(\_s*\[\_[^\]]\{-}\]\)\?"rs=s \ end="\\end{lstlisting}\|%stopzone\>"re=e \ keepend @@ -27,7 +27,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 let l:cluster = vimtex#syntax#misc#include(l:nested) if empty(l:cluster) | continue | endif - let l:group_main = 'texZoneListings' . toupper(l:nested[0]) . l:nested[1:] + let l:group_main = 'texRegionListings' . toupper(l:nested[0]) . l:nested[1:] let l:group_lstset = l:group_main . 'Lstset' let l:group_contained = l:group_main . 'Contained' execute 'syntax cluster texFoldGroup add=' . l:group_main @@ -57,7 +57,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 \ 'contains=texStatement,texBeginEnd,@' . l:cluster endfor - highlight link texZoneListings texZone + highlight link texRegionListings texRegion endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/luacode.vim b/autoload/vimtex/syntax/p/luacode.vim index 5211268492..7c17439050 100644 --- a/autoload/vimtex/syntax/p/luacode.vim +++ b/autoload/vimtex/syntax/p/luacode.vim @@ -9,14 +9,14 @@ function! vimtex#syntax#p#luacode#load() abort " {{{1 let b:vimtex_syntax.luacode = 1 call vimtex#syntax#misc#include('lua') - syntax region texZoneLua + syntax region texRegionLua \ start='\\begin{luacode\*\?}'rs=s \ end='\\end{luacode\*\?}'re=e \ keepend \ transparent \ contains=texBeginEnd,@vimtex_nested_lua - syntax match texStatement '\\\(directlua\|luadirect\)' nextgroup=texZoneLuaArg - syntax region texZoneLuaArg matchgroup=Delimiter + syntax match texStatement '\\\(directlua\|luadirect\)' nextgroup=texRegionLuaArg + syntax region texRegionLuaArg matchgroup=Delimiter \ start='{' \ end='}' \ contained diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index 8db9af5012..eb8c0e90d5 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -15,7 +15,7 @@ function! vimtex#syntax#p#markdown#load() abort " {{{1 \ '\(\\begin\>\|\\end\>\)\ze{markdown}' \ nextgroup=texBeginEndName - syntax region texZoneMarkdown + syntax region texRegionMarkdown \ start='\\begin{markdown}'rs=s \ end='\\end{markdown}'re=e \ keepend diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index f9e9763187..6a1c89ecf2 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -43,7 +43,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 syntax match texStatement '\\newmint\%(ed\|inline\)\?' nextgroup=texMintedName,texMintedNameOpt " Match "unknown" environments - syntax region texZoneMinted + syntax region texRegionMinted \ start="\\begin{minted}\%(\_s*\[\_[^\]]\{-}\]\)\?\_s*{\w\+}"rs=s \ end="\\end{minted}"re=e \ keepend @@ -53,12 +53,12 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 syntax match texArgMinted "{\w\+}" \ contained \ contains=texMintedName - \ nextgroup=texZoneMintedCmd - syntax region texZoneMintedCmd matchgroup=Delimiter + \ nextgroup=texRegionMintedCmd + syntax region texRegionMintedCmd matchgroup=Delimiter \ start='\z([|+/]\)' \ end='\z1' \ contained - syntax region texZoneMintedCmd matchgroup=Delimiter + syntax region texRegionMintedCmd matchgroup=Delimiter \ start='{' \ end='}' \ contained @@ -68,7 +68,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 let l:cluster = vimtex#syntax#misc#include(l:nested) let l:name = 'Minted' . toupper(l:nested[0]) . l:nested[1:] - let l:group_main = 'texZone' . l:name + let l:group_main = 'texRegion' . l:name let l:group_arg = 'texArg' . l:name let l:group_arg_zone = 'texArgZone' . l:name @@ -76,8 +76,8 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 let l:transparent = '' let l:contains_env = '' let l:contains_macro = '' - execute 'highlight link' l:group_main 'texZoneMinted' - execute 'highlight link' l:group_arg_zone 'texZoneMinted' + execute 'highlight link' l:group_main 'texRegionMinted' + execute 'highlight link' l:group_arg_zone 'texRegionMinted' else let l:transparent = 'transparent' let l:contains_env = ',@' . l:cluster @@ -140,8 +140,8 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 \ contained \ nextgroup=texArgMinted.* - highlight link texZoneMinted texZone - highlight link texZoneMintedCmd texZone + highlight link texRegionMinted texRegion + highlight link texRegionMintedCmd texRegion highlight link texMintedName texInputFileOpt highlight link texMintedNameOpt texMintedName endfunction diff --git a/autoload/vimtex/syntax/p/moreverb.vim b/autoload/vimtex/syntax/p/moreverb.vim index 8074ba4d47..79daf24cb4 100644 --- a/autoload/vimtex/syntax/p/moreverb.vim +++ b/autoload/vimtex/syntax/p/moreverb.vim @@ -9,13 +9,13 @@ function! vimtex#syntax#p#moreverb#load() abort " {{{1 let b:vimtex_syntax.moreverb = 1 if exists('g:tex_verbspell') - syntax region texZone start="\\begin{verbatimtab}" end="\\end{verbatimtab}\|%stopzone\>" contains=@Spell - syntax region texZone start="\\begin{verbatimwrite}" end="\\end{verbatimwrite}\|%stopzone\>" contains=@Spell - syntax region texZone start="\\begin{boxedverbatim}" end="\\end{boxedverbatim}\|%stopzone\>" contains=@Spell + syntax region texRegion start="\\begin{verbatimtab}" end="\\end{verbatimtab}\|%stopzone\>" contains=@Spell + syntax region texRegion start="\\begin{verbatimwrite}" end="\\end{verbatimwrite}\|%stopzone\>" contains=@Spell + syntax region texRegion start="\\begin{boxedverbatim}" end="\\end{boxedverbatim}\|%stopzone\>" contains=@Spell else - syntax region texZone start="\\begin{verbatimtab}" end="\\end{verbatimtab}\|%stopzone\>" - syntax region texZone start="\\begin{verbatimwrite}" end="\\end{verbatimwrite}\|%stopzone\>" - syntax region texZone start="\\begin{boxedverbatim}" end="\\end{boxedverbatim}\|%stopzone\>" + syntax region texRegion start="\\begin{verbatimtab}" end="\\end{verbatimtab}\|%stopzone\>" + syntax region texRegion start="\\begin{verbatimwrite}" end="\\end{verbatimwrite}\|%stopzone\>" + syntax region texRegion start="\\begin{boxedverbatim}" end="\\end{boxedverbatim}\|%stopzone\>" endif endfunction diff --git a/autoload/vimtex/syntax/p/pythontex.vim b/autoload/vimtex/syntax/p/pythontex.vim index 3080b8ffaf..9efa91a9f4 100644 --- a/autoload/vimtex/syntax/p/pythontex.vim +++ b/autoload/vimtex/syntax/p/pythontex.vim @@ -18,13 +18,13 @@ function! vimtex#syntax#p#pythontex#load() abort " {{{1 \ start='\z([#@]\)' end='\z1' \ contained contains=@vimtex_nested_python - syntax region texZonePythontex + syntax region texRegionPythontex \ start='\\begin{pyblock}'rs=s \ end='\\end{pyblock}'re=e \ keepend \ transparent \ contains=texBeginEnd,@vimtex_nested_python - syntax region texZonePythontex + syntax region texRegionPythontex \ start='\\begin{pycode}'rs=s \ end='\\end{pycode}'re=e \ keepend diff --git a/autoload/vimtex/syntax/p/varioref.vim b/autoload/vimtex/syntax/p/varioref.vim index ea14e062d1..24e7941f07 100644 --- a/autoload/vimtex/syntax/p/varioref.vim +++ b/autoload/vimtex/syntax/p/varioref.vim @@ -9,13 +9,13 @@ function! vimtex#syntax#p#varioref#load() abort " {{{1 let b:vimtex_syntax.varioref = 1 if get(g:, 'tex_fast', 'r') !~# 'r' | return | endif - syntax match texStatement '\\Vref\>' nextgroup=texVarioRefZone + syntax match texStatement '\\Vref\>' nextgroup=texRegionVarioref - syntax region texVarioRefZone contained matchgroup=Delimiter + syntax region texRegionVarioref contained matchgroup=Delimiter \ start="{" end="}" - \ contains=@texRefGroup,texRefZone + \ contains=@texClusterRef,texRegionRef - highlight link texVarioRefZone texRefZone + highlight link texRegionVarioref texRegionRef endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/wiki.vim b/autoload/vimtex/syntax/p/wiki.vim index de759807d0..286806cb55 100644 --- a/autoload/vimtex/syntax/p/wiki.vim +++ b/autoload/vimtex/syntax/p/wiki.vim @@ -10,7 +10,7 @@ function! vimtex#syntax#p#wiki#load() abort " {{{1 call vimtex#syntax#misc#include('markdown') - syntax region texZoneWiki + syntax region texRegionWiki \ start='\\wikimarkup\>' \ end='\\nowikimarkup\>'re=e \ keepend diff --git a/test/tests/test-syntax/test-markdown.vim b/test/tests/test-syntax/test-markdown.vim index c79725a874..672a7c3033 100644 --- a/test/tests/test-syntax/test-markdown.vim +++ b/test/tests/test-syntax/test-markdown.vim @@ -4,7 +4,7 @@ silent edit test-markdown.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texZoneMarkdown', 7, 1)) +call vimtex#test#assert(vimtex#syntax#in('texRegionMarkdown', 7, 1)) call vimtex#test#assert(vimtex#syntax#in('markdownItalic', 7, 1)) call vimtex#test#assert(vimtex#syntax#in('markdownLink', 11, 12)) call vimtex#test#assert(vimtex#syntax#in('texInputFileArg', 16, 16)) diff --git a/test/tests/test-syntax/test-minted.vim b/test/tests/test-syntax/test-minted.vim index eaa4b72cdf..bfc0beb8fe 100644 --- a/test/tests/test-syntax/test-minted.vim +++ b/test/tests/test-syntax/test-minted.vim @@ -8,8 +8,8 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('javaScopeDecl', 72, 3)) " Newminted on unrecognized languages (#1616) -call vimtex#test#assert(vimtex#syntax#in('texZoneMintedLog', 112, 1)) -call vimtex#test#assert(vimtex#syntax#in('texZoneMintedShellsession', 116, 1)) +call vimtex#test#assert(vimtex#syntax#in('texRegionMintedLog', 112, 1)) +call vimtex#test#assert(vimtex#syntax#in('texRegionMintedShellsession', 116, 1)) " Doing :e should not destroy nested syntax and similar call vimtex#test#assert(vimtex#syntax#in('pythonFunction', 38, 5)) diff --git a/test/tests/test-syntax/test-wiki.vim b/test/tests/test-syntax/test-wiki.vim index 6339071341..c0868b40e8 100644 --- a/test/tests/test-syntax/test-wiki.vim +++ b/test/tests/test-syntax/test-wiki.vim @@ -4,7 +4,7 @@ silent edit test-wiki.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texZoneWiki', 6, 1)) +call vimtex#test#assert(vimtex#syntax#in('texRegionWiki', 6, 1)) " call vimtex#test#assert(vimtex#syntax#in('markdownHeader', 7, 1)) quit! From e5bde25e34ca127a5989e9f79b70292f09942880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Tue, 20 Oct 2020 00:02:15 +0200 Subject: [PATCH 03/99] wip: fixed texErrorStatement --- autoload/vimtex/syntax/core.vim | 24 ++++++++++++------------ test/tests/test-syntax/test-core.vim | 10 ++++++++++ 2 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 test/tests/test-syntax/test-core.vim diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index bd29e2c3c5..48aadef4e7 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -31,15 +31,15 @@ function! vimtex#syntax#core#init() abort " {{{1 " {{{2 Primitives " Delimiters + syntax region texParen start="(" end=")" transparent contains=TOP,@Spell syntax region texMatcher matchgroup=Delimiter start="{" skip="\%(\\\\\)*\\}" end="}" transparent contains=TOP syntax region texMatcher matchgroup=Delimiter start="\[" end="]" transparent contains=TOP,@NoSpell syntax region texMatcherMath matchgroup=Delimiter start="{" skip="\%(\\\\\)*\\}" end="}" contained contains=@texClusterMathMatch - syntax region texParen start="(" end=")" transparent contains=TOP,@Spell syntax match texDelimiter "&" " TeX String Delimiters - syntax match texString "\(``\|''\|,,\)" + syntax match texString "\v%(``|''|,,)" " Flag mismatching ending delimiters } and ] syntax match texError "[}\]]" @@ -286,10 +286,10 @@ function! vimtex#syntax#core#init() abort " {{{1 " \makeatletter ... \makeatother sections " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do " In short: allow @ in multicharacter macro name - syntax match texStatementSty "\\[a-zA-Z@]\+" contained - syntax region texRegionSty matchgroup=texStatement start='\\makeatletter' end='\\makeatother' contains=TOP,texStatementSty - syntax region texMatcherSty matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=TOP,texStatementSty contained - syntax region texMatcherSty matchgroup=Delimiter start="\[" end="]" contains=TOP,texStatementSty contained + syntax region texRegionSty matchgroup=texStatement start='\\makeatletter' end='\\makeatother' contains=TOP,texErrorStatement + syntax region texMatcherSty matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=TOP,texErrorStatement contained + syntax region texMatcherSty matchgroup=Delimiter start="\[" end="]" contains=TOP,texErrorStatement contained + syntax match texStatementSty "\\[a-zA-Z@]\+" contained containedin=texRegionSty " }}}2 @@ -464,12 +464,12 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texMathZoneY texMath highlight def link texMathZoneV texMath highlight def link texMathZoneZ texMath - highlight def link texBeginEnd texCmdName - highlight def link texBeginEndName texSection - highlight def link texSpaceCode texStatement - highlight def link texStyleStatement texStatement - highlight def link texTypeSize texType - highlight def link texTypeStyle texType + highlight def link texBeginEnd texCmdName + highlight def link texBeginEndName texSection + highlight def link texSpaceCode texStatement + highlight def link texStatementSty texStatement + highlight def link texTypeSize texType + highlight def link texTypeStyle texType " Basic TeX highlighting groups highlight def link texCmdArgs Number diff --git a/test/tests/test-syntax/test-core.vim b/test/tests/test-syntax/test-core.vim new file mode 100644 index 0000000000..b1c96cde3c --- /dev/null +++ b/test/tests/test-syntax/test-core.vim @@ -0,0 +1,10 @@ +source common.vim + +silent edit test-core.tex + +if empty($INMAKE) | finish | endif + +call vimtex#test#assert(vimtex#syntax#in('texErrorStatement', 5, 3)) +call vimtex#test#assert(vimtex#syntax#in('texStatementSty', 8, 3)) + +quit! From c99997dde0a8c92d8965993cba08f864c50f9a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 21 Oct 2020 15:17:35 +0200 Subject: [PATCH 04/99] fix: add texRegionVerb default highlight --- autoload/vimtex/syntax/core.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 48aadef4e7..4778faebe7 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -497,6 +497,9 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texType Type highlight def link texRegion PreCondit + " Inherited groups + highlight def link texRegionVerb texRegion + " New highlight def link texCommentURL Comment highlight def link texCommentAcronym Comment From 4bb94751e60020dcdc1c8b8dbf19c34153754567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 21 Oct 2020 15:19:51 +0200 Subject: [PATCH 05/99] wip: removed g:tex_fast --- autoload/vimtex/syntax/p/array.vim | 1 - autoload/vimtex/syntax/p/biblatex.vim | 2 -- autoload/vimtex/syntax/p/cleveref.vim | 1 - autoload/vimtex/syntax/p/varioref.vim | 1 - doc/vimtex.txt | 6 ------ 5 files changed, 11 deletions(-) diff --git a/autoload/vimtex/syntax/p/array.vim b/autoload/vimtex/syntax/p/array.vim index cced938f7e..7ee79a3e25 100644 --- a/autoload/vimtex/syntax/p/array.vim +++ b/autoload/vimtex/syntax/p/array.vim @@ -9,7 +9,6 @@ function! vimtex#syntax#p#array#load() abort " {{{1 let b:vimtex_syntax.array = 1 call vimtex#syntax#p#tabularx#load() - if !get(g:, 'tex_fast', 'M') =~# 'M' | return | endif let l:concealed = has('conceal') \ && &enc ==# 'utf-8' diff --git a/autoload/vimtex/syntax/p/biblatex.vim b/autoload/vimtex/syntax/p/biblatex.vim index 2eec747479..8a37c32cc9 100644 --- a/autoload/vimtex/syntax/p/biblatex.vim +++ b/autoload/vimtex/syntax/p/biblatex.vim @@ -8,8 +8,6 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 if has_key(b:vimtex_syntax, 'biblatex') | return | endif let b:vimtex_syntax.biblatex = 1 - if get(g:, 'tex_fast', 'r') !~# 'r' | return | endif - for l:pattern in [ \ 'bibentry', \ 'cite[pt]?\*?', diff --git a/autoload/vimtex/syntax/p/cleveref.vim b/autoload/vimtex/syntax/p/cleveref.vim index 55b1b68450..55187d2f8d 100644 --- a/autoload/vimtex/syntax/p/cleveref.vim +++ b/autoload/vimtex/syntax/p/cleveref.vim @@ -7,7 +7,6 @@ function! vimtex#syntax#p#cleveref#load() abort " {{{1 if has_key(b:vimtex_syntax, 'cleveref') | return | endif let b:vimtex_syntax.cleveref = 1 - if get(g:, 'tex_fast', 'r') !~# 'r' | return | endif syntax match texStatement '\\\(\(label\)\?c\(page\)\?\|C\)ref\>' \ nextgroup=texCRefZone diff --git a/autoload/vimtex/syntax/p/varioref.vim b/autoload/vimtex/syntax/p/varioref.vim index 24e7941f07..3973a7ee34 100644 --- a/autoload/vimtex/syntax/p/varioref.vim +++ b/autoload/vimtex/syntax/p/varioref.vim @@ -7,7 +7,6 @@ function! vimtex#syntax#p#varioref#load() abort " {{{1 if has_key(b:vimtex_syntax, 'varioref') | return | endif let b:vimtex_syntax.varioref = 1 - if get(g:, 'tex_fast', 'r') !~# 'r' | return | endif syntax match texStatement '\\Vref\>' nextgroup=texRegionVarioref diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 0a13b5402a..e694f92950 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -3644,12 +3644,6 @@ packages for new documents or documents that are not compiled. One may therefore specify a list of packages to autoload regardless of the package detection, see |g:vimtex_syntax_autoload_packages|. -Before enabling additional syntax highlighting, |vimtex| also checks the -|g:tex_fast| variable (defined by |ft-tex-syntax|) that allows one to -selectively enable or disable highlighting for specific groups. If -|g:tex_fast| is set, additional syntax highlighting for bold, italic, and -reference groups are enabled only if they are explicitly allowed. - Note: The default syntax highlighting of vim maintained by Charles Campbell does not support any package (:h tex-package). However, C. Campbell provides syntax highlighting files on his website for some packages, see From 262bb404bc7533b216cb8355db7ba87cff8004da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 25 Oct 2020 11:55:51 +0100 Subject: [PATCH 06/99] wip: texStatement -> texCmd --- autoload/vimtex/syntax/core.vim | 126 ++++++++++++------------ autoload/vimtex/syntax/p/beamer.vim | 8 +- autoload/vimtex/syntax/p/biblatex.vim | 6 +- autoload/vimtex/syntax/p/cleveref.vim | 6 +- autoload/vimtex/syntax/p/glossaries.vim | 2 +- autoload/vimtex/syntax/p/hyperref.vim | 10 +- autoload/vimtex/syntax/p/listings.vim | 6 +- autoload/vimtex/syntax/p/luacode.vim | 2 +- autoload/vimtex/syntax/p/markdown.vim | 2 +- autoload/vimtex/syntax/p/minted.vim | 6 +- autoload/vimtex/syntax/p/pdfpages.vim | 2 +- autoload/vimtex/syntax/p/pgfplots.vim | 4 +- autoload/vimtex/syntax/p/pythontex.vim | 2 +- autoload/vimtex/syntax/p/subfile.vim | 2 +- autoload/vimtex/syntax/p/tabularx.vim | 4 +- autoload/vimtex/syntax/p/tikz.vim | 6 +- autoload/vimtex/syntax/p/varioref.vim | 2 +- test/tests/test-syntax/test-core.vim | 2 +- 18 files changed, 99 insertions(+), 99 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 4778faebe7..146de744e5 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -24,8 +24,8 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax cluster texClusterBold contains=TOP,texItalStyle,texItalBoldStyle,texEmphStyle syntax cluster texClusterItal contains=TOP,texBoldStyle,texBoldItalStyle syntax cluster texClusterComment contains=texTodo,@Spell - syntax cluster texClusterMath contains=texComment,texDelimiter,texErrorMath,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texRegionRef,texSpecialChar,texStatement,texSubscript,texSuperscript,texTypeSize,texTypeStyle,@NoSpell - syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texDelimiter,texDocType,texErrorMath,texGreek,texInput,texLength,texLigature,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texNewCmd,texNewEnv,texRegion,texRegionRef,texSection,texSpecialChar,texStatement,texString,texSubscript,texSuperscript,texTypeSize,texTypeStyle + syntax cluster texClusterMath contains=texComment,texDelimiter,texErrorMath,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texRegionRef,texSpecialChar,texCmd,texSubscript,texSuperscript,texTypeSize,texTypeStyle,@NoSpell + syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texDelimiter,texDocType,texErrorMath,texGreek,texInput,texLength,texLigature,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texNewCmd,texNewEnv,texRegion,texRegionRef,texSection,texSpecialChar,texCmd,texString,texSubscript,texSuperscript,texTypeSize,texTypeStyle syntax cluster texClusterRef contains=texComment,texDelimiter,texMatcher " {{{2 Primitives @@ -46,7 +46,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texErrorMath "}" contained " Tex commands - syntax match texStatement "\\\a\+" + syntax match texCmd "\\\a\+" syntax match texErrorStatement "\\\a*@\a*" " Accents and ligatures @@ -60,7 +60,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texLigature '---' if l:cfg.is_style_document - syntax match texStatement "\\[a-zA-Z@]\+" + syntax match texCmd "\\[a-zA-Z@]\+" syntax match texAccent "\\[bcdvuH]\ze[^a-zA-Z@]" syntax match texLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze[^a-zA-Z@]" endif @@ -79,9 +79,9 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texOption "\v%(^|[^\\]\zs)#\d+" " TeX input - syntax match texInput "\\input\s\+[a-zA-Z/.0-9_^]\+"hs=s+7 contains=texStatement - syntax match texInputFile "\v\\include%(graphics|list)?%(\[.{-}\])?\s*\{.{-}\}" contains=texStatement,texInputCurlies,texInputFileOpt - syntax match texInputFile "\v\\%(epsfig|input)\s*%(\[.*\])?\{.{-}\}" contains=texStatement,texInputCurlies,texInputFileOpt + syntax match texInput "\\input\s\+[a-zA-Z/.0-9_^]\+"hs=s+7 contains=texCmd + syntax match texInputFile "\v\\include%(graphics|list)?%(\[.{-}\])?\s*\{.{-}\}" contains=texCmd,texInputCurlies,texInputFileOpt + syntax match texInputFile "\v\\%(epsfig|input)\s*%(\[.*\])?\{.{-}\}" contains=texCmd,texInputCurlies,texInputFileOpt syntax match texInputCurlies "[{}]" contained syntax region texInputFileOpt matchgroup=Delimiter start="\[" end="\]" contains=texComment contained @@ -114,7 +114,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax case ignore syntax keyword texTodo contained combak fixme todo xxx syntax case match - syntax match texStatement '\\todo\w*' contains=texTodo + syntax match texCmd '\\todo\w*' contains=texTodo syntax match texTodo '\\todo\w*' " TeX Lengths @@ -206,7 +206,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texMathOper "[_^=]" contained " Text Inside Math Zones - syntax region texMathText matchgroup=texStatement start="\\\(\(inter\)\?text\|mbox\)\s*{" end="}" contains=TOP,@Spell + syntax region texMathText matchgroup=texCmd start="\\\(\(inter\)\?text\|mbox\)\s*{" end="}" contains=TOP,@Spell " Math environments call vimtex#syntax#core#new_math_zone('A', 'displaymath', 1) @@ -215,7 +215,7 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_math_zone('D', 'math', 1) " Inline Math Zones - syntax region texMathZoneZ matchgroup=texStatement start="\\ensuremath\s*{" matchgroup=texStatement end="}" contains=@texClusterMath + syntax region texMathZoneZ matchgroup=texCmd start="\\ensuremath\s*{" matchgroup=texCmd end="}" contains=@texClusterMath if l:cfg.conceal =~# 'd' && &encoding ==# 'utf-8' syntax region texMathZoneV matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" concealends contains=@texClusterMath keepend syntax region texMathZoneW matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" concealends contains=@texClusterMath keepend @@ -275,21 +275,21 @@ function! vimtex#syntax#core#init() abort " {{{1 " Tex Reference Zones syntax match texRegionRef '\\cite\%([tp]\*\?\)\?\>' nextgroup=texRefOption,texRefCite - syntax region texRegionRef matchgroup=texStatement start="\\nocite{" end="}" contains=@texClusterRef - syntax region texRegionRef matchgroup=texStatement start="\\bibliography{" end="}" contains=@texClusterRef - syntax region texRegionRef matchgroup=texStatement start="\\label{" end="}" contains=@texClusterRef - syntax region texRegionRef matchgroup=texStatement start="\\\(page\|eq\)ref{" end="}" contains=@texClusterRef - syntax region texRegionRef matchgroup=texStatement start="\\v\?ref{" end="}" contains=@texClusterRef + syntax region texRegionRef matchgroup=texCmd start="\\nocite{" end="}" contains=@texClusterRef + syntax region texRegionRef matchgroup=texCmd start="\\bibliography{" end="}" contains=@texClusterRef + syntax region texRegionRef matchgroup=texCmd start="\\label{" end="}" contains=@texClusterRef + syntax region texRegionRef matchgroup=texCmd start="\\\(page\|eq\)ref{" end="}" contains=@texClusterRef + syntax region texRegionRef matchgroup=texCmd start="\\v\?ref{" end="}" contains=@texClusterRef syntax region texRefOption matchgroup=Delimiter start='\[' end=']' contains=@texClusterRef,texRegionRef nextgroup=texRefOption,texRefCite contained syntax region texRefCite matchgroup=Delimiter start='{' end='}' contains=@texClusterRef,texRegionRef,texRefCite contained " \makeatletter ... \makeatother sections " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do " In short: allow @ in multicharacter macro name - syntax region texRegionSty matchgroup=texStatement start='\\makeatletter' end='\\makeatother' contains=TOP,texErrorStatement + syntax region texRegionSty matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP,texErrorStatement syntax region texMatcherSty matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=TOP,texErrorStatement contained syntax region texMatcherSty matchgroup=Delimiter start="\[" end="]" contains=TOP,texErrorStatement contained - syntax match texStatementSty "\\[a-zA-Z@]\+" contained containedin=texRegionSty + syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=texRegionSty " }}}2 @@ -387,7 +387,7 @@ function! vimtex#syntax#core#init() abort " {{{1 \ start='{' end='}' \ contained contains=@NoSpell for l:macro in g:vimtex_syntax_nospell_commands - execute 'syntax match texStatement /\\' . l:macro . '/' + execute 'syntax match texCmd /\\' . l:macro . '/' \ 'nextgroup=texVimtexNospell' endfor @@ -438,26 +438,26 @@ function! s:init_highlights(cfg) abort " {{{1 highlight texItalStyle gui=italic cterm=italic highlight texBoldItalStyle gui=bold,italic cterm=bold,italic highlight texItalBoldStyle gui=bold,italic cterm=bold,italic - highlight def link texEmphStyle texItalStyle - highlight def link texRefCite texRegionRef - highlight def link texDefCmd texDef - highlight def link texDefName texDef - highlight def link texDocType texCmdName - highlight def link texDocTypeArgs texCmdArgs - highlight def link texInputFileOpt texCmdArgs - highlight def link texInputCurlies texDelimiter - highlight def link texLigature texSpecialChar + highlight def link texEmphStyle texItalStyle + highlight def link texRefCite texRegionRef + highlight def link texDefCmd texDef + highlight def link texDefName texDef + highlight def link texDocType texCmdName + highlight def link texDocTypeArgs texCmdArgs + highlight def link texInputFileOpt texCmdArgs + highlight def link texInputCurlies texDelimiter + highlight def link texLigature texSpecialChar highlight def link texMathDelimSet1 texMathDelim highlight def link texMathDelimSet2 texMathDelim highlight def link texMathDelimKey texMathDelim highlight def link texMatcherMath texMath - highlight def link texAccent texStatement - highlight def link texGreek texStatement - highlight def link texSuperscript texStatement - highlight def link texSubscript texStatement + highlight def link texAccent texCmd + highlight def link texGreek texCmd + highlight def link texSuperscript texCmd + highlight def link texSubscript texCmd highlight def link texSuperscripts texSuperscript highlight def link texSubscripts texSubscript - highlight def link texMathSymbol texStatement + highlight def link texMathSymbol texCmd highlight def link texMathZoneV texMath highlight def link texMathZoneW texMath highlight def link texMathZoneX texMath @@ -466,44 +466,44 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texMathZoneZ texMath highlight def link texBeginEnd texCmdName highlight def link texBeginEndName texSection - highlight def link texSpaceCode texStatement - highlight def link texStatementSty texStatement + highlight def link texSpaceCode texCmd + highlight def link texCmdSty texCmd highlight def link texTypeSize texType highlight def link texTypeStyle texType " Basic TeX highlighting groups - highlight def link texCmdArgs Number - highlight def link texCmdName Statement - highlight def link texComment Comment - highlight def link texDef Statement - highlight def link texDefParm Special - highlight def link texDelimiter Delimiter - highlight def link texInput Special - highlight def link texInputFile Special - highlight def link texLength Number - highlight def link texMath Special - highlight def link texMathDelim Statement - highlight def link texMathOper Operator - highlight def link texNewCmd Statement - highlight def link texNewEnv Statement - highlight def link texOption Number - highlight def link texRegionRef Special - highlight def link texSection PreCondit - highlight def link texSpaceCodeChar Special - highlight def link texSpecialChar SpecialChar - highlight def link texStatement Statement - highlight def link texString String - highlight def link texTodo Todo - highlight def link texType Type - highlight def link texRegion PreCondit + highlight def link texCmdArgs Number + highlight def link texCmdName Statement + highlight def link texComment Comment + highlight def link texDef Statement + highlight def link texDefParm Special + highlight def link texDelimiter Delimiter + highlight def link texInput Special + highlight def link texInputFile Special + highlight def link texLength Number + highlight def link texMath Special + highlight def link texMathDelim Statement + highlight def link texMathOper Operator + highlight def link texNewCmd Statement + highlight def link texNewEnv Statement + highlight def link texOption Number + highlight def link texRegionRef Special + highlight def link texSection PreCondit + highlight def link texSpaceCodeChar Special + highlight def link texSpecialChar SpecialChar + highlight def link texCmd Statement + highlight def link texString String + highlight def link texTodo Todo + highlight def link texType Type + highlight def link texRegion PreCondit " Inherited groups - highlight def link texRegionVerb texRegion + highlight def link texRegionVerb texRegion " New - highlight def link texCommentURL Comment + highlight def link texCommentURL Comment highlight def link texCommentAcronym Comment - highlight def link texDefParmNested Identifier + highlight def link texDefParmNested Identifier endfunction " }}}1 @@ -925,8 +925,8 @@ endfunction " }}}1 function! s:match_conceal_super_sub(cfg) " {{{1 - syntax region texSuperscript matchgroup=Delimiter start='\^{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSuperscripts,texStatement,texSubscript,texSuperscript,texMatcherMath - syntax region texSubscript matchgroup=Delimiter start='_{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSubscripts,texStatement,texSubscript,texSuperscript,texMatcherMath + syntax region texSuperscript matchgroup=Delimiter start='\^{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSuperscripts,texCmd,texSubscript,texSuperscript,texMatcherMath + syntax region texSubscript matchgroup=Delimiter start='_{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSubscripts,texCmd,texSubscript,texSuperscript,texMatcherMath for [l:from, l:to] in filter(copy(s:map_super), \ {_, x -> x[0][0] ==# '\' || x[0] =~# a:cfg.conceal_set_super}) diff --git a/autoload/vimtex/syntax/p/beamer.vim b/autoload/vimtex/syntax/p/beamer.vim index 69fae16917..109dd0e9e6 100644 --- a/autoload/vimtex/syntax/p/beamer.vim +++ b/autoload/vimtex/syntax/p/beamer.vim @@ -11,14 +11,14 @@ function! vimtex#syntax#p#beamer#load() abort " {{{1 syntax match texBeamerDelimiter '<\|>' contained syntax match texBeamerOpt '<[^>]*>' contained contains=texBeamerDelimiter - syntax match texStatementBeamer '\\only\(<[^>]*>\)\?' contains=texBeamerOpt - syntax match texStatementBeamer '\\item<[^>]*>' contains=texBeamerOpt + syntax match texCmdBeamer '\\only\(<[^>]*>\)\?' contains=texBeamerOpt + syntax match texCmdBeamer '\\item<[^>]*>' contains=texBeamerOpt syntax match texInputFile \ '\\includegraphics<[^>]*>\(\[.\{-}\]\)\=\s*{.\{-}}' - \ contains=texStatement,texBeamerOpt,texInputCurlies,texInputFileOpt + \ contains=texCmd,texBeamerOpt,texInputCurlies,texInputFileOpt - highlight link texStatementBeamer texStatement + highlight link texCmdBeamer texCmd highlight link texBeamerOpt Identifier highlight link texBeamerDelimiter Delimiter endfunction diff --git a/autoload/vimtex/syntax/p/biblatex.vim b/autoload/vimtex/syntax/p/biblatex.vim index 8a37c32cc9..e606bd5500 100644 --- a/autoload/vimtex/syntax/p/biblatex.vim +++ b/autoload/vimtex/syntax/p/biblatex.vim @@ -24,7 +24,7 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 \ '[Ppf]?[Nn]otecite', \ '%(text|block)cquote\*?', \] - execute 'syntax match texStatement' + execute 'syntax match texCmd' \ '/\v\\' . l:pattern . '\ze\s*%(\[|\{)/' \ 'nextgroup=texRefOption,texRefCite' endfor @@ -40,7 +40,7 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 \ '[pPfFsStTaA]?[Vv]olcites?', \ 'cite%(field|list|name)', \] - execute 'syntax match texStatement' + execute 'syntax match texCmd' \ '/\v\\' . l:pattern . '\ze\s*%(\[|\{)/' \ 'nextgroup=texRefOptions,texRefCites' endfor @@ -50,7 +50,7 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 \ '%(foreign|hyphen)blockcquote', \ 'hybridblockcquote', \] - execute 'syntax match texStatement' + execute 'syntax match texCmd' \ '/\v\\' . l:pattern . '\ze\s*%(\[|\{)/' \ 'nextgroup=texQuoteLang' endfor diff --git a/autoload/vimtex/syntax/p/cleveref.vim b/autoload/vimtex/syntax/p/cleveref.vim index 55187d2f8d..2c48017e16 100644 --- a/autoload/vimtex/syntax/p/cleveref.vim +++ b/autoload/vimtex/syntax/p/cleveref.vim @@ -8,15 +8,15 @@ function! vimtex#syntax#p#cleveref#load() abort " {{{1 if has_key(b:vimtex_syntax, 'cleveref') | return | endif let b:vimtex_syntax.cleveref = 1 - syntax match texStatement '\\\(\(label\)\?c\(page\)\?\|C\)ref\>' + syntax match texCmd '\\\(\(label\)\?c\(page\)\?\|C\)ref\>' \ nextgroup=texCRefZone " \crefrange, \cpagerefrange (these commands expect two arguments) - syntax match texStatement '\\c\(page\)\?refrange\>' + syntax match texCmd '\\c\(page\)\?refrange\>' \ nextgroup=texCRefZoneRange skipwhite skipnl " \label[xxx]{asd} - syntax match texStatement '\\label\[.\{-}\]' + syntax match texCmd '\\label\[.\{-}\]' \ nextgroup=texCRefZone skipwhite skipnl \ contains=texCRefLabelOpts diff --git a/autoload/vimtex/syntax/p/glossaries.vim b/autoload/vimtex/syntax/p/glossaries.vim index 108fd9ef6c..dbe8a7d533 100644 --- a/autoload/vimtex/syntax/p/glossaries.vim +++ b/autoload/vimtex/syntax/p/glossaries.vim @@ -10,7 +10,7 @@ function! vimtex#syntax#p#glossaries#load() abort " {{{1 if has_key(b:vimtex_syntax, 'glossaries') | return | endif let b:vimtex_syntax.glossaries = 1 - syntax match texStatement '\\gls\>' nextgroup=texGls + syntax match texCmd '\\gls\>' nextgroup=texGls syntax region texGls matchgroup=Delimiter \ start='{' end='}' \ contained diff --git a/autoload/vimtex/syntax/p/hyperref.vim b/autoload/vimtex/syntax/p/hyperref.vim index f15cf361da..bbe26fb6f9 100644 --- a/autoload/vimtex/syntax/p/hyperref.vim +++ b/autoload/vimtex/syntax/p/hyperref.vim @@ -8,19 +8,19 @@ function! vimtex#syntax#p#hyperref#load() abort " {{{1 if has_key(b:vimtex_syntax, 'hyperref') | return | endif let b:vimtex_syntax.hyperref = 1 - syntax match texStatement '\\url\ze[^\ta-zA-Z]' nextgroup=texUrlVerb + syntax match texCmd '\\url\ze[^\ta-zA-Z]' nextgroup=texUrlVerb syntax region texUrlVerb matchgroup=Delimiter \ start='\z([^\ta-zA-Z]\)' end='\z1' contained - syntax match texStatement '\\url\ze\s*{' nextgroup=texUrl + syntax match texCmd '\\url\ze\s*{' nextgroup=texUrl syntax region texUrl matchgroup=Delimiter start='{' end='}' contained - syntax match texStatement '\\href' nextgroup=texHref + syntax match texCmd '\\href' nextgroup=texHref syntax region texHref matchgroup=Delimiter start='{' end='}' contained \ nextgroup=texMatcher - syntax match texStatement '\\hyperref\>' nextgroup=texHyperref - syntax match texStatement '\\autoref\>' nextgroup=texHyperref + syntax match texCmd '\\hyperref\>' nextgroup=texHyperref + syntax match texCmd '\\autoref\>' nextgroup=texHyperref syntax region texHyperref matchgroup=Delimiter start='\[' end='\]' contained \ contains=@texClusterRef,texRegionRef syntax region texHyperref matchgroup=Delimiter start='{' end='}' contained diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index 9ac9f8c14a..61ed445296 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -11,7 +11,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 " First some general support syntax match texInputFile \ "\\lstinputlisting\s*\(\[.\{-}\]\)\={.\{-}}" - \ contains=texStatement,texInputCurlies,texInputFileOpt + \ contains=texCmd,texInputCurlies,texInputFileOpt syntax match texRegion "\\lstinline\s*\(\[.\{-}\]\)\={.\{-}}" " Set all listings environments to listings @@ -44,7 +44,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 execute 'syntax match' l:group_lstset \ '"\c\\lstset{.*language=' . l:nested . '\%(\s*,\|}\)"' \ 'transparent' - \ 'contains=texStatement,texMatcher' + \ 'contains=texCmd,texMatcher' \ 'skipwhite skipempty' \ 'nextgroup=' . l:group_contained @@ -54,7 +54,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 \ 'keepend' \ 'transparent' \ 'containedin=' . l:group_lstset - \ 'contains=texStatement,texBeginEnd,@' . l:cluster + \ 'contains=texCmd,texBeginEnd,@' . l:cluster endfor highlight link texRegionListings texRegion diff --git a/autoload/vimtex/syntax/p/luacode.vim b/autoload/vimtex/syntax/p/luacode.vim index 7c17439050..35d59e0938 100644 --- a/autoload/vimtex/syntax/p/luacode.vim +++ b/autoload/vimtex/syntax/p/luacode.vim @@ -15,7 +15,7 @@ function! vimtex#syntax#p#luacode#load() abort " {{{1 \ keepend \ transparent \ contains=texBeginEnd,@vimtex_nested_lua - syntax match texStatement '\\\(directlua\|luadirect\)' nextgroup=texRegionLuaArg + syntax match texCmd '\\\(directlua\|luadirect\)' nextgroup=texRegionLuaArg syntax region texRegionLuaArg matchgroup=Delimiter \ start='{' \ end='}' diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index eb8c0e90d5..b4c7f9b571 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -24,7 +24,7 @@ function! vimtex#syntax#p#markdown#load() abort " {{{1 " Input files syntax match texInputFile /\\markdownInput\>/ - \ contains=texStatement + \ contains=texCmd \ nextgroup=texInputFileArg syntax region texInputFileArg \ matchgroup=texInputCurlies diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index 6a1c89ecf2..297cedced2 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -40,7 +40,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 \ containedin=texMintedStarred " Match \newminted type macros - syntax match texStatement '\\newmint\%(ed\|inline\)\?' nextgroup=texMintedName,texMintedNameOpt + syntax match texCmd '\\newmint\%(ed\|inline\)\?' nextgroup=texMintedName,texMintedNameOpt " Match "unknown" environments syntax region texRegionMinted @@ -126,14 +126,14 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " Match minted custom macros for l:cmd in sort(get(l:config, 'commands', [])) - execute printf('syntax match texStatement ''\\%s'' nextgroup=%s', + execute printf('syntax match texCmd ''\\%s'' nextgroup=%s', \ l:cmd, l:group_arg_zone) endfor endfor " Main matcher for the minted statements/commands " - Note: This comes last to allow the nextgroup pattern - syntax match texStatement '\\mint\(inline\)\?' nextgroup=texArgOptMinted,texArgMinted.* + syntax match texCmd '\\mint\(inline\)\?' nextgroup=texArgOptMinted,texArgMinted.* syntax region texArgOptMinted matchgroup=Delimiter \ start='\[' \ end='\]' diff --git a/autoload/vimtex/syntax/p/pdfpages.vim b/autoload/vimtex/syntax/p/pdfpages.vim index 2eddac2b5a..5d02023d3d 100644 --- a/autoload/vimtex/syntax/p/pdfpages.vim +++ b/autoload/vimtex/syntax/p/pdfpages.vim @@ -9,7 +9,7 @@ function! vimtex#syntax#p#pdfpages#load() abort " {{{1 let b:vimtex_syntax.pdfpages = 1 syntax match texInputFile /\\includepdf\>/ - \ contains=texStatement + \ contains=texCmd \ nextgroup=texInputFileOpt,texInputFileArg syntax region texInputFileOpt \ matchgroup=Delimiter diff --git a/autoload/vimtex/syntax/p/pgfplots.vim b/autoload/vimtex/syntax/p/pgfplots.vim index 0b076097ee..315b111aa5 100644 --- a/autoload/vimtex/syntax/p/pgfplots.vim +++ b/autoload/vimtex/syntax/p/pgfplots.vim @@ -16,7 +16,7 @@ function! vimtex#syntax#p#pgfplots#load() abort " {{{1 " Match pgfplotsset and axis environments syntax match texTikzSet /\\pgfplotsset\>/ - \ contains=texStatement skipwhite nextgroup=texTikzOptsCurly + \ contains=texCmd skipwhite nextgroup=texTikzOptsCurly syntax match texTikzEnv /\v\\begin\{%(log)*axis}/ \ contains=texBeginEnd nextgroup=texTikzOpts skipwhite syntax match texTikzEnv /\v\\begin\{groupplot}/ @@ -28,7 +28,7 @@ function! vimtex#syntax#p#pgfplots#load() abort " {{{1 syntax match texAxisStatement /\\nextgroupplot\>/ \ contained skipwhite nextgroup=texTikzOpts - highlight def link texAxisStatement texStatement + highlight def link texAxisStatement texCmd endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/pythontex.vim b/autoload/vimtex/syntax/p/pythontex.vim index 9efa91a9f4..0d90e2ca8d 100644 --- a/autoload/vimtex/syntax/p/pythontex.vim +++ b/autoload/vimtex/syntax/p/pythontex.vim @@ -10,7 +10,7 @@ function! vimtex#syntax#p#pythontex#load() abort " {{{1 call vimtex#syntax#misc#include('python') - syntax match texStatement /\\py[bsc]\?/ contained nextgroup=texPythontexArg + syntax match texCmd /\\py[bsc]\?/ contained nextgroup=texPythontexArg syntax region texPythontexArg matchgroup=Delimiter \ start='{' end='}' \ contained contains=@vimtex_nested_python diff --git a/autoload/vimtex/syntax/p/subfile.vim b/autoload/vimtex/syntax/p/subfile.vim index 188c6058e9..cd3c46b411 100644 --- a/autoload/vimtex/syntax/p/subfile.vim +++ b/autoload/vimtex/syntax/p/subfile.vim @@ -9,7 +9,7 @@ function! vimtex#syntax#p#subfile#load() abort " {{{1 let b:vimtex_syntax.subfile = 1 syntax match texInputFile /\\subfile\s*\%(\[.\{-}\]\)\=\s*{.\{-}}/ - \ contains=texStatement,texInputCurlies,texInputFileOpt + \ contains=texCmd,texInputCurlies,texInputFileOpt endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/tabularx.vim b/autoload/vimtex/syntax/p/tabularx.vim index f5647d5d9f..f07f4c11ee 100644 --- a/autoload/vimtex/syntax/p/tabularx.vim +++ b/autoload/vimtex/syntax/p/tabularx.vim @@ -47,13 +47,13 @@ function! vimtex#syntax#p#tabularx#load() abort " {{{1 syntax region texTabularPostPreArg matchgroup=Delimiter \ start='{' end='}' \ containedin=texTabularArg - \ contains=texLength,texStatement,texMathDelimSingle + \ contains=texLength,texCmd,texMathDelimSingle \ contained syntax region texTabularLength matchgroup=Delimiter \ start='{' end='}' \ containedin=texTabularArg - \ contains=texLength,texStatement + \ contains=texLength,texCmd \ contained syntax match texMathDelimSingle /\$\$\?/ diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index 929a830ad7..9a426240da 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -9,12 +9,12 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 let b:vimtex_syntax.tikz = 1 " Define clusters - syntax cluster texTikz contains=texTikzEnv,texBeginEnd,texStatement,texTikzSemicolon,texComment,@texVimtexGlobal - syntax cluster texTikzOS contains=texTikzOptsCurly,texTikzEqual,texMathZoneX,texTypeSize,texStatement,texLength,texComment + syntax cluster texTikz contains=texTikzEnv,texBeginEnd,texCmd,texTikzSemicolon,texComment,@texVimtexGlobal + syntax cluster texTikzOS contains=texTikzOptsCurly,texTikzEqual,texMathZoneX,texTypeSize,texCmd,texLength,texComment " Define tikz option groups syntax match texTikzSet /\\tikzset\>/ - \ contains=texStatement skipwhite nextgroup=texTikzOptsCurly + \ contains=texCmd skipwhite nextgroup=texTikzOptsCurly syntax region texTikzOpts matchgroup=Delimiter \ start='\[' end='\]' contained contains=@texTikzOS syntax region texTikzOptsCurly matchgroup=Delimiter diff --git a/autoload/vimtex/syntax/p/varioref.vim b/autoload/vimtex/syntax/p/varioref.vim index 3973a7ee34..c12a85ef4e 100644 --- a/autoload/vimtex/syntax/p/varioref.vim +++ b/autoload/vimtex/syntax/p/varioref.vim @@ -8,7 +8,7 @@ function! vimtex#syntax#p#varioref#load() abort " {{{1 if has_key(b:vimtex_syntax, 'varioref') | return | endif let b:vimtex_syntax.varioref = 1 - syntax match texStatement '\\Vref\>' nextgroup=texRegionVarioref + syntax match texCmd '\\Vref\>' nextgroup=texRegionVarioref syntax region texRegionVarioref contained matchgroup=Delimiter \ start="{" end="}" diff --git a/test/tests/test-syntax/test-core.vim b/test/tests/test-syntax/test-core.vim index b1c96cde3c..87d95cf9bf 100644 --- a/test/tests/test-syntax/test-core.vim +++ b/test/tests/test-syntax/test-core.vim @@ -5,6 +5,6 @@ silent edit test-core.tex if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texErrorStatement', 5, 3)) -call vimtex#test#assert(vimtex#syntax#in('texStatementSty', 8, 3)) +call vimtex#test#assert(vimtex#syntax#in('texCmdSty', 8, 3)) quit! From 21e78319b9152e69c790467f7745102f20dfbc22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 25 Oct 2020 12:41:42 +0100 Subject: [PATCH 07/99] wip: more consistent group names --- autoload/vimtex/syntax/core.vim | 212 +++++++++++++----------- autoload/vimtex/syntax/p/amsmath.vim | 4 +- autoload/vimtex/syntax/p/asymptote.vim | 4 +- autoload/vimtex/syntax/p/dot2texi.vim | 2 +- autoload/vimtex/syntax/p/gnuplottex.vim | 2 +- autoload/vimtex/syntax/p/listings.vim | 6 +- autoload/vimtex/syntax/p/luacode.vim | 2 +- autoload/vimtex/syntax/p/markdown.vim | 4 +- autoload/vimtex/syntax/p/minted.vim | 8 +- autoload/vimtex/syntax/p/pgfplots.vim | 4 +- autoload/vimtex/syntax/p/pythontex.vim | 4 +- autoload/vimtex/syntax/p/tabularx.vim | 2 +- autoload/vimtex/syntax/p/tikz.vim | 4 +- test/tests/test-syntax/test-core.vim | 2 +- 14 files changed, 135 insertions(+), 125 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 146de744e5..e218b77875 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -25,7 +25,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax cluster texClusterItal contains=TOP,texBoldStyle,texBoldItalStyle syntax cluster texClusterComment contains=texTodo,@Spell syntax cluster texClusterMath contains=texComment,texDelimiter,texErrorMath,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texRegionRef,texSpecialChar,texCmd,texSubscript,texSuperscript,texTypeSize,texTypeStyle,@NoSpell - syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texDelimiter,texDocType,texErrorMath,texGreek,texInput,texLength,texLigature,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texNewCmd,texNewEnv,texRegion,texRegionRef,texSection,texSpecialChar,texCmd,texString,texSubscript,texSuperscript,texTypeSize,texTypeStyle + syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texDelimiter,texDocType,texErrorMath,texGreek,texInput,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texNewCmd,texNewEnv,texRegion,texRegionRef,texSection,texSpecialChar,texCmd,texSymbolString,texSubscript,texSuperscript,texTypeSize,texTypeStyle syntax cluster texClusterRef contains=texComment,texDelimiter,texMatcher " {{{2 Primitives @@ -38,42 +38,42 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texDelimiter "&" - " TeX String Delimiters - syntax match texString "\v%(``|''|,,)" - " Flag mismatching ending delimiters } and ] syntax match texError "[}\]]" syntax match texErrorMath "}" contained " Tex commands syntax match texCmd "\\\a\+" - syntax match texErrorStatement "\\\a*@\a*" + syntax match texCmdError "\\\a*@\a*" " Accents and ligatures - syntax match texAccent "\\[bcdvuH]$" - syntax match texAccent "\\[bcdvuH]\ze\A" - syntax match texAccent /\\[=^.\~"`']/ - syntax match texAccent /\\['=t'.c^ud"vb~Hr]{\a}/ - syntax match texLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)$" - syntax match texLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze\A" - syntax match texLigature '--' - syntax match texLigature '---' + syntax match texCmdAccent "\\[bcdvuH]$" + syntax match texCmdAccent "\\[bcdvuH]\ze\A" + syntax match texCmdAccent /\\[=^.\~"`']/ + syntax match texCmdAccent /\\['=t'.c^ud"vb~Hr]{\a}/ + syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)$" + syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze\A" + + " Various TeX symbols + syntax match texSymbolString "\v%(``|''|,,)" + syntax match texSymbolDash '--' + syntax match texSymbolDash '---' if l:cfg.is_style_document syntax match texCmd "\\[a-zA-Z@]\+" - syntax match texAccent "\\[bcdvuH]\ze[^a-zA-Z@]" - syntax match texLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze[^a-zA-Z@]" + syntax match texCmdAccent "\\[bcdvuH]\ze[^a-zA-Z@]" + syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze[^a-zA-Z@]" endif " Environments - syntax match texBeginEnd "\v\\%(begin|end)>" nextgroup=texBeginEndName - syntax region texBeginEndName matchgroup=Delimiter start="{" end="}" contained contains=texComment nextgroup=texBeginEndModifier - syntax region texBeginEndModifier matchgroup=Delimiter start="\[" end="]" contained contains=texComment,@NoSpell + syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvName + syntax region texEnvName matchgroup=Delimiter start="{" end="}" contained contains=texComment nextgroup=texEnvModifier + syntax region texEnvModifier matchgroup=Delimiter start="\[" end="]" contained contains=texComment,@NoSpell " Some common, specific LaTeX commands " TODO: This should be updated! - syntax match texDocType "\v\\%(documentclass|documentstyle|usepackage)>" nextgroup=texBeginEndName,texDocTypeArgs - syntax region texDocTypeArgs matchgroup=Delimiter start="\[" end="]" contained nextgroup=texBeginEndName contains=texComment,@NoSpell + syntax match texDocType "\v\\%(documentclass|documentstyle|usepackage)>" nextgroup=texEnvName,texDocTypeArgs + syntax region texDocTypeArgs matchgroup=Delimiter start="\[" end="]" contained nextgroup=texEnvName contains=texComment,@NoSpell " Other syntax match texOption "\v%(^|[^\\]\zs)#\d+" @@ -187,15 +187,23 @@ function! vimtex#syntax#core#init() abort " {{{1 " }}}2 - " Should probably add highlighting of things like this: - " \section - " \frontmatter -> \part - " \paragraph - " \chapter " \author " \title " \begin{abstract}? + " {{{2 Sections and parts + + syntax match texCmdParts "\\\(front\|main\|back\)matter\>" + syntax match texCmdParts "\\part\>" nextgroup=texPartTitle + syntax match texCmdParts "\\chapter\>" nextgroup=texPartTitle + syntax match texCmdParts "\\\(sub\)*section\>" nextgroup=texPartTitle + syntax match texCmdParts "\\\(sub\)\?paragraph\>" nextgroup=texPartTitle + syntax region texPartTitle matchgroup=Delimiter + \ start='{' end='}' + \ contained contains=TOP + + " }}}2 + " {{{2 Math stuff " Bad/Mismatched math @@ -286,9 +294,9 @@ function! vimtex#syntax#core#init() abort " {{{1 " \makeatletter ... \makeatother sections " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do " In short: allow @ in multicharacter macro name - syntax region texRegionSty matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP,texErrorStatement - syntax region texMatcherSty matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=TOP,texErrorStatement contained - syntax region texMatcherSty matchgroup=Delimiter start="\[" end="]" contains=TOP,texErrorStatement contained + syntax region texRegionSty matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP,texCmdError + syntax region texMatcherSty matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=TOP,texCmdError contained + syntax region texMatcherSty matchgroup=Delimiter start="\[" end="]" contains=TOP,texCmdError contained syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=texRegionSty " }}}2 @@ -424,86 +432,88 @@ endfunction " }}}1 function! s:init_highlights(cfg) abort " {{{1 + " Basic TeX highlighting groups + highlight def link texCmd Statement + highlight def link texCmdArgs Number + highlight def link texCmdName Statement + highlight def link texComment Comment + highlight def link texCommentAcronym Comment + highlight def link texCommentURL Comment + highlight def link texDef Statement + highlight def link texDefParm Special + highlight def link texDefParmNested Identifier + highlight def link texDelimiter Delimiter + highlight def link texError Error + highlight def link texInput Special + highlight def link texInputFile Special + highlight def link texLength Number + highlight def link texMath Special + highlight def link texMathDelim Statement + highlight def link texMathOper Operator + highlight def link texNewCmd Statement + highlight def link texNewEnv Statement + highlight def link texOption Number + highlight def link texRegion PreCondit + highlight def link texRegionRef Special + highlight def link texSection PreCondit + highlight def link texSpaceCodeChar Special + highlight def link texSpecialChar SpecialChar + highlight def link texSymbolString String + highlight def link texTitle String + highlight def link texTodo Todo + highlight def link texType Type + + highlight def texBoldStyle gui=bold cterm=bold + highlight def texItalStyle gui=italic cterm=italic + highlight def texBoldItalStyle gui=bold,italic cterm=bold,italic + highlight def texItalBoldStyle gui=bold,italic cterm=bold,italic + " TeX highlighting groups which should share similar highlighting - highlight def link texBadMath texError - highlight def link texMathDelimBad texError - highlight def link texErrorMath texError - highlight def link texErrorStatement texError - highlight def link texError Error + highlight def link texBadMath texError + highlight def link texMathDelimBad texError + highlight def link texErrorMath texError + highlight def link texCmdError texError if a:cfg.is_style_document - highlight def link texOnlyMath texError + highlight def link texOnlyMath texError endif - highlight texBoldStyle gui=bold cterm=bold - highlight texItalStyle gui=italic cterm=italic - highlight texBoldItalStyle gui=bold,italic cterm=bold,italic - highlight texItalBoldStyle gui=bold,italic cterm=bold,italic - highlight def link texEmphStyle texItalStyle - highlight def link texRefCite texRegionRef + " Inherited groups + highlight def link texCmdAccent texCmd + highlight def link texCmdEnv texCmdName + highlight def link texCmdLigature texSpecialChar + highlight def link texCmdParts texCmd + highlight def link texCmdSty texCmd highlight def link texDefCmd texDef highlight def link texDefName texDef highlight def link texDocType texCmdName highlight def link texDocTypeArgs texCmdArgs - highlight def link texInputFileOpt texCmdArgs + highlight def link texEmphStyle texItalStyle + highlight def link texEnvName texSection + highlight def link texGreek texCmd highlight def link texInputCurlies texDelimiter - highlight def link texLigature texSpecialChar + highlight def link texInputFileOpt texCmdArgs + highlight def link texMatcherMath texMath + highlight def link texMathDelimKey texMathDelim highlight def link texMathDelimSet1 texMathDelim highlight def link texMathDelimSet2 texMathDelim - highlight def link texMathDelimKey texMathDelim - highlight def link texMatcherMath texMath - highlight def link texAccent texCmd - highlight def link texGreek texCmd - highlight def link texSuperscript texCmd - highlight def link texSubscript texCmd - highlight def link texSuperscripts texSuperscript - highlight def link texSubscripts texSubscript highlight def link texMathSymbol texCmd highlight def link texMathZoneV texMath + highlight def link texMathZoneV texMath highlight def link texMathZoneW texMath highlight def link texMathZoneX texMath highlight def link texMathZoneY texMath - highlight def link texMathZoneV texMath highlight def link texMathZoneZ texMath - highlight def link texBeginEnd texCmdName - highlight def link texBeginEndName texSection + highlight def link texPartTitle texTitle + highlight def link texRefCite texRegionRef + highlight def link texRegionVerb texRegion highlight def link texSpaceCode texCmd - highlight def link texCmdSty texCmd + highlight def link texSubscript texCmd + highlight def link texSubscripts texSubscript + highlight def link texSuperscript texCmd + highlight def link texSuperscripts texSuperscript + highlight def link texSymbolDash texSpecialChar highlight def link texTypeSize texType highlight def link texTypeStyle texType - - " Basic TeX highlighting groups - highlight def link texCmdArgs Number - highlight def link texCmdName Statement - highlight def link texComment Comment - highlight def link texDef Statement - highlight def link texDefParm Special - highlight def link texDelimiter Delimiter - highlight def link texInput Special - highlight def link texInputFile Special - highlight def link texLength Number - highlight def link texMath Special - highlight def link texMathDelim Statement - highlight def link texMathOper Operator - highlight def link texNewCmd Statement - highlight def link texNewEnv Statement - highlight def link texOption Number - highlight def link texRegionRef Special - highlight def link texSection PreCondit - highlight def link texSpaceCodeChar Special - highlight def link texSpecialChar SpecialChar - highlight def link texCmd Statement - highlight def link texString String - highlight def link texTodo Todo - highlight def link texType Type - highlight def link texRegion PreCondit - - " Inherited groups - highlight def link texRegionVerb texRegion - - " New - highlight def link texCommentURL Comment - highlight def link texCommentAcronym Comment - highlight def link texDefParmNested Identifier endfunction " }}}1 @@ -801,24 +811,24 @@ function! s:match_conceal_accents() " {{{1 let l:accent = s:key_accents[i] let l:target = l:targets[i] if l:accent =~# '\a' - execute 'syntax match texAccent /' . l:accent . '\%(\s*{' . l:chr . '}\|\s\+' . l:chr . '\)' . '/ conceal cchar=' . l:target + execute 'syntax match texCmdAccent /' . l:accent . '\%(\s*{' . l:chr . '}\|\s\+' . l:chr . '\)' . '/ conceal cchar=' . l:target else - execute 'syntax match texAccent /' . l:accent . '\s*\%({' . l:chr . '}\|' . l:chr . '\)' . '/ conceal cchar=' . l:target + execute 'syntax match texCmdAccent /' . l:accent . '\s*\%({' . l:chr . '}\|' . l:chr . '\)' . '/ conceal cchar=' . l:target endif endfor endfor - syntax match texAccent '\\aa\>' conceal cchar=å - syntax match texAccent '\\AA\>' conceal cchar=Å - syntax match texAccent '\\o\>' conceal cchar=ø - syntax match texAccent '\\O\>' conceal cchar=Ø - syntax match texLigature '\\AE\>' conceal cchar=Æ - syntax match texLigature '\\ae\>' conceal cchar=æ - syntax match texLigature '\\oe\>' conceal cchar=œ - syntax match texLigature '\\OE\>' conceal cchar=Œ - syntax match texLigature '\\ss\>' conceal cchar=ß - syntax match texLigature '--' conceal cchar=– - syntax match texLigature '---' conceal cchar=— + syntax match texCmdAccent '\\aa\>' conceal cchar=å + syntax match texCmdAccent '\\AA\>' conceal cchar=Å + syntax match texCmdAccent '\\o\>' conceal cchar=ø + syntax match texCmdAccent '\\O\>' conceal cchar=Ø + syntax match texCmdLigature '\\AE\>' conceal cchar=Æ + syntax match texCmdLigature '\\ae\>' conceal cchar=æ + syntax match texCmdLigature '\\oe\>' conceal cchar=œ + syntax match texCmdLigature '\\OE\>' conceal cchar=Œ + syntax match texCmdLigature '\\ss\>' conceal cchar=ß + syntax match texSymbolDash '--' conceal cchar=– + syntax match texSymbolDash '---' conceal cchar=— endfunction let s:key_accents = [ diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index 66b2b4c6c4..5905b87f57 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -13,9 +13,9 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 " Allow subequations (fixes #1019) " - This should be temporary, as it seems subequations is erroneously part of " texBadMath from Charles Campbell's syntax plugin. - syntax match texBeginEnd + syntax match texCmdEnv \ "\(\\begin\>\|\\end\>\)\ze{subequations}" - \ nextgroup=texBeginEndName + \ nextgroup=texEnvName call vimtex#syntax#core#new_math_zone('AmsA', 'align', 1) call vimtex#syntax#core#new_math_zone('AmsB', 'alignat', 1) diff --git a/autoload/vimtex/syntax/p/asymptote.vim b/autoload/vimtex/syntax/p/asymptote.vim index a88afdfe61..941e3d3cd6 100644 --- a/autoload/vimtex/syntax/p/asymptote.vim +++ b/autoload/vimtex/syntax/p/asymptote.vim @@ -14,13 +14,13 @@ function! vimtex#syntax#p#asymptote#load() abort " {{{1 \ end='\\end{asy\z1}'re=e \ keepend \ transparent - \ contains=texBeginEnd,@vimtex_nested_asy + \ contains=texCmdEnv,@vimtex_nested_asy else syntax region texRegionAsymptote \ start='\\begin{asy\z(def\)\?}'rs=s \ end='\\end{asy\z1}'re=e \ keepend - \ contains=texBeginEnd + \ contains=texCmdEnv highlight def link texRegionAsymptote texRegion endif endfunction diff --git a/autoload/vimtex/syntax/p/dot2texi.vim b/autoload/vimtex/syntax/p/dot2texi.vim index 8f0bd9acfb..7271b4bbc4 100644 --- a/autoload/vimtex/syntax/p/dot2texi.vim +++ b/autoload/vimtex/syntax/p/dot2texi.vim @@ -14,7 +14,7 @@ function! vimtex#syntax#p#dot2texi#load() abort " {{{1 \ end="\\end{dot2tex}"re=e \ keepend \ transparent - \ contains=texBeginEnd,@vimtex_nested_dot + \ contains=texCmdEnv,@vimtex_nested_dot endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/gnuplottex.vim b/autoload/vimtex/syntax/p/gnuplottex.vim index 8e22f6c3ea..3f2e495928 100644 --- a/autoload/vimtex/syntax/p/gnuplottex.vim +++ b/autoload/vimtex/syntax/p/gnuplottex.vim @@ -14,7 +14,7 @@ function! vimtex#syntax#p#gnuplottex#load() abort " {{{1 \ end='\\end{gnuplot}'re=e \ keepend \ transparent - \ contains=texBeginEnd,texBeginEndModifier,@vimtex_nested_gnuplot + \ contains=texCmdEnv,texEnvModifier,@vimtex_nested_gnuplot endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index 61ed445296..5c0058bdfa 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -20,7 +20,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 \ start="\\begin{lstlisting}\(\_s*\[\_[^\]]\{-}\]\)\?"rs=s \ end="\\end{lstlisting}\|%stopzone\>"re=e \ keepend - \ contains=texBeginEnd + \ contains=texCmdEnv " Next add nested syntax support for desired languages for l:nested in b:vimtex_syntax.listings @@ -39,7 +39,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 \ 'end="\\end{lstlisting}"re=e' \ 'keepend' \ 'transparent' - \ 'contains=texBeginEnd,@' . l:cluster + \ 'contains=texCmdEnv,@' . l:cluster execute 'syntax match' l:group_lstset \ '"\c\\lstset{.*language=' . l:nested . '\%(\s*,\|}\)"' @@ -54,7 +54,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 \ 'keepend' \ 'transparent' \ 'containedin=' . l:group_lstset - \ 'contains=texCmd,texBeginEnd,@' . l:cluster + \ 'contains=texCmd,texCmdEnv,@' . l:cluster endfor highlight link texRegionListings texRegion diff --git a/autoload/vimtex/syntax/p/luacode.vim b/autoload/vimtex/syntax/p/luacode.vim index 35d59e0938..4c5ecdb7f9 100644 --- a/autoload/vimtex/syntax/p/luacode.vim +++ b/autoload/vimtex/syntax/p/luacode.vim @@ -14,7 +14,7 @@ function! vimtex#syntax#p#luacode#load() abort " {{{1 \ end='\\end{luacode\*\?}'re=e \ keepend \ transparent - \ contains=texBeginEnd,@vimtex_nested_lua + \ contains=texCmdEnv,@vimtex_nested_lua syntax match texCmd '\\\(directlua\|luadirect\)' nextgroup=texRegionLuaArg syntax region texRegionLuaArg matchgroup=Delimiter \ start='{' diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index b4c7f9b571..9bc21e9555 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -11,9 +11,9 @@ function! vimtex#syntax#p#markdown#load() abort " {{{1 call vimtex#syntax#misc#include('markdown') " Don't quite know why this is necessary, but it is - syntax match texBeginEnd + syntax match texCmdEnv \ '\(\\begin\>\|\\end\>\)\ze{markdown}' - \ nextgroup=texBeginEndName + \ nextgroup=texEnvName syntax region texRegionMarkdown \ start='\\begin{markdown}'rs=s diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index 297cedced2..be166257c0 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -18,10 +18,10 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " Match boundaries of minted environments syntax match texMintedBounds '\\end{minted}' \ contained - \ contains=texBeginEnd + \ contains=texCmdEnv syntax match texMintedBounds '\\begin{minted}' \ contained - \ contains=texBeginEnd + \ contains=texCmdEnv \ nextgroup=texMintedBoundsOpts,texMintedName syntax region texMintedBoundsOpts matchgroup=Delimiter \ start="\[" end="\]" @@ -31,7 +31,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " Match starred custom minted environments with options syntax match texMintedStarred "\\begin{\w\+\*}" \ contained - \ contains=texBeginEnd + \ contains=texCmdEnv \ nextgroup=texMintedStarredOpts syntax region texMintedStarredOpts matchgroup=Delimiter \ start='{' @@ -99,7 +99,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 \ 'end="\\end{\z1}"re=e' \ 'keepend' \ l:transparent - \ 'contains=texMintedStarred,texBeginEnd' . l:contains_env + \ 'contains=texMintedStarred,texCmdEnv' . l:contains_env endfor " Match minted macros diff --git a/autoload/vimtex/syntax/p/pgfplots.vim b/autoload/vimtex/syntax/p/pgfplots.vim index 315b111aa5..1b8919d0ae 100644 --- a/autoload/vimtex/syntax/p/pgfplots.vim +++ b/autoload/vimtex/syntax/p/pgfplots.vim @@ -18,9 +18,9 @@ function! vimtex#syntax#p#pgfplots#load() abort " {{{1 syntax match texTikzSet /\\pgfplotsset\>/ \ contains=texCmd skipwhite nextgroup=texTikzOptsCurly syntax match texTikzEnv /\v\\begin\{%(log)*axis}/ - \ contains=texBeginEnd nextgroup=texTikzOpts skipwhite + \ contains=texCmdEnv nextgroup=texTikzOpts skipwhite syntax match texTikzEnv /\v\\begin\{groupplot}/ - \ contains=texBeginEnd nextgroup=texTikzOpts skipwhite + \ contains=texCmdEnv nextgroup=texTikzOpts skipwhite " Match some custom pgfplots macros syntax match texAxisStatement /\\addplot3\>/ diff --git a/autoload/vimtex/syntax/p/pythontex.vim b/autoload/vimtex/syntax/p/pythontex.vim index 0d90e2ca8d..0e191f3a70 100644 --- a/autoload/vimtex/syntax/p/pythontex.vim +++ b/autoload/vimtex/syntax/p/pythontex.vim @@ -23,13 +23,13 @@ function! vimtex#syntax#p#pythontex#load() abort " {{{1 \ end='\\end{pyblock}'re=e \ keepend \ transparent - \ contains=texBeginEnd,@vimtex_nested_python + \ contains=texCmdEnv,@vimtex_nested_python syntax region texRegionPythontex \ start='\\begin{pycode}'rs=s \ end='\\end{pycode}'re=e \ keepend \ transparent - \ contains=texBeginEnd,@vimtex_nested_python + \ contains=texCmdEnv,@vimtex_nested_python endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/tabularx.vim b/autoload/vimtex/syntax/p/tabularx.vim index f07f4c11ee..514b2e3890 100644 --- a/autoload/vimtex/syntax/p/tabularx.vim +++ b/autoload/vimtex/syntax/p/tabularx.vim @@ -9,7 +9,7 @@ function! vimtex#syntax#p#tabularx#load() abort " {{{1 let b:vimtex_syntax.tabularx = 1 syntax match texTabular '\\begin{tabular}\_[^{]\{-}\ze{' - \ contains=texBeginEnd + \ contains=texCmdEnv \ nextgroup=texTabularArg syntax region texTabularArg matchgroup=Delimiter \ start='{' end='}' diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index 9a426240da..d63ac8f724 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -9,7 +9,7 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 let b:vimtex_syntax.tikz = 1 " Define clusters - syntax cluster texTikz contains=texTikzEnv,texBeginEnd,texCmd,texTikzSemicolon,texComment,@texVimtexGlobal + syntax cluster texTikz contains=texTikzEnv,texCmdEnv,texCmd,texTikzSemicolon,texComment,@texVimtexGlobal syntax cluster texTikzOS contains=texTikzOptsCurly,texTikzEqual,texMathZoneX,texTypeSize,texCmd,texLength,texComment " Define tikz option groups @@ -27,7 +27,7 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 \ transparent \ contains=@texTikz syntax match texTikzEnv /\v\\begin\{tikzpicture\}/ - \ contains=texBeginEnd nextgroup=texTikzOpts skipwhite + \ contains=texCmdEnv nextgroup=texTikzOpts skipwhite syntax match texTikzEqual /=/ contained syntax match texTikzSemicolon /;/ contained diff --git a/test/tests/test-syntax/test-core.vim b/test/tests/test-syntax/test-core.vim index 87d95cf9bf..6d0a76fad3 100644 --- a/test/tests/test-syntax/test-core.vim +++ b/test/tests/test-syntax/test-core.vim @@ -4,7 +4,7 @@ silent edit test-core.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texErrorStatement', 5, 3)) +call vimtex#test#assert(vimtex#syntax#in('texCmdError', 5, 3)) call vimtex#test#assert(vimtex#syntax#in('texCmdSty', 8, 3)) quit! From b0c4c5a3ccc9b296d66cd9da7f872af96667d7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 25 Oct 2020 12:59:57 +0100 Subject: [PATCH 08/99] wip: simplified and more consistent math zones --- autoload/vimtex/delim.vim | 2 +- autoload/vimtex/syntax.vim | 2 +- autoload/vimtex/syntax/core.vim | 123 +++++++++--------- autoload/vimtex/syntax/p/amsmath.vim | 23 ++-- autoload/vimtex/syntax/p/array.vim | 4 +- autoload/vimtex/syntax/p/breqn.vim | 8 +- autoload/vimtex/syntax/p/ieeetrantools.vim | 12 +- autoload/vimtex/syntax/p/tikz.vim | 2 +- test/tests/test-syntax/test-breqn.vim | 2 +- test/tests/test-syntax/test-ieeetrantools.vim | 10 +- 10 files changed, 87 insertions(+), 101 deletions(-) diff --git a/autoload/vimtex/delim.vim b/autoload/vimtex/delim.vim index df3df9e00b..3354c19c8c 100644 --- a/autoload/vimtex/delim.vim +++ b/autoload/vimtex/delim.vim @@ -591,7 +591,7 @@ function! s:parser_tex(match, lnum, cnum, side, type, direction) abort " {{{1 \ 'close' : '\m' . escape(a:match, '$'), \} let result.side = vimtex#syntax#in( - \ (a:match ==# '$' ? 'texMathZoneX' : 'texMathZoneY'), + \ (a:match ==# '$' ? 'texRegionMathX' : 'texRegionMathY'), \ a:lnum, a:cnum+1) \ ? 'open' : 'close' let result.is_open = result.side ==# 'open' diff --git a/autoload/vimtex/syntax.vim b/autoload/vimtex/syntax.vim index 48c81238d5..de88477846 100644 --- a/autoload/vimtex/syntax.vim +++ b/autoload/vimtex/syntax.vim @@ -26,7 +26,7 @@ endfunction " }}}1 function! vimtex#syntax#in_mathzone(...) abort " {{{1 - return call('vimtex#syntax#in', ['texMathZone'] + a:000) + return call('vimtex#syntax#in', ['texRegionMath'] + a:000) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index e218b77875..d7df043bfe 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -207,8 +207,8 @@ function! vimtex#syntax#core#init() abort " {{{1 " {{{2 Math stuff " Bad/Mismatched math - syntax match texBadMath "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}" - syntax match texBadMath "\\[\])]" + syntax match texErrorMath "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}" + syntax match texErrorMath "\\[\])]" " Operators and similar syntax match texMathOper "[_^=]" contained @@ -217,25 +217,30 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax region texMathText matchgroup=texCmd start="\\\(\(inter\)\?text\|mbox\)\s*{" end="}" contains=TOP,@Spell " Math environments - call vimtex#syntax#core#new_math_zone('A', 'displaymath', 1) - call vimtex#syntax#core#new_math_zone('B', 'eqnarray', 1) - call vimtex#syntax#core#new_math_zone('C', 'equation', 1) - call vimtex#syntax#core#new_math_zone('D', 'math', 1) + call vimtex#syntax#core#new_math_zone('displaymath', 1) + call vimtex#syntax#core#new_math_zone('eqnarray', 1) + call vimtex#syntax#core#new_math_zone('equation', 1) + call vimtex#syntax#core#new_math_zone('math', 1) " Inline Math Zones - syntax region texMathZoneZ matchgroup=texCmd start="\\ensuremath\s*{" matchgroup=texCmd end="}" contains=@texClusterMath if l:cfg.conceal =~# 'd' && &encoding ==# 'utf-8' - syntax region texMathZoneV matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" concealends contains=@texClusterMath keepend - syntax region texMathZoneW matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" concealends contains=@texClusterMath keepend - syntax region texMathZoneX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" concealends contains=@texClusterMath - syntax region texMathZoneY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" concealends contains=@texClusterMath keepend + syntax region texRegionMath matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" concealends contains=@texClusterMath keepend + syntax region texRegionMath matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" concealends contains=@texClusterMath keepend + syntax region texRegionMathX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" concealends contains=@texClusterMath + syntax region texRegionMathY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" concealends contains=@texClusterMath keepend else - syntax region texMathZoneV matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" contains=@texClusterMath keepend - syntax region texMathZoneW matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" contains=@texClusterMath keepend - syntax region texMathZoneX matchgroup=Delimiter start="\$" skip="\%(\\\\\)*\\\$" matchgroup=Delimiter end="\$" contains=@texClusterMath - syntax region texMathZoneY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" contains=@texClusterMath keepend + syntax region texRegionMath matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" contains=@texClusterMath keepend + syntax region texRegionMath matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" contains=@texClusterMath keepend + syntax region texRegionMathX matchgroup=Delimiter start="\$" skip="\%(\\\\\)*\\\$" matchgroup=Delimiter end="\$" contains=@texClusterMath + syntax region texRegionMathY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" contains=@texClusterMath keepend endif + syntax match texCmd "\\ensuremath\>" nextgroup=texRegionMathEnsured + syntax region texRegionMathEnsured matchgroup=Delimiter + \ start="{" end="}" + \ contained + \ contains=@texClusterMath + " Math delimiters: \left... and \right... syntax match texMathDelimBad contained "\S" if l:cfg.conceal !~# 'm' || &encoding !=# 'utf-8' @@ -406,27 +411,20 @@ endfunction " }}}1 -function! vimtex#syntax#core#new_math_zone(sfx, mathzone, starred) abort " {{{1 - " This function is based on Charles E. Campbell's syntax script (version 119, - " dated 2020-06-29) - - execute 'syntax match texBadMath /\\end\s*{\s*' . a:mathzone . '\*\?\s*}/' +function! vimtex#syntax#core#new_math_zone(mathzone, starred) abort " {{{1 + execute 'syntax match texErrorMath /\\end\s*{\s*' . a:mathzone . '\*\?\s*}/' - let grp = 'texMathZone' . a:sfx - execute 'syntax region ' . grp + execute 'syntax region texRegionMathEnv' \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\s*}''' \ . ' end=''\\end\s*{\s*' . a:mathzone . '\s*}''' \ . ' keepend contains=@texClusterMath' - execute 'highlight def link ' . grp . ' texMath' if !a:starred | return | endif - let grp .= 'S' - execute 'syntax region ' . grp + execute 'syntax region texRegionMathEnvStarred' \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\*\s*}''' \ . ' end=''\\end\s*{\s*' . a:mathzone . '\*\s*}''' \ . ' keepend contains=@texClusterMath' - execute 'highlight def link ' . grp . ' texMath' endfunction " }}}1 @@ -469,7 +467,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def texItalBoldStyle gui=bold,italic cterm=bold,italic " TeX highlighting groups which should share similar highlighting - highlight def link texBadMath texError highlight def link texMathDelimBad texError highlight def link texErrorMath texError highlight def link texCmdError texError @@ -478,42 +475,42 @@ function! s:init_highlights(cfg) abort " {{{1 endif " Inherited groups - highlight def link texCmdAccent texCmd - highlight def link texCmdEnv texCmdName - highlight def link texCmdLigature texSpecialChar - highlight def link texCmdParts texCmd - highlight def link texCmdSty texCmd - highlight def link texDefCmd texDef - highlight def link texDefName texDef - highlight def link texDocType texCmdName - highlight def link texDocTypeArgs texCmdArgs - highlight def link texEmphStyle texItalStyle - highlight def link texEnvName texSection - highlight def link texGreek texCmd - highlight def link texInputCurlies texDelimiter - highlight def link texInputFileOpt texCmdArgs - highlight def link texMatcherMath texMath - highlight def link texMathDelimKey texMathDelim - highlight def link texMathDelimSet1 texMathDelim - highlight def link texMathDelimSet2 texMathDelim - highlight def link texMathSymbol texCmd - highlight def link texMathZoneV texMath - highlight def link texMathZoneV texMath - highlight def link texMathZoneW texMath - highlight def link texMathZoneX texMath - highlight def link texMathZoneY texMath - highlight def link texMathZoneZ texMath - highlight def link texPartTitle texTitle - highlight def link texRefCite texRegionRef - highlight def link texRegionVerb texRegion - highlight def link texSpaceCode texCmd - highlight def link texSubscript texCmd - highlight def link texSubscripts texSubscript - highlight def link texSuperscript texCmd - highlight def link texSuperscripts texSuperscript - highlight def link texSymbolDash texSpecialChar - highlight def link texTypeSize texType - highlight def link texTypeStyle texType + highlight def link texCmdAccent texCmd + highlight def link texCmdEnv texCmdName + highlight def link texCmdLigature texSpecialChar + highlight def link texCmdParts texCmd + highlight def link texCmdSty texCmd + highlight def link texDefCmd texDef + highlight def link texDefName texDef + highlight def link texDocType texCmdName + highlight def link texDocTypeArgs texCmdArgs + highlight def link texEmphStyle texItalStyle + highlight def link texEnvName texSection + highlight def link texGreek texCmd + highlight def link texInputCurlies texDelimiter + highlight def link texInputFileOpt texCmdArgs + highlight def link texMatcherMath texMath + highlight def link texMathDelimKey texMathDelim + highlight def link texMathDelimSet1 texMathDelim + highlight def link texMathDelimSet2 texMathDelim + highlight def link texMathSymbol texCmd + highlight def link texPartTitle texTitle + highlight def link texRefCite texRegionRef + highlight def link texRegionMath texMath + highlight def link texRegionMathEnsured texMath + highlight def link texRegionMathEnv texMath + highlight def link texRegionMathEnvStarred texMath + highlight def link texRegionMathX texMath + highlight def link texRegionMathY texMath + highlight def link texRegionVerb texRegion + highlight def link texSpaceCode texCmd + highlight def link texSubscript texCmd + highlight def link texSubscripts texSubscript + highlight def link texSuperscript texCmd + highlight def link texSuperscripts texSuperscript + highlight def link texSymbolDash texSpecialChar + highlight def link texTypeSize texType + highlight def link texTypeStyle texType endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index 5905b87f57..43af44d639 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -10,21 +10,14 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 if has_key(b:vimtex_syntax, 'amsmath') | return | endif let b:vimtex_syntax.amsmath = 1 - " Allow subequations (fixes #1019) - " - This should be temporary, as it seems subequations is erroneously part of - " texBadMath from Charles Campbell's syntax plugin. - syntax match texCmdEnv - \ "\(\\begin\>\|\\end\>\)\ze{subequations}" - \ nextgroup=texEnvName - - call vimtex#syntax#core#new_math_zone('AmsA', 'align', 1) - call vimtex#syntax#core#new_math_zone('AmsB', 'alignat', 1) - call vimtex#syntax#core#new_math_zone('AmsD', 'flalign', 1) - call vimtex#syntax#core#new_math_zone('AmsC', 'gather', 1) - call vimtex#syntax#core#new_math_zone('AmsD', 'multline', 1) - call vimtex#syntax#core#new_math_zone('AmsE', 'xalignat', 1) - call vimtex#syntax#core#new_math_zone('AmsF', 'xxalignat', 0) - call vimtex#syntax#core#new_math_zone('AmsG', 'mathpar', 1) + call vimtex#syntax#core#new_math_zone('align', 1) + call vimtex#syntax#core#new_math_zone('alignat', 1) + call vimtex#syntax#core#new_math_zone('flalign', 1) + call vimtex#syntax#core#new_math_zone('gather', 1) + call vimtex#syntax#core#new_math_zone('multline', 1) + call vimtex#syntax#core#new_math_zone('xalignat', 1) + call vimtex#syntax#core#new_math_zone('xxalignat', 0) + call vimtex#syntax#core#new_math_zone('mathpar', 1) " Amsmath [lr][vV]ert (Holger Mitschke) if has('conceal') && &enc ==# 'utf-8' && get(g:, 'tex_conceal', 'd') =~# 'd' diff --git a/autoload/vimtex/syntax/p/array.vim b/autoload/vimtex/syntax/p/array.vim index 7ee79a3e25..61e6502c69 100644 --- a/autoload/vimtex/syntax/p/array.vim +++ b/autoload/vimtex/syntax/p/array.vim @@ -19,8 +19,8 @@ function! vimtex#syntax#p#array#load() abort " {{{1 " \begin{tabular}{*{3}{>{$}c<{$}}} " " See: https://en.wikibooks.org/wiki/LaTeX/Tables#Column_specification_using_.3E.7B.5Ccmd.7D_and_.3C.7B.5Ccmd.7D - syntax clear texMathZoneX - execute 'syntax region texMathZoneX' + syntax clear texRegionMathX + execute 'syntax region texRegionMathX' \ 'matchgroup=Delimiter' \ 'start="\([<>]{\)\@/ diff --git a/test/tests/test-syntax/test-breqn.vim b/test/tests/test-syntax/test-breqn.vim index 556d23a9bb..70ca346c21 100644 --- a/test/tests/test-syntax/test-breqn.vim +++ b/test/tests/test-syntax/test-breqn.vim @@ -4,7 +4,7 @@ silent edit test-breqn.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texMathZoneBreqnA', 9, 1)) +call vimtex#test#assert(vimtex#syntax#in('texRegionMathEnv', 9, 1)) quit! diff --git a/test/tests/test-syntax/test-ieeetrantools.vim b/test/tests/test-syntax/test-ieeetrantools.vim index 81eb5d0273..bf79c9e71d 100644 --- a/test/tests/test-syntax/test-ieeetrantools.vim +++ b/test/tests/test-syntax/test-ieeetrantools.vim @@ -4,11 +4,9 @@ silent edit test-ieeetrantools.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texMathZoneIEEEeqnA', 8, 1)) -call vimtex#test#assert(vimtex#syntax#in('texMathZoneIEEEeqnA', 13, 1)) - -call vimtex#test#assert(vimtex#syntax#in('texMathZoneC', 24, 1)) - -call vimtex#test#assert(vimtex#syntax#in('texMathZoneIEEEeqnB', 31, 1)) +call vimtex#test#assert(vimtex#syntax#in('texRegionMathEnv', 8, 1)) +call vimtex#test#assert(vimtex#syntax#in('texRegionMathEnv', 13, 1)) +call vimtex#test#assert(vimtex#syntax#in('texRegionMathEnv', 24, 1)) +call vimtex#test#assert(vimtex#syntax#in('texRegionMathEnv', 31, 1)) quit! From a482c1d2b5996a9eebd6744577135c5b9558daeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 25 Oct 2020 13:22:05 +0100 Subject: [PATCH 09/99] wip: consistent math environment matching --- autoload/vimtex/syntax/core.vim | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index d7df043bfe..9772f6d36d 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -24,8 +24,8 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax cluster texClusterBold contains=TOP,texItalStyle,texItalBoldStyle,texEmphStyle syntax cluster texClusterItal contains=TOP,texBoldStyle,texBoldItalStyle syntax cluster texClusterComment contains=texTodo,@Spell - syntax cluster texClusterMath contains=texComment,texDelimiter,texErrorMath,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texRegionRef,texSpecialChar,texCmd,texSubscript,texSuperscript,texTypeSize,texTypeStyle,@NoSpell - syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texDelimiter,texDocType,texErrorMath,texGreek,texInput,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texNewCmd,texNewEnv,texRegion,texRegionRef,texSection,texSpecialChar,texCmd,texSymbolString,texSubscript,texSuperscript,texTypeSize,texTypeStyle + syntax cluster texClusterMath contains=texCmdEnvMath,texEnvMathName,texComment,texDelimiter,texErrorMathDelim,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texRegionRef,texSpecialChar,texCmd,texSubscript,texSuperscript,texTypeSize,texTypeStyle,@NoSpell + syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texDelimiter,texDocType,texErrorMathDelim,texGreek,texInput,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texNewCmd,texNewEnv,texRegion,texRegionRef,texSection,texSpecialChar,texCmd,texSymbolString,texSubscript,texSuperscript,texTypeSize,texTypeStyle syntax cluster texClusterRef contains=texComment,texDelimiter,texMatcher " {{{2 Primitives @@ -40,7 +40,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " Flag mismatching ending delimiters } and ] syntax match texError "[}\]]" - syntax match texErrorMath "}" contained + syntax match texErrorMathDelim "}" contained " Tex commands syntax match texCmd "\\\a\+" @@ -67,8 +67,16 @@ function! vimtex#syntax#core#init() abort " {{{1 " Environments syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvName - syntax region texEnvName matchgroup=Delimiter start="{" end="}" contained contains=texComment nextgroup=texEnvModifier - syntax region texEnvModifier matchgroup=Delimiter start="\[" end="]" contained contains=texComment,@NoSpell + syntax region texEnvName matchgroup=Delimiter + \ start="{" end="}" + \ contained contains=texComment nextgroup=texEnvModifier + syntax region texEnvModifier matchgroup=Delimiter + \ start="\[" end="]" + \ contained contains=texComment,@NoSpell + syntax match texCmdEnvMath "\v\\%(begin|end)>" contained nextgroup=texEnvMathName + syntax region texEnvMathName matchgroup=Delimiter + \ start="{" end="}" + \ contained contains=texComment " Some common, specific LaTeX commands " TODO: This should be updated! @@ -477,6 +485,7 @@ function! s:init_highlights(cfg) abort " {{{1 " Inherited groups highlight def link texCmdAccent texCmd highlight def link texCmdEnv texCmdName + highlight def link texCmdEnvMath texCmdEnv highlight def link texCmdLigature texSpecialChar highlight def link texCmdParts texCmd highlight def link texCmdSty texCmd @@ -485,6 +494,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texDocType texCmdName highlight def link texDocTypeArgs texCmdArgs highlight def link texEmphStyle texItalStyle + highlight def link texEnvMathName Delimiter highlight def link texEnvName texSection highlight def link texGreek texCmd highlight def link texInputCurlies texDelimiter From cc2b0cb226d5c3bc5b2ba5f1face0e0d00442b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 25 Oct 2020 21:28:34 +0100 Subject: [PATCH 10/99] wip: fixed verbatim groups --- autoload/vimtex/syntax/core.vim | 22 +++++++++++++++++----- test/tests/test-syntax/test-core.tex | 3 +++ test/tests/test-syntax/test-core.vim | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 9772f6d36d..52e997c798 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -285,15 +285,26 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texOnlyMath "[_^]" contained syntax match texSpecialChar "\^\^[0-9a-f]\{2}\|\^\^\S" - " {{{2 Specific commands/environments + " {{{2 Verbatim + + " Verbatim environment + syntax region texRegionVerb + \ start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}" + \ contains=texCmdEnv,texEnvName - " Verbatim - syntax region texRegionVerb start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}" - syntax region texRegionVerb start="\\verb\*\?\z([^\ta-zA-Z]\)" end="\z1" + " Verbatim inline + syntax match texCmd "\\verb\>\*\?" nextgroup=texRegionVerbInline if l:cfg.is_style_document - syntax region texRegionVerb start="\\verb\*\?\z([^\ta-zA-Z@]\)" end="\z1" + syntax region texRegionVerbInline matchgroup=Delimiter + \ start="\z([^\ta-zA-Z@]\)" end="\z1" contained + else + syntax region texRegionVerbInline matchgroup=Delimiter + \ start="\z([^\ta-zA-Z]\)" end="\z1" contained endif + " }}}2 + " {{{2 Specific commands/environments + " Tex Reference Zones syntax match texRegionRef '\\cite\%([tp]\*\?\)\?\>' nextgroup=texRefOption,texRefCite syntax region texRegionRef matchgroup=texCmd start="\\nocite{" end="}" contains=@texClusterRef @@ -513,6 +524,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texRegionMathX texMath highlight def link texRegionMathY texMath highlight def link texRegionVerb texRegion + highlight def link texRegionVerbInline texRegionVerb highlight def link texSpaceCode texCmd highlight def link texSubscript texCmd highlight def link texSubscripts texSubscript diff --git a/test/tests/test-syntax/test-core.tex b/test/tests/test-syntax/test-core.tex index 8e6479a7c0..966720f9dc 100644 --- a/test/tests/test-syntax/test-core.tex +++ b/test/tests/test-syntax/test-core.tex @@ -13,4 +13,7 @@ \v! \v@ +Line with inline verbatim: \verb+verb+ +Line with inline verbatim: \verb*+verb+ + \end{document} diff --git a/test/tests/test-syntax/test-core.vim b/test/tests/test-syntax/test-core.vim index 6d0a76fad3..b951f711f9 100644 --- a/test/tests/test-syntax/test-core.vim +++ b/test/tests/test-syntax/test-core.vim @@ -7,4 +7,6 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texCmdError', 5, 3)) call vimtex#test#assert(vimtex#syntax#in('texCmdSty', 8, 3)) +call vimtex#test#assert(vimtex#syntax#in('texRegionVerbInline', 17, 36)) + quit! From 6ace9bee4b43abe8ae63b90115355c1b19a5b975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 25 Oct 2020 22:56:51 +0100 Subject: [PATCH 11/99] wip: more consistent fileinclude groups --- autoload/vimtex/options.vim | 15 +-- autoload/vimtex/syntax/core.vim | 119 +++++++++++++---------- autoload/vimtex/syntax/p/beamer.vim | 6 +- autoload/vimtex/syntax/p/listings.vim | 5 +- autoload/vimtex/syntax/p/markdown.vim | 25 ++--- autoload/vimtex/syntax/p/minted.vim | 2 +- autoload/vimtex/syntax/p/pdfpages.vim | 17 +--- autoload/vimtex/syntax/p/subfile.vim | 4 +- test/tests/test-syntax/test-markdown.vim | 2 +- 9 files changed, 93 insertions(+), 102 deletions(-) diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index 4f7badc109..0fcc9f1494 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -279,16 +279,19 @@ function! vimtex#options#init() abort " {{{1 \ 'cs' : [ \ 'csBraces', \ ], - \ 'python' : [ - \ 'pythonEscape', - \ 'pythonBEscape', - \ 'pythonBytesEscape', + \ 'haskell' : [ + \ 'hsVarSym', \ ], \ 'java' : [ \ 'javaError', \ ], - \ 'haskell' : [ - \ 'hsVarSym', + \ 'markdown' : [ + \ 'mkdNonListItemBlock', + \ ], + \ 'python' : [ + \ 'pythonEscape', + \ 'pythonBEscape', + \ 'pythonBytesEscape', \ ], \ } \}) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 52e997c798..de8fb68ae5 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -25,7 +25,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax cluster texClusterItal contains=TOP,texBoldStyle,texBoldItalStyle syntax cluster texClusterComment contains=texTodo,@Spell syntax cluster texClusterMath contains=texCmdEnvMath,texEnvMathName,texComment,texDelimiter,texErrorMathDelim,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texRegionRef,texSpecialChar,texCmd,texSubscript,texSuperscript,texTypeSize,texTypeStyle,@NoSpell - syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texDelimiter,texDocType,texErrorMathDelim,texGreek,texInput,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texNewCmd,texNewEnv,texRegion,texRegionRef,texSection,texSpecialChar,texCmd,texSymbolString,texSubscript,texSuperscript,texTypeSize,texTypeStyle + syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texDelimiter,texErrorMathDelim,texGreek,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texNewCmd,texNewEnv,texRegion,texRegionRef,texSection,texSpecialChar,texCmd,texSymbolString,texSubscript,texSuperscript,texTypeSize,texTypeStyle syntax cluster texClusterRef contains=texComment,texDelimiter,texMatcher " {{{2 Primitives @@ -66,33 +66,21 @@ function! vimtex#syntax#core#init() abort " {{{1 endif " Environments - syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvName + syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvName syntax region texEnvName matchgroup=Delimiter \ start="{" end="}" \ contained contains=texComment nextgroup=texEnvModifier syntax region texEnvModifier matchgroup=Delimiter \ start="\[" end="]" \ contained contains=texComment,@NoSpell - syntax match texCmdEnvMath "\v\\%(begin|end)>" contained nextgroup=texEnvMathName + syntax match texCmdEnvMath "\v\\%(begin|end)>" contained nextgroup=texEnvMathName syntax region texEnvMathName matchgroup=Delimiter \ start="{" end="}" \ contained contains=texComment - " Some common, specific LaTeX commands - " TODO: This should be updated! - syntax match texDocType "\v\\%(documentclass|documentstyle|usepackage)>" nextgroup=texEnvName,texDocTypeArgs - syntax region texDocTypeArgs matchgroup=Delimiter start="\[" end="]" contained nextgroup=texEnvName contains=texComment,@NoSpell - " Other syntax match texOption "\v%(^|[^\\]\zs)#\d+" - " TeX input - syntax match texInput "\\input\s\+[a-zA-Z/.0-9_^]\+"hs=s+7 contains=texCmd - syntax match texInputFile "\v\\include%(graphics|list)?%(\[.{-}\])?\s*\{.{-}\}" contains=texCmd,texInputCurlies,texInputFileOpt - syntax match texInputFile "\v\\%(epsfig|input)\s*%(\[.*\])?\{.{-}\}" contains=texCmd,texInputCurlies,texInputFileOpt - syntax match texInputCurlies "[{}]" contained - syntax region texInputFileOpt matchgroup=Delimiter start="\[" end="\]" contains=texComment contained - " Spacecodes (TeX'isms) " * \mathcode`\^^@ = "2201 " * \delcode`\( = "028300 @@ -305,15 +293,33 @@ function! vimtex#syntax#core#init() abort " {{{1 " }}}2 " {{{2 Specific commands/environments + " Various commands that take a file argument (or similar) + syntax match texCmd "\\input\>" nextgroup=texFilename + syntax match texCmd "\\include\>" nextgroup=texFilename + syntax match texCmd "\\includeonly\>" nextgroup=texFilenames + syntax match texCmd "\\includegraphics\>" nextgroup=texOptGenericFile,texFilename + syntax match texCmd "\\bibliography\>" nextgroup=texFilenames + syntax match texCmd "\\document\%(class\|style\)\>" nextgroup=texOptGenericFile,texFilename + syntax match texCmd "\\usepackage\>" nextgroup=texOptGenericFiles,texFilenames + syntax match texCmd "\\RequirePackage\>" nextgroup=texOptGenericFiles,texFilenames + + call s:add_opt_group('GenericFile', 'texFilename') + call s:add_opt_group('GenericFiles', 'texFilenames') + + syntax region texFilename matchgroup=Delimiter + \ start="{" end="}" contained contains=texCmd,texComment,@NoSpell + syntax region texFilenames matchgroup=Delimiter + \ start="{" end="}" contained contains=texFilenameSeparator,texCmd,texComment,@NoSpell + syntax match texFilenameSeparator ",\s*" contained + " Tex Reference Zones syntax match texRegionRef '\\cite\%([tp]\*\?\)\?\>' nextgroup=texRefOption,texRefCite syntax region texRegionRef matchgroup=texCmd start="\\nocite{" end="}" contains=@texClusterRef - syntax region texRegionRef matchgroup=texCmd start="\\bibliography{" end="}" contains=@texClusterRef syntax region texRegionRef matchgroup=texCmd start="\\label{" end="}" contains=@texClusterRef syntax region texRegionRef matchgroup=texCmd start="\\\(page\|eq\)ref{" end="}" contains=@texClusterRef syntax region texRegionRef matchgroup=texCmd start="\\v\?ref{" end="}" contains=@texClusterRef - syntax region texRefOption matchgroup=Delimiter start='\[' end=']' contains=@texClusterRef,texRegionRef nextgroup=texRefOption,texRefCite contained - syntax region texRefCite matchgroup=Delimiter start='{' end='}' contains=@texClusterRef,texRegionRef,texRefCite contained + syntax region texRefOption matchgroup=Delimiter start='\[' end=']' contains=@texClusterRef,texRegionRef nextgroup=texRefOption,texRefCite contained + syntax region texRefCite matchgroup=Delimiter start='{' end='}' contains=@texClusterRef,texRegionRef,texRefCite contained " \makeatletter ... \makeatother sections " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do @@ -449,36 +455,38 @@ endfunction " }}}1 function! s:init_highlights(cfg) abort " {{{1 + " See :help group-names for list of conventional group names + " Basic TeX highlighting groups - highlight def link texCmd Statement - highlight def link texCmdArgs Number - highlight def link texCmdName Statement - highlight def link texComment Comment - highlight def link texCommentAcronym Comment - highlight def link texCommentURL Comment - highlight def link texDef Statement - highlight def link texDefParm Special - highlight def link texDefParmNested Identifier - highlight def link texDelimiter Delimiter - highlight def link texError Error - highlight def link texInput Special - highlight def link texInputFile Special - highlight def link texLength Number - highlight def link texMath Special - highlight def link texMathDelim Statement - highlight def link texMathOper Operator - highlight def link texNewCmd Statement - highlight def link texNewEnv Statement - highlight def link texOption Number - highlight def link texRegion PreCondit - highlight def link texRegionRef Special - highlight def link texSection PreCondit - highlight def link texSpaceCodeChar Special - highlight def link texSpecialChar SpecialChar - highlight def link texSymbolString String - highlight def link texTitle String - highlight def link texTodo Todo - highlight def link texType Type + highlight def link texCmd Statement + highlight def link texCmdArgs Number + highlight def link texCmdName Statement + highlight def link texComment Comment + highlight def link texCommentAcronym Comment + highlight def link texCommentURL Comment + highlight def link texDef Statement + highlight def link texDefParm Special + highlight def link texDefParmNested Identifier + highlight def link texDelimiter Delimiter + highlight def link texError Error + highlight def link texFilename Include + highlight def link texFilenameSeparator NormalNC + highlight def link texLength Number + highlight def link texMath Special + highlight def link texMathDelim Statement + highlight def link texMathOper Operator + highlight def link texNewCmd Statement + highlight def link texNewEnv Statement + highlight def link texOption Number + highlight def link texRegion PreCondit + highlight def link texRegionRef Special + highlight def link texSection PreCondit + highlight def link texSpaceCodeChar Special + highlight def link texSpecialChar SpecialChar + highlight def link texSymbolString String + highlight def link texTitle String + highlight def link texTodo Todo + highlight def link texType Type highlight def texBoldStyle gui=bold cterm=bold highlight def texItalStyle gui=italic cterm=italic @@ -502,19 +510,18 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdSty texCmd highlight def link texDefCmd texDef highlight def link texDefName texDef - highlight def link texDocType texCmdName - highlight def link texDocTypeArgs texCmdArgs highlight def link texEmphStyle texItalStyle highlight def link texEnvMathName Delimiter highlight def link texEnvName texSection + highlight def link texFilenames texFilename highlight def link texGreek texCmd - highlight def link texInputCurlies texDelimiter - highlight def link texInputFileOpt texCmdArgs highlight def link texMatcherMath texMath highlight def link texMathDelimKey texMathDelim highlight def link texMathDelimSet1 texMathDelim highlight def link texMathDelimSet2 texMathDelim highlight def link texMathSymbol texCmd + highlight def link texOptGenericFile texCmdArgs + highlight def link texOptGenericFiles texCmdArgs highlight def link texPartTitle texTitle highlight def link texRefCite texRegionRef highlight def link texRegionMath texMath @@ -537,6 +544,16 @@ endfunction " }}}1 + function! s:add_opt_group(grp, next) abort " {{{1 + execute 'syntax region texOpt' . a:grp + \ 'matchgroup=Delimiter' + \ 'start="\[" end="\]" contained' + \ 'contains=texComment' + \ 'nextgroup=' . a:next + endfunction + + " }}}1 + function! s:match_conceal_math_delims() abort " {{{1 syntax match texMathSymbol "\\[bB]igg\?[lr]\?<" contained conceal cchar=< syntax match texMathSymbol "\\[bB]igg\?[lr]\?>" contained conceal cchar=> diff --git a/autoload/vimtex/syntax/p/beamer.vim b/autoload/vimtex/syntax/p/beamer.vim index 109dd0e9e6..3cc9b8dc80 100644 --- a/autoload/vimtex/syntax/p/beamer.vim +++ b/autoload/vimtex/syntax/p/beamer.vim @@ -14,9 +14,9 @@ function! vimtex#syntax#p#beamer#load() abort " {{{1 syntax match texCmdBeamer '\\only\(<[^>]*>\)\?' contains=texBeamerOpt syntax match texCmdBeamer '\\item<[^>]*>' contains=texBeamerOpt - syntax match texInputFile - \ '\\includegraphics<[^>]*>\(\[.\{-}\]\)\=\s*{.\{-}}' - \ contains=texCmd,texBeamerOpt,texInputCurlies,texInputFileOpt + syntax match texCmd "\\includegraphics<[^>]*>" + \ contains=texBeamerOpt, + \ nextgroup=texOptGenericFile,texFilename highlight link texCmdBeamer texCmd highlight link texBeamerOpt Identifier diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index 5c0058bdfa..3d6cc4c114 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -9,9 +9,8 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 let b:vimtex_syntax.listings = s:get_nested_languages() " First some general support - syntax match texInputFile - \ "\\lstinputlisting\s*\(\[.\{-}\]\)\={.\{-}}" - \ contains=texCmd,texInputCurlies,texInputFileOpt + syntax match texCmd "\\lstinputlisting\>" + \ nextgroup=texOptGenericFile,texFilename syntax match texRegion "\\lstinline\s*\(\[.\{-}\]\)\={.\{-}}" " Set all listings environments to listings diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index 9bc21e9555..94bc30da0a 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -11,28 +11,15 @@ function! vimtex#syntax#p#markdown#load() abort " {{{1 call vimtex#syntax#misc#include('markdown') " Don't quite know why this is necessary, but it is - syntax match texCmdEnv - \ '\(\\begin\>\|\\end\>\)\ze{markdown}' - \ nextgroup=texEnvName + syntax match texCmdEnv "\\\%(begin\|end\)\>\ze{markdown}" nextgroup=texEnvName syntax region texRegionMarkdown - \ start='\\begin{markdown}'rs=s - \ end='\\end{markdown}'re=e - \ keepend - \ transparent - \ contains=@texFoldGroup,@texDocGroup,@vimtex_nested_markdown + \ start="\\begin{markdown}" + \ end="\\end{markdown}" + \ keepend transparent + \ contains=texCmdEnv,texEnvName,@vimtex_nested_markdown - " Input files - syntax match texInputFile /\\markdownInput\>/ - \ contains=texCmd - \ nextgroup=texInputFileArg - syntax region texInputFileArg - \ matchgroup=texInputCurlies - \ start="{" end="}" - \ contained - \ contains=texComment - - highlight default link texInputFileArg texInputFile + syntax match texCmd "\\markdownInput\>" nextgroup=texFilename endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index be166257c0..e23a327aa8 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -142,7 +142,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 highlight link texRegionMinted texRegion highlight link texRegionMintedCmd texRegion - highlight link texMintedName texInputFileOpt + highlight link texMintedName texCmdArgs highlight link texMintedNameOpt texMintedName endfunction diff --git a/autoload/vimtex/syntax/p/pdfpages.vim b/autoload/vimtex/syntax/p/pdfpages.vim index 5d02023d3d..b2c944ef19 100644 --- a/autoload/vimtex/syntax/p/pdfpages.vim +++ b/autoload/vimtex/syntax/p/pdfpages.vim @@ -8,22 +8,7 @@ function! vimtex#syntax#p#pdfpages#load() abort " {{{1 if has_key(b:vimtex_syntax, 'pdfpages') | return | endif let b:vimtex_syntax.pdfpages = 1 - syntax match texInputFile /\\includepdf\>/ - \ contains=texCmd - \ nextgroup=texInputFileOpt,texInputFileArg - syntax region texInputFileOpt - \ matchgroup=Delimiter - \ start="\[" end="\]" - \ contained - \ contains=texComment,@NoSpell - \ nextgroup=texInputFileArg - syntax region texInputFileArg - \ matchgroup=texInputCurlies - \ start="{" end="}" - \ contained - \ contains=texComment - - highlight default link texInputFileArg texInputFile + syntax match texCmd "\\includepdf\>" nextgroup=texOptGenericFile,texFilename endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/subfile.vim b/autoload/vimtex/syntax/p/subfile.vim index cd3c46b411..565b606b69 100644 --- a/autoload/vimtex/syntax/p/subfile.vim +++ b/autoload/vimtex/syntax/p/subfile.vim @@ -8,8 +8,8 @@ function! vimtex#syntax#p#subfile#load() abort " {{{1 if has_key(b:vimtex_syntax, 'subfile') | return | endif let b:vimtex_syntax.subfile = 1 - syntax match texInputFile /\\subfile\s*\%(\[.\{-}\]\)\=\s*{.\{-}}/ - \ contains=texCmd,texInputCurlies,texInputFileOpt + syntax match texCmd "\\subfile\>" nextgroup=texFilename + syntax match texCmd "\\subfileinclude\>" nextgroup=texFilename endfunction " }}}1 diff --git a/test/tests/test-syntax/test-markdown.vim b/test/tests/test-syntax/test-markdown.vim index 672a7c3033..e4db74cbf3 100644 --- a/test/tests/test-syntax/test-markdown.vim +++ b/test/tests/test-syntax/test-markdown.vim @@ -7,6 +7,6 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texRegionMarkdown', 7, 1)) call vimtex#test#assert(vimtex#syntax#in('markdownItalic', 7, 1)) call vimtex#test#assert(vimtex#syntax#in('markdownLink', 11, 12)) -call vimtex#test#assert(vimtex#syntax#in('texInputFileArg', 16, 16)) +call vimtex#test#assert(vimtex#syntax#in('texFilename', 16, 16)) quit! From 4fd42f59a547bdf132b937e40b3ad825c641428a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 25 Oct 2020 23:07:12 +0100 Subject: [PATCH 12/99] wip: minor improvements --- autoload/vimtex/syntax/core.vim | 8 ++++---- autoload/vimtex/syntax/p/beamer.vim | 4 ++-- autoload/vimtex/syntax/p/biblatex.vim | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index de8fb68ae5..5ed3d99fd6 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -25,7 +25,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax cluster texClusterItal contains=TOP,texBoldStyle,texBoldItalStyle syntax cluster texClusterComment contains=texTodo,@Spell syntax cluster texClusterMath contains=texCmdEnvMath,texEnvMathName,texComment,texDelimiter,texErrorMathDelim,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texRegionRef,texSpecialChar,texCmd,texSubscript,texSuperscript,texTypeSize,texTypeStyle,@NoSpell - syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texDelimiter,texErrorMathDelim,texGreek,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texNewCmd,texNewEnv,texRegion,texRegionRef,texSection,texSpecialChar,texCmd,texSymbolString,texSubscript,texSuperscript,texTypeSize,texTypeStyle + syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texDelimiter,texErrorMathDelim,texGreek,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texNewCmd,texNewEnv,texRegion,texRegionRef,texSpecialChar,texCmd,texSymbolString,texSubscript,texSuperscript,texTypeSize,texTypeStyle syntax cluster texClusterRef contains=texComment,texDelimiter,texMatcher " {{{2 Primitives @@ -299,6 +299,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmd "\\includeonly\>" nextgroup=texFilenames syntax match texCmd "\\includegraphics\>" nextgroup=texOptGenericFile,texFilename syntax match texCmd "\\bibliography\>" nextgroup=texFilenames + syntax match texCmd "\\bibliographystyle\>" nextgroup=texFilename syntax match texCmd "\\document\%(class\|style\)\>" nextgroup=texOptGenericFile,texFilename syntax match texCmd "\\usepackage\>" nextgroup=texOptGenericFiles,texFilenames syntax match texCmd "\\RequirePackage\>" nextgroup=texOptGenericFiles,texFilenames @@ -459,7 +460,7 @@ function! s:init_highlights(cfg) abort " {{{1 " Basic TeX highlighting groups highlight def link texCmd Statement - highlight def link texCmdArgs Number + highlight def link texCmdArgs Identifier highlight def link texCmdName Statement highlight def link texComment Comment highlight def link texCommentAcronym Comment @@ -468,6 +469,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texDefParm Special highlight def link texDefParmNested Identifier highlight def link texDelimiter Delimiter + highlight def link texEnvName PreCondit highlight def link texError Error highlight def link texFilename Include highlight def link texFilenameSeparator NormalNC @@ -480,7 +482,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texOption Number highlight def link texRegion PreCondit highlight def link texRegionRef Special - highlight def link texSection PreCondit highlight def link texSpaceCodeChar Special highlight def link texSpecialChar SpecialChar highlight def link texSymbolString String @@ -512,7 +513,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texDefName texDef highlight def link texEmphStyle texItalStyle highlight def link texEnvMathName Delimiter - highlight def link texEnvName texSection highlight def link texFilenames texFilename highlight def link texGreek texCmd highlight def link texMatcherMath texMath diff --git a/autoload/vimtex/syntax/p/beamer.vim b/autoload/vimtex/syntax/p/beamer.vim index 3cc9b8dc80..a431f6d336 100644 --- a/autoload/vimtex/syntax/p/beamer.vim +++ b/autoload/vimtex/syntax/p/beamer.vim @@ -19,8 +19,8 @@ function! vimtex#syntax#p#beamer#load() abort " {{{1 \ nextgroup=texOptGenericFile,texFilename highlight link texCmdBeamer texCmd - highlight link texBeamerOpt Identifier - highlight link texBeamerDelimiter Delimiter + highlight link texBeamerOpt texCmdArgs + highlight link texBeamerDelimiter texDelimiter endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/biblatex.vim b/autoload/vimtex/syntax/p/biblatex.vim index e606bd5500..f289b8b6a4 100644 --- a/autoload/vimtex/syntax/p/biblatex.vim +++ b/autoload/vimtex/syntax/p/biblatex.vim @@ -8,6 +8,8 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 if has_key(b:vimtex_syntax, 'biblatex') | return | endif let b:vimtex_syntax.biblatex = 1 + syntax match texCmd "\\addbibresource\>" nextgroup=texFilenames + for l:pattern in [ \ 'bibentry', \ 'cite[pt]?\*?', From 63d1f53436a3c319aa4e494feba777592c939a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 25 Oct 2020 23:12:05 +0100 Subject: [PATCH 13/99] test: allow MYVIM in startup-timing test --- test/examples/startup-timing/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/examples/startup-timing/Makefile b/test/examples/startup-timing/Makefile index 9a2220af68..4ebe5de8f6 100644 --- a/test/examples/startup-timing/Makefile +++ b/test/examples/startup-timing/Makefile @@ -1,7 +1,9 @@ +MYVIM ?= nvim + .PHONY: default default: - hyperfine --min-runs 5 'nvim -u minivimrc' + hyperfine --min-runs 5 '$(MYVIM) -u minivimrc' basic: - time nvim -u minivimrc + time $(MYVIM) -u minivimrc From 346d739f48345292318e7665efef842cd92b52a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 26 Oct 2020 23:08:32 +0100 Subject: [PATCH 14/99] wip: a lot of updates --- autoload/vimtex/syntax/core.vim | 570 ++++++++++---------- autoload/vimtex/syntax/p/beamer.vim | 2 +- autoload/vimtex/syntax/p/cleveref.vim | 2 +- autoload/vimtex/syntax/p/minted.vim | 2 +- test/tests/test-syntax/common.vim | 1 - test/tests/test-syntax/test-bold-italic.tex | 8 +- test/tests/test-syntax/test-bold-italic.vim | 9 +- test/tests/test-syntax/test-nospell.tex | 2 - test/tests/test-syntax/test-nospell.vim | 4 +- 9 files changed, 305 insertions(+), 295 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 5ed3d99fd6..05037faf24 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -19,30 +19,45 @@ function! vimtex#syntax#core#init() abort " {{{1 let l:cfg.is_style_document = \ index(['sty', 'cls', 'clo', 'dtx', 'ltx'], l:cfg.ext) >= 0 - " Define clusters - - syntax cluster texClusterBold contains=TOP,texItalStyle,texItalBoldStyle,texEmphStyle - syntax cluster texClusterItal contains=TOP,texBoldStyle,texBoldItalStyle - syntax cluster texClusterComment contains=texTodo,@Spell - syntax cluster texClusterMath contains=texCmdEnvMath,texEnvMathName,texComment,texDelimiter,texErrorMathDelim,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texRegionRef,texSpecialChar,texCmd,texSubscript,texSuperscript,texTypeSize,texTypeStyle,@NoSpell - syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texDelimiter,texErrorMathDelim,texGreek,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texNewCmd,texNewEnv,texRegion,texRegionRef,texSpecialChar,texCmd,texSymbolString,texSubscript,texSuperscript,texTypeSize,texTypeStyle - syntax cluster texClusterRef contains=texComment,texDelimiter,texMatcher - " {{{2 Primitives " Delimiters - syntax region texParen start="(" end=")" transparent contains=TOP,@Spell - syntax region texMatcher matchgroup=Delimiter start="{" skip="\%(\\\\\)*\\}" end="}" transparent contains=TOP - syntax region texMatcher matchgroup=Delimiter start="\[" end="]" transparent contains=TOP,@NoSpell - syntax region texMatcherMath matchgroup=Delimiter start="{" skip="\%(\\\\\)*\\}" end="}" contained contains=@texClusterMathMatch + syntax region texMatcher matchgroup=Delimiter start="{" skip="\%(\\\\\)*\\}" end="}" transparent contains=TOP + + " Flag mismatching ending brace delimiter + syntax match texError "}" + + " Comments + if l:cfg.ext ==# 'dtx' + " Documented TeX Format: Only leading "^^A" and "%" + syntax match texComment "\^\^A.*$" + syntax match texComment "^%\+" + else + syntax match texComment "%.*$" + endif + + " Do not check URLs and acronyms in comments + " Source: https://github.com/lervag/vimtex/issues/562 + syntax match texCommentURL "\w\+:\/\/[^[:space:]]\+" + \ containedin=texComment contained contains=@NoSpell + syntax match texCommentAcronym '\v<(\u|\d){3,}s?>' + \ containedin=texComment contained contains=@NoSpell - syntax match texDelimiter "&" + " Todo and similar within comments + syntax case ignore + syntax keyword texCommentTodo combak fixme todo xxx + \ containedin=texComment contained + syntax case match + + " TeX Lengths + syntax match texLength "\<\d\+\([.,]\d\+\)\?\s*\(true\)\?\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>" - " Flag mismatching ending delimiters } and ] - syntax match texError "[}\]]" - syntax match texErrorMathDelim "}" contained + " Other + syntax match texOption "\v%(^|[^\\]\zs)#\d+" + + " }}}2 + " {{{2 Commands - " Tex commands syntax match texCmd "\\\a\+" syntax match texCmdError "\\\a*@\a*" @@ -54,139 +69,191 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)$" syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze\A" - " Various TeX symbols - syntax match texSymbolString "\v%(``|''|,,)" - syntax match texSymbolDash '--' - syntax match texSymbolDash '---' - if l:cfg.is_style_document syntax match texCmd "\\[a-zA-Z@]\+" syntax match texCmdAccent "\\[bcdvuH]\ze[^a-zA-Z@]" syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze[^a-zA-Z@]" endif - " Environments - syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvName - syntax region texEnvName matchgroup=Delimiter - \ start="{" end="}" - \ contained contains=texComment nextgroup=texEnvModifier - syntax region texEnvModifier matchgroup=Delimiter - \ start="\[" end="]" - \ contained contains=texComment,@NoSpell - syntax match texCmdEnvMath "\v\\%(begin|end)>" contained nextgroup=texEnvMathName - syntax region texEnvMathName matchgroup=Delimiter - \ start="{" end="}" - \ contained contains=texComment - - " Other - syntax match texOption "\v%(^|[^\\]\zs)#\d+" - " Spacecodes (TeX'isms) + " * See e.g. https://en.wikibooks.org/wiki/TeX/catcode " * \mathcode`\^^@ = "2201 " * \delcode`\( = "028300 " * \sfcode`\) = 0 " * \uccode`X = `X " * \lccode`x = `x - syntax match texSpaceCode "\v\\%(math|cat|del|lc|sf|uc)code`"me=e-1 nextgroup=texSpaceCodeChar - syntax match texSpaceCodeChar "\v`\\?.%(\^.)?\?%(\d|\"\x{1,6}|`.)" contained + syntax match texCmdSpaceCode "\v\\%(math|cat|del|lc|sf|uc)code`"me=e-1 + \ nextgroup=texCmdSpaceCodeChar + syntax match texCmdSpaceCodeChar "\v`\\?.%(\^.)?\?%(\d|\"\x{1,6}|`.)" contained - " Comments - if l:cfg.ext ==# 'dtx' - " Documented TeX Format: Only leading "^^A" and "%" - syntax match texComment "\^\^A.*$" contains=@texClusterComment - syntax match texComment "^%\+" contains=@texClusterComment + " Todo commands + syntax match texCmdTodo '\\todo\w*' + + " TODO: Special for author and title type of commands? + " \author + " \title + + " Various commands that take a file argument (or similar) + syntax match texCmd "\\input\>" nextgroup=texFilename + syntax match texCmd "\\include\>" nextgroup=texFilename + syntax match texCmd "\\includeonly\>" nextgroup=texFilenames + syntax match texCmd "\\includegraphics\>" nextgroup=texOptGenericFile,texFilename + syntax match texCmd "\\bibliography\>" nextgroup=texFilenames + syntax match texCmd "\\bibliographystyle\>" nextgroup=texFilename + syntax match texCmd "\\document\%(class\|style\)\>" nextgroup=texOptGenericFile,texFilename + syntax match texCmd "\\usepackage\>" nextgroup=texOptGenericFiles,texFilenames + syntax match texCmd "\\RequirePackage\>" nextgroup=texOptGenericFiles,texFilenames + + call s:add_opt_group('GenericFile', 'texFilename') + call s:add_opt_group('GenericFiles', 'texFilenames') + + syntax region texFilename matchgroup=Delimiter start="{" end="}" contained contains=texCmd,texComment,@NoSpell + syntax region texFilenames matchgroup=Delimiter start="{" end="}" contained contains=texFilenameSeparator,texCmd,texComment,@NoSpell + syntax match texFilenameSeparator ",\s*" contained + + " LaTeX 2.09 type styles + syntax match texCmdStyle "\\rm\>" + syntax match texCmdStyle "\\em\>" + syntax match texCmdStyle "\\bf\>" + syntax match texCmdStyle "\\it\>" + syntax match texCmdStyle "\\sl\>" + syntax match texCmdStyle "\\sf\>" + syntax match texCmdStyle "\\sc\>" + syntax match texCmdStyle "\\tt\>" + + " LaTeX2E type styles + syntax match texCmdStyle "\\textbf\>" + syntax match texCmdStyle "\\textit\>" + syntax match texCmdStyle "\\textmd\>" + syntax match texCmdStyle "\\textrm\>" + syntax match texCmdStyle "\\texts[cfl]\>" + syntax match texCmdStyle "\\texttt\>" + syntax match texCmdStyle "\\textup\>" + syntax match texCmdStyle "\\emph\>" + + syntax match texCmdStyle "\\mathbb\>" + syntax match texCmdStyle "\\mathbf\>" + syntax match texCmdStyle "\\mathcal\>" + syntax match texCmdStyle "\\mathfrak\>" + syntax match texCmdStyle "\\mathit\>" + syntax match texCmdStyle "\\mathnormal\>" + syntax match texCmdStyle "\\mathrm\>" + syntax match texCmdStyle "\\mathsf\>" + syntax match texCmdStyle "\\mathtt\>" + + syntax match texCmdStyle "\\rmfamily\>" + syntax match texCmdStyle "\\sffamily\>" + syntax match texCmdStyle "\\ttfamily\>" + + syntax match texCmdStyle "\\itshape\>" + syntax match texCmdStyle "\\scshape\>" + syntax match texCmdStyle "\\slshape\>" + syntax match texCmdStyle "\\upshape\>" + + syntax match texCmdStyle "\\bfseries\>" + syntax match texCmdStyle "\\mdseries\>" + + " Bold and italic commands + call s:match_bold_italic(l:cfg) + + " Type sizes + syntax match texCmdSize "\\tiny\>" + syntax match texCmdSize "\\scriptsize\>" + syntax match texCmdSize "\\footnotesize\>" + syntax match texCmdSize "\\small\>" + syntax match texCmdSize "\\normalsize\>" + syntax match texCmdSize "\\large\>" + syntax match texCmdSize "\\Large\>" + syntax match texCmdSize "\\LARGE\>" + syntax match texCmdSize "\\huge\>" + syntax match texCmdSize "\\Huge\>" + + " \newcommand + syntax match texCmdNewcmd "\\\%(re\)\?newcommand\>" nextgroup=texNewcmdName skipwhite skipnl + syntax region texNewcmdName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texNewcmdArgs,texNewcmdBody skipwhite skipnl + syntax region texNewcmdArgs contained matchgroup=Delimiter start="\["rs=s+1 end="]" nextgroup=texNewcmdBody skipwhite skipnl + syntax region texNewcmdBody contained matchgroup=Delimiter start="{"rs=s+1 skip="\\\\\|\\[{}]" matchgroup=Delimiter end="}" contains=TOP + + " \newenvironment + syntax match texCmdNewenv "\\\%(re\)\?newenvironment\>" nextgroup=texNewenvName skipwhite skipnl + syntax region texNewenvName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texNewenvBgn,texNewenvArgs skipwhite skipnl + syntax region texNewenvArgs contained matchgroup=Delimiter start="\["rs=s+1 end="]" nextgroup=texNewenvBgn,texNewenvArgs skipwhite skipnl + syntax region texNewenvBgn contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texNewenvEnd skipwhite skipnl contains=TOP + syntax region texNewenvEnd contained matchgroup=Delimiter start="{"rs=s+1 end="}" skipwhite skipnl contains=TOP + + " Definitions/Commands + syntax match texDefCmd "\\def\>" nextgroup=texDefName skipwhite skipnl + if l:cfg.is_style_document + syntax match texDefName contained "\\[a-zA-Z@]\+" nextgroup=texDefParms,texNewcmdBody skipwhite skipnl + syntax match texDefName contained "\\[^a-zA-Z@]" nextgroup=texDefParms,texNewcmdBody skipwhite skipnl else - syntax match texComment "%.*$" contains=@texClusterComment + syntax match texDefName contained "\\\a\+" nextgroup=texDefParms,texNewcmdBody skipwhite skipnl + syntax match texDefName contained "\\\A" nextgroup=texDefParms,texNewcmdBody skipwhite skipnl endif + syntax match texDefParms contained "#[^{]*" contains=texDefParm nextgroup=texNewcmdBody skipwhite skipnl + syntax match texDefParm contained "#\d\+" - " Do not check URLs and acronyms in comments - " Source: https://github.com/lervag/vimtex/issues/562 - syntax match texCommentURL "\w\+:\/\/[^[:space:]]\+" - \ contains=@NoSpell containedin=texComment contained - syntax match texCommentAcronym '\v<(\u|\d){3,}s?>' - \ contains=@NoSpell containedin=texComment contained + " Tex Reference Zones + syntax cluster texClusterRef contains=texComment,texSymbolAmp,texMatcher + syntax match texRegionRef '\\cite\%([tp]\*\?\)\?\>' nextgroup=texRefOption,texRefCite + syntax region texRegionRef matchgroup=texCmd start="\\nocite{" end="}" contains=@texClusterRef + syntax region texRegionRef matchgroup=texCmd start="\\label{" end="}" contains=@texClusterRef + syntax region texRegionRef matchgroup=texCmd start="\\\(page\|eq\)ref{" end="}" contains=@texClusterRef + syntax region texRegionRef matchgroup=texCmd start="\\v\?ref{" end="}" contains=@texClusterRef + syntax region texRefOption matchgroup=Delimiter start='\[' end=']' contains=@texClusterRef,texRegionRef nextgroup=texRefOption,texRefCite contained + syntax region texRefCite matchgroup=Delimiter start='{' end='}' contains=@texClusterRef,texRegionRef,texRefCite contained - " Todo and similar within comments - syntax case ignore - syntax keyword texTodo contained combak fixme todo xxx - syntax case match - syntax match texCmd '\\todo\w*' contains=texTodo - syntax match texTodo '\\todo\w*' + " \makeatletter ... \makeatother sections + " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do + " In short: allow @ in multicharacter macro name + syntax region texRegionSty matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP,texCmdError + syntax region texMatcherSty matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=TOP,texCmdError contained + syntax region texMatcherSty matchgroup=Delimiter start="\[" end="]" contains=TOP,texCmdError contained + syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=texRegionSty - " TeX Lengths - syntax match texLength "\<\d\+\([.,]\d\+\)\?\s*\(true\)\?\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>" + " Add nospell for commands per configuration + syntax region texVimtexNoSpell matchgroup=Delimiter + \ start='{' end='}' + \ contained contains=@NoSpell + for l:macro in g:vimtex_syntax_nospell_commands + execute 'syntax match texCmd /\\' . l:macro . '/' + \ 'nextgroup=texVimtexNospell' + endfor " }}}2 - " {{{2 Type Styles - - " LaTeX 2.09: - syntax match texTypeStyle "\\rm\>" - syntax match texTypeStyle "\\em\>" - syntax match texTypeStyle "\\bf\>" - syntax match texTypeStyle "\\it\>" - syntax match texTypeStyle "\\sl\>" - syntax match texTypeStyle "\\sf\>" - syntax match texTypeStyle "\\sc\>" - syntax match texTypeStyle "\\tt\>" - - " LaTeX2E - syntax match texTypeStyle "\\textbf\>" - syntax match texTypeStyle "\\textit\>" - syntax match texTypeStyle "\\emph\>" - syntax match texTypeStyle "\\textmd\>" - syntax match texTypeStyle "\\textrm\>" - - syntax region texBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" end="}" contains=@texClusterBold - syntax region texBoldItalStyle matchgroup=texTypeStyle start="\\textit\s*{" end="}" contains=@texClusterItal - syntax region texItalStyle matchgroup=texTypeStyle start="\\textit\s*{" end="}" contains=@texClusterItal - syntax region texItalBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" end="}" contains=@texClusterBold - syntax region texEmphStyle matchgroup=texTypeStyle start="\\emph\s*{" end="}" contains=@texClusterItal - syntax region texEmphStyle matchgroup=texTypeStyle start="\\texts[cfl]\s*{" end="}" contains=@texClusterBold - syntax region texEmphStyle matchgroup=texTypeStyle start="\\textup\s*{" end="}" contains=@texClusterBold - syntax region texEmphStyle matchgroup=texTypeStyle start="\\texttt\s*{" end="}" contains=@texClusterBold - - syntax match texTypeStyle "\\mathbb\>" - syntax match texTypeStyle "\\mathbf\>" - syntax match texTypeStyle "\\mathcal\>" - syntax match texTypeStyle "\\mathfrak\>" - syntax match texTypeStyle "\\mathit\>" - syntax match texTypeStyle "\\mathnormal\>" - syntax match texTypeStyle "\\mathrm\>" - syntax match texTypeStyle "\\mathsf\>" - syntax match texTypeStyle "\\mathtt\>" - - syntax match texTypeStyle "\\rmfamily\>" - syntax match texTypeStyle "\\sffamily\>" - syntax match texTypeStyle "\\ttfamily\>" - - syntax match texTypeStyle "\\itshape\>" - syntax match texTypeStyle "\\scshape\>" - syntax match texTypeStyle "\\slshape\>" - syntax match texTypeStyle "\\upshape\>" - - syntax match texTypeStyle "\\bfseries\>" - syntax match texTypeStyle "\\mdseries\>" + " {{{2 Environments - " }}}2 - " {{{2 Type sizes - - syntax match texTypeSize "\\tiny\>" - syntax match texTypeSize "\\scriptsize\>" - syntax match texTypeSize "\\footnotesize\>" - syntax match texTypeSize "\\small\>" - syntax match texTypeSize "\\normalsize\>" - syntax match texTypeSize "\\large\>" - syntax match texTypeSize "\\Large\>" - syntax match texTypeSize "\\LARGE\>" - syntax match texTypeSize "\\huge\>" - syntax match texTypeSize "\\Huge\>" + syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvName + syntax region texEnvName matchgroup=Delimiter + \ start="{" end="}" + \ contained contains=texComment nextgroup=texEnvModifier + syntax region texEnvModifier matchgroup=Delimiter + \ start="\[" end="]" + \ contained contains=texComment,@NoSpell + syntax match texCmdEnvMath "\v\\%(begin|end)>" contained nextgroup=texEnvMathName + syntax region texEnvMathName matchgroup=Delimiter + \ start="{" end="}" + \ contained contains=texComment " }}}2 + " {{{2 Verbatim - " \author - " \title - " \begin{abstract}? + " Verbatim environment + syntax region texRegionVerb + \ start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}" + \ contains=texCmdEnv,texEnvName + + " Verbatim inline + syntax match texCmd "\\verb\>\*\?" nextgroup=texRegionVerbInline + if l:cfg.is_style_document + syntax region texRegionVerbInline matchgroup=Delimiter + \ start="\z([^\ta-zA-Z@]\)" end="\z1" contained + else + syntax region texRegionVerbInline matchgroup=Delimiter + \ start="\z([^\ta-zA-Z]\)" end="\z1" contained + endif + " }}}2 " {{{2 Sections and parts syntax match texCmdParts "\\\(front\|main\|back\)matter\>" @@ -199,8 +266,31 @@ function! vimtex#syntax#core#init() abort " {{{1 \ contained contains=TOP " }}}2 + " {{{2 Various TeX symbols + + syntax match texSymbolString "\v%(``|''|,,)" + syntax match texSymbolDash "--" + syntax match texSymbolDash "---" + syntax match texSymbolAmp "&" + + " E.g.: \$ \& \% \# \{ \} \_ \S \P + syntax match texSpecialChar "\\[$&%#{}_]" + if l:cfg.is_style_document + syntax match texSpecialChar "\\[SP@]\ze[^a-zA-Z@]" + else + syntax match texSpecialChar "\\[SP@]\ze\A" + endif + syntax match texSpecialChar "\\\\" + syntax match texSpecialChar "\^\^\%(\S\|[0-9a-f]\{2}\)" + + " }}}2 + " {{{2 Math - " {{{2 Math stuff + syntax match texOnlyMath "[_^]" contained + + syntax cluster texClusterMath contains=texCmdEnvMath,texEnvMathName,texComment,texSymbolAmp,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texRegionRef,texSpecialChar,texCmd,texSubscript,texSuperscript,texCmdSize,texCmdStyle,@NoSpell + syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texSymbolAmp,texGreek,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texCmdNewcmd,texCmdNewenv,texRegion,texRegionRef,texSpecialChar,texCmd,texSymbolString,texSubscript,texSuperscript,texCmdSize,texCmdStyle + syntax region texMatcherMath matchgroup=Delimiter start="{" skip="\%(\\\\\)*\\}" end="}" contained contains=@texClusterMathMatch " Bad/Mismatched math syntax match texErrorMath "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}" @@ -259,137 +349,13 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texMathDelim contained "\\\(left\|right\)arrow\>\|\<\([aA]rrow\|brace\)\?vert\>" syntax match texMathDelim contained "\\lefteqn\>" - " {{{2 Special TeX characters - - " E.g.: \$ \& \% \# \{ \} \_ \S \P - - syntax match texSpecialChar "\\[$&%#{}_]" - if l:cfg.is_style_document - syntax match texSpecialChar "\\[SP@]\ze[^a-zA-Z@]" - else - syntax match texSpecialChar "\\[SP@]\ze\A" - endif - syntax match texSpecialChar "\\\\" - syntax match texOnlyMath "[_^]" contained - syntax match texSpecialChar "\^\^[0-9a-f]\{2}\|\^\^\S" - - " {{{2 Verbatim - - " Verbatim environment - syntax region texRegionVerb - \ start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}" - \ contains=texCmdEnv,texEnvName - - " Verbatim inline - syntax match texCmd "\\verb\>\*\?" nextgroup=texRegionVerbInline - if l:cfg.is_style_document - syntax region texRegionVerbInline matchgroup=Delimiter - \ start="\z([^\ta-zA-Z@]\)" end="\z1" contained - else - syntax region texRegionVerbInline matchgroup=Delimiter - \ start="\z([^\ta-zA-Z]\)" end="\z1" contained - endif - - " }}}2 - " {{{2 Specific commands/environments - - " Various commands that take a file argument (or similar) - syntax match texCmd "\\input\>" nextgroup=texFilename - syntax match texCmd "\\include\>" nextgroup=texFilename - syntax match texCmd "\\includeonly\>" nextgroup=texFilenames - syntax match texCmd "\\includegraphics\>" nextgroup=texOptGenericFile,texFilename - syntax match texCmd "\\bibliography\>" nextgroup=texFilenames - syntax match texCmd "\\bibliographystyle\>" nextgroup=texFilename - syntax match texCmd "\\document\%(class\|style\)\>" nextgroup=texOptGenericFile,texFilename - syntax match texCmd "\\usepackage\>" nextgroup=texOptGenericFiles,texFilenames - syntax match texCmd "\\RequirePackage\>" nextgroup=texOptGenericFiles,texFilenames - - call s:add_opt_group('GenericFile', 'texFilename') - call s:add_opt_group('GenericFiles', 'texFilenames') - - syntax region texFilename matchgroup=Delimiter - \ start="{" end="}" contained contains=texCmd,texComment,@NoSpell - syntax region texFilenames matchgroup=Delimiter - \ start="{" end="}" contained contains=texFilenameSeparator,texCmd,texComment,@NoSpell - syntax match texFilenameSeparator ",\s*" contained - - " Tex Reference Zones - syntax match texRegionRef '\\cite\%([tp]\*\?\)\?\>' nextgroup=texRefOption,texRefCite - syntax region texRegionRef matchgroup=texCmd start="\\nocite{" end="}" contains=@texClusterRef - syntax region texRegionRef matchgroup=texCmd start="\\label{" end="}" contains=@texClusterRef - syntax region texRegionRef matchgroup=texCmd start="\\\(page\|eq\)ref{" end="}" contains=@texClusterRef - syntax region texRegionRef matchgroup=texCmd start="\\v\?ref{" end="}" contains=@texClusterRef - syntax region texRefOption matchgroup=Delimiter start='\[' end=']' contains=@texClusterRef,texRegionRef nextgroup=texRefOption,texRefCite contained - syntax region texRefCite matchgroup=Delimiter start='{' end='}' contains=@texClusterRef,texRegionRef,texRefCite contained - " \makeatletter ... \makeatother sections - " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do - " In short: allow @ in multicharacter macro name - syntax region texRegionSty matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP,texCmdError - syntax region texMatcherSty matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=TOP,texCmdError contained - syntax region texMatcherSty matchgroup=Delimiter start="\[" end="]" contains=TOP,texCmdError contained - syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=texRegionSty - - " }}}2 - - " {{{2 Handle new(command|environment) - - syntax match texNewCmd "\\newcommand\>" nextgroup=texCmdName skipwhite skipnl - syntax region texCmdName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texCmdArgs,texCmdBody skipwhite skipnl - syntax region texCmdArgs contained matchgroup=Delimiter start="\["rs=s+1 end="]" nextgroup=texCmdBody skipwhite skipnl - syntax region texCmdBody contained matchgroup=Delimiter start="{"rs=s+1 skip="\\\\\|\\[{}]" matchgroup=Delimiter end="}" contains=TOP - - syntax match texNewEnv "\\newenvironment\>" nextgroup=texEnvName skipwhite skipnl - syntax region texEnvName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texEnvBgn skipwhite skipnl - syntax region texEnvBgn contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texEnvEnd skipwhite skipnl contains=TOP - syntax region texEnvEnd contained matchgroup=Delimiter start="{"rs=s+1 end="}" skipwhite skipnl contains=TOP - - " Allow arguments in newenvironments - syntax region texEnvName contained matchgroup=Delimiter - \ start="{"rs=s+1 end="}" - \ nextgroup=texEnvBgn,texEnvArgs contained skipwhite skipnl - syntax region texEnvArgs contained matchgroup=Delimiter - \ start="\["rs=s+1 end="]" - \ nextgroup=texEnvBgn,texEnvArgs skipwhite skipnl - - " Add support for \renewenvironment and \renewcommand - syntax match texNewEnv "\\renewenvironment\>" - \ nextgroup=texEnvName skipwhite skipnl - syntax match texNewCmd "\\renewcommand\>" - \ nextgroup=texCmdName skipwhite skipnl - - " Match nested DefParms - syntax match texDefParmNested contained "##\+\d\+" - - " {{{2 Definitions/Commands - - syntax match texDefCmd "\\def\>" nextgroup=texDefName skipwhite skipnl - if l:cfg.is_style_document - syntax match texDefName contained "\\[a-zA-Z@]\+" nextgroup=texDefParms,texCmdBody skipwhite skipnl - syntax match texDefName contained "\\[^a-zA-Z@]" nextgroup=texDefParms,texCmdBody skipwhite skipnl - else - syntax match texDefName contained "\\\a\+" nextgroup=texDefParms,texCmdBody skipwhite skipnl - syntax match texDefName contained "\\\A" nextgroup=texDefParms,texCmdBody skipwhite skipnl - endif - syntax match texDefParms contained "#[^{]*" contains=texDefParm nextgroup=texCmdBody skipwhite skipnl - syntax match texDefParm contained "#\d\+" " {{{2 Conceal mode support " Add support for conceal with custom replacement (conceallevel = 2) if &encoding ==# 'utf-8' - if l:cfg.conceal =~# 'b' - syntax region texBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" end="}" concealends contains=@texClusterBold,@Spell - syntax region texBoldItalStyle matchgroup=texTypeStyle start="\\textit\s*{" end="}" concealends contains=@texClusterItal,@Spell - syntax region texItalStyle matchgroup=texTypeStyle start="\\textit\s*{" end="}" concealends contains=@texClusterItal,@Spell - syntax region texItalBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" end="}" concealends contains=@texClusterBold,@Spell - syntax region texEmphStyle matchgroup=texTypeStyle start="\\emph\s*{" end="}" concealends contains=@texClusterItal,@Spell - syntax region texEmphStyle matchgroup=texTypeStyle start="\\texts[cfl]\s*{" end="}" concealends contains=@texClusterBold,@Spell - syntax region texEmphStyle matchgroup=texTypeStyle start="\\textup\s*{" end="}" concealends contains=@texClusterBold,@Spell - syntax region texEmphStyle matchgroup=texTypeStyle start="\\texttt\s*{" end="}" concealends contains=@texClusterBold,@Spell - endif - if l:cfg.conceal =~# 'S' syntax match texSpecialChar '\\glq\>' contained conceal cchar=‚ syntax match texSpecialChar '\\grq\>' contained conceal cchar=‘ @@ -421,15 +387,6 @@ function! vimtex#syntax#core#init() abort " {{{1 " }}}2 - " Add nospell for commands per configuration - syntax region texVimtexNoSpell matchgroup=Delimiter - \ start='{' end='}' - \ contained contains=@NoSpell - for l:macro in g:vimtex_syntax_nospell_commands - execute 'syntax match texCmd /\\' . l:macro . '/' - \ 'nextgroup=texVimtexNospell' - endfor - call s:init_highlights(l:cfg) let b:current_syntax = 'tex' @@ -460,15 +417,12 @@ function! s:init_highlights(cfg) abort " {{{1 " Basic TeX highlighting groups highlight def link texCmd Statement - highlight def link texCmdArgs Identifier - highlight def link texCmdName Statement + highlight def link texCmdSpaceCodeChar Special + highlight def link texCmdTodo Todo highlight def link texComment Comment - highlight def link texCommentAcronym Comment - highlight def link texCommentURL Comment + highlight def link texCommentTodo Todo highlight def link texDef Statement highlight def link texDefParm Special - highlight def link texDefParmNested Identifier - highlight def link texDelimiter Delimiter highlight def link texEnvName PreCondit highlight def link texError Error highlight def link texFilename Include @@ -477,22 +431,20 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texMath Special highlight def link texMathDelim Statement highlight def link texMathOper Operator - highlight def link texNewCmd Statement - highlight def link texNewEnv Statement + highlight def link texNewcmdArgs Identifier highlight def link texOption Number highlight def link texRegion PreCondit highlight def link texRegionRef Special - highlight def link texSpaceCodeChar Special highlight def link texSpecialChar SpecialChar + highlight def link texSymbol SpecialChar + highlight def link texSymbolAmp Delimiter highlight def link texSymbolString String highlight def link texTitle String - highlight def link texTodo Todo highlight def link texType Type - highlight def texBoldStyle gui=bold cterm=bold - highlight def texItalStyle gui=italic cterm=italic - highlight def texBoldItalStyle gui=bold,italic cterm=bold,italic - highlight def texItalBoldStyle gui=bold,italic cterm=bold,italic + highlight def texStyleBold gui=bold cterm=bold + highlight def texStyleItal gui=italic cterm=italic + highlight def texStyleBoth gui=bold,italic cterm=bold,italic " TeX highlighting groups which should share similar highlighting highlight def link texMathDelimBad texError @@ -504,14 +456,25 @@ function! s:init_highlights(cfg) abort " {{{1 " Inherited groups highlight def link texCmdAccent texCmd - highlight def link texCmdEnv texCmdName + highlight def link texCmdEnv texCmd highlight def link texCmdEnvMath texCmdEnv highlight def link texCmdLigature texSpecialChar + highlight def link texCmdNewcmd texCmd + highlight def link texCmdNewenv texCmd highlight def link texCmdParts texCmd + highlight def link texCmdSize texType + highlight def link texCmdSpaceCode texCmd highlight def link texCmdSty texCmd + highlight def link texCmdStyle texCmd + highlight def link texCmdStyle texType + highlight def link texCmdStyleBold texCmd + highlight def link texCmdStyleBoldItal texCmd + highlight def link texCmdStyleItal texCmd + highlight def link texCmdStyleItalBold texCmd + highlight def link texCommentAcronym texComment + highlight def link texCommentURL texComment highlight def link texDefCmd texDef highlight def link texDefName texDef - highlight def link texEmphStyle texItalStyle highlight def link texEnvMathName Delimiter highlight def link texFilenames texFilename highlight def link texGreek texCmd @@ -520,8 +483,11 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texMathDelimSet1 texMathDelim highlight def link texMathDelimSet2 texMathDelim highlight def link texMathSymbol texCmd - highlight def link texOptGenericFile texCmdArgs - highlight def link texOptGenericFiles texCmdArgs + highlight def link texNewcmdName texCmd + highlight def link texNewenvArgs texNewcmdArgs + highlight def link texNewenvName texEnvName + highlight def link texOptGenericFile texNewcmdArgs + highlight def link texOptGenericFiles texNewcmdArgs highlight def link texPartTitle texTitle highlight def link texRefCite texRegionRef highlight def link texRegionMath texMath @@ -532,14 +498,11 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texRegionMathY texMath highlight def link texRegionVerb texRegion highlight def link texRegionVerbInline texRegionVerb - highlight def link texSpaceCode texCmd highlight def link texSubscript texCmd highlight def link texSubscripts texSubscript highlight def link texSuperscript texCmd highlight def link texSuperscripts texSuperscript - highlight def link texSymbolDash texSpecialChar - highlight def link texTypeSize texType - highlight def link texTypeStyle texType + highlight def link texSymbolDash texSymbol endfunction " }}}1 @@ -554,6 +517,49 @@ endfunction " }}}1 +function! s:match_bold_italic(cfg) abort " {{{1 + let [l:conceal, l:concealends] = + \ (a:cfg.conceal =~# 'b' ? ['conceal', 'concealends'] : ['', '']) + + syntax cluster texClusterBold contains=TOP,texCmdStyleItal,texCmdStyleBold,texCmdStyleItalBold + syntax cluster texClusterItal contains=TOP,texCmdStyleItal,texCmdStyleBold,texCmdStyleBoldItal + syntax cluster texClusterItalBold contains=TOP,texCmdStyleItal,texCmdStyleBold,texCmdStyleItalBold,texCmdStyleBoldItal + + let l:map = { + \ 'texCmdStyleBold': 'texStyleBold', + \ 'texCmdStyleBoldItal': 'texStyleBoth', + \ 'texCmdStyleItal': 'texStyleItal', + \ 'texCmdStyleItalBold': 'texStyleBoth', + \} + + for [l:group, l:pattern] in [ + \ ['texCmdStyleBoldItal', 'emph'], + \ ['texCmdStyleBoldItal', 'textit'], + \ ['texCmdStyleBoldItal', 'texts[cfl]'], + \ ['texCmdStyleBoldItal', 'texttt'], + \ ['texCmdStyleBoldItal', 'textup'], + \ ['texCmdStyleItalBold', 'textbf'], + \ ['texCmdStyleBold', 'textbf'], + \ ['texCmdStyleItal', 'emph'], + \ ['texCmdStyleItal', 'textit'], + \ ['texCmdStyleItal', 'texts[cfl]'], + \ ['texCmdStyleItal', 'texttt'], + \ ['texCmdStyleItal', 'textup'], + \] + execute 'syntax match' l:group '"\\' . l:pattern . '\>\s*"' + \ 'nextgroup=' . l:map[l:group] l:conceal + endfor + + execute 'syntax region texStyleBold matchgroup=Delimiter start=/{/ end=/}/' + \ 'contained contains=@texClusterBold' l:concealends + execute 'syntax region texStyleItal matchgroup=Delimiter start=/{/ end=/}/' + \ 'contained contains=@texClusterItal' l:concealends + execute 'syntax region texStyleBoth matchgroup=Delimiter start=/{/ end=/}/' + \ 'contained contains=@texClusterItalBold' l:concealends +endfunction + +" }}}1 + function! s:match_conceal_math_delims() abort " {{{1 syntax match texMathSymbol "\\[bB]igg\?[lr]\?<" contained conceal cchar=< syntax match texMathSymbol "\\[bB]igg\?[lr]\?>" contained conceal cchar=> diff --git a/autoload/vimtex/syntax/p/beamer.vim b/autoload/vimtex/syntax/p/beamer.vim index a431f6d336..6d079226ae 100644 --- a/autoload/vimtex/syntax/p/beamer.vim +++ b/autoload/vimtex/syntax/p/beamer.vim @@ -19,7 +19,7 @@ function! vimtex#syntax#p#beamer#load() abort " {{{1 \ nextgroup=texOptGenericFile,texFilename highlight link texCmdBeamer texCmd - highlight link texBeamerOpt texCmdArgs + highlight link texBeamerOpt texNewcmdArgs highlight link texBeamerDelimiter texDelimiter endfunction diff --git a/autoload/vimtex/syntax/p/cleveref.vim b/autoload/vimtex/syntax/p/cleveref.vim index 2c48017e16..e022ae55e5 100644 --- a/autoload/vimtex/syntax/p/cleveref.vim +++ b/autoload/vimtex/syntax/p/cleveref.vim @@ -33,7 +33,7 @@ function! vimtex#syntax#p#cleveref#load() abort " {{{1 highlight link texCRefZone texRegionRef highlight link texCRefZoneRange texRegionRef - highlight link texCRefLabelOpts texCmdArgs + highlight link texCRefLabelOpts texNewcmdArgs endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index e23a327aa8..9d9224c98d 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -142,7 +142,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 highlight link texRegionMinted texRegion highlight link texRegionMintedCmd texRegion - highlight link texMintedName texCmdArgs + highlight link texMintedName texNewcmdArgs highlight link texMintedNameOpt texMintedName endfunction diff --git a/test/tests/test-syntax/common.vim b/test/tests/test-syntax/common.vim index 19311404b5..ea19073d3b 100644 --- a/test/tests/test-syntax/common.vim +++ b/test/tests/test-syntax/common.vim @@ -1,6 +1,5 @@ set nocompatible let &rtp = '../../..,' . &rtp -let &rtp .= ',../../../after' filetype plugin on syntax enable diff --git a/test/tests/test-syntax/test-bold-italic.tex b/test/tests/test-syntax/test-bold-italic.tex index b30d4f299c..3b0f258cf8 100644 --- a/test/tests/test-syntax/test-bold-italic.tex +++ b/test/tests/test-syntax/test-bold-italic.tex @@ -2,7 +2,13 @@ \begin{document} -\textit{\textbf{This is bold-italic, but it looks italic}} +\textit {\textbf {This is bold-italic, but it looks italic}} \textbf{\textit{This is bold-italic, but it looks italic}} +\textbf{\texttt{This is bold-italic, but it looks italic}} +\textbf{\textbf{This is bold-italic, but it looks italic}} +\textit{\textit{This is bold-italic, but it looks italic}} +\textbf{\emph{This is bold-italic, but it looks italic}} +\textit{\emph{This is bold-italic, but it looks italic}} +\emph{\textbf{This is bold-italic, but it looks italic}} \end{document} diff --git a/test/tests/test-syntax/test-bold-italic.vim b/test/tests/test-syntax/test-bold-italic.vim index 9088003f49..7fdf012f8c 100644 --- a/test/tests/test-syntax/test-bold-italic.vim +++ b/test/tests/test-syntax/test-bold-italic.vim @@ -1,12 +1,15 @@ source common.vim -let g:tex_conceal = '' +let g:tex_conceal = 'b' silent edit test-bold-italic.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texItalBoldStyle', 5, 55)) -call vimtex#test#assert(vimtex#syntax#in('texBoldItalStyle', 6, 55)) +call vimtex#test#assert(vimtex#syntax#in('texStyleBoth', 5, 50)) +call vimtex#test#assert(vimtex#syntax#in('texStyleBoth', 6, 50)) +call vimtex#test#assert(vimtex#syntax#in('texStyleBoth', 7, 50)) +call vimtex#test#assert(vimtex#syntax#in('texStyleBoth', 10, 50)) +call vimtex#test#assert(vimtex#syntax#in('texCmdStyle', 8, 14)) quit! diff --git a/test/tests/test-syntax/test-nospell.tex b/test/tests/test-syntax/test-nospell.tex index ce6c5001c7..6820cc2f51 100644 --- a/test/tests/test-syntax/test-nospell.tex +++ b/test/tests/test-syntax/test-nospell.tex @@ -6,7 +6,5 @@ \section{First section} \gls{spellingerror} \mygls{spellingerror} -\textbf{\textit{test}} -\textit{test} \end{document} diff --git a/test/tests/test-syntax/test-nospell.vim b/test/tests/test-syntax/test-nospell.vim index 29e1f04d8a..f09db7d441 100644 --- a/test/tests/test-syntax/test-nospell.vim +++ b/test/tests/test-syntax/test-nospell.vim @@ -7,9 +7,7 @@ silent edit test-nospell.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texVimtexNoSpell', 8, 14)) call vimtex#test#assert(vimtex#syntax#in('texMatcher', 7, 14)) -call vimtex#test#assert(vimtex#syntax#in('texBoldItalStyle', 9, 18)) -call vimtex#test#assert(vimtex#syntax#in('texItalStyle', 10, 11)) +call vimtex#test#assert(vimtex#syntax#in('texVimtexNoSpell', 8, 14)) quit! From 20a6fe9bd5e1c4c19f78a1f27d3f59b163a8499d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 26 Oct 2020 23:28:44 +0100 Subject: [PATCH 15/99] wip: improve conceal config --- autoload/vimtex/options.vim | 14 ++++++--- autoload/vimtex/syntax/core.vim | 35 ++++++++++----------- autoload/vimtex/syntax/p/amsmath.vim | 2 +- autoload/vimtex/syntax/p/array.vim | 8 ++--- test/tests/test-syntax/test-bold-italic.vim | 3 +- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index 0fcc9f1494..d6eed8e8c4 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -262,11 +262,15 @@ function! vimtex#options#init() abort " {{{1 call s:init_option('vimtex_subfile_start_local', 0) call s:init_option('vimtex_syntax_config', { - \ 'conceal': get(g:, 'tex_conceal', 'abdmgsS'), - \ 'conceal_set_super': - \ get(g:, 'tex_superscripts', '[0-9a-zA-W.,:;+-<>/()=]'), - \ 'conceal_set_sub': - \ get(g:, 'tex_subscripts', '[0-9aehijklmnoprstuvx,+-/().]'), + \ 'conceal': { + \ 'accents': 1, + \ 'greek': 1, + \ 'math_bounds': 1, + \ 'math_delimiters': 1, + \ 'special_chars': 1, + \ 'styles': 1, + \ 'super_sub': 1, + \ }, \}) call s:init_option('vimtex_syntax_enabled', 1) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 05037faf24..4f9ddf5698 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -309,7 +309,7 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_math_zone('math', 1) " Inline Math Zones - if l:cfg.conceal =~# 'd' && &encoding ==# 'utf-8' + if l:cfg.conceal.math_bounds && &encoding ==# 'utf-8' syntax region texRegionMath matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" concealends contains=@texClusterMath keepend syntax region texRegionMath matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" concealends contains=@texClusterMath keepend syntax region texRegionMathX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" concealends contains=@texClusterMath @@ -329,7 +329,13 @@ function! vimtex#syntax#core#init() abort " {{{1 " Math delimiters: \left... and \right... syntax match texMathDelimBad contained "\S" - if l:cfg.conceal !~# 'm' || &encoding !=# 'utf-8' + if l:cfg.conceal.math_delimiters && &encoding ==# 'utf-8' + syntax match texMathDelim "\\left\[" contained + syntax match texMathDelim "\\left\\{" contained skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad contains=texMathSymbol cchar={ + syntax match texMathDelim "\\right\\}" contained skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad contains=texMathSymbol cchar=} + syntax match texMathDelim '\\[bB]igg\?[lr]' contained nextgroup=texMathDelimBad + call s:match_conceal_math_delims() + else syntax match texMathDelim "\\\(left\|right\)\>" contained skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad syntax match texMathDelim "\\[bB]igg\?[lr]\?\>" contained skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad syntax match texMathDelimSet2 "\\" contained nextgroup=texMathDelimKey,texMathDelimBad @@ -339,24 +345,17 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax keyword texMathDelimKey contained Downarrow lgroup rbrace rvert updownarrow syntax keyword texMathDelimKey contained langle lmoustache rceil rVert Updownarrow syntax keyword texMathDelimKey contained lbrace lvert rfloor - else - syntax match texMathDelim "\\left\[" contained - syntax match texMathDelim "\\left\\{" contained skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad contains=texMathSymbol cchar={ - syntax match texMathDelim "\\right\\}" contained skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad contains=texMathSymbol cchar=} - syntax match texMathDelim '\\[bB]igg\?[lr]' contained nextgroup=texMathDelimBad - call s:match_conceal_math_delims() endif syntax match texMathDelim contained "\\\(left\|right\)arrow\>\|\<\([aA]rrow\|brace\)\?vert\>" syntax match texMathDelim contained "\\lefteqn\>" - - + " }}}2 " {{{2 Conceal mode support " Add support for conceal with custom replacement (conceallevel = 2) if &encoding ==# 'utf-8' - if l:cfg.conceal =~# 'S' + if l:cfg.conceal.special_chars syntax match texSpecialChar '\\glq\>' contained conceal cchar=‚ syntax match texSpecialChar '\\grq\>' contained conceal cchar=‘ syntax match texSpecialChar '\\glqq\>' contained conceal cchar=„ @@ -365,22 +364,22 @@ function! vimtex#syntax#core#init() abort " {{{1 endif " Many of these symbols were contributed by Björn Winckler - if l:cfg.conceal =~# 'm' + if l:cfg.conceal.math_delimiters call s:match_conceal_math_symbols() endif " Conceal replace greek letters - if l:cfg.conceal =~# 'g' + if l:cfg.conceal.greek call s:match_conceal_greek() endif " Conceal replace superscripts and subscripts - if l:cfg.conceal =~# 's' + if l:cfg.conceal.super_sub call s:match_conceal_super_sub(l:cfg) endif " Conceal replace accented characters and ligatures - if l:cfg.conceal =~# 'a' && !l:cfg.is_style_document + if l:cfg.conceal.accents && !l:cfg.is_style_document call s:match_conceal_accents() endif endif @@ -519,7 +518,7 @@ endfunction function! s:match_bold_italic(cfg) abort " {{{1 let [l:conceal, l:concealends] = - \ (a:cfg.conceal =~# 'b' ? ['conceal', 'concealends'] : ['', '']) + \ (a:cfg.conceal.styles ? ['conceal', 'concealends'] : ['', '']) syntax cluster texClusterBold contains=TOP,texCmdStyleItal,texCmdStyleBold,texCmdStyleItalBold syntax cluster texClusterItal contains=TOP,texCmdStyleItal,texCmdStyleBold,texCmdStyleBoldItal @@ -981,13 +980,13 @@ function! s:match_conceal_super_sub(cfg) " {{{1 syntax region texSubscript matchgroup=Delimiter start='_{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSubscripts,texCmd,texSubscript,texSuperscript,texMatcherMath for [l:from, l:to] in filter(copy(s:map_super), - \ {_, x -> x[0][0] ==# '\' || x[0] =~# a:cfg.conceal_set_super}) + \ {_, x -> x[0][0] ==# '\' || x[0] =~# '[0-9a-zA-W.,:;+-<>/()=]'}) execute 'syntax match texSuperscript /\^' . l:from . '/ contained conceal cchar=' . l:to execute 'syntax match texSuperscripts /' . l:from . '/ contained conceal cchar=' . l:to 'nextgroup=texSuperscripts' endfor for [l:from, l:to] in filter(copy(s:map_sub), - \ {_, x -> x[0][0] ==# '\' || x[0] =~# a:cfg.conceal_set_sub}) + \ {_, x -> x[0][0] ==# '\' || x[0] =~# '[0-9aehijklmnoprstuvx,+-/().]'}) execute 'syntax match texSubscript /_' . l:from . '/ contained conceal cchar=' . l:to execute 'syntax match texSubscripts /' . l:from . '/ contained conceal cchar=' . l:to . ' nextgroup=texSubscripts' endfor diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index 43af44d639..24171b23e9 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -20,7 +20,7 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 call vimtex#syntax#core#new_math_zone('mathpar', 1) " Amsmath [lr][vV]ert (Holger Mitschke) - if has('conceal') && &enc ==# 'utf-8' && get(g:, 'tex_conceal', 'd') =~# 'd' + if &encoding ==# 'utf-8' && g:vimtex_syntax_config.conceal.math_delimiters for l:texmath in [ \ ['\\lvert', '|'] , \ ['\\rvert', '|'] , diff --git a/autoload/vimtex/syntax/p/array.vim b/autoload/vimtex/syntax/p/array.vim index 61e6502c69..e118a1cb05 100644 --- a/autoload/vimtex/syntax/p/array.vim +++ b/autoload/vimtex/syntax/p/array.vim @@ -10,9 +10,9 @@ function! vimtex#syntax#p#array#load() abort " {{{1 call vimtex#syntax#p#tabularx#load() - let l:concealed = has('conceal') - \ && &enc ==# 'utf-8' - \ && get(g:, 'tex_conceal', 'd') =~# 'd' + let l:concealends = &encoding ==# 'utf-8' + \ && g:vimtex_syntax_config.conceal.math_delimiters + \ ? 'concealends' : '' " Change inline math to improve column specifiers, e.g. " @@ -27,7 +27,7 @@ function! vimtex#syntax#p#array#load() abort " {{{1 \ 'end="\$"' \ 'end="%stopzone\>"' \ 'contains=@texClusterMath' - \ (l:concealed ? 'concealends' : '') + \ l:concealends endfunction " }}}1 diff --git a/test/tests/test-syntax/test-bold-italic.vim b/test/tests/test-syntax/test-bold-italic.vim index 7fdf012f8c..94017922cc 100644 --- a/test/tests/test-syntax/test-bold-italic.vim +++ b/test/tests/test-syntax/test-bold-italic.vim @@ -1,6 +1,7 @@ source common.vim -let g:tex_conceal = 'b' +" let g:vimtex_syntax_config = {'conceal': {'styles': 0}} +set conceallevel=2 silent edit test-bold-italic.tex From 9f7951ade2f5c163e58f8e4abaafd9044b8bfe6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Tue, 27 Oct 2020 22:48:04 +0100 Subject: [PATCH 16/99] wip: a lot more refinements and improvements --- autoload/vimtex/delim.vim | 2 +- autoload/vimtex/syntax/core.vim | 282 +++++++++++---------- autoload/vimtex/syntax/p/amsmath.vim | 16 +- autoload/vimtex/syntax/p/beamer.vim | 6 +- autoload/vimtex/syntax/p/biblatex.vim | 2 +- autoload/vimtex/syntax/p/breqn.vim | 8 +- autoload/vimtex/syntax/p/cases.vim | 2 +- autoload/vimtex/syntax/p/cleveref.vim | 2 +- autoload/vimtex/syntax/p/ieeetrantools.vim | 8 +- autoload/vimtex/syntax/p/listings.vim | 2 +- autoload/vimtex/syntax/p/markdown.vim | 2 +- autoload/vimtex/syntax/p/minted.vim | 2 +- autoload/vimtex/syntax/p/pdfpages.vim | 2 +- autoload/vimtex/syntax/p/subfile.vim | 4 +- test/tests/test-syntax/test-core.tex | 31 ++- test/tests/test-syntax/test-core.vim | 4 +- test/tests/test-syntax/test-markdown.vim | 2 +- 17 files changed, 204 insertions(+), 173 deletions(-) diff --git a/autoload/vimtex/delim.vim b/autoload/vimtex/delim.vim index 3354c19c8c..ddc34ea0b0 100644 --- a/autoload/vimtex/delim.vim +++ b/autoload/vimtex/delim.vim @@ -591,7 +591,7 @@ function! s:parser_tex(match, lnum, cnum, side, type, direction) abort " {{{1 \ 'close' : '\m' . escape(a:match, '$'), \} let result.side = vimtex#syntax#in( - \ (a:match ==# '$' ? 'texRegionMathX' : 'texRegionMathY'), + \ (a:match ==# '$' ? 'texRegionMathX' : 'texRegionMathXX'), \ a:lnum, a:cnum+1) \ ? 'open' : 'close' let result.is_open = result.side ==# 'open' diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 4f9ddf5698..eac3d41c7f 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -22,7 +22,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " {{{2 Primitives " Delimiters - syntax region texMatcher matchgroup=Delimiter start="{" skip="\%(\\\\\)*\\}" end="}" transparent contains=TOP + syntax region texMatcher matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}" " Flag mismatching ending brace delimiter syntax match texError "}" @@ -33,7 +33,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texComment "\^\^A.*$" syntax match texComment "^%\+" else - syntax match texComment "%.*$" + syntax match texComment "%.*$" contains=@Spell endif " Do not check URLs and acronyms in comments @@ -52,9 +52,6 @@ function! vimtex#syntax#core#init() abort " {{{1 " TeX Lengths syntax match texLength "\<\d\+\([.,]\d\+\)\?\s*\(true\)\?\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>" - " Other - syntax match texOption "\v%(^|[^\\]\zs)#\d+" - " }}}2 " {{{2 Commands @@ -94,22 +91,20 @@ function! vimtex#syntax#core#init() abort " {{{1 " \title " Various commands that take a file argument (or similar) - syntax match texCmd "\\input\>" nextgroup=texFilename - syntax match texCmd "\\include\>" nextgroup=texFilename - syntax match texCmd "\\includeonly\>" nextgroup=texFilenames - syntax match texCmd "\\includegraphics\>" nextgroup=texOptGenericFile,texFilename - syntax match texCmd "\\bibliography\>" nextgroup=texFilenames - syntax match texCmd "\\bibliographystyle\>" nextgroup=texFilename - syntax match texCmd "\\document\%(class\|style\)\>" nextgroup=texOptGenericFile,texFilename - syntax match texCmd "\\usepackage\>" nextgroup=texOptGenericFiles,texFilenames - syntax match texCmd "\\RequirePackage\>" nextgroup=texOptGenericFiles,texFilenames - - call s:add_opt_group('GenericFile', 'texFilename') - call s:add_opt_group('GenericFiles', 'texFilenames') - - syntax region texFilename matchgroup=Delimiter start="{" end="}" contained contains=texCmd,texComment,@NoSpell - syntax region texFilenames matchgroup=Delimiter start="{" end="}" contained contains=texFilenameSeparator,texCmd,texComment,@NoSpell - syntax match texFilenameSeparator ",\s*" contained + syntax match texCmd nextgroup=texFileArg skipwhite skipnl "\\input\>" + syntax match texCmd nextgroup=texFileArg skipwhite skipnl "\\include\>" + syntax match texCmd nextgroup=texFileArgs skipwhite skipnl "\\includeonly\>" + syntax match texCmd nextgroup=texFileOpt,texFileArg skipwhite skipnl "\\includegraphics\>" + syntax match texCmd nextgroup=texFileArgs skipwhite skipnl "\\bibliography\>" + syntax match texCmd nextgroup=texFileArg skipwhite skipnl "\\bibliographystyle\>" + syntax match texCmd nextgroup=texFileOpt,texFileArg skipwhite skipnl "\\document\%(class\|style\)\>" + syntax match texCmd nextgroup=texFileOpts,texFileArgs skipwhite skipnl "\\usepackage\>" + syntax match texCmd nextgroup=texFileOpts,texFileArgs skipwhite skipnl "\\RequirePackage\>" + call s:cmd_opt('texFileOpt', 'texFileArg') + call s:cmd_opt('texFileOpts', 'texFileArgs') + call s:cmd_arg('texFileArg', '', 'texCmd,texComment,@NoSpell') + call s:cmd_arg('texFileArgs', '', 'texFileArgSep,texCmd,texComment,@NoSpell') + syntax match texFileArgSep ",\s*" contained " LaTeX 2.09 type styles syntax match texCmdStyle "\\rm\>" @@ -169,71 +164,74 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdSize "\\Huge\>" " \newcommand - syntax match texCmdNewcmd "\\\%(re\)\?newcommand\>" nextgroup=texNewcmdName skipwhite skipnl - syntax region texNewcmdName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texNewcmdArgs,texNewcmdBody skipwhite skipnl - syntax region texNewcmdArgs contained matchgroup=Delimiter start="\["rs=s+1 end="]" nextgroup=texNewcmdBody skipwhite skipnl - syntax region texNewcmdBody contained matchgroup=Delimiter start="{"rs=s+1 skip="\\\\\|\\[{}]" matchgroup=Delimiter end="}" contains=TOP + syntax match texCmdNewcmd nextgroup=texNewcmdName skipwhite skipnl "\\\%(re\)\?newcommand\>" + call s:cmd_arg('texNewcmdName', 'texNewcmdOpt,texNewcmdBody') + call s:cmd_opt('texNewcmdOpt', 'texNewcmdOpt,texNewcmdBody', '', 'oneline') + call s:cmd_arg('texNewcmdBody', '', 'TOP') + syntax match texNewcmdParm contained "#\d\+" containedin=texNewcmdBody " \newenvironment - syntax match texCmdNewenv "\\\%(re\)\?newenvironment\>" nextgroup=texNewenvName skipwhite skipnl - syntax region texNewenvName contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texNewenvBgn,texNewenvArgs skipwhite skipnl - syntax region texNewenvArgs contained matchgroup=Delimiter start="\["rs=s+1 end="]" nextgroup=texNewenvBgn,texNewenvArgs skipwhite skipnl - syntax region texNewenvBgn contained matchgroup=Delimiter start="{"rs=s+1 end="}" nextgroup=texNewenvEnd skipwhite skipnl contains=TOP - syntax region texNewenvEnd contained matchgroup=Delimiter start="{"rs=s+1 end="}" skipwhite skipnl contains=TOP + syntax match texCmdNewenv nextgroup=texNewenvName skipwhite skipnl "\\\%(re\)\?newenvironment\>" + call s:cmd_arg('texNewenvName', 'texNewenvBgn,texNewenvOpt') + call s:cmd_opt('texNewenvOpt', 'texNewenvBgn,texNewenvOpt', '', 'oneline') + call s:cmd_arg('texNewenvBgn', 'texNewenvEnd', 'TOP') + call s:cmd_arg('texNewenvEnd', '', 'TOP') + syntax match texNewenvParm contained "#\d\+" containedin=texNewenvBgn,texNewenvEnd " Definitions/Commands - syntax match texDefCmd "\\def\>" nextgroup=texDefName skipwhite skipnl + " E.g. \def \foo #1#2 {foo #1 bar #2 baz} + syntax match texCmdDef "\\def\>" nextgroup=texDefName skipwhite skipnl if l:cfg.is_style_document - syntax match texDefName contained "\\[a-zA-Z@]\+" nextgroup=texDefParms,texNewcmdBody skipwhite skipnl - syntax match texDefName contained "\\[^a-zA-Z@]" nextgroup=texDefParms,texNewcmdBody skipwhite skipnl + syntax match texDefName contained nextgroup=texDefParmPre,texDefBody skipwhite skipnl "\\[a-zA-Z@]\+" + syntax match texDefName contained nextgroup=texDefParmPre,texDefBody skipwhite skipnl "\\[^a-zA-Z@]" else - syntax match texDefName contained "\\\a\+" nextgroup=texDefParms,texNewcmdBody skipwhite skipnl - syntax match texDefName contained "\\\A" nextgroup=texDefParms,texNewcmdBody skipwhite skipnl + syntax match texDefName contained nextgroup=texDefParmPre,texDefBody skipwhite skipnl "\\\a\+" + syntax match texDefName contained nextgroup=texDefParmPre,texDefBody skipwhite skipnl "\\\A" endif - syntax match texDefParms contained "#[^{]*" contains=texDefParm nextgroup=texNewcmdBody skipwhite skipnl - syntax match texDefParm contained "#\d\+" - - " Tex Reference Zones - syntax cluster texClusterRef contains=texComment,texSymbolAmp,texMatcher - syntax match texRegionRef '\\cite\%([tp]\*\?\)\?\>' nextgroup=texRefOption,texRefCite - syntax region texRegionRef matchgroup=texCmd start="\\nocite{" end="}" contains=@texClusterRef - syntax region texRegionRef matchgroup=texCmd start="\\label{" end="}" contains=@texClusterRef - syntax region texRegionRef matchgroup=texCmd start="\\\(page\|eq\)ref{" end="}" contains=@texClusterRef - syntax region texRegionRef matchgroup=texCmd start="\\v\?ref{" end="}" contains=@texClusterRef - syntax region texRefOption matchgroup=Delimiter start='\[' end=']' contains=@texClusterRef,texRegionRef nextgroup=texRefOption,texRefCite contained - syntax region texRefCite matchgroup=Delimiter start='{' end='}' contains=@texClusterRef,texRegionRef,texRefCite contained + syntax match texDefParmPre contained nextgroup=texDefBody skipwhite skipnl "#[^{]*" + syntax match texDefParm contained "#\d\+" containedin=texDefParmPre,texDefBody + call s:cmd_arg('texDefBody', '', 'TOP') + + " Reference and cite commands + syntax match texCmdRef nextgroup=texRef skipwhite skipnl "\\nocite\>" + syntax match texCmdRef nextgroup=texRef skipwhite skipnl "\\label\>" + syntax match texCmdRef nextgroup=texRef skipwhite skipnl "\\\(page\|eq\)ref\>" + syntax match texCmdRef nextgroup=texRef skipwhite skipnl "\\v\?ref\>" + syntax match texCmdRef nextgroup=texRefOpt,texRef skipwhite skipnl "\\cite\>" + syntax match texCmdRef nextgroup=texRefOpt,texRef skipwhite skipnl "\\cite[tp]\>\*\?" + call s:cmd_arg('texRef', '', 'texComment,@NoSpell') + call s:cmd_opt('texRefOpt', 'texRefOpt,texRef') " \makeatletter ... \makeatother sections " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do " In short: allow @ in multicharacter macro name - syntax region texRegionSty matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP,texCmdError - syntax region texMatcherSty matchgroup=Delimiter start="{" skip="\\\\\|\\[{}]" end="}" contains=TOP,texCmdError contained - syntax region texMatcherSty matchgroup=Delimiter start="\[" end="]" contains=TOP,texCmdError contained + syntax region texRegionSty matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=texRegionSty - " Add nospell for commands per configuration - syntax region texVimtexNoSpell matchgroup=Delimiter - \ start='{' end='}' - \ contained contains=@NoSpell + " Add @NoSpell for commands per configuration for l:macro in g:vimtex_syntax_nospell_commands - execute 'syntax match texCmd /\\' . l:macro . '/' - \ 'nextgroup=texVimtexNospell' + execute 'syntax match texCmd skipwhite skipnl "\\' . l:macro . '"' + \ 'nextgroup=texVimtexNoSpell' endfor + call s:cmd_arg('texVimtexNoSpell', '', '@NoSpell') + + " Sections and parts + syntax match texCmdParts "\\\(front\|main\|back\)matter\>" + syntax match texCmdParts nextgroup=texPartTitle "\\part\>" + syntax match texCmdParts nextgroup=texPartTitle "\\chapter\>" + syntax match texCmdParts nextgroup=texPartTitle "\\\(sub\)*section\>" + syntax match texCmdParts nextgroup=texPartTitle "\\\(sub\)\?paragraph\>" + call s:cmd_arg('texPartTitle', '', 'TOP') " }}}2 " {{{2 Environments syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvName - syntax region texEnvName matchgroup=Delimiter - \ start="{" end="}" - \ contained contains=texComment nextgroup=texEnvModifier - syntax region texEnvModifier matchgroup=Delimiter - \ start="\[" end="]" - \ contained contains=texComment,@NoSpell + call s:cmd_arg('texEnvName', 'texEnvModifier') + call s:cmd_opt('texEnvModifier', '', 'texComment,@NoSpell') + syntax match texCmdEnvMath "\v\\%(begin|end)>" contained nextgroup=texEnvMathName - syntax region texEnvMathName matchgroup=Delimiter - \ start="{" end="}" - \ contained contains=texComment + call s:cmd_arg('texEnvMathName', '') " }}}2 " {{{2 Verbatim @@ -253,18 +251,6 @@ function! vimtex#syntax#core#init() abort " {{{1 \ start="\z([^\ta-zA-Z]\)" end="\z1" contained endif - " }}}2 - " {{{2 Sections and parts - - syntax match texCmdParts "\\\(front\|main\|back\)matter\>" - syntax match texCmdParts "\\part\>" nextgroup=texPartTitle - syntax match texCmdParts "\\chapter\>" nextgroup=texPartTitle - syntax match texCmdParts "\\\(sub\)*section\>" nextgroup=texPartTitle - syntax match texCmdParts "\\\(sub\)\?paragraph\>" nextgroup=texPartTitle - syntax region texPartTitle matchgroup=Delimiter - \ start='{' end='}' - \ contained contains=TOP - " }}}2 " {{{2 Various TeX symbols @@ -288,9 +274,9 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texOnlyMath "[_^]" contained - syntax cluster texClusterMath contains=texCmdEnvMath,texEnvMathName,texComment,texSymbolAmp,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texRegionRef,texSpecialChar,texCmd,texSubscript,texSuperscript,texCmdSize,texCmdStyle,@NoSpell - syntax cluster texClusterMathMatch contains=texComment,texDefCmd,texSymbolAmp,texGreek,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texCmdNewcmd,texCmdNewenv,texRegion,texRegionRef,texSpecialChar,texCmd,texSymbolString,texSubscript,texSuperscript,texCmdSize,texCmdStyle - syntax region texMatcherMath matchgroup=Delimiter start="{" skip="\%(\\\\\)*\\}" end="}" contained contains=@texClusterMathMatch + syntax cluster texClusterMath contains=texCmdEnvMath,texEnvMathName,texComment,texSymbolAmp,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texCmdRef,texSpecialChar,texCmd,texSubscript,texSuperscript,texCmdSize,texCmdStyle,@NoSpell + syntax cluster texClusterMathMatch contains=texComment,texCmdDef,texSymbolAmp,texGreek,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texCmdNewcmd,texCmdNewenv,texRegion,texCmdRef,texSpecialChar,texCmd,texSymbolString,texSubscript,texSuperscript,texCmdSize,texCmdStyle + syntax region texMatcherMath matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMathMatch " Bad/Mismatched math syntax match texErrorMath "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}" @@ -299,26 +285,26 @@ function! vimtex#syntax#core#init() abort " {{{1 " Operators and similar syntax match texMathOper "[_^=]" contained - " Text Inside Math Zones + " Text Inside Math regions syntax region texMathText matchgroup=texCmd start="\\\(\(inter\)\?text\|mbox\)\s*{" end="}" contains=TOP,@Spell " Math environments - call vimtex#syntax#core#new_math_zone('displaymath', 1) - call vimtex#syntax#core#new_math_zone('eqnarray', 1) - call vimtex#syntax#core#new_math_zone('equation', 1) - call vimtex#syntax#core#new_math_zone('math', 1) + call vimtex#syntax#core#new_math_region('displaymath', 1) + call vimtex#syntax#core#new_math_region('eqnarray', 1) + call vimtex#syntax#core#new_math_region('equation', 1) + call vimtex#syntax#core#new_math_region('math', 1) " Inline Math Zones if l:cfg.conceal.math_bounds && &encoding ==# 'utf-8' syntax region texRegionMath matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" concealends contains=@texClusterMath keepend syntax region texRegionMath matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" concealends contains=@texClusterMath keepend syntax region texRegionMathX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" concealends contains=@texClusterMath - syntax region texRegionMathY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" concealends contains=@texClusterMath keepend + syntax region texRegionMathXX matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" concealends contains=@texClusterMath keepend else syntax region texRegionMath matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" contains=@texClusterMath keepend syntax region texRegionMath matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" contains=@texClusterMath keepend - syntax region texRegionMathX matchgroup=Delimiter start="\$" skip="\%(\\\\\)*\\\$" matchgroup=Delimiter end="\$" contains=@texClusterMath - syntax region texRegionMathY matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" contains=@texClusterMath keepend + syntax region texRegionMathX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" contains=@texClusterMath + syntax region texRegionMathXX matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" contains=@texClusterMath keepend endif syntax match texCmd "\\ensuremath\>" nextgroup=texRegionMathEnsured @@ -393,7 +379,7 @@ endfunction " }}}1 -function! vimtex#syntax#core#new_math_zone(mathzone, starred) abort " {{{1 +function! vimtex#syntax#core#new_math_region(mathzone, starred) abort " {{{1 execute 'syntax match texErrorMath /\\end\s*{\s*' . a:mathzone . '\*\?\s*}/' execute 'syntax region texRegionMathEnv' @@ -415,52 +401,45 @@ function! s:init_highlights(cfg) abort " {{{1 " See :help group-names for list of conventional group names " Basic TeX highlighting groups - highlight def link texCmd Statement - highlight def link texCmdSpaceCodeChar Special - highlight def link texCmdTodo Todo - highlight def link texComment Comment - highlight def link texCommentTodo Todo - highlight def link texDef Statement - highlight def link texDefParm Special - highlight def link texEnvName PreCondit - highlight def link texError Error - highlight def link texFilename Include - highlight def link texFilenameSeparator NormalNC - highlight def link texLength Number - highlight def link texMath Special - highlight def link texMathDelim Statement - highlight def link texMathOper Operator - highlight def link texNewcmdArgs Identifier - highlight def link texOption Number - highlight def link texRegion PreCondit - highlight def link texRegionRef Special - highlight def link texSpecialChar SpecialChar - highlight def link texSymbol SpecialChar - highlight def link texSymbolAmp Delimiter - highlight def link texSymbolString String - highlight def link texTitle String - highlight def link texType Type + highlight def link texCmd Statement + highlight def link texCmdSpaceCodeChar Special + highlight def link texCmdTodo Todo + highlight def link texComment Comment + highlight def link texCommentTodo Todo + highlight def link texEnvName PreCondit + highlight def link texEnvMathName Delimiter + highlight def link texError Error + highlight def link texGenericArg Include + highlight def link texGenericOpt Identifier + highlight def link texGenericParm Special + highlight def link texGenericSep NormalNC + highlight def link texLength Number + highlight def link texMath Special + highlight def link texMathDelim Statement + highlight def link texMathOper Operator + highlight def link texRef Special + highlight def link texRegion PreCondit + highlight def link texSpecialChar SpecialChar + highlight def link texSymbol SpecialChar + highlight def link texSymbolString String + highlight def link texTitle String + highlight def link texType Type highlight def texStyleBold gui=bold cterm=bold highlight def texStyleItal gui=italic cterm=italic highlight def texStyleBoth gui=bold,italic cterm=bold,italic - " TeX highlighting groups which should share similar highlighting - highlight def link texMathDelimBad texError - highlight def link texErrorMath texError - highlight def link texCmdError texError - if a:cfg.is_style_document - highlight def link texOnlyMath texError - endif - " Inherited groups highlight def link texCmdAccent texCmd + highlight def link texCmdDef texCmd highlight def link texCmdEnv texCmd highlight def link texCmdEnvMath texCmdEnv + highlight def link texCmdError texError highlight def link texCmdLigature texSpecialChar highlight def link texCmdNewcmd texCmd highlight def link texCmdNewenv texCmd highlight def link texCmdParts texCmd + highlight def link texCmdRef texCmd highlight def link texCmdSize texType highlight def link texCmdSpaceCode texCmd highlight def link texCmdSty texCmd @@ -472,49 +451,72 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdStyleItalBold texCmd highlight def link texCommentAcronym texComment highlight def link texCommentURL texComment - highlight def link texDefCmd texDef - highlight def link texDefName texDef - highlight def link texEnvMathName Delimiter - highlight def link texFilenames texFilename + highlight def link texDefName texCmd + highlight def link texErrorMath texError + highlight def link texFileArg texGenericArg + highlight def link texFileArgSep texGenericSep + highlight def link texFileArgs texGenericArg + highlight def link texFileOpt texGenericOpt + highlight def link texFileOpts texGenericOpt highlight def link texGreek texCmd highlight def link texMatcherMath texMath + highlight def link texMathDelimBad texError highlight def link texMathDelimKey texMathDelim highlight def link texMathDelimSet1 texMathDelim highlight def link texMathDelimSet2 texMathDelim highlight def link texMathSymbol texCmd highlight def link texNewcmdName texCmd - highlight def link texNewenvArgs texNewcmdArgs + highlight def link texNewcmdOpt texGenericOpt + highlight def link texNewcmdParm texGenericParm highlight def link texNewenvName texEnvName - highlight def link texOptGenericFile texNewcmdArgs - highlight def link texOptGenericFiles texNewcmdArgs + highlight def link texNewenvOpt texGenericOpt + highlight def link texNewenvParm texGenericParm + highlight def link texOnlyMath texError highlight def link texPartTitle texTitle highlight def link texRefCite texRegionRef + highlight def link texRefOpt texGenericOpt highlight def link texRegionMath texMath highlight def link texRegionMathEnsured texMath highlight def link texRegionMathEnv texMath highlight def link texRegionMathEnvStarred texMath highlight def link texRegionMathX texMath - highlight def link texRegionMathY texMath + highlight def link texRegionMathXX texMath highlight def link texRegionVerb texRegion highlight def link texRegionVerbInline texRegionVerb highlight def link texSubscript texCmd highlight def link texSubscripts texSubscript highlight def link texSuperscript texCmd highlight def link texSuperscripts texSuperscript + highlight def link texSymbolAmp texSymbol highlight def link texSymbolDash texSymbol endfunction " }}}1 - function! s:add_opt_group(grp, next) abort " {{{1 - execute 'syntax region texOpt' . a:grp - \ 'matchgroup=Delimiter' - \ 'start="\[" end="\]" contained' - \ 'contains=texComment' - \ 'nextgroup=' . a:next - endfunction +function! s:cmd_arg(grp, next, ...) abort " {{{1 + let l:contains = a:0 >= 1 ? a:1 : 'texComment' + let l:options = a:0 >= 2 ? a:2 : '' + + execute 'syntax region' a:grp + \ 'contained matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}"' + \ (empty(l:contains) ? '' : 'contains=' . l:contains) + \ (empty(a:next) ? '' : 'nextgroup=' . a:next . ' skipwhite skipnl') + \ l:options +endfunction + +" }}}1 +function! s:cmd_opt(grp, next, ...) abort " {{{1 + let l:contains = a:0 > 0 ? a:1 : 'texComment' + let l:options = a:0 >= 2 ? a:2 : '' + + execute 'syntax region' a:grp + \ 'contained matchgroup=Delimiter start="\[" skip="\\\\\|\\\]" end="\]"' + \ (empty(l:contains) ? '' : 'contains=' . l:contains) + \ (empty(a:next) ? '' : 'nextgroup=' . a:next . ' skipwhite skipnl') + \ l:options +endfunction - " }}}1 +" }}}1 function! s:match_bold_italic(cfg) abort " {{{1 let [l:conceal, l:concealends] = @@ -976,8 +978,8 @@ endfunction " }}}1 function! s:match_conceal_super_sub(cfg) " {{{1 - syntax region texSuperscript matchgroup=Delimiter start='\^{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSuperscripts,texCmd,texSubscript,texSuperscript,texMatcherMath - syntax region texSubscript matchgroup=Delimiter start='_{' skip="\\\\\|\\[{}]" end='}' contained concealends contains=texSpecialChar,texSubscripts,texCmd,texSubscript,texSuperscript,texMatcherMath + syntax region texSuperscript matchgroup=Delimiter start='\^{' skip="\\\\\|\\}" end='}' contained concealends contains=texSpecialChar,texSuperscripts,texCmd,texSubscript,texSuperscript,texMatcherMath + syntax region texSubscript matchgroup=Delimiter start='_{' skip="\\\\\|\\}" end='}' contained concealends contains=texSpecialChar,texSubscripts,texCmd,texSubscript,texSuperscript,texMatcherMath for [l:from, l:to] in filter(copy(s:map_super), \ {_, x -> x[0][0] ==# '\' || x[0] =~# '[0-9a-zA-W.,:;+-<>/()=]'}) diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index 24171b23e9..99c9dd631c 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -10,14 +10,14 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 if has_key(b:vimtex_syntax, 'amsmath') | return | endif let b:vimtex_syntax.amsmath = 1 - call vimtex#syntax#core#new_math_zone('align', 1) - call vimtex#syntax#core#new_math_zone('alignat', 1) - call vimtex#syntax#core#new_math_zone('flalign', 1) - call vimtex#syntax#core#new_math_zone('gather', 1) - call vimtex#syntax#core#new_math_zone('multline', 1) - call vimtex#syntax#core#new_math_zone('xalignat', 1) - call vimtex#syntax#core#new_math_zone('xxalignat', 0) - call vimtex#syntax#core#new_math_zone('mathpar', 1) + call vimtex#syntax#core#new_math_region('align', 1) + call vimtex#syntax#core#new_math_region('alignat', 1) + call vimtex#syntax#core#new_math_region('flalign', 1) + call vimtex#syntax#core#new_math_region('gather', 1) + call vimtex#syntax#core#new_math_region('multline', 1) + call vimtex#syntax#core#new_math_region('xalignat', 1) + call vimtex#syntax#core#new_math_region('xxalignat', 0) + call vimtex#syntax#core#new_math_region('mathpar', 1) " Amsmath [lr][vV]ert (Holger Mitschke) if &encoding ==# 'utf-8' && g:vimtex_syntax_config.conceal.math_delimiters diff --git a/autoload/vimtex/syntax/p/beamer.vim b/autoload/vimtex/syntax/p/beamer.vim index 6d079226ae..b55aada52b 100644 --- a/autoload/vimtex/syntax/p/beamer.vim +++ b/autoload/vimtex/syntax/p/beamer.vim @@ -15,11 +15,11 @@ function! vimtex#syntax#p#beamer#load() abort " {{{1 syntax match texCmdBeamer '\\item<[^>]*>' contains=texBeamerOpt syntax match texCmd "\\includegraphics<[^>]*>" - \ contains=texBeamerOpt, - \ nextgroup=texOptGenericFile,texFilename + \ contains=texBeamerOpt + \ nextgroup=texFileOpt,texFileArg highlight link texCmdBeamer texCmd - highlight link texBeamerOpt texNewcmdArgs + highlight link texBeamerOpt texNewcmdOpt highlight link texBeamerDelimiter texDelimiter endfunction diff --git a/autoload/vimtex/syntax/p/biblatex.vim b/autoload/vimtex/syntax/p/biblatex.vim index f289b8b6a4..eb22f57450 100644 --- a/autoload/vimtex/syntax/p/biblatex.vim +++ b/autoload/vimtex/syntax/p/biblatex.vim @@ -8,7 +8,7 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 if has_key(b:vimtex_syntax, 'biblatex') | return | endif let b:vimtex_syntax.biblatex = 1 - syntax match texCmd "\\addbibresource\>" nextgroup=texFilenames + syntax match texCmd "\\addbibresource\>" nextgroup=texFileArgs for l:pattern in [ \ 'bibentry', diff --git a/autoload/vimtex/syntax/p/breqn.vim b/autoload/vimtex/syntax/p/breqn.vim index 1696f6cb7d..655cd93268 100644 --- a/autoload/vimtex/syntax/p/breqn.vim +++ b/autoload/vimtex/syntax/p/breqn.vim @@ -10,10 +10,10 @@ function! vimtex#syntax#p#breqn#load() abort " {{{1 if has_key(b:vimtex_syntax, 'breqn') | return | endif let b:vimtex_syntax.breqn = 1 - call vimtex#syntax#core#new_math_zone('dmath', 1) - call vimtex#syntax#core#new_math_zone('dseries', 1) - call vimtex#syntax#core#new_math_zone('dgroup', 1) - call vimtex#syntax#core#new_math_zone('darray', 1) + call vimtex#syntax#core#new_math_region('dmath', 1) + call vimtex#syntax#core#new_math_region('dseries', 1) + call vimtex#syntax#core#new_math_region('dgroup', 1) + call vimtex#syntax#core#new_math_region('darray', 1) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/cases.vim b/autoload/vimtex/syntax/p/cases.vim index 8916d235d5..f8b4b843a2 100644 --- a/autoload/vimtex/syntax/p/cases.vim +++ b/autoload/vimtex/syntax/p/cases.vim @@ -10,7 +10,7 @@ function! vimtex#syntax#p#cases#load() abort " {{{1 if has_key(b:vimtex_syntax, 'cases') | return | endif let b:vimtex_syntax.cases = 1 - call VimtexNewMathZone('E', '\(sub\)\?numcases', 0) + call vimtex#syntax#core#new_math_region('\(sub\)\?numcases', 0) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/cleveref.vim b/autoload/vimtex/syntax/p/cleveref.vim index e022ae55e5..668142b80e 100644 --- a/autoload/vimtex/syntax/p/cleveref.vim +++ b/autoload/vimtex/syntax/p/cleveref.vim @@ -33,7 +33,7 @@ function! vimtex#syntax#p#cleveref#load() abort " {{{1 highlight link texCRefZone texRegionRef highlight link texCRefZoneRange texRegionRef - highlight link texCRefLabelOpts texNewcmdArgs + highlight link texCRefLabelOpts texNewcmdOpt endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/ieeetrantools.vim b/autoload/vimtex/syntax/p/ieeetrantools.vim index 8a152456d9..7f54d8b613 100644 --- a/autoload/vimtex/syntax/p/ieeetrantools.vim +++ b/autoload/vimtex/syntax/p/ieeetrantools.vim @@ -10,14 +10,14 @@ function! vimtex#syntax#p#ieeetrantools#load() abort " {{{1 if has_key(b:vimtex_syntax, 'ieeetrantools') | return | endif let b:vimtex_syntax.ieeetrantools = 1 - call s:new_math_zone('IEEEeqnarray') - call s:new_math_zone('IEEEeqnarrayboxm') + call s:new_math_region('IEEEeqnarray') + call s:new_math_region('IEEEeqnarrayboxm') endfunction " }}}1 -function! s:new_math_zone(mathzone) abort " {{{1 - " This needs to be slightly different than vimtex#syntax#core#new_math_zone +function! s:new_math_region(mathzone) abort " {{{1 + " This needs to be slightly different than vimtex#syntax#core#new_math_region " to handle options for the environment. execute 'syntax match texErrorMath ''\\end\s*{\s*' . a:mathzone . '\*\?\s*}''' diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index 3d6cc4c114..de1a28caef 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -10,7 +10,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 " First some general support syntax match texCmd "\\lstinputlisting\>" - \ nextgroup=texOptGenericFile,texFilename + \ nextgroup=texFileOpt,texFileArg syntax match texRegion "\\lstinline\s*\(\[.\{-}\]\)\={.\{-}}" " Set all listings environments to listings diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index 94bc30da0a..44373bccf2 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -19,7 +19,7 @@ function! vimtex#syntax#p#markdown#load() abort " {{{1 \ keepend transparent \ contains=texCmdEnv,texEnvName,@vimtex_nested_markdown - syntax match texCmd "\\markdownInput\>" nextgroup=texFilename + syntax match texCmd "\\markdownInput\>" nextgroup=texFileArg endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index 9d9224c98d..de884aa51a 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -142,7 +142,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 highlight link texRegionMinted texRegion highlight link texRegionMintedCmd texRegion - highlight link texMintedName texNewcmdArgs + highlight link texMintedName texNewcmdOpt highlight link texMintedNameOpt texMintedName endfunction diff --git a/autoload/vimtex/syntax/p/pdfpages.vim b/autoload/vimtex/syntax/p/pdfpages.vim index b2c944ef19..c2878fb385 100644 --- a/autoload/vimtex/syntax/p/pdfpages.vim +++ b/autoload/vimtex/syntax/p/pdfpages.vim @@ -8,7 +8,7 @@ function! vimtex#syntax#p#pdfpages#load() abort " {{{1 if has_key(b:vimtex_syntax, 'pdfpages') | return | endif let b:vimtex_syntax.pdfpages = 1 - syntax match texCmd "\\includepdf\>" nextgroup=texOptGenericFile,texFilename + syntax match texCmd "\\includepdf\>" nextgroup=texFileOpt,texFileArg endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/subfile.vim b/autoload/vimtex/syntax/p/subfile.vim index 565b606b69..0ee01b8f6c 100644 --- a/autoload/vimtex/syntax/p/subfile.vim +++ b/autoload/vimtex/syntax/p/subfile.vim @@ -8,8 +8,8 @@ function! vimtex#syntax#p#subfile#load() abort " {{{1 if has_key(b:vimtex_syntax, 'subfile') | return | endif let b:vimtex_syntax.subfile = 1 - syntax match texCmd "\\subfile\>" nextgroup=texFilename - syntax match texCmd "\\subfileinclude\>" nextgroup=texFilename + syntax match texCmd "\\subfile\>" nextgroup=texFileArg + syntax match texCmd "\\subfileinclude\>" nextgroup=texFileArg endfunction " }}}1 diff --git a/test/tests/test-syntax/test-core.tex b/test/tests/test-syntax/test-core.tex index 966720f9dc..e408dc8238 100644 --- a/test/tests/test-syntax/test-core.tex +++ b/test/tests/test-syntax/test-core.tex @@ -8,12 +8,39 @@ \@asd{asd} \makeatother +% TODO fixme +% +% bad speled text +% ABC +% https://www.example.com +% + +\newcommand{\testnc}[2]{#1 something #1 here #2} +\def \foo #1#2 {#1 foo #1 bar #2 baz} +\newenvironment{test}[3]{#1 before #2}{#3 after #1} + \begin{document} -\v! -\v@ +Test accents \v! and \v@ here. Line with inline verbatim: \verb+verb+ Line with inline verbatim: \verb*+verb+ +Line with $inline math$ here. + +\section{First} +\label{sec:first} + +% Various cite and ref commands +\ref{sec:first} +\pageref{sec:second} +\nocite{bibkey0} +\cite{bibkey1} +\citet*{bibkey2} +\citep{bibkey3} +\citep[e.g.][]{bibkey4} + +\section{Second} +\label{sec:second} + \end{document} diff --git a/test/tests/test-syntax/test-core.vim b/test/tests/test-syntax/test-core.vim index b951f711f9..500b9d1840 100644 --- a/test/tests/test-syntax/test-core.vim +++ b/test/tests/test-syntax/test-core.vim @@ -7,6 +7,8 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texCmdError', 5, 3)) call vimtex#test#assert(vimtex#syntax#in('texCmdSty', 8, 3)) -call vimtex#test#assert(vimtex#syntax#in('texRegionVerbInline', 17, 36)) +call vimtex#test#assert(vimtex#syntax#in('texNewenvParm', 20, 36)) + +call vimtex#test#assert(vimtex#syntax#in('texRegionVerbInline', 26, 36)) quit! diff --git a/test/tests/test-syntax/test-markdown.vim b/test/tests/test-syntax/test-markdown.vim index e4db74cbf3..13f5019106 100644 --- a/test/tests/test-syntax/test-markdown.vim +++ b/test/tests/test-syntax/test-markdown.vim @@ -7,6 +7,6 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texRegionMarkdown', 7, 1)) call vimtex#test#assert(vimtex#syntax#in('markdownItalic', 7, 1)) call vimtex#test#assert(vimtex#syntax#in('markdownLink', 11, 12)) -call vimtex#test#assert(vimtex#syntax#in('texFilename', 16, 16)) +call vimtex#test#assert(vimtex#syntax#in('texFileArg', 16, 16)) quit! From f6ecd2e266fbcb63cbbed58d423973c8d8100bf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Tue, 27 Oct 2020 22:50:51 +0100 Subject: [PATCH 17/99] chore: minor rebasing --- autoload/vimtex/syntax/core.vim | 88 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index eac3d41c7f..b6b3b07637 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -100,10 +100,10 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmd nextgroup=texFileOpt,texFileArg skipwhite skipnl "\\document\%(class\|style\)\>" syntax match texCmd nextgroup=texFileOpts,texFileArgs skipwhite skipnl "\\usepackage\>" syntax match texCmd nextgroup=texFileOpts,texFileArgs skipwhite skipnl "\\RequirePackage\>" - call s:cmd_opt('texFileOpt', 'texFileArg') - call s:cmd_opt('texFileOpts', 'texFileArgs') - call s:cmd_arg('texFileArg', '', 'texCmd,texComment,@NoSpell') - call s:cmd_arg('texFileArgs', '', 'texFileArgSep,texCmd,texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_opt('texFileOpt', 'texFileArg') + call vimtex#syntax#core#new_cmd_opt('texFileOpts', 'texFileArgs') + call vimtex#syntax#core#new_cmd_arg('texFileArg', '', 'texCmd,texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texFileArgs', '', 'texFileArgSep,texCmd,texComment,@NoSpell') syntax match texFileArgSep ",\s*" contained " LaTeX 2.09 type styles @@ -165,17 +165,17 @@ function! vimtex#syntax#core#init() abort " {{{1 " \newcommand syntax match texCmdNewcmd nextgroup=texNewcmdName skipwhite skipnl "\\\%(re\)\?newcommand\>" - call s:cmd_arg('texNewcmdName', 'texNewcmdOpt,texNewcmdBody') - call s:cmd_opt('texNewcmdOpt', 'texNewcmdOpt,texNewcmdBody', '', 'oneline') - call s:cmd_arg('texNewcmdBody', '', 'TOP') + call vimtex#syntax#core#new_cmd_arg('texNewcmdName', 'texNewcmdOpt,texNewcmdBody') + call vimtex#syntax#core#new_cmd_opt('texNewcmdOpt', 'texNewcmdOpt,texNewcmdBody', '', 'oneline') + call vimtex#syntax#core#new_cmd_arg('texNewcmdBody', '', 'TOP') syntax match texNewcmdParm contained "#\d\+" containedin=texNewcmdBody " \newenvironment syntax match texCmdNewenv nextgroup=texNewenvName skipwhite skipnl "\\\%(re\)\?newenvironment\>" - call s:cmd_arg('texNewenvName', 'texNewenvBgn,texNewenvOpt') - call s:cmd_opt('texNewenvOpt', 'texNewenvBgn,texNewenvOpt', '', 'oneline') - call s:cmd_arg('texNewenvBgn', 'texNewenvEnd', 'TOP') - call s:cmd_arg('texNewenvEnd', '', 'TOP') + call vimtex#syntax#core#new_cmd_arg('texNewenvName', 'texNewenvBgn,texNewenvOpt') + call vimtex#syntax#core#new_cmd_opt('texNewenvOpt', 'texNewenvBgn,texNewenvOpt', '', 'oneline') + call vimtex#syntax#core#new_cmd_arg('texNewenvBgn', 'texNewenvEnd', 'TOP') + call vimtex#syntax#core#new_cmd_arg('texNewenvEnd', '', 'TOP') syntax match texNewenvParm contained "#\d\+" containedin=texNewenvBgn,texNewenvEnd " Definitions/Commands @@ -190,7 +190,7 @@ function! vimtex#syntax#core#init() abort " {{{1 endif syntax match texDefParmPre contained nextgroup=texDefBody skipwhite skipnl "#[^{]*" syntax match texDefParm contained "#\d\+" containedin=texDefParmPre,texDefBody - call s:cmd_arg('texDefBody', '', 'TOP') + call vimtex#syntax#core#new_cmd_arg('texDefBody', '', 'TOP') " Reference and cite commands syntax match texCmdRef nextgroup=texRef skipwhite skipnl "\\nocite\>" @@ -199,8 +199,8 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdRef nextgroup=texRef skipwhite skipnl "\\v\?ref\>" syntax match texCmdRef nextgroup=texRefOpt,texRef skipwhite skipnl "\\cite\>" syntax match texCmdRef nextgroup=texRefOpt,texRef skipwhite skipnl "\\cite[tp]\>\*\?" - call s:cmd_arg('texRef', '', 'texComment,@NoSpell') - call s:cmd_opt('texRefOpt', 'texRefOpt,texRef') + call vimtex#syntax#core#new_cmd_arg('texRef', '', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_opt('texRefOpt', 'texRefOpt,texRef') " \makeatletter ... \makeatother sections " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do @@ -213,7 +213,7 @@ function! vimtex#syntax#core#init() abort " {{{1 execute 'syntax match texCmd skipwhite skipnl "\\' . l:macro . '"' \ 'nextgroup=texVimtexNoSpell' endfor - call s:cmd_arg('texVimtexNoSpell', '', '@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texVimtexNoSpell', '', '@NoSpell') " Sections and parts syntax match texCmdParts "\\\(front\|main\|back\)matter\>" @@ -221,17 +221,17 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdParts nextgroup=texPartTitle "\\chapter\>" syntax match texCmdParts nextgroup=texPartTitle "\\\(sub\)*section\>" syntax match texCmdParts nextgroup=texPartTitle "\\\(sub\)\?paragraph\>" - call s:cmd_arg('texPartTitle', '', 'TOP') + call vimtex#syntax#core#new_cmd_arg('texPartTitle', '', 'TOP') " }}}2 " {{{2 Environments syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvName - call s:cmd_arg('texEnvName', 'texEnvModifier') - call s:cmd_opt('texEnvModifier', '', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texEnvName', 'texEnvModifier') + call vimtex#syntax#core#new_cmd_opt('texEnvModifier', '', 'texComment,@NoSpell') syntax match texCmdEnvMath "\v\\%(begin|end)>" contained nextgroup=texEnvMathName - call s:cmd_arg('texEnvMathName', '') + call vimtex#syntax#core#new_cmd_arg('texEnvMathName', '') " }}}2 " {{{2 Verbatim @@ -379,6 +379,30 @@ endfunction " }}}1 +function! vimtex#syntax#core#new_cmd_arg(grp, next, ...) abort " {{{1 + let l:contains = a:0 >= 1 ? a:1 : 'texComment' + let l:options = a:0 >= 2 ? a:2 : '' + + execute 'syntax region' a:grp + \ 'contained matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}"' + \ (empty(l:contains) ? '' : 'contains=' . l:contains) + \ (empty(a:next) ? '' : 'nextgroup=' . a:next . ' skipwhite skipnl') + \ l:options +endfunction + +" }}}1 +function! vimtex#syntax#core#new_cmd_opt(grp, next, ...) abort " {{{1 + let l:contains = a:0 > 0 ? a:1 : 'texComment' + let l:options = a:0 >= 2 ? a:2 : '' + + execute 'syntax region' a:grp + \ 'contained matchgroup=Delimiter start="\[" skip="\\\\\|\\\]" end="\]"' + \ (empty(l:contains) ? '' : 'contains=' . l:contains) + \ (empty(a:next) ? '' : 'nextgroup=' . a:next . ' skipwhite skipnl') + \ l:options +endfunction + +" }}}1 function! vimtex#syntax#core#new_math_region(mathzone, starred) abort " {{{1 execute 'syntax match texErrorMath /\\end\s*{\s*' . a:mathzone . '\*\?\s*}/' @@ -397,6 +421,7 @@ endfunction " }}}1 + function! s:init_highlights(cfg) abort " {{{1 " See :help group-names for list of conventional group names @@ -493,31 +518,6 @@ endfunction " }}}1 -function! s:cmd_arg(grp, next, ...) abort " {{{1 - let l:contains = a:0 >= 1 ? a:1 : 'texComment' - let l:options = a:0 >= 2 ? a:2 : '' - - execute 'syntax region' a:grp - \ 'contained matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}"' - \ (empty(l:contains) ? '' : 'contains=' . l:contains) - \ (empty(a:next) ? '' : 'nextgroup=' . a:next . ' skipwhite skipnl') - \ l:options -endfunction - -" }}}1 -function! s:cmd_opt(grp, next, ...) abort " {{{1 - let l:contains = a:0 > 0 ? a:1 : 'texComment' - let l:options = a:0 >= 2 ? a:2 : '' - - execute 'syntax region' a:grp - \ 'contained matchgroup=Delimiter start="\[" skip="\\\\\|\\\]" end="\]"' - \ (empty(l:contains) ? '' : 'contains=' . l:contains) - \ (empty(a:next) ? '' : 'nextgroup=' . a:next . ' skipwhite skipnl') - \ l:options -endfunction - -" }}}1 - function! s:match_bold_italic(cfg) abort " {{{1 let [l:conceal, l:concealends] = \ (a:cfg.conceal.styles ? ['conceal', 'concealends'] : ['', '']) From b3ec5f1f1dbac282947bd059a90c77de9b8e5807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 28 Oct 2020 20:06:06 +0100 Subject: [PATCH 18/99] wip: some fixes and improvements --- autoload/vimtex/syntax/core.vim | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index b6b3b07637..c01c633290 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -22,7 +22,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " {{{2 Primitives " Delimiters - syntax region texMatcher matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}" + syntax region texMatcher matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}" contains=TOP " Flag mismatching ending brace delimiter syntax match texError "}" @@ -55,9 +55,14 @@ function! vimtex#syntax#core#init() abort " {{{1 " }}}2 " {{{2 Commands + " Most general version first syntax match texCmd "\\\a\+" syntax match texCmdError "\\\a*@\a*" + " Add some standard contained stuff + syntax match texOptEqual contained "=" + syntax match texOptSep contained ",\s*" + " Accents and ligatures syntax match texCmdAccent "\\[bcdvuH]$" syntax match texCmdAccent "\\[bcdvuH]\ze\A" @@ -103,8 +108,7 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_cmd_opt('texFileOpt', 'texFileArg') call vimtex#syntax#core#new_cmd_opt('texFileOpts', 'texFileArgs') call vimtex#syntax#core#new_cmd_arg('texFileArg', '', 'texCmd,texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texFileArgs', '', 'texFileArgSep,texCmd,texComment,@NoSpell') - syntax match texFileArgSep ",\s*" contained + call vimtex#syntax#core#new_cmd_arg('texFileArgs', '', 'texOptSep,texCmd,texComment,@NoSpell') " LaTeX 2.09 type styles syntax match texCmdStyle "\\rm\>" @@ -239,7 +243,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " Verbatim environment syntax region texRegionVerb \ start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}" - \ contains=texCmdEnv,texEnvName + \ keepend contains=texCmdEnv,texEnvName " Verbatim inline syntax match texCmd "\\verb\>\*\?" nextgroup=texRegionVerbInline @@ -392,7 +396,7 @@ endfunction " }}}1 function! vimtex#syntax#core#new_cmd_opt(grp, next, ...) abort " {{{1 - let l:contains = a:0 > 0 ? a:1 : 'texComment' + let l:contains = a:0 > 0 ? a:1 : 'texComment,texCmd,texLength,texOptSep,texOptEqual' let l:options = a:0 >= 2 ? a:2 : '' execute 'syntax region' a:grp @@ -479,7 +483,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texDefName texCmd highlight def link texErrorMath texError highlight def link texFileArg texGenericArg - highlight def link texFileArgSep texGenericSep highlight def link texFileArgs texGenericArg highlight def link texFileOpt texGenericOpt highlight def link texFileOpts texGenericOpt @@ -496,6 +499,8 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texNewenvName texEnvName highlight def link texNewenvOpt texGenericOpt highlight def link texNewenvParm texGenericParm + highlight def link texOptEqual texSymbol + highlight def link texOptSep texGenericSep highlight def link texOnlyMath texError highlight def link texPartTitle texTitle highlight def link texRefCite texRegionRef From 0d4b04ff277c424c7364942d318dacf9bf296060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 29 Oct 2020 00:00:27 +0100 Subject: [PATCH 19/99] wip: even better consistency now --- autoload/vimtex/syntax/core.vim | 275 ++++++++++++----------- autoload/vimtex/syntax/p/beamer.vim | 4 +- autoload/vimtex/syntax/p/biblatex.vim | 2 +- autoload/vimtex/syntax/p/cleveref.vim | 2 +- autoload/vimtex/syntax/p/gnuplottex.vim | 2 +- autoload/vimtex/syntax/p/listings.vim | 2 +- autoload/vimtex/syntax/p/markdown.vim | 6 +- autoload/vimtex/syntax/p/minted.vim | 2 +- autoload/vimtex/syntax/p/pdfpages.vim | 2 +- autoload/vimtex/syntax/p/subfile.vim | 4 +- test/tests/test-syntax/test-core.vim | 2 +- test/tests/test-syntax/test-markdown.vim | 2 +- 12 files changed, 156 insertions(+), 149 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index c01c633290..ae7d5e3a02 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -21,15 +21,22 @@ function! vimtex#syntax#core#init() abort " {{{1 " {{{2 Primitives - " Delimiters - syntax region texMatcher matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}" contains=TOP + " Match TeX braces in general + " TODO: Do we really need this?? + syntax region texMatcher matchgroup=Delimiter + \ start="{" skip="\\\\\|\\}" end="}" contains=TOP " Flag mismatching ending brace delimiter syntax match texError "}" " Comments + " * In documented TeX Format, actual comments are defined by leading "^^A". + " Almost all other lines start with one or more "%", which may be matched + " as comment characters. The remaining part of the line can be interpreted + " as TeX syntax. + " * For more info on dtx files, see e.g. + " https://ctan.uib.no/info/dtxtut/dtxtut.pdf if l:cfg.ext ==# 'dtx' - " Documented TeX Format: Only leading "^^A" and "%" syntax match texComment "\^\^A.*$" syntax match texComment "^%\+" else @@ -91,24 +98,26 @@ function! vimtex#syntax#core#init() abort " {{{1 " Todo commands syntax match texCmdTodo '\\todo\w*' - " TODO: Special for author and title type of commands? - " \author - " \title + " Author and title commands + syntax match texCmd nextgroup=texArgAuthor skipwhite skipnl "\\author\>" + syntax match texCmd nextgroup=texArgTitle skipwhite skipnl "\\title\>" + call vimtex#syntax#core#new_cmd_arg('texArgAuthor', '', 'texCmd,texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texArgTitle', '', 'texCmd,texComment') " Various commands that take a file argument (or similar) - syntax match texCmd nextgroup=texFileArg skipwhite skipnl "\\input\>" - syntax match texCmd nextgroup=texFileArg skipwhite skipnl "\\include\>" - syntax match texCmd nextgroup=texFileArgs skipwhite skipnl "\\includeonly\>" - syntax match texCmd nextgroup=texFileOpt,texFileArg skipwhite skipnl "\\includegraphics\>" - syntax match texCmd nextgroup=texFileArgs skipwhite skipnl "\\bibliography\>" - syntax match texCmd nextgroup=texFileArg skipwhite skipnl "\\bibliographystyle\>" - syntax match texCmd nextgroup=texFileOpt,texFileArg skipwhite skipnl "\\document\%(class\|style\)\>" - syntax match texCmd nextgroup=texFileOpts,texFileArgs skipwhite skipnl "\\usepackage\>" - syntax match texCmd nextgroup=texFileOpts,texFileArgs skipwhite skipnl "\\RequirePackage\>" - call vimtex#syntax#core#new_cmd_opt('texFileOpt', 'texFileArg') - call vimtex#syntax#core#new_cmd_opt('texFileOpts', 'texFileArgs') - call vimtex#syntax#core#new_cmd_arg('texFileArg', '', 'texCmd,texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texFileArgs', '', 'texOptSep,texCmd,texComment,@NoSpell') + syntax match texCmd nextgroup=texArgFile skipwhite skipnl "\\input\>" + syntax match texCmd nextgroup=texArgFile skipwhite skipnl "\\include\>" + syntax match texCmd nextgroup=texArgFiles skipwhite skipnl "\\includeonly\>" + syntax match texCmd nextgroup=texOptFile,texArgFile skipwhite skipnl "\\includegraphics\>" + syntax match texCmd nextgroup=texArgFiles skipwhite skipnl "\\bibliography\>" + syntax match texCmd nextgroup=texArgFile skipwhite skipnl "\\bibliographystyle\>" + syntax match texCmd nextgroup=texOptFile,texArgFile skipwhite skipnl "\\document\%(class\|style\)\>" + syntax match texCmd nextgroup=texOptFiles,texArgFiles skipwhite skipnl "\\usepackage\>" + syntax match texCmd nextgroup=texOptFiles,texArgFiles skipwhite skipnl "\\RequirePackage\>" + call vimtex#syntax#core#new_cmd_opt('texOptFile', 'texArgFile') + call vimtex#syntax#core#new_cmd_opt('texOptFiles', 'texArgFiles') + call vimtex#syntax#core#new_cmd_arg('texArgFile', '', 'texCmd,texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texArgFiles', '', 'texOptSep,texCmd,texComment,@NoSpell') " LaTeX 2.09 type styles syntax match texCmdStyle "\\rm\>" @@ -168,43 +177,43 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdSize "\\Huge\>" " \newcommand - syntax match texCmdNewcmd nextgroup=texNewcmdName skipwhite skipnl "\\\%(re\)\?newcommand\>" - call vimtex#syntax#core#new_cmd_arg('texNewcmdName', 'texNewcmdOpt,texNewcmdBody') - call vimtex#syntax#core#new_cmd_opt('texNewcmdOpt', 'texNewcmdOpt,texNewcmdBody', '', 'oneline') - call vimtex#syntax#core#new_cmd_arg('texNewcmdBody', '', 'TOP') - syntax match texNewcmdParm contained "#\d\+" containedin=texNewcmdBody + syntax match texCmd nextgroup=texArgNewcmdName skipwhite skipnl "\\\%(re\)\?newcommand\>" + call vimtex#syntax#core#new_cmd_arg('texArgNewcmdName', 'texOptNewcmd,texArgNewcmdBody') + call vimtex#syntax#core#new_cmd_opt('texOptNewcmd', 'texOptNewcmd,texArgNewcmdBody', '', 'oneline') + call vimtex#syntax#core#new_cmd_arg('texArgNewcmdBody', '', 'TOP') + syntax match texParmNewcmd contained "#\d\+" containedin=texArgNewcmdBody " \newenvironment - syntax match texCmdNewenv nextgroup=texNewenvName skipwhite skipnl "\\\%(re\)\?newenvironment\>" - call vimtex#syntax#core#new_cmd_arg('texNewenvName', 'texNewenvBgn,texNewenvOpt') - call vimtex#syntax#core#new_cmd_opt('texNewenvOpt', 'texNewenvBgn,texNewenvOpt', '', 'oneline') - call vimtex#syntax#core#new_cmd_arg('texNewenvBgn', 'texNewenvEnd', 'TOP') - call vimtex#syntax#core#new_cmd_arg('texNewenvEnd', '', 'TOP') - syntax match texNewenvParm contained "#\d\+" containedin=texNewenvBgn,texNewenvEnd + syntax match texCmd nextgroup=texArgNewenvName skipwhite skipnl "\\\%(re\)\?newenvironment\>" + call vimtex#syntax#core#new_cmd_arg('texArgNewenvName', 'texArgNewenvBegin,texOptNewenv') + call vimtex#syntax#core#new_cmd_opt('texOptNewenv', 'texArgNewenvBegin,texOptNewenv', '', 'oneline') + call vimtex#syntax#core#new_cmd_arg('texArgNewenvBegin', 'texArgNewenvEnd', 'TOP') + call vimtex#syntax#core#new_cmd_arg('texArgNewenvEnd', '', 'TOP') + syntax match texParmNewenv contained "#\d\+" containedin=texArgNewenvBegin,texArgNewenvEnd " Definitions/Commands " E.g. \def \foo #1#2 {foo #1 bar #2 baz} - syntax match texCmdDef "\\def\>" nextgroup=texDefName skipwhite skipnl + syntax match texCmd "\\def\>" nextgroup=texArgDefName skipwhite skipnl if l:cfg.is_style_document - syntax match texDefName contained nextgroup=texDefParmPre,texDefBody skipwhite skipnl "\\[a-zA-Z@]\+" - syntax match texDefName contained nextgroup=texDefParmPre,texDefBody skipwhite skipnl "\\[^a-zA-Z@]" + syntax match texArgDefName contained nextgroup=texParmDefPre,texArgDefBody skipwhite skipnl "\\[a-zA-Z@]\+" + syntax match texArgDefName contained nextgroup=texParmDefPre,texArgDefBody skipwhite skipnl "\\[^a-zA-Z@]" else - syntax match texDefName contained nextgroup=texDefParmPre,texDefBody skipwhite skipnl "\\\a\+" - syntax match texDefName contained nextgroup=texDefParmPre,texDefBody skipwhite skipnl "\\\A" + syntax match texArgDefName contained nextgroup=texParmDefPre,texArgDefBody skipwhite skipnl "\\\a\+" + syntax match texArgDefName contained nextgroup=texParmDefPre,texArgDefBody skipwhite skipnl "\\\A" endif - syntax match texDefParmPre contained nextgroup=texDefBody skipwhite skipnl "#[^{]*" - syntax match texDefParm contained "#\d\+" containedin=texDefParmPre,texDefBody - call vimtex#syntax#core#new_cmd_arg('texDefBody', '', 'TOP') + syntax match texParmDefPre contained nextgroup=texArgDefBody skipwhite skipnl "#[^{]*" + syntax match texParmDef contained "#\d\+" containedin=texParmDefPre,texArgDefBody + call vimtex#syntax#core#new_cmd_arg('texArgDefBody', '', 'TOP') " Reference and cite commands - syntax match texCmdRef nextgroup=texRef skipwhite skipnl "\\nocite\>" - syntax match texCmdRef nextgroup=texRef skipwhite skipnl "\\label\>" - syntax match texCmdRef nextgroup=texRef skipwhite skipnl "\\\(page\|eq\)ref\>" - syntax match texCmdRef nextgroup=texRef skipwhite skipnl "\\v\?ref\>" - syntax match texCmdRef nextgroup=texRefOpt,texRef skipwhite skipnl "\\cite\>" - syntax match texCmdRef nextgroup=texRefOpt,texRef skipwhite skipnl "\\cite[tp]\>\*\?" - call vimtex#syntax#core#new_cmd_arg('texRef', '', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_opt('texRefOpt', 'texRefOpt,texRef') + syntax match texCmd nextgroup=texArgRef skipwhite skipnl "\\nocite\>" + syntax match texCmd nextgroup=texArgRef skipwhite skipnl "\\label\>" + syntax match texCmd nextgroup=texArgRef skipwhite skipnl "\\\(page\|eq\)ref\>" + syntax match texCmd nextgroup=texArgRef skipwhite skipnl "\\v\?ref\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\cite\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\cite[tp]\>\*\?" + call vimtex#syntax#core#new_cmd_arg('texArgRef', '', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_opt('texOptRef', 'texOptRef,texArgRef') " \makeatletter ... \makeatother sections " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do @@ -215,27 +224,27 @@ function! vimtex#syntax#core#init() abort " {{{1 " Add @NoSpell for commands per configuration for l:macro in g:vimtex_syntax_nospell_commands execute 'syntax match texCmd skipwhite skipnl "\\' . l:macro . '"' - \ 'nextgroup=texVimtexNoSpell' + \ 'nextgroup=texArgNoSpell' endfor - call vimtex#syntax#core#new_cmd_arg('texVimtexNoSpell', '', '@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texArgNoSpell', '', '@NoSpell') " Sections and parts syntax match texCmdParts "\\\(front\|main\|back\)matter\>" - syntax match texCmdParts nextgroup=texPartTitle "\\part\>" - syntax match texCmdParts nextgroup=texPartTitle "\\chapter\>" - syntax match texCmdParts nextgroup=texPartTitle "\\\(sub\)*section\>" - syntax match texCmdParts nextgroup=texPartTitle "\\\(sub\)\?paragraph\>" - call vimtex#syntax#core#new_cmd_arg('texPartTitle', '', 'TOP') + syntax match texCmdParts nextgroup=texArgPartTitle "\\part\>" + syntax match texCmdParts nextgroup=texArgPartTitle "\\chapter\>" + syntax match texCmdParts nextgroup=texArgPartTitle "\\\(sub\)*section\>" + syntax match texCmdParts nextgroup=texArgPartTitle "\\\(sub\)\?paragraph\>" + call vimtex#syntax#core#new_cmd_arg('texArgPartTitle', '', 'TOP') " }}}2 " {{{2 Environments - syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvName - call vimtex#syntax#core#new_cmd_arg('texEnvName', 'texEnvModifier') - call vimtex#syntax#core#new_cmd_opt('texEnvModifier', '', 'texComment,@NoSpell') + syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texArgEnvName + call vimtex#syntax#core#new_cmd_arg('texArgEnvName', 'texOptEnvModifier') + call vimtex#syntax#core#new_cmd_opt('texOptEnvModifier', '', 'texComment,@NoSpell') - syntax match texCmdEnvMath "\v\\%(begin|end)>" contained nextgroup=texEnvMathName - call vimtex#syntax#core#new_cmd_arg('texEnvMathName', '') + syntax match texCmdEnvMath "\v\\%(begin|end)>" contained nextgroup=texArgEnvMathName + call vimtex#syntax#core#new_cmd_arg('texArgEnvMathName', '') " }}}2 " {{{2 Verbatim @@ -243,7 +252,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " Verbatim environment syntax region texRegionVerb \ start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}" - \ keepend contains=texCmdEnv,texEnvName + \ keepend contains=texCmdEnv,texArgEnvName " Verbatim inline syntax match texCmd "\\verb\>\*\?" nextgroup=texRegionVerbInline @@ -276,15 +285,14 @@ function! vimtex#syntax#core#init() abort " {{{1 " }}}2 " {{{2 Math - syntax match texOnlyMath "[_^]" contained - - syntax cluster texClusterMath contains=texCmdEnvMath,texEnvMathName,texComment,texSymbolAmp,texGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texCmdRef,texSpecialChar,texCmd,texSubscript,texSuperscript,texCmdSize,texCmdStyle,@NoSpell - syntax cluster texClusterMathMatch contains=texComment,texCmdDef,texSymbolAmp,texGreek,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texCmdNewcmd,texCmdNewenv,texRegion,texCmdRef,texSpecialChar,texCmd,texSymbolString,texSubscript,texSuperscript,texCmdSize,texCmdStyle + syntax cluster texClusterMath contains=texCmdEnvMath,texArgEnvMathName,texComment,texSymbolAmp,texCmdGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texSpecialChar,texCmd,texSubscript,texSuperscript,texCmdSize,texCmdStyle,@NoSpell + syntax cluster texClusterMathMatch contains=texComment,texCmd,texSymbolAmp,texCmdGreek,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texRegion,texSpecialChar,texSymbolString,texSubscript,texSuperscript,texCmdSize,texCmdStyle syntax region texMatcherMath matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMathMatch " Bad/Mismatched math - syntax match texErrorMath "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}" + syntax match texErrorOnlyMath "[_^]" syntax match texErrorMath "\\[\])]" + syntax match texErrorMath "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}" " Operators and similar syntax match texMathOper "[_^=]" contained @@ -299,7 +307,7 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_math_region('math', 1) " Inline Math Zones - if l:cfg.conceal.math_bounds && &encoding ==# 'utf-8' + if l:cfg.conceal.math_bounds syntax region texRegionMath matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" concealends contains=@texClusterMath keepend syntax region texRegionMath matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" concealends contains=@texClusterMath keepend syntax region texRegionMathX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" concealends contains=@texClusterMath @@ -427,26 +435,28 @@ endfunction function! s:init_highlights(cfg) abort " {{{1 - " See :help group-names for list of conventional group names + " See :help group-name for list of conventional group names " Basic TeX highlighting groups + highlight def link texArg Include + highlight def link texArgAuthor Identifier + highlight def link texArgEnvMathName Delimiter + highlight def link texArgEnvName PreCondit + highlight def link texArgRef Special + highlight def link texArgTitle Underlined highlight def link texCmd Statement highlight def link texCmdSpaceCodeChar Special highlight def link texCmdTodo Todo highlight def link texComment Comment highlight def link texCommentTodo Todo - highlight def link texEnvName PreCondit - highlight def link texEnvMathName Delimiter highlight def link texError Error - highlight def link texGenericArg Include - highlight def link texGenericOpt Identifier - highlight def link texGenericParm Special - highlight def link texGenericSep NormalNC highlight def link texLength Number highlight def link texMath Special highlight def link texMathDelim Statement highlight def link texMathOper Operator - highlight def link texRef Special + highlight def link texOpt Identifier + highlight def link texOptSep NormalNC + highlight def link texParm Special highlight def link texRegion PreCondit highlight def link texSpecialChar SpecialChar highlight def link texSymbol SpecialChar @@ -459,16 +469,20 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def texStyleBoth gui=bold,italic cterm=bold,italic " Inherited groups + highlight def link texArgDefName texCmd + highlight def link texArgFile texArg + highlight def link texArgFiles texArg + highlight def link texArgNewcmdName texCmd + highlight def link texArgNewenvName texArgEnvName + highlight def link texArgPartTitle texTitle + highlight def link texCmd texCmd highlight def link texCmdAccent texCmd - highlight def link texCmdDef texCmd highlight def link texCmdEnv texCmd highlight def link texCmdEnvMath texCmdEnv highlight def link texCmdError texError + highlight def link texCmdGreek texCmd highlight def link texCmdLigature texSpecialChar - highlight def link texCmdNewcmd texCmd - highlight def link texCmdNewenv texCmd highlight def link texCmdParts texCmd - highlight def link texCmdRef texCmd highlight def link texCmdSize texType highlight def link texCmdSpaceCode texCmd highlight def link texCmdSty texCmd @@ -480,31 +494,24 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdStyleItalBold texCmd highlight def link texCommentAcronym texComment highlight def link texCommentURL texComment - highlight def link texDefName texCmd highlight def link texErrorMath texError - highlight def link texFileArg texGenericArg - highlight def link texFileArgs texGenericArg - highlight def link texFileOpt texGenericOpt - highlight def link texFileOpts texGenericOpt - highlight def link texGreek texCmd highlight def link texMatcherMath texMath highlight def link texMathDelimBad texError highlight def link texMathDelimKey texMathDelim highlight def link texMathDelimSet1 texMathDelim highlight def link texMathDelimSet2 texMathDelim highlight def link texMathSymbol texCmd - highlight def link texNewcmdName texCmd - highlight def link texNewcmdOpt texGenericOpt - highlight def link texNewcmdParm texGenericParm - highlight def link texNewenvName texEnvName - highlight def link texNewenvOpt texGenericOpt - highlight def link texNewenvParm texGenericParm + highlight def link texErrorOnlyMath texError highlight def link texOptEqual texSymbol - highlight def link texOptSep texGenericSep - highlight def link texOnlyMath texError - highlight def link texPartTitle texTitle + highlight def link texOptFile texOpt + highlight def link texOptFiles texOpt + highlight def link texOptNewcmd texOpt + highlight def link texOptNewenv texOpt + highlight def link texOptRef texOpt + highlight def link texParmDef texParm + highlight def link texParmNewcmd texParm + highlight def link texParmNewenv texParm highlight def link texRefCite texRegionRef - highlight def link texRefOpt texGenericOpt highlight def link texRegionMath texMath highlight def link texRegionMathEnsured texMath highlight def link texRegionMathEnv texMath @@ -938,47 +945,47 @@ let s:map_accents = [ " }}}1 function! s:match_conceal_greek() " {{{1 - syntax match texGreek "\\alpha\>" contained conceal cchar=α - syntax match texGreek "\\beta\>" contained conceal cchar=β - syntax match texGreek "\\gamma\>" contained conceal cchar=γ - syntax match texGreek "\\delta\>" contained conceal cchar=δ - syntax match texGreek "\\epsilon\>" contained conceal cchar=ϵ - syntax match texGreek "\\varepsilon\>" contained conceal cchar=ε - syntax match texGreek "\\zeta\>" contained conceal cchar=ζ - syntax match texGreek "\\eta\>" contained conceal cchar=η - syntax match texGreek "\\theta\>" contained conceal cchar=θ - syntax match texGreek "\\vartheta\>" contained conceal cchar=ϑ - syntax match texGreek "\\iota\>" contained conceal cchar=ι - syntax match texGreek "\\kappa\>" contained conceal cchar=κ - syntax match texGreek "\\lambda\>" contained conceal cchar=λ - syntax match texGreek "\\mu\>" contained conceal cchar=μ - syntax match texGreek "\\nu\>" contained conceal cchar=ν - syntax match texGreek "\\xi\>" contained conceal cchar=ξ - syntax match texGreek "\\pi\>" contained conceal cchar=π - syntax match texGreek "\\varpi\>" contained conceal cchar=ϖ - syntax match texGreek "\\rho\>" contained conceal cchar=ρ - syntax match texGreek "\\varrho\>" contained conceal cchar=ϱ - syntax match texGreek "\\sigma\>" contained conceal cchar=σ - syntax match texGreek "\\varsigma\>" contained conceal cchar=ς - syntax match texGreek "\\tau\>" contained conceal cchar=τ - syntax match texGreek "\\upsilon\>" contained conceal cchar=υ - syntax match texGreek "\\phi\>" contained conceal cchar=ϕ - syntax match texGreek "\\varphi\>" contained conceal cchar=φ - syntax match texGreek "\\chi\>" contained conceal cchar=χ - syntax match texGreek "\\psi\>" contained conceal cchar=ψ - syntax match texGreek "\\omega\>" contained conceal cchar=ω - syntax match texGreek "\\Gamma\>" contained conceal cchar=Γ - syntax match texGreek "\\Delta\>" contained conceal cchar=Δ - syntax match texGreek "\\Theta\>" contained conceal cchar=Θ - syntax match texGreek "\\Lambda\>" contained conceal cchar=Λ - syntax match texGreek "\\Xi\>" contained conceal cchar=Ξ - syntax match texGreek "\\Pi\>" contained conceal cchar=Π - syntax match texGreek "\\Sigma\>" contained conceal cchar=Σ - syntax match texGreek "\\Upsilon\>" contained conceal cchar=Υ - syntax match texGreek "\\Phi\>" contained conceal cchar=Φ - syntax match texGreek "\\Chi\>" contained conceal cchar=Χ - syntax match texGreek "\\Psi\>" contained conceal cchar=Ψ - syntax match texGreek "\\Omega\>" contained conceal cchar=Ω + syntax match texCmdGreek "\\alpha\>" contained conceal cchar=α + syntax match texCmdGreek "\\beta\>" contained conceal cchar=β + syntax match texCmdGreek "\\gamma\>" contained conceal cchar=γ + syntax match texCmdGreek "\\delta\>" contained conceal cchar=δ + syntax match texCmdGreek "\\epsilon\>" contained conceal cchar=ϵ + syntax match texCmdGreek "\\varepsilon\>" contained conceal cchar=ε + syntax match texCmdGreek "\\zeta\>" contained conceal cchar=ζ + syntax match texCmdGreek "\\eta\>" contained conceal cchar=η + syntax match texCmdGreek "\\theta\>" contained conceal cchar=θ + syntax match texCmdGreek "\\vartheta\>" contained conceal cchar=ϑ + syntax match texCmdGreek "\\iota\>" contained conceal cchar=ι + syntax match texCmdGreek "\\kappa\>" contained conceal cchar=κ + syntax match texCmdGreek "\\lambda\>" contained conceal cchar=λ + syntax match texCmdGreek "\\mu\>" contained conceal cchar=μ + syntax match texCmdGreek "\\nu\>" contained conceal cchar=ν + syntax match texCmdGreek "\\xi\>" contained conceal cchar=ξ + syntax match texCmdGreek "\\pi\>" contained conceal cchar=π + syntax match texCmdGreek "\\varpi\>" contained conceal cchar=ϖ + syntax match texCmdGreek "\\rho\>" contained conceal cchar=ρ + syntax match texCmdGreek "\\varrho\>" contained conceal cchar=ϱ + syntax match texCmdGreek "\\sigma\>" contained conceal cchar=σ + syntax match texCmdGreek "\\varsigma\>" contained conceal cchar=ς + syntax match texCmdGreek "\\tau\>" contained conceal cchar=τ + syntax match texCmdGreek "\\upsilon\>" contained conceal cchar=υ + syntax match texCmdGreek "\\phi\>" contained conceal cchar=ϕ + syntax match texCmdGreek "\\varphi\>" contained conceal cchar=φ + syntax match texCmdGreek "\\chi\>" contained conceal cchar=χ + syntax match texCmdGreek "\\psi\>" contained conceal cchar=ψ + syntax match texCmdGreek "\\omega\>" contained conceal cchar=ω + syntax match texCmdGreek "\\Gamma\>" contained conceal cchar=Γ + syntax match texCmdGreek "\\Delta\>" contained conceal cchar=Δ + syntax match texCmdGreek "\\Theta\>" contained conceal cchar=Θ + syntax match texCmdGreek "\\Lambda\>" contained conceal cchar=Λ + syntax match texCmdGreek "\\Xi\>" contained conceal cchar=Ξ + syntax match texCmdGreek "\\Pi\>" contained conceal cchar=Π + syntax match texCmdGreek "\\Sigma\>" contained conceal cchar=Σ + syntax match texCmdGreek "\\Upsilon\>" contained conceal cchar=Υ + syntax match texCmdGreek "\\Phi\>" contained conceal cchar=Φ + syntax match texCmdGreek "\\Chi\>" contained conceal cchar=Χ + syntax match texCmdGreek "\\Psi\>" contained conceal cchar=Ψ + syntax match texCmdGreek "\\Omega\>" contained conceal cchar=Ω endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/beamer.vim b/autoload/vimtex/syntax/p/beamer.vim index b55aada52b..1f9566d7a2 100644 --- a/autoload/vimtex/syntax/p/beamer.vim +++ b/autoload/vimtex/syntax/p/beamer.vim @@ -16,10 +16,10 @@ function! vimtex#syntax#p#beamer#load() abort " {{{1 syntax match texCmd "\\includegraphics<[^>]*>" \ contains=texBeamerOpt - \ nextgroup=texFileOpt,texFileArg + \ nextgroup=texOptFile,texArgFile highlight link texCmdBeamer texCmd - highlight link texBeamerOpt texNewcmdOpt + highlight link texBeamerOpt texOptNewcmd highlight link texBeamerDelimiter texDelimiter endfunction diff --git a/autoload/vimtex/syntax/p/biblatex.vim b/autoload/vimtex/syntax/p/biblatex.vim index eb22f57450..cbe469b6e7 100644 --- a/autoload/vimtex/syntax/p/biblatex.vim +++ b/autoload/vimtex/syntax/p/biblatex.vim @@ -8,7 +8,7 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 if has_key(b:vimtex_syntax, 'biblatex') | return | endif let b:vimtex_syntax.biblatex = 1 - syntax match texCmd "\\addbibresource\>" nextgroup=texFileArgs + syntax match texCmd "\\addbibresource\>" nextgroup=texArgFiles for l:pattern in [ \ 'bibentry', diff --git a/autoload/vimtex/syntax/p/cleveref.vim b/autoload/vimtex/syntax/p/cleveref.vim index 668142b80e..f9df407d7a 100644 --- a/autoload/vimtex/syntax/p/cleveref.vim +++ b/autoload/vimtex/syntax/p/cleveref.vim @@ -33,7 +33,7 @@ function! vimtex#syntax#p#cleveref#load() abort " {{{1 highlight link texCRefZone texRegionRef highlight link texCRefZoneRange texRegionRef - highlight link texCRefLabelOpts texNewcmdOpt + highlight link texCRefLabelOpts texOptNewcmd endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/gnuplottex.vim b/autoload/vimtex/syntax/p/gnuplottex.vim index 3f2e495928..93f269f1c8 100644 --- a/autoload/vimtex/syntax/p/gnuplottex.vim +++ b/autoload/vimtex/syntax/p/gnuplottex.vim @@ -14,7 +14,7 @@ function! vimtex#syntax#p#gnuplottex#load() abort " {{{1 \ end='\\end{gnuplot}'re=e \ keepend \ transparent - \ contains=texCmdEnv,texEnvModifier,@vimtex_nested_gnuplot + \ contains=texCmdEnv,texOptEnvModifier,@vimtex_nested_gnuplot endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index de1a28caef..183cc83f70 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -10,7 +10,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 " First some general support syntax match texCmd "\\lstinputlisting\>" - \ nextgroup=texFileOpt,texFileArg + \ nextgroup=texOptFile,texArgFile syntax match texRegion "\\lstinline\s*\(\[.\{-}\]\)\={.\{-}}" " Set all listings environments to listings diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index 44373bccf2..98ed02af5e 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -11,15 +11,15 @@ function! vimtex#syntax#p#markdown#load() abort " {{{1 call vimtex#syntax#misc#include('markdown') " Don't quite know why this is necessary, but it is - syntax match texCmdEnv "\\\%(begin\|end\)\>\ze{markdown}" nextgroup=texEnvName + syntax match texCmdEnv "\\\%(begin\|end\)\>\ze{markdown}" nextgroup=texArgEnvName syntax region texRegionMarkdown \ start="\\begin{markdown}" \ end="\\end{markdown}" \ keepend transparent - \ contains=texCmdEnv,texEnvName,@vimtex_nested_markdown + \ contains=texCmdEnv,texArgEnvName,@vimtex_nested_markdown - syntax match texCmd "\\markdownInput\>" nextgroup=texFileArg + syntax match texCmd "\\markdownInput\>" nextgroup=texArgFile endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index de884aa51a..0eea0cd24f 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -142,7 +142,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 highlight link texRegionMinted texRegion highlight link texRegionMintedCmd texRegion - highlight link texMintedName texNewcmdOpt + highlight link texMintedName texOptNewcmd highlight link texMintedNameOpt texMintedName endfunction diff --git a/autoload/vimtex/syntax/p/pdfpages.vim b/autoload/vimtex/syntax/p/pdfpages.vim index c2878fb385..9716394952 100644 --- a/autoload/vimtex/syntax/p/pdfpages.vim +++ b/autoload/vimtex/syntax/p/pdfpages.vim @@ -8,7 +8,7 @@ function! vimtex#syntax#p#pdfpages#load() abort " {{{1 if has_key(b:vimtex_syntax, 'pdfpages') | return | endif let b:vimtex_syntax.pdfpages = 1 - syntax match texCmd "\\includepdf\>" nextgroup=texFileOpt,texFileArg + syntax match texCmd "\\includepdf\>" nextgroup=texOptFile,texArgFile endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/subfile.vim b/autoload/vimtex/syntax/p/subfile.vim index 0ee01b8f6c..d1fba51b18 100644 --- a/autoload/vimtex/syntax/p/subfile.vim +++ b/autoload/vimtex/syntax/p/subfile.vim @@ -8,8 +8,8 @@ function! vimtex#syntax#p#subfile#load() abort " {{{1 if has_key(b:vimtex_syntax, 'subfile') | return | endif let b:vimtex_syntax.subfile = 1 - syntax match texCmd "\\subfile\>" nextgroup=texFileArg - syntax match texCmd "\\subfileinclude\>" nextgroup=texFileArg + syntax match texCmd "\\subfile\>" nextgroup=texArgFile + syntax match texCmd "\\subfileinclude\>" nextgroup=texArgFile endfunction " }}}1 diff --git a/test/tests/test-syntax/test-core.vim b/test/tests/test-syntax/test-core.vim index 500b9d1840..02a19172a3 100644 --- a/test/tests/test-syntax/test-core.vim +++ b/test/tests/test-syntax/test-core.vim @@ -7,7 +7,7 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texCmdError', 5, 3)) call vimtex#test#assert(vimtex#syntax#in('texCmdSty', 8, 3)) -call vimtex#test#assert(vimtex#syntax#in('texNewenvParm', 20, 36)) +call vimtex#test#assert(vimtex#syntax#in('texParmNewenv', 20, 36)) call vimtex#test#assert(vimtex#syntax#in('texRegionVerbInline', 26, 36)) diff --git a/test/tests/test-syntax/test-markdown.vim b/test/tests/test-syntax/test-markdown.vim index 13f5019106..6a20b2dd21 100644 --- a/test/tests/test-syntax/test-markdown.vim +++ b/test/tests/test-syntax/test-markdown.vim @@ -7,6 +7,6 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texRegionMarkdown', 7, 1)) call vimtex#test#assert(vimtex#syntax#in('markdownItalic', 7, 1)) call vimtex#test#assert(vimtex#syntax#in('markdownLink', 11, 12)) -call vimtex#test#assert(vimtex#syntax#in('texFileArg', 16, 16)) +call vimtex#test#assert(vimtex#syntax#in('texArgFile', 16, 16)) quit! From 6957d536e664311b70be849348540450e9106d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 29 Oct 2020 00:06:40 +0100 Subject: [PATCH 20/99] wip: minor updates --- autoload/vimtex/syntax/core.vim | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index ae7d5e3a02..ccf89c4dcf 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -99,6 +99,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdTodo '\\todo\w*' " Author and title commands + " TODO: Option groups here syntax match texCmd nextgroup=texArgAuthor skipwhite skipnl "\\author\>" syntax match texCmd nextgroup=texArgTitle skipwhite skipnl "\\title\>" call vimtex#syntax#core#new_cmd_arg('texArgAuthor', '', 'texCmd,texComment,@NoSpell') @@ -308,15 +309,15 @@ function! vimtex#syntax#core#init() abort " {{{1 " Inline Math Zones if l:cfg.conceal.math_bounds - syntax region texRegionMath matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" concealends contains=@texClusterMath keepend - syntax region texRegionMath matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" concealends contains=@texClusterMath keepend - syntax region texRegionMathX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" concealends contains=@texClusterMath - syntax region texRegionMathXX matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" concealends contains=@texClusterMath keepend + syntax region texRegionMath matchgroup=Delimiter concealends contains=@texClusterMath keepend start="\\(" end="\\)" + syntax region texRegionMath matchgroup=Delimiter concealends contains=@texClusterMath keepend start="\\\[" end="\\]" + syntax region texRegionMathX matchgroup=Delimiter concealends contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" + syntax region texRegionMathXX matchgroup=Delimiter concealends contains=@texClusterMath keepend start="\$\$" end="\$\$" else - syntax region texRegionMath matchgroup=Delimiter start="\\(" matchgroup=Delimiter end="\\)" contains=@texClusterMath keepend - syntax region texRegionMath matchgroup=Delimiter start="\\\[" matchgroup=Delimiter end="\\]" contains=@texClusterMath keepend - syntax region texRegionMathX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" contains=@texClusterMath - syntax region texRegionMathXX matchgroup=Delimiter start="\$\$" matchgroup=Delimiter end="\$\$" contains=@texClusterMath keepend + syntax region texRegionMath matchgroup=Delimiter contains=@texClusterMath keepend start="\\(" end="\\)" + syntax region texRegionMath matchgroup=Delimiter contains=@texClusterMath keepend start="\\\[" end="\\]" + syntax region texRegionMathX matchgroup=Delimiter contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" + syntax region texRegionMathXX matchgroup=Delimiter contains=@texClusterMath keepend start="\$\$" end="\$\$" endif syntax match texCmd "\\ensuremath\>" nextgroup=texRegionMathEnsured From 338cda771fd34eed322676ba03cb312583dfd369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 29 Oct 2020 17:33:59 +0100 Subject: [PATCH 21/99] test: fix failing test --- test/tests/test-syntax/test-nospell.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests/test-syntax/test-nospell.vim b/test/tests/test-syntax/test-nospell.vim index f09db7d441..1d4708b450 100644 --- a/test/tests/test-syntax/test-nospell.vim +++ b/test/tests/test-syntax/test-nospell.vim @@ -8,6 +8,6 @@ silent edit test-nospell.tex if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texMatcher', 7, 14)) -call vimtex#test#assert(vimtex#syntax#in('texVimtexNoSpell', 8, 14)) +call vimtex#test#assert(vimtex#syntax#in('texArgNoSpell', 8, 14)) quit! From fd1767af3e19cc1cd1489af404f08cb259a14356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 29 Oct 2020 18:13:34 +0100 Subject: [PATCH 22/99] wip: more consistency improvement and some general refinements --- autoload/vimtex/syntax/core.vim | 98 ++++++++++++------------ autoload/vimtex/syntax/p/amsmath.vim | 2 +- autoload/vimtex/syntax/p/hyperref.vim | 31 +++----- test/tests/test-syntax/test-hyperref.vim | 3 +- 4 files changed, 64 insertions(+), 70 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index ccf89c4dcf..ed0f22dd4e 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -23,7 +23,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " Match TeX braces in general " TODO: Do we really need this?? - syntax region texMatcher matchgroup=Delimiter + syntax region texMatcher matchgroup=texDelim \ start="{" skip="\\\\\|\\}" end="}" contains=TOP " Flag mismatching ending brace delimiter @@ -258,10 +258,10 @@ function! vimtex#syntax#core#init() abort " {{{1 " Verbatim inline syntax match texCmd "\\verb\>\*\?" nextgroup=texRegionVerbInline if l:cfg.is_style_document - syntax region texRegionVerbInline matchgroup=Delimiter + syntax region texRegionVerbInline matchgroup=texDelim \ start="\z([^\ta-zA-Z@]\)" end="\z1" contained else - syntax region texRegionVerbInline matchgroup=Delimiter + syntax region texRegionVerbInline matchgroup=texDelim \ start="\z([^\ta-zA-Z]\)" end="\z1" contained endif @@ -286,9 +286,9 @@ function! vimtex#syntax#core#init() abort " {{{1 " }}}2 " {{{2 Math - syntax cluster texClusterMath contains=texCmdEnvMath,texArgEnvMathName,texComment,texSymbolAmp,texCmdGreek,texLength,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texMathSymbol,texMathText,texSpecialChar,texCmd,texSubscript,texSuperscript,texCmdSize,texCmdStyle,@NoSpell - syntax cluster texClusterMathMatch contains=texComment,texCmd,texSymbolAmp,texCmdGreek,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texMathDelim,texMathOper,texMathSymbol,texRegion,texSpecialChar,texSymbolString,texSubscript,texSuperscript,texCmdSize,texCmdStyle - syntax region texMatcherMath matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMathMatch + syntax cluster texClusterMath contains=texCmdEnvMath,texArgEnvMathName,texComment,texSymbolAmp,texCmdGreek,texLength,texMatcherMath,texDelimMath,texMathOper,texMathSymbol,texMathSymbol,texSpecialChar,texCmd,texSubscript,texSuperscript,texCmdSize,texCmdStyle,@NoSpell + syntax cluster texClusterMatcherMath contains=texComment,texCmd,texSymbolAmp,texCmdGreek,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texDelimMath,texMathOper,texMathSymbol,texRegion,texSpecialChar,texSymbolString,texSubscript,texSuperscript,texCmdSize,texCmdStyle + syntax region texMatcherMath matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMatcherMath " Bad/Mismatched math syntax match texErrorOnlyMath "[_^]" @@ -298,9 +298,6 @@ function! vimtex#syntax#core#init() abort " {{{1 " Operators and similar syntax match texMathOper "[_^=]" contained - " Text Inside Math regions - syntax region texMathText matchgroup=texCmd start="\\\(\(inter\)\?text\|mbox\)\s*{" end="}" contains=TOP,@Spell - " Math environments call vimtex#syntax#core#new_math_region('displaymath', 1) call vimtex#syntax#core#new_math_region('eqnarray', 1) @@ -309,44 +306,45 @@ function! vimtex#syntax#core#init() abort " {{{1 " Inline Math Zones if l:cfg.conceal.math_bounds - syntax region texRegionMath matchgroup=Delimiter concealends contains=@texClusterMath keepend start="\\(" end="\\)" - syntax region texRegionMath matchgroup=Delimiter concealends contains=@texClusterMath keepend start="\\\[" end="\\]" - syntax region texRegionMathX matchgroup=Delimiter concealends contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" - syntax region texRegionMathXX matchgroup=Delimiter concealends contains=@texClusterMath keepend start="\$\$" end="\$\$" + syntax region texRegionMath matchgroup=texDelimMathmode concealends contains=@texClusterMath keepend start="\\(" end="\\)" + syntax region texRegionMath matchgroup=texDelimMathmode concealends contains=@texClusterMath keepend start="\\\[" end="\\]" + syntax region texRegionMathX matchgroup=texDelimMathmode concealends contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" + syntax region texRegionMathXX matchgroup=texDelimMathmode concealends contains=@texClusterMath keepend start="\$\$" end="\$\$" else - syntax region texRegionMath matchgroup=Delimiter contains=@texClusterMath keepend start="\\(" end="\\)" - syntax region texRegionMath matchgroup=Delimiter contains=@texClusterMath keepend start="\\\[" end="\\]" - syntax region texRegionMathX matchgroup=Delimiter contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" - syntax region texRegionMathXX matchgroup=Delimiter contains=@texClusterMath keepend start="\$\$" end="\$\$" + syntax region texRegionMath matchgroup=texDelimMathmode contains=@texClusterMath keepend start="\\(" end="\\)" + syntax region texRegionMath matchgroup=texDelimMathmode contains=@texClusterMath keepend start="\\\[" end="\\]" + syntax region texRegionMathX matchgroup=texDelimMathmode contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" + syntax region texRegionMathXX matchgroup=texDelimMathmode contains=@texClusterMath keepend start="\$\$" end="\$\$" endif + " Text Inside Math regions + syntax match texCmd "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texArgMathText + call vimtex#syntax#core#new_cmd_arg('texArgMathText', '', 'TOP,@Spell') + syntax match texCmd "\\ensuremath\>" nextgroup=texRegionMathEnsured - syntax region texRegionMathEnsured matchgroup=Delimiter - \ start="{" end="}" - \ contained - \ contains=@texClusterMath + call vimtex#syntax#core#new_cmd_arg('texRegionMathEnsured', '', '@texClusterMath') " Math delimiters: \left... and \right... - syntax match texMathDelimBad contained "\S" + syntax match texErrorMathDelim contained "\S" if l:cfg.conceal.math_delimiters && &encoding ==# 'utf-8' - syntax match texMathDelim "\\left\[" contained - syntax match texMathDelim "\\left\\{" contained skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad contains=texMathSymbol cchar={ - syntax match texMathDelim "\\right\\}" contained skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad contains=texMathSymbol cchar=} - syntax match texMathDelim '\\[bB]igg\?[lr]' contained nextgroup=texMathDelimBad + syntax match texDelimMath "\\left\[" contained + syntax match texDelimMath "\\left\\{" contained skipwhite nextgroup=texDelimMathSet1,texDelimMathSet2,texErrorMathDelim contains=texMathSymbol cchar={ + syntax match texDelimMath "\\right\\}" contained skipwhite nextgroup=texDelimMathSet1,texDelimMathSet2,texErrorMathDelim contains=texMathSymbol cchar=} + syntax match texDelimMath '\\[bB]igg\?[lr]' contained nextgroup=texErrorMathDelim call s:match_conceal_math_delims() else - syntax match texMathDelim "\\\(left\|right\)\>" contained skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad - syntax match texMathDelim "\\[bB]igg\?[lr]\?\>" contained skipwhite nextgroup=texMathDelimSet1,texMathDelimSet2,texMathDelimBad - syntax match texMathDelimSet2 "\\" contained nextgroup=texMathDelimKey,texMathDelimBad - syntax match texMathDelimSet1 "[<>()[\]|/.]\|\\[{}|]" contained - syntax keyword texMathDelimKey contained backslash lceil lVert rgroup uparrow - syntax keyword texMathDelimKey contained downarrow lfloor rangle rmoustache Uparrow - syntax keyword texMathDelimKey contained Downarrow lgroup rbrace rvert updownarrow - syntax keyword texMathDelimKey contained langle lmoustache rceil rVert Updownarrow - syntax keyword texMathDelimKey contained lbrace lvert rfloor + syntax match texDelimMath "\\\(left\|right\)\>" contained skipwhite nextgroup=texDelimMathSet1,texDelimMathSet2,texErrorMathDelim + syntax match texDelimMath "\\[bB]igg\?[lr]\?\>" contained skipwhite nextgroup=texDelimMathSet1,texDelimMathSet2,texErrorMathDelim + syntax match texDelimMathSet2 "\\" contained nextgroup=texDelimMathKey,texErrorMathDelim + syntax match texDelimMathSet1 "[<>()[\]|/.]\|\\[{}|]" contained + syntax keyword texDelimMathKey contained backslash lceil lVert rgroup uparrow + syntax keyword texDelimMathKey contained downarrow lfloor rangle rmoustache Uparrow + syntax keyword texDelimMathKey contained Downarrow lgroup rbrace rvert updownarrow + syntax keyword texDelimMathKey contained langle lmoustache rceil rVert Updownarrow + syntax keyword texDelimMathKey contained lbrace lvert rfloor endif - syntax match texMathDelim contained "\\\(left\|right\)arrow\>\|\<\([aA]rrow\|brace\)\?vert\>" - syntax match texMathDelim contained "\\lefteqn\>" + syntax match texDelimMath contained "\\\(left\|right\)arrow\>\|\<\([aA]rrow\|brace\)\?vert\>" + syntax match texDelimMath contained "\\lefteqn\>" " }}}2 " {{{2 Conceal mode support @@ -397,7 +395,7 @@ function! vimtex#syntax#core#new_cmd_arg(grp, next, ...) abort " {{{1 let l:options = a:0 >= 2 ? a:2 : '' execute 'syntax region' a:grp - \ 'contained matchgroup=Delimiter start="{" skip="\\\\\|\\}" end="}"' + \ 'contained matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}"' \ (empty(l:contains) ? '' : 'contains=' . l:contains) \ (empty(a:next) ? '' : 'nextgroup=' . a:next . ' skipwhite skipnl') \ l:options @@ -409,7 +407,7 @@ function! vimtex#syntax#core#new_cmd_opt(grp, next, ...) abort " {{{1 let l:options = a:0 >= 2 ? a:2 : '' execute 'syntax region' a:grp - \ 'contained matchgroup=Delimiter start="\[" skip="\\\\\|\\\]" end="\]"' + \ 'contained matchgroup=texDelim start="\[" skip="\\\\\|\\\]" end="\]"' \ (empty(l:contains) ? '' : 'contains=' . l:contains) \ (empty(a:next) ? '' : 'nextgroup=' . a:next . ' skipwhite skipnl') \ l:options @@ -450,10 +448,11 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdTodo Todo highlight def link texComment Comment highlight def link texCommentTodo Todo + highlight def link texDelim Delimiter highlight def link texError Error highlight def link texLength Number highlight def link texMath Special - highlight def link texMathDelim Statement + highlight def link texDelimMath Statement highlight def link texMathOper Operator highlight def link texOpt Identifier highlight def link texOptSep NormalNC @@ -470,6 +469,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def texStyleBoth gui=bold,italic cterm=bold,italic " Inherited groups + highlight def link texDelimMathmode texDelim highlight def link texArgDefName texCmd highlight def link texArgFile texArg highlight def link texArgFiles texArg @@ -497,10 +497,10 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCommentURL texComment highlight def link texErrorMath texError highlight def link texMatcherMath texMath - highlight def link texMathDelimBad texError - highlight def link texMathDelimKey texMathDelim - highlight def link texMathDelimSet1 texMathDelim - highlight def link texMathDelimSet2 texMathDelim + highlight def link texErrorMathDelim texError + highlight def link texDelimMathKey texDelimMath + highlight def link texDelimMathSet1 texDelimMath + highlight def link texDelimMathSet2 texDelimMath highlight def link texMathSymbol texCmd highlight def link texErrorOnlyMath texError highlight def link texOptEqual texSymbol @@ -564,11 +564,11 @@ function! s:match_bold_italic(cfg) abort " {{{1 \ 'nextgroup=' . l:map[l:group] l:conceal endfor - execute 'syntax region texStyleBold matchgroup=Delimiter start=/{/ end=/}/' + execute 'syntax region texStyleBold matchgroup=texDelim start=/{/ end=/}/' \ 'contained contains=@texClusterBold' l:concealends - execute 'syntax region texStyleItal matchgroup=Delimiter start=/{/ end=/}/' + execute 'syntax region texStyleItal matchgroup=texDelim start=/{/ end=/}/' \ 'contained contains=@texClusterItal' l:concealends - execute 'syntax region texStyleBoth matchgroup=Delimiter start=/{/ end=/}/' + execute 'syntax region texStyleBoth matchgroup=texDelim start=/{/ end=/}/' \ 'contained contains=@texClusterItalBold' l:concealends endfunction @@ -991,8 +991,8 @@ endfunction " }}}1 function! s:match_conceal_super_sub(cfg) " {{{1 - syntax region texSuperscript matchgroup=Delimiter start='\^{' skip="\\\\\|\\}" end='}' contained concealends contains=texSpecialChar,texSuperscripts,texCmd,texSubscript,texSuperscript,texMatcherMath - syntax region texSubscript matchgroup=Delimiter start='_{' skip="\\\\\|\\}" end='}' contained concealends contains=texSpecialChar,texSubscripts,texCmd,texSubscript,texSuperscript,texMatcherMath + syntax region texSuperscript matchgroup=texDelim start='\^{' skip="\\\\\|\\}" end='}' contained concealends contains=texSpecialChar,texSuperscripts,texCmd,texSubscript,texSuperscript,texMatcherMath + syntax region texSubscript matchgroup=texDelim start='_{' skip="\\\\\|\\}" end='}' contained concealends contains=texSpecialChar,texSubscripts,texCmd,texSubscript,texSuperscript,texMatcherMath for [l:from, l:to] in filter(copy(s:map_super), \ {_, x -> x[0][0] ==# '\' || x[0] =~# '[0-9a-zA-W.,:;+-<>/()=]'}) diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index 99c9dd631c..5361dd1480 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -27,7 +27,7 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 \ ['\\lVert', '‖'] , \ ['\\rVert', '‖'] , \ ] - execute "syntax match texMathDelim '\\\\[bB]igg\\=[lr]\\=" + execute "syntax match texDelimMath '\\\\[bB]igg\\=[lr]\\=" \ . l:texmath[0] . "' contained conceal cchar=" . l:texmath[1] endfor endif diff --git a/autoload/vimtex/syntax/p/hyperref.vim b/autoload/vimtex/syntax/p/hyperref.vim index bbe26fb6f9..96b1a1650a 100644 --- a/autoload/vimtex/syntax/p/hyperref.vim +++ b/autoload/vimtex/syntax/p/hyperref.vim @@ -8,28 +8,21 @@ function! vimtex#syntax#p#hyperref#load() abort " {{{1 if has_key(b:vimtex_syntax, 'hyperref') | return | endif let b:vimtex_syntax.hyperref = 1 - syntax match texCmd '\\url\ze[^\ta-zA-Z]' nextgroup=texUrlVerb - syntax region texUrlVerb matchgroup=Delimiter - \ start='\z([^\ta-zA-Z]\)' end='\z1' contained + syntax match texCmd "\\url\>" nextgroup=texArgUrl skipwhite + syntax region texArgUrl matchgroup=texDelim + \ contained contains=@NoSpell,texComment + \ start="\z([^\ta-zA-Z]\)" end="\z1" + call vimtex#syntax#core#new_cmd_arg('texArgUrl', '', 'texComment,@NoSpell') - syntax match texCmd '\\url\ze\s*{' nextgroup=texUrl - syntax region texUrl matchgroup=Delimiter start='{' end='}' contained + syntax match texCmd '\\href\>' nextgroup=texArgHrefLink + call vimtex#syntax#core#new_cmd_arg('texArgHrefLink', 'texArgHrefText', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texArgHrefText', '', 'TOP') - syntax match texCmd '\\href' nextgroup=texHref - syntax region texHref matchgroup=Delimiter start='{' end='}' contained - \ nextgroup=texMatcher + syntax match texCmd '\\hyperref\>' nextgroup=texOptRef,texArgRef + syntax match texCmd '\\autoref\>' nextgroup=texOptRef,texArgRef - syntax match texCmd '\\hyperref\>' nextgroup=texHyperref - syntax match texCmd '\\autoref\>' nextgroup=texHyperref - syntax region texHyperref matchgroup=Delimiter start='\[' end='\]' contained - \ contains=@texClusterRef,texRegionRef - syntax region texHyperref matchgroup=Delimiter start='{' end='}' contained - \ contains=@texClusterRef,texRegionRef - - highlight link texUrl Function - highlight link texUrlVerb texUrl - highlight link texHref texUrl - highlight link texHyperref texRegionRef + highlight link texArgUrl texOpt + highlight link texArgHrefLink texOpt endfunction " }}}1 diff --git a/test/tests/test-syntax/test-hyperref.vim b/test/tests/test-syntax/test-hyperref.vim index fd891de33f..497fef5908 100644 --- a/test/tests/test-syntax/test-hyperref.vim +++ b/test/tests/test-syntax/test-hyperref.vim @@ -4,6 +4,7 @@ silent edit test-hyperref.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texHyperref', 16, 35)) +call vimtex#test#assert(vimtex#syntax#in('texArgUrl', 6, 25)) +call vimtex#test#assert(vimtex#syntax#in('texArgRef', 16, 35)) quit! From 1baacb4233465b78baba3220db9f538fab1c13aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 29 Oct 2020 18:17:47 +0100 Subject: [PATCH 23/99] wip: minor update --- autoload/vimtex/syntax/core.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index ed0f22dd4e..7bb8613452 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -449,10 +449,10 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texComment Comment highlight def link texCommentTodo Todo highlight def link texDelim Delimiter + highlight def link texDelimMath Statement highlight def link texError Error highlight def link texLength Number highlight def link texMath Special - highlight def link texDelimMath Statement highlight def link texMathOper Operator highlight def link texOpt Identifier highlight def link texOptSep NormalNC @@ -469,7 +469,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def texStyleBoth gui=bold,italic cterm=bold,italic " Inherited groups - highlight def link texDelimMathmode texDelim highlight def link texArgDefName texCmd highlight def link texArgFile texArg highlight def link texArgFiles texArg @@ -495,14 +494,15 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdStyleItalBold texCmd highlight def link texCommentAcronym texComment highlight def link texCommentURL texComment - highlight def link texErrorMath texError - highlight def link texMatcherMath texMath - highlight def link texErrorMathDelim texError highlight def link texDelimMathKey texDelimMath highlight def link texDelimMathSet1 texDelimMath highlight def link texDelimMathSet2 texDelimMath - highlight def link texMathSymbol texCmd + highlight def link texDelimMathmode texDelim + highlight def link texErrorMath texError + highlight def link texErrorMathDelim texError highlight def link texErrorOnlyMath texError + highlight def link texMatcherMath texMath + highlight def link texMathSymbol texCmd highlight def link texOptEqual texSymbol highlight def link texOptFile texOpt highlight def link texOptFiles texOpt From 22e6aa59de1fb4df166c231ea4ff7a8155680d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 29 Oct 2020 23:41:13 +0100 Subject: [PATCH 24/99] wip: improve math syntax --- autoload/vimtex/syntax/core.vim | 636 +++++++++++---------- autoload/vimtex/syntax/p/array.vim | 17 +- autoload/vimtex/syntax/p/ieeetrantools.vim | 2 +- 3 files changed, 331 insertions(+), 324 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 7bb8613452..c0c9ace1b9 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -286,25 +286,17 @@ function! vimtex#syntax#core#init() abort " {{{1 " }}}2 " {{{2 Math - syntax cluster texClusterMath contains=texCmdEnvMath,texArgEnvMathName,texComment,texSymbolAmp,texCmdGreek,texLength,texMatcherMath,texDelimMath,texMathOper,texMathSymbol,texMathSymbol,texSpecialChar,texCmd,texSubscript,texSuperscript,texCmdSize,texCmdStyle,@NoSpell - syntax cluster texClusterMatcherMath contains=texComment,texCmd,texSymbolAmp,texCmdGreek,texLength,texCmdLigature,texSymbolDash,texMatcherMath,texDelimMath,texMathOper,texMathSymbol,texRegion,texSpecialChar,texSymbolString,texSubscript,texSuperscript,texCmdSize,texCmdStyle - syntax region texMatcherMath matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMatcherMath + " Math clusters for use in math regions + syntax cluster texClusterMath contains=texCmd,texCmdGreek,texCmdSize,texCmdStyle,texComment,texDelimMath,texDelimMathMod,texLength,texMatcherMath,texMathOper,texSymbolMath,texSpecialChar,texSubscript,texSuperscript,texSymbolAmp,texSymbolDash,@NoSpell + syntax region texMatcherMath matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath - " Bad/Mismatched math - syntax match texErrorOnlyMath "[_^]" - syntax match texErrorMath "\\[\])]" - syntax match texErrorMath "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}" - - " Operators and similar - syntax match texMathOper "[_^=]" contained - - " Math environments + " Math regions: environments call vimtex#syntax#core#new_math_region('displaymath', 1) call vimtex#syntax#core#new_math_region('eqnarray', 1) call vimtex#syntax#core#new_math_region('equation', 1) call vimtex#syntax#core#new_math_region('math', 1) - " Inline Math Zones + " Math regions: Inline Math Zones if l:cfg.conceal.math_bounds syntax region texRegionMath matchgroup=texDelimMathmode concealends contains=@texClusterMath keepend start="\\(" end="\\)" syntax region texRegionMath matchgroup=texDelimMathmode concealends contains=@texClusterMath keepend start="\\\[" end="\\]" @@ -317,34 +309,24 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax region texRegionMathXX matchgroup=texDelimMathmode contains=@texClusterMath keepend start="\$\$" end="\$\$" endif + " Math regions: \ensuremath{...} + syntax match texCmd "\\ensuremath\>" nextgroup=texRegionMathEnsured + call vimtex#syntax#core#new_cmd_arg('texRegionMathEnsured', '', '@texClusterMath') + + " Bad/Mismatched math + syntax match texErrorOnlyMath "[_^]" + syntax match texErrorMath "\\[\])]" + syntax match texErrorMath "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}" + + " Operators and similar + syntax match texMathOper "[_^=]" contained + " Text Inside Math regions syntax match texCmd "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texArgMathText call vimtex#syntax#core#new_cmd_arg('texArgMathText', '', 'TOP,@Spell') - syntax match texCmd "\\ensuremath\>" nextgroup=texRegionMathEnsured - call vimtex#syntax#core#new_cmd_arg('texRegionMathEnsured', '', '@texClusterMath') - " Math delimiters: \left... and \right... - syntax match texErrorMathDelim contained "\S" - if l:cfg.conceal.math_delimiters && &encoding ==# 'utf-8' - syntax match texDelimMath "\\left\[" contained - syntax match texDelimMath "\\left\\{" contained skipwhite nextgroup=texDelimMathSet1,texDelimMathSet2,texErrorMathDelim contains=texMathSymbol cchar={ - syntax match texDelimMath "\\right\\}" contained skipwhite nextgroup=texDelimMathSet1,texDelimMathSet2,texErrorMathDelim contains=texMathSymbol cchar=} - syntax match texDelimMath '\\[bB]igg\?[lr]' contained nextgroup=texErrorMathDelim - call s:match_conceal_math_delims() - else - syntax match texDelimMath "\\\(left\|right\)\>" contained skipwhite nextgroup=texDelimMathSet1,texDelimMathSet2,texErrorMathDelim - syntax match texDelimMath "\\[bB]igg\?[lr]\?\>" contained skipwhite nextgroup=texDelimMathSet1,texDelimMathSet2,texErrorMathDelim - syntax match texDelimMathSet2 "\\" contained nextgroup=texDelimMathKey,texErrorMathDelim - syntax match texDelimMathSet1 "[<>()[\]|/.]\|\\[{}|]" contained - syntax keyword texDelimMathKey contained backslash lceil lVert rgroup uparrow - syntax keyword texDelimMathKey contained downarrow lfloor rangle rmoustache Uparrow - syntax keyword texDelimMathKey contained Downarrow lgroup rbrace rvert updownarrow - syntax keyword texDelimMathKey contained langle lmoustache rceil rVert Updownarrow - syntax keyword texDelimMathKey contained lbrace lvert rfloor - endif - syntax match texDelimMath contained "\\\(left\|right\)arrow\>\|\<\([aA]rrow\|brace\)\?vert\>" - syntax match texDelimMath contained "\\lefteqn\>" + call s:match_math_delims(l:cfg) " }}}2 " {{{2 Conceal mode support @@ -420,14 +402,14 @@ function! vimtex#syntax#core#new_math_region(mathzone, starred) abort " {{{1 execute 'syntax region texRegionMathEnv' \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\s*}''' \ . ' end=''\\end\s*{\s*' . a:mathzone . '\s*}''' - \ . ' keepend contains=@texClusterMath' + \ . ' keepend contains=texCmdEnvMath,texArgEnvMathName,@texClusterMath' if !a:starred | return | endif execute 'syntax region texRegionMathEnvStarred' \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\*\s*}''' \ . ' end=''\\end\s*{\s*' . a:mathzone . '\*\s*}''' - \ . ' keepend contains=@texClusterMath' + \ . ' keepend contains=texCmdEnvMath,texArgEnvMathName,@texClusterMath' endfunction " }}}1 @@ -449,7 +431,8 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texComment Comment highlight def link texCommentTodo Todo highlight def link texDelim Delimiter - highlight def link texDelimMath Statement + highlight def link texDelimMath Type + highlight def link texDelimMathMod Statement highlight def link texError Error highlight def link texLength Number highlight def link texMath Special @@ -502,7 +485,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texErrorMathDelim texError highlight def link texErrorOnlyMath texError highlight def link texMatcherMath texMath - highlight def link texMathSymbol texCmd + highlight def link texSymbolMath texCmd highlight def link texOptEqual texSymbol highlight def link texOptFile texOpt highlight def link texOptFiles texOpt @@ -561,7 +544,7 @@ function! s:match_bold_italic(cfg) abort " {{{1 \ ['texCmdStyleItal', 'textup'], \] execute 'syntax match' l:group '"\\' . l:pattern . '\>\s*"' - \ 'nextgroup=' . l:map[l:group] l:conceal + \ 'skipwhite skipnl nextgroup=' . l:map[l:group] l:conceal endfor execute 'syntax region texStyleBold matchgroup=texDelim start=/{/ end=/}/' @@ -573,290 +556,321 @@ function! s:match_bold_italic(cfg) abort " {{{1 endfunction " }}}1 +function! s:match_math_delims(cfg) abort " {{{1 + syntax match texDelimMathMod contained skipwhite nextgroup=texDelimMath "\\\(left\|right\)\>" + syntax match texDelimMathMod contained skipwhite nextgroup=texDelimMath "\\[bB]igg\?[lr]\?\>" + syntax match texDelimMath contained "[<>()[\]|/.]\|\\[{}|]" + syntax match texDelimMath contained "\\backslash" + syntax match texDelimMath contained "\\downarrow" + syntax match texDelimMath contained "\\Downarrow" + syntax match texDelimMath contained "\\lVert" + syntax match texDelimMath contained "\\langle" + syntax match texDelimMath contained "\\lbrace" + syntax match texDelimMath contained "\\lceil" + syntax match texDelimMath contained "\\lfloor" + syntax match texDelimMath contained "\\lgroup" + syntax match texDelimMath contained "\\lmoustache" + syntax match texDelimMath contained "\\lvert" + syntax match texDelimMath contained "\\rVert" + syntax match texDelimMath contained "\\rangle" + syntax match texDelimMath contained "\\rbrace" + syntax match texDelimMath contained "\\rceil" + syntax match texDelimMath contained "\\rfloor" + syntax match texDelimMath contained "\\rgroup" + syntax match texDelimMath contained "\\rmoustache" + syntax match texDelimMath contained "\\rvert" + syntax match texDelimMath contained "\\uparrow" + syntax match texDelimMath contained "\\Uparrow" + syntax match texDelimMath contained "\\updownarrow" + syntax match texDelimMath contained "\\Updownarrow" + + if !a:cfg.conceal.math_delimiters || &encoding !=# 'utf-8' + return + endif -function! s:match_conceal_math_delims() abort " {{{1 - syntax match texMathSymbol "\\[bB]igg\?[lr]\?<" contained conceal cchar=< - syntax match texMathSymbol "\\[bB]igg\?[lr]\?>" contained conceal cchar=> - syntax match texMathSymbol "\\[bB]igg\?[lr]\?(" contained conceal cchar=( - syntax match texMathSymbol "\\[bB]igg\?[lr]\?)" contained conceal cchar=) - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\[" contained conceal cchar=[ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?]" contained conceal cchar=] - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\{" contained conceal cchar={ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\}" contained conceal cchar=} - syntax match texMathSymbol "\\[bB]igg\?[lr]\?|" contained conceal cchar=| - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\|" contained conceal cchar=‖ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\downarrow" contained conceal cchar=↓ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\Downarrow" contained conceal cchar=⇓ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\lbrace" contained conceal cchar=[ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\lceil" contained conceal cchar=⌈ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\lfloor" contained conceal cchar=⌊ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\lgroup" contained conceal cchar=⌊ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\lmoustache" contained conceal cchar=⎛ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\rbrace" contained conceal cchar=] - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\rceil" contained conceal cchar=⌉ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\rfloor" contained conceal cchar=⌋ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\rgroup" contained conceal cchar=⌋ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\rmoustache" contained conceal cchar=⎞ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\uparrow" contained conceal cchar=↑ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\Uparrow" contained conceal cchar=↑ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\updownarrow" contained conceal cchar=↕ - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\Updownarrow" contained conceal cchar=⇕ + syntax match texDelimMath contained conceal cchar=< "\\\%([bB]igg\?l\|left\)<" + syntax match texDelimMath contained conceal cchar=> "\\\%([bB]igg\?r\|right\)>" + syntax match texDelimMath contained conceal cchar=( "\\\%([bB]igg\?l\|left\)(" + syntax match texDelimMath contained conceal cchar=) "\\\%([bB]igg\?r\|right\))" + syntax match texDelimMath contained conceal cchar=[ "\\\%([bB]igg\?l\|left\)\[" + syntax match texDelimMath contained conceal cchar=] "\\\%([bB]igg\?r\|right\)]" + syntax match texDelimMath contained conceal cchar={ "\\\%([bB]igg\?l\|left\)\\{" + syntax match texDelimMath contained conceal cchar=} "\\\%([bB]igg\?r\|right\)\\}" + syntax match texDelimMath contained conceal cchar=[ "\\\%([bB]igg\?l\|left\)\\lbrace" + syntax match texDelimMath contained conceal cchar=⌈ "\\\%([bB]igg\?l\|left\)\\lceil" + syntax match texDelimMath contained conceal cchar=⌊ "\\\%([bB]igg\?l\|left\)\\lfloor" + syntax match texDelimMath contained conceal cchar=⌊ "\\\%([bB]igg\?l\|left\)\\lgroup" + syntax match texDelimMath contained conceal cchar=⎛ "\\\%([bB]igg\?l\|left\)\\lmoustache" + syntax match texDelimMath contained conceal cchar=] "\\\%([bB]igg\?r\|right\)\\rbrace" + syntax match texDelimMath contained conceal cchar=⌉ "\\\%([bB]igg\?r\|right\)\\rceil" + syntax match texDelimMath contained conceal cchar=⌋ "\\\%([bB]igg\?r\|right\)\\rfloor" + syntax match texDelimMath contained conceal cchar=⌋ "\\\%([bB]igg\?r\|right\)\\rgroup" + syntax match texDelimMath contained conceal cchar=⎞ "\\\%([bB]igg\?r\|right\)\\rmoustache" + syntax match texDelimMath contained conceal cchar=| "\\\%([bB]igg\?[lr]\?\|left\|right\)|" + syntax match texDelimMath contained conceal cchar=‖ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\|" + syntax match texDelimMath contained conceal cchar=↓ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\downarrow" + syntax match texDelimMath contained conceal cchar=⇓ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Downarrow" + syntax match texDelimMath contained conceal cchar=↑ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\uparrow" + syntax match texDelimMath contained conceal cchar=↑ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Uparrow" + syntax match texDelimMath contained conceal cchar=↕ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\updownarrow" + syntax match texDelimMath contained conceal cchar=⇕ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Updownarrow" if &ambiwidth ==# 'double' - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\langle" contained conceal cchar=〈 - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\rangle" contained conceal cchar=〉 + syntax match texDelimMath contained conceal cchar=〈 "\\\%([bB]igg\?l\|left\)\\langle" + syntax match texDelimMath contained conceal cchar=〉 "\\\%([bB]igg\?r\|right\)\\rangle" else - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\langle" contained conceal cchar=< - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\rangle" contained conceal cchar=> + syntax match texDelimMath contained conceal cchar=< "\\\%([bB]igg\?l\|left\)\\langle" + syntax match texDelimMath contained conceal cchar=> "\\\%([bB]igg\?r\|right\)\\rangle" endif endfunction " }}}1 + function! s:match_conceal_math_symbols() abort " {{{1 - syntax match texMathSymbol "\\|" contained conceal cchar=‖ - syntax match texMathSymbol "\\aleph\>" contained conceal cchar=ℵ - syntax match texMathSymbol "\\amalg\>" contained conceal cchar=∐ - syntax match texMathSymbol "\\angle\>" contained conceal cchar=∠ - syntax match texMathSymbol "\\approx\>" contained conceal cchar=≈ - syntax match texMathSymbol "\\ast\>" contained conceal cchar=∗ - syntax match texMathSymbol "\\asymp\>" contained conceal cchar=≍ - syntax match texMathSymbol "\\backslash\>" contained conceal cchar=∖ - syntax match texMathSymbol "\\bigcap\>" contained conceal cchar=∩ - syntax match texMathSymbol "\\bigcirc\>" contained conceal cchar=○ - syntax match texMathSymbol "\\bigcup\>" contained conceal cchar=∪ - syntax match texMathSymbol "\\bigodot\>" contained conceal cchar=⊙ - syntax match texMathSymbol "\\bigoplus\>" contained conceal cchar=⊕ - syntax match texMathSymbol "\\bigotimes\>" contained conceal cchar=⊗ - syntax match texMathSymbol "\\bigsqcup\>" contained conceal cchar=⊔ - syntax match texMathSymbol "\\bigtriangledown\>" contained conceal cchar=∇ - syntax match texMathSymbol "\\bigtriangleup\>" contained conceal cchar=∆ - syntax match texMathSymbol "\\bigvee\>" contained conceal cchar=⋁ - syntax match texMathSymbol "\\bigwedge\>" contained conceal cchar=⋀ - syntax match texMathSymbol "\\bot\>" contained conceal cchar=⊥ - syntax match texMathSymbol "\\bowtie\>" contained conceal cchar=⋈ - syntax match texMathSymbol "\\bullet\>" contained conceal cchar=• - syntax match texMathSymbol "\\cap\>" contained conceal cchar=∩ - syntax match texMathSymbol "\\cdot\>" contained conceal cchar=· - syntax match texMathSymbol "\\cdots\>" contained conceal cchar=⋯ - syntax match texMathSymbol "\\circ\>" contained conceal cchar=∘ - syntax match texMathSymbol "\\clubsuit\>" contained conceal cchar=♣ - syntax match texMathSymbol "\\cong\>" contained conceal cchar=≅ - syntax match texMathSymbol "\\coprod\>" contained conceal cchar=∐ - syntax match texMathSymbol "\\copyright\>" contained conceal cchar=© - syntax match texMathSymbol "\\cup\>" contained conceal cchar=∪ - syntax match texMathSymbol "\\dagger\>" contained conceal cchar=† - syntax match texMathSymbol "\\dashv\>" contained conceal cchar=⊣ - syntax match texMathSymbol "\\ddagger\>" contained conceal cchar=‡ - syntax match texMathSymbol "\\ddots\>" contained conceal cchar=⋱ - syntax match texMathSymbol "\\diamond\>" contained conceal cchar=⋄ - syntax match texMathSymbol "\\diamondsuit\>" contained conceal cchar=♢ - syntax match texMathSymbol "\\div\>" contained conceal cchar=÷ - syntax match texMathSymbol "\\doteq\>" contained conceal cchar=≐ - syntax match texMathSymbol "\\dots\>" contained conceal cchar=… - syntax match texMathSymbol "\\downarrow\>" contained conceal cchar=↓ - syntax match texMathSymbol "\\Downarrow\>" contained conceal cchar=⇓ - syntax match texMathSymbol "\\ell\>" contained conceal cchar=ℓ - syntax match texMathSymbol "\\emptyset\>" contained conceal cchar=∅ - syntax match texMathSymbol "\\equiv\>" contained conceal cchar=≡ - syntax match texMathSymbol "\\exists\>" contained conceal cchar=∃ - syntax match texMathSymbol "\\flat\>" contained conceal cchar=♭ - syntax match texMathSymbol "\\forall\>" contained conceal cchar=∀ - syntax match texMathSymbol "\\frown\>" contained conceal cchar=⁔ - syntax match texMathSymbol "\\ge\>" contained conceal cchar=≥ - syntax match texMathSymbol "\\geq\>" contained conceal cchar=≥ - syntax match texMathSymbol "\\gets\>" contained conceal cchar=← - syntax match texMathSymbol "\\gg\>" contained conceal cchar=⟫ - syntax match texMathSymbol "\\hbar\>" contained conceal cchar=ℏ - syntax match texMathSymbol "\\heartsuit\>" contained conceal cchar=♡ - syntax match texMathSymbol "\\hookleftarrow\>" contained conceal cchar=↩ - syntax match texMathSymbol "\\hookrightarrow\>" contained conceal cchar=↪ - syntax match texMathSymbol "\\iff\>" contained conceal cchar=⇔ - syntax match texMathSymbol "\\Im\>" contained conceal cchar=ℑ - syntax match texMathSymbol "\\imath\>" contained conceal cchar=ɩ - syntax match texMathSymbol "\\in\>" contained conceal cchar=∈ - syntax match texMathSymbol "\\infty\>" contained conceal cchar=∞ - syntax match texMathSymbol "\\int\>" contained conceal cchar=∫ - syntax match texMathSymbol "\\jmath\>" contained conceal cchar=𝚥 - syntax match texMathSymbol "\\land\>" contained conceal cchar=∧ - syntax match texMathSymbol "\\lceil\>" contained conceal cchar=⌈ - syntax match texMathSymbol "\\ldots\>" contained conceal cchar=… - syntax match texMathSymbol "\\le\>" contained conceal cchar=≤ - syntax match texMathSymbol "\\left|" contained conceal cchar=| - syntax match texMathSymbol "\\left\\|" contained conceal cchar=‖ - syntax match texMathSymbol "\\left(" contained conceal cchar=( - syntax match texMathSymbol "\\left\[" contained conceal cchar=[ - syntax match texMathSymbol "\\left\\{" contained conceal cchar={ - syntax match texMathSymbol "\\leftarrow\>" contained conceal cchar=← - syntax match texMathSymbol "\\Leftarrow\>" contained conceal cchar=⇐ - syntax match texMathSymbol "\\leftharpoondown\>" contained conceal cchar=↽ - syntax match texMathSymbol "\\leftharpoonup\>" contained conceal cchar=↼ - syntax match texMathSymbol "\\leftrightarrow\>" contained conceal cchar=↔ - syntax match texMathSymbol "\\Leftrightarrow\>" contained conceal cchar=⇔ - syntax match texMathSymbol "\\leq\>" contained conceal cchar=≤ - syntax match texMathSymbol "\\leq\>" contained conceal cchar=≤ - syntax match texMathSymbol "\\lfloor\>" contained conceal cchar=⌊ - syntax match texMathSymbol "\\ll\>" contained conceal cchar=≪ - syntax match texMathSymbol "\\lmoustache\>" contained conceal cchar=╭ - syntax match texMathSymbol "\\lor\>" contained conceal cchar=∨ - syntax match texMathSymbol "\\mapsto\>" contained conceal cchar=↦ - syntax match texMathSymbol "\\mid\>" contained conceal cchar=∣ - syntax match texMathSymbol "\\models\>" contained conceal cchar=╞ - syntax match texMathSymbol "\\mp\>" contained conceal cchar=∓ - syntax match texMathSymbol "\\nabla\>" contained conceal cchar=∇ - syntax match texMathSymbol "\\natural\>" contained conceal cchar=♮ - syntax match texMathSymbol "\\ne\>" contained conceal cchar=≠ - syntax match texMathSymbol "\\nearrow\>" contained conceal cchar=↗ - syntax match texMathSymbol "\\neg\>" contained conceal cchar=¬ - syntax match texMathSymbol "\\neq\>" contained conceal cchar=≠ - syntax match texMathSymbol "\\ni\>" contained conceal cchar=∋ - syntax match texMathSymbol "\\notin\>" contained conceal cchar=∉ - syntax match texMathSymbol "\\nwarrow\>" contained conceal cchar=↖ - syntax match texMathSymbol "\\odot\>" contained conceal cchar=⊙ - syntax match texMathSymbol "\\oint\>" contained conceal cchar=∮ - syntax match texMathSymbol "\\ominus\>" contained conceal cchar=⊖ - syntax match texMathSymbol "\\oplus\>" contained conceal cchar=⊕ - syntax match texMathSymbol "\\oslash\>" contained conceal cchar=⊘ - syntax match texMathSymbol "\\otimes\>" contained conceal cchar=⊗ - syntax match texMathSymbol "\\owns\>" contained conceal cchar=∋ - syntax match texMathSymbol "\\P\>" contained conceal cchar=¶ - syntax match texMathSymbol "\\parallel\>" contained conceal cchar=║ - syntax match texMathSymbol "\\partial\>" contained conceal cchar=∂ - syntax match texMathSymbol "\\perp\>" contained conceal cchar=⊥ - syntax match texMathSymbol "\\pm\>" contained conceal cchar=± - syntax match texMathSymbol "\\prec\>" contained conceal cchar=≺ - syntax match texMathSymbol "\\preceq\>" contained conceal cchar=⪯ - syntax match texMathSymbol "\\prime\>" contained conceal cchar=′ - syntax match texMathSymbol "\\prod\>" contained conceal cchar=∏ - syntax match texMathSymbol "\\propto\>" contained conceal cchar=∝ - syntax match texMathSymbol "\\rceil\>" contained conceal cchar=⌉ - syntax match texMathSymbol "\\Re\>" contained conceal cchar=ℜ - syntax match texMathSymbol "\\quad\>" contained conceal cchar=  - syntax match texMathSymbol "\\qquad\>" contained conceal cchar=  - syntax match texMathSymbol "\\rfloor\>" contained conceal cchar=⌋ - syntax match texMathSymbol "\\right|" contained conceal cchar=| - syntax match texMathSymbol "\\right\\|" contained conceal cchar=‖ - syntax match texMathSymbol "\\right)" contained conceal cchar=) - syntax match texMathSymbol "\\right]" contained conceal cchar=] - syntax match texMathSymbol "\\right\\}" contained conceal cchar=} - syntax match texMathSymbol "\\rightarrow\>" contained conceal cchar=→ - syntax match texMathSymbol "\\Rightarrow\>" contained conceal cchar=⇒ - syntax match texMathSymbol "\\rightleftharpoons\>" contained conceal cchar=⇌ - syntax match texMathSymbol "\\rmoustache\>" contained conceal cchar=╮ - syntax match texMathSymbol "\\S\>" contained conceal cchar=§ - syntax match texMathSymbol "\\searrow\>" contained conceal cchar=↘ - syntax match texMathSymbol "\\setminus\>" contained conceal cchar=∖ - syntax match texMathSymbol "\\sharp\>" contained conceal cchar=♯ - syntax match texMathSymbol "\\sim\>" contained conceal cchar=∼ - syntax match texMathSymbol "\\simeq\>" contained conceal cchar=⋍ - syntax match texMathSymbol "\\smile\>" contained conceal cchar=‿ - syntax match texMathSymbol "\\spadesuit\>" contained conceal cchar=♠ - syntax match texMathSymbol "\\sqcap\>" contained conceal cchar=⊓ - syntax match texMathSymbol "\\sqcup\>" contained conceal cchar=⊔ - syntax match texMathSymbol "\\sqsubset\>" contained conceal cchar=⊏ - syntax match texMathSymbol "\\sqsubseteq\>" contained conceal cchar=⊑ - syntax match texMathSymbol "\\sqsupset\>" contained conceal cchar=⊐ - syntax match texMathSymbol "\\sqsupseteq\>" contained conceal cchar=⊒ - syntax match texMathSymbol "\\star\>" contained conceal cchar=✫ - syntax match texMathSymbol "\\subset\>" contained conceal cchar=⊂ - syntax match texMathSymbol "\\subseteq\>" contained conceal cchar=⊆ - syntax match texMathSymbol "\\succ\>" contained conceal cchar=≻ - syntax match texMathSymbol "\\succeq\>" contained conceal cchar=⪰ - syntax match texMathSymbol "\\sum\>" contained conceal cchar=∑ - syntax match texMathSymbol "\\supset\>" contained conceal cchar=⊃ - syntax match texMathSymbol "\\supseteq\>" contained conceal cchar=⊇ - syntax match texMathSymbol "\\surd\>" contained conceal cchar=√ - syntax match texMathSymbol "\\swarrow\>" contained conceal cchar=↙ - syntax match texMathSymbol "\\times\>" contained conceal cchar=× - syntax match texMathSymbol "\\to\>" contained conceal cchar=→ - syntax match texMathSymbol "\\top\>" contained conceal cchar=⊤ - syntax match texMathSymbol "\\triangle\>" contained conceal cchar=∆ - syntax match texMathSymbol "\\triangleleft\>" contained conceal cchar=⊲ - syntax match texMathSymbol "\\triangleright\>" contained conceal cchar=⊳ - syntax match texMathSymbol "\\uparrow\>" contained conceal cchar=↑ - syntax match texMathSymbol "\\Uparrow\>" contained conceal cchar=⇑ - syntax match texMathSymbol "\\updownarrow\>" contained conceal cchar=↕ - syntax match texMathSymbol "\\Updownarrow\>" contained conceal cchar=⇕ - syntax match texMathSymbol "\\vdash\>" contained conceal cchar=⊢ - syntax match texMathSymbol "\\vdots\>" contained conceal cchar=⋮ - syntax match texMathSymbol "\\vee\>" contained conceal cchar=∨ - syntax match texMathSymbol "\\wedge\>" contained conceal cchar=∧ - syntax match texMathSymbol "\\wp\>" contained conceal cchar=℘ - syntax match texMathSymbol "\\wr\>" contained conceal cchar=≀ + syntax match texSymbolMath "\\|" contained conceal cchar=‖ + syntax match texSymbolMath "\\aleph\>" contained conceal cchar=ℵ + syntax match texSymbolMath "\\amalg\>" contained conceal cchar=∐ + syntax match texSymbolMath "\\angle\>" contained conceal cchar=∠ + syntax match texSymbolMath "\\approx\>" contained conceal cchar=≈ + syntax match texSymbolMath "\\ast\>" contained conceal cchar=∗ + syntax match texSymbolMath "\\asymp\>" contained conceal cchar=≍ + syntax match texSymbolMath "\\backslash\>" contained conceal cchar=∖ + syntax match texSymbolMath "\\bigcap\>" contained conceal cchar=∩ + syntax match texSymbolMath "\\bigcirc\>" contained conceal cchar=○ + syntax match texSymbolMath "\\bigcup\>" contained conceal cchar=∪ + syntax match texSymbolMath "\\bigodot\>" contained conceal cchar=⊙ + syntax match texSymbolMath "\\bigoplus\>" contained conceal cchar=⊕ + syntax match texSymbolMath "\\bigotimes\>" contained conceal cchar=⊗ + syntax match texSymbolMath "\\bigsqcup\>" contained conceal cchar=⊔ + syntax match texSymbolMath "\\bigtriangledown\>" contained conceal cchar=∇ + syntax match texSymbolMath "\\bigtriangleup\>" contained conceal cchar=∆ + syntax match texSymbolMath "\\bigvee\>" contained conceal cchar=⋁ + syntax match texSymbolMath "\\bigwedge\>" contained conceal cchar=⋀ + syntax match texSymbolMath "\\bot\>" contained conceal cchar=⊥ + syntax match texSymbolMath "\\bowtie\>" contained conceal cchar=⋈ + syntax match texSymbolMath "\\bullet\>" contained conceal cchar=• + syntax match texSymbolMath "\\cap\>" contained conceal cchar=∩ + syntax match texSymbolMath "\\cdot\>" contained conceal cchar=· + syntax match texSymbolMath "\\cdots\>" contained conceal cchar=⋯ + syntax match texSymbolMath "\\circ\>" contained conceal cchar=∘ + syntax match texSymbolMath "\\clubsuit\>" contained conceal cchar=♣ + syntax match texSymbolMath "\\cong\>" contained conceal cchar=≅ + syntax match texSymbolMath "\\coprod\>" contained conceal cchar=∐ + syntax match texSymbolMath "\\copyright\>" contained conceal cchar=© + syntax match texSymbolMath "\\cup\>" contained conceal cchar=∪ + syntax match texSymbolMath "\\dagger\>" contained conceal cchar=† + syntax match texSymbolMath "\\dashv\>" contained conceal cchar=⊣ + syntax match texSymbolMath "\\ddagger\>" contained conceal cchar=‡ + syntax match texSymbolMath "\\ddots\>" contained conceal cchar=⋱ + syntax match texSymbolMath "\\diamond\>" contained conceal cchar=⋄ + syntax match texSymbolMath "\\diamondsuit\>" contained conceal cchar=♢ + syntax match texSymbolMath "\\div\>" contained conceal cchar=÷ + syntax match texSymbolMath "\\doteq\>" contained conceal cchar=≐ + syntax match texSymbolMath "\\dots\>" contained conceal cchar=… + syntax match texSymbolMath "\\downarrow\>" contained conceal cchar=↓ + syntax match texSymbolMath "\\Downarrow\>" contained conceal cchar=⇓ + syntax match texSymbolMath "\\ell\>" contained conceal cchar=ℓ + syntax match texSymbolMath "\\emptyset\>" contained conceal cchar=∅ + syntax match texSymbolMath "\\equiv\>" contained conceal cchar=≡ + syntax match texSymbolMath "\\exists\>" contained conceal cchar=∃ + syntax match texSymbolMath "\\flat\>" contained conceal cchar=♭ + syntax match texSymbolMath "\\forall\>" contained conceal cchar=∀ + syntax match texSymbolMath "\\frown\>" contained conceal cchar=⁔ + syntax match texSymbolMath "\\ge\>" contained conceal cchar=≥ + syntax match texSymbolMath "\\geq\>" contained conceal cchar=≥ + syntax match texSymbolMath "\\gets\>" contained conceal cchar=← + syntax match texSymbolMath "\\gg\>" contained conceal cchar=⟫ + syntax match texSymbolMath "\\hbar\>" contained conceal cchar=ℏ + syntax match texSymbolMath "\\heartsuit\>" contained conceal cchar=♡ + syntax match texSymbolMath "\\hookleftarrow\>" contained conceal cchar=↩ + syntax match texSymbolMath "\\hookrightarrow\>" contained conceal cchar=↪ + syntax match texSymbolMath "\\iff\>" contained conceal cchar=⇔ + syntax match texSymbolMath "\\Im\>" contained conceal cchar=ℑ + syntax match texSymbolMath "\\imath\>" contained conceal cchar=ɩ + syntax match texSymbolMath "\\in\>" contained conceal cchar=∈ + syntax match texSymbolMath "\\infty\>" contained conceal cchar=∞ + syntax match texSymbolMath "\\int\>" contained conceal cchar=∫ + syntax match texSymbolMath "\\jmath\>" contained conceal cchar=𝚥 + syntax match texSymbolMath "\\land\>" contained conceal cchar=∧ + syntax match texSymbolMath "\\lceil\>" contained conceal cchar=⌈ + syntax match texSymbolMath "\\ldots\>" contained conceal cchar=… + syntax match texSymbolMath "\\le\>" contained conceal cchar=≤ + syntax match texSymbolMath "\\left|" contained conceal cchar=| + syntax match texSymbolMath "\\left\\|" contained conceal cchar=‖ + syntax match texSymbolMath "\\left(" contained conceal cchar=( + syntax match texSymbolMath "\\left\[" contained conceal cchar=[ + syntax match texSymbolMath "\\left\\{" contained conceal cchar={ + syntax match texSymbolMath "\\leftarrow\>" contained conceal cchar=← + syntax match texSymbolMath "\\Leftarrow\>" contained conceal cchar=⇐ + syntax match texSymbolMath "\\leftharpoondown\>" contained conceal cchar=↽ + syntax match texSymbolMath "\\leftharpoonup\>" contained conceal cchar=↼ + syntax match texSymbolMath "\\leftrightarrow\>" contained conceal cchar=↔ + syntax match texSymbolMath "\\Leftrightarrow\>" contained conceal cchar=⇔ + syntax match texSymbolMath "\\leq\>" contained conceal cchar=≤ + syntax match texSymbolMath "\\leq\>" contained conceal cchar=≤ + syntax match texSymbolMath "\\lfloor\>" contained conceal cchar=⌊ + syntax match texSymbolMath "\\ll\>" contained conceal cchar=≪ + syntax match texSymbolMath "\\lmoustache\>" contained conceal cchar=╭ + syntax match texSymbolMath "\\lor\>" contained conceal cchar=∨ + syntax match texSymbolMath "\\mapsto\>" contained conceal cchar=↦ + syntax match texSymbolMath "\\mid\>" contained conceal cchar=∣ + syntax match texSymbolMath "\\models\>" contained conceal cchar=╞ + syntax match texSymbolMath "\\mp\>" contained conceal cchar=∓ + syntax match texSymbolMath "\\nabla\>" contained conceal cchar=∇ + syntax match texSymbolMath "\\natural\>" contained conceal cchar=♮ + syntax match texSymbolMath "\\ne\>" contained conceal cchar=≠ + syntax match texSymbolMath "\\nearrow\>" contained conceal cchar=↗ + syntax match texSymbolMath "\\neg\>" contained conceal cchar=¬ + syntax match texSymbolMath "\\neq\>" contained conceal cchar=≠ + syntax match texSymbolMath "\\ni\>" contained conceal cchar=∋ + syntax match texSymbolMath "\\notin\>" contained conceal cchar=∉ + syntax match texSymbolMath "\\nwarrow\>" contained conceal cchar=↖ + syntax match texSymbolMath "\\odot\>" contained conceal cchar=⊙ + syntax match texSymbolMath "\\oint\>" contained conceal cchar=∮ + syntax match texSymbolMath "\\ominus\>" contained conceal cchar=⊖ + syntax match texSymbolMath "\\oplus\>" contained conceal cchar=⊕ + syntax match texSymbolMath "\\oslash\>" contained conceal cchar=⊘ + syntax match texSymbolMath "\\otimes\>" contained conceal cchar=⊗ + syntax match texSymbolMath "\\owns\>" contained conceal cchar=∋ + syntax match texSymbolMath "\\P\>" contained conceal cchar=¶ + syntax match texSymbolMath "\\parallel\>" contained conceal cchar=║ + syntax match texSymbolMath "\\partial\>" contained conceal cchar=∂ + syntax match texSymbolMath "\\perp\>" contained conceal cchar=⊥ + syntax match texSymbolMath "\\pm\>" contained conceal cchar=± + syntax match texSymbolMath "\\prec\>" contained conceal cchar=≺ + syntax match texSymbolMath "\\preceq\>" contained conceal cchar=⪯ + syntax match texSymbolMath "\\prime\>" contained conceal cchar=′ + syntax match texSymbolMath "\\prod\>" contained conceal cchar=∏ + syntax match texSymbolMath "\\propto\>" contained conceal cchar=∝ + syntax match texSymbolMath "\\rceil\>" contained conceal cchar=⌉ + syntax match texSymbolMath "\\Re\>" contained conceal cchar=ℜ + syntax match texSymbolMath "\\quad\>" contained conceal cchar=  + syntax match texSymbolMath "\\qquad\>" contained conceal cchar=  + syntax match texSymbolMath "\\rfloor\>" contained conceal cchar=⌋ + syntax match texSymbolMath "\\right|" contained conceal cchar=| + syntax match texSymbolMath "\\right\\|" contained conceal cchar=‖ + syntax match texSymbolMath "\\right)" contained conceal cchar=) + syntax match texSymbolMath "\\right]" contained conceal cchar=] + syntax match texSymbolMath "\\right\\}" contained conceal cchar=} + syntax match texSymbolMath "\\rightarrow\>" contained conceal cchar=→ + syntax match texSymbolMath "\\Rightarrow\>" contained conceal cchar=⇒ + syntax match texSymbolMath "\\rightleftharpoons\>" contained conceal cchar=⇌ + syntax match texSymbolMath "\\rmoustache\>" contained conceal cchar=╮ + syntax match texSymbolMath "\\S\>" contained conceal cchar=§ + syntax match texSymbolMath "\\searrow\>" contained conceal cchar=↘ + syntax match texSymbolMath "\\setminus\>" contained conceal cchar=∖ + syntax match texSymbolMath "\\sharp\>" contained conceal cchar=♯ + syntax match texSymbolMath "\\sim\>" contained conceal cchar=∼ + syntax match texSymbolMath "\\simeq\>" contained conceal cchar=⋍ + syntax match texSymbolMath "\\smile\>" contained conceal cchar=‿ + syntax match texSymbolMath "\\spadesuit\>" contained conceal cchar=♠ + syntax match texSymbolMath "\\sqcap\>" contained conceal cchar=⊓ + syntax match texSymbolMath "\\sqcup\>" contained conceal cchar=⊔ + syntax match texSymbolMath "\\sqsubset\>" contained conceal cchar=⊏ + syntax match texSymbolMath "\\sqsubseteq\>" contained conceal cchar=⊑ + syntax match texSymbolMath "\\sqsupset\>" contained conceal cchar=⊐ + syntax match texSymbolMath "\\sqsupseteq\>" contained conceal cchar=⊒ + syntax match texSymbolMath "\\star\>" contained conceal cchar=✫ + syntax match texSymbolMath "\\subset\>" contained conceal cchar=⊂ + syntax match texSymbolMath "\\subseteq\>" contained conceal cchar=⊆ + syntax match texSymbolMath "\\succ\>" contained conceal cchar=≻ + syntax match texSymbolMath "\\succeq\>" contained conceal cchar=⪰ + syntax match texSymbolMath "\\sum\>" contained conceal cchar=∑ + syntax match texSymbolMath "\\supset\>" contained conceal cchar=⊃ + syntax match texSymbolMath "\\supseteq\>" contained conceal cchar=⊇ + syntax match texSymbolMath "\\surd\>" contained conceal cchar=√ + syntax match texSymbolMath "\\swarrow\>" contained conceal cchar=↙ + syntax match texSymbolMath "\\times\>" contained conceal cchar=× + syntax match texSymbolMath "\\to\>" contained conceal cchar=→ + syntax match texSymbolMath "\\top\>" contained conceal cchar=⊤ + syntax match texSymbolMath "\\triangle\>" contained conceal cchar=∆ + syntax match texSymbolMath "\\triangleleft\>" contained conceal cchar=⊲ + syntax match texSymbolMath "\\triangleright\>" contained conceal cchar=⊳ + syntax match texSymbolMath "\\uparrow\>" contained conceal cchar=↑ + syntax match texSymbolMath "\\Uparrow\>" contained conceal cchar=⇑ + syntax match texSymbolMath "\\updownarrow\>" contained conceal cchar=↕ + syntax match texSymbolMath "\\Updownarrow\>" contained conceal cchar=⇕ + syntax match texSymbolMath "\\vdash\>" contained conceal cchar=⊢ + syntax match texSymbolMath "\\vdots\>" contained conceal cchar=⋮ + syntax match texSymbolMath "\\vee\>" contained conceal cchar=∨ + syntax match texSymbolMath "\\wedge\>" contained conceal cchar=∧ + syntax match texSymbolMath "\\wp\>" contained conceal cchar=℘ + syntax match texSymbolMath "\\wr\>" contained conceal cchar=≀ if &ambiwidth ==# 'double' - syntax match texMathSymbol "right\\rangle\>" contained conceal cchar=〉 - syntax match texMathSymbol "left\\langle\>" contained conceal cchar=〈 - syntax match texMathSymbol '\\gg\>' contained conceal cchar=≫ - syntax match texMathSymbol '\\ll\>' contained conceal cchar=≪ + syntax match texSymbolMath "right\\rangle\>" contained conceal cchar=〉 + syntax match texSymbolMath "left\\langle\>" contained conceal cchar=〈 + syntax match texSymbolMath '\\gg\>' contained conceal cchar=≫ + syntax match texSymbolMath '\\ll\>' contained conceal cchar=≪ else - syntax match texMathSymbol "right\\rangle\>" contained conceal cchar=> - syntax match texMathSymbol "left\\langle\>" contained conceal cchar=< - syntax match texMathSymbol '\\gg\>' contained conceal cchar=⟫ - syntax match texMathSymbol '\\ll\>' contained conceal cchar=⟪ + syntax match texSymbolMath "right\\rangle\>" contained conceal cchar=> + syntax match texSymbolMath "left\\langle\>" contained conceal cchar=< + syntax match texSymbolMath '\\gg\>' contained conceal cchar=⟫ + syntax match texSymbolMath '\\ll\>' contained conceal cchar=⟪ endif - syntax match texMathSymbol '\\bar{a}' contained conceal cchar=a̅ - - syntax match texMathSymbol '\\dot{A}' contained conceal cchar=Ȧ - syntax match texMathSymbol '\\dot{a}' contained conceal cchar=ȧ - syntax match texMathSymbol '\\dot{B}' contained conceal cchar=Ḃ - syntax match texMathSymbol '\\dot{b}' contained conceal cchar=ḃ - syntax match texMathSymbol '\\dot{C}' contained conceal cchar=Ċ - syntax match texMathSymbol '\\dot{c}' contained conceal cchar=ċ - syntax match texMathSymbol '\\dot{D}' contained conceal cchar=Ḋ - syntax match texMathSymbol '\\dot{d}' contained conceal cchar=ḋ - syntax match texMathSymbol '\\dot{E}' contained conceal cchar=Ė - syntax match texMathSymbol '\\dot{e}' contained conceal cchar=ė - syntax match texMathSymbol '\\dot{F}' contained conceal cchar=Ḟ - syntax match texMathSymbol '\\dot{f}' contained conceal cchar=ḟ - syntax match texMathSymbol '\\dot{G}' contained conceal cchar=Ġ - syntax match texMathSymbol '\\dot{g}' contained conceal cchar=ġ - syntax match texMathSymbol '\\dot{H}' contained conceal cchar=Ḣ - syntax match texMathSymbol '\\dot{h}' contained conceal cchar=ḣ - syntax match texMathSymbol '\\dot{I}' contained conceal cchar=İ - syntax match texMathSymbol '\\dot{M}' contained conceal cchar=Ṁ - syntax match texMathSymbol '\\dot{m}' contained conceal cchar=ṁ - syntax match texMathSymbol '\\dot{N}' contained conceal cchar=Ṅ - syntax match texMathSymbol '\\dot{n}' contained conceal cchar=ṅ - syntax match texMathSymbol '\\dot{O}' contained conceal cchar=Ȯ - syntax match texMathSymbol '\\dot{o}' contained conceal cchar=ȯ - syntax match texMathSymbol '\\dot{P}' contained conceal cchar=Ṗ - syntax match texMathSymbol '\\dot{p}' contained conceal cchar=ṗ - syntax match texMathSymbol '\\dot{R}' contained conceal cchar=Ṙ - syntax match texMathSymbol '\\dot{r}' contained conceal cchar=ṙ - syntax match texMathSymbol '\\dot{S}' contained conceal cchar=Ṡ - syntax match texMathSymbol '\\dot{s}' contained conceal cchar=ṡ - syntax match texMathSymbol '\\dot{T}' contained conceal cchar=Ṫ - syntax match texMathSymbol '\\dot{t}' contained conceal cchar=ṫ - syntax match texMathSymbol '\\dot{W}' contained conceal cchar=Ẇ - syntax match texMathSymbol '\\dot{w}' contained conceal cchar=ẇ - syntax match texMathSymbol '\\dot{X}' contained conceal cchar=Ẋ - syntax match texMathSymbol '\\dot{x}' contained conceal cchar=ẋ - syntax match texMathSymbol '\\dot{Y}' contained conceal cchar=Ẏ - syntax match texMathSymbol '\\dot{y}' contained conceal cchar=ẏ - syntax match texMathSymbol '\\dot{Z}' contained conceal cchar=Ż - syntax match texMathSymbol '\\dot{z}' contained conceal cchar=ż - - syntax match texMathSymbol '\\hat{a}' contained conceal cchar=â - syntax match texMathSymbol '\\hat{A}' contained conceal cchar= - syntax match texMathSymbol '\\hat{c}' contained conceal cchar=ĉ - syntax match texMathSymbol '\\hat{C}' contained conceal cchar=Ĉ - syntax match texMathSymbol '\\hat{e}' contained conceal cchar=ê - syntax match texMathSymbol '\\hat{E}' contained conceal cchar=Ê - syntax match texMathSymbol '\\hat{g}' contained conceal cchar=ĝ - syntax match texMathSymbol '\\hat{G}' contained conceal cchar=Ĝ - syntax match texMathSymbol '\\hat{i}' contained conceal cchar=î - syntax match texMathSymbol '\\hat{I}' contained conceal cchar=Î - syntax match texMathSymbol '\\hat{o}' contained conceal cchar=ô - syntax match texMathSymbol '\\hat{O}' contained conceal cchar=Ô - syntax match texMathSymbol '\\hat{s}' contained conceal cchar=ŝ - syntax match texMathSymbol '\\hat{S}' contained conceal cchar=Ŝ - syntax match texMathSymbol '\\hat{u}' contained conceal cchar=û - syntax match texMathSymbol '\\hat{U}' contained conceal cchar=Û - syntax match texMathSymbol '\\hat{w}' contained conceal cchar=ŵ - syntax match texMathSymbol '\\hat{W}' contained conceal cchar=Ŵ - syntax match texMathSymbol '\\hat{y}' contained conceal cchar=ŷ - syntax match texMathSymbol '\\hat{Y}' contained conceal cchar=Ŷ + syntax match texSymbolMath '\\bar{a}' contained conceal cchar=a̅ + + syntax match texSymbolMath '\\dot{A}' contained conceal cchar=Ȧ + syntax match texSymbolMath '\\dot{a}' contained conceal cchar=ȧ + syntax match texSymbolMath '\\dot{B}' contained conceal cchar=Ḃ + syntax match texSymbolMath '\\dot{b}' contained conceal cchar=ḃ + syntax match texSymbolMath '\\dot{C}' contained conceal cchar=Ċ + syntax match texSymbolMath '\\dot{c}' contained conceal cchar=ċ + syntax match texSymbolMath '\\dot{D}' contained conceal cchar=Ḋ + syntax match texSymbolMath '\\dot{d}' contained conceal cchar=ḋ + syntax match texSymbolMath '\\dot{E}' contained conceal cchar=Ė + syntax match texSymbolMath '\\dot{e}' contained conceal cchar=ė + syntax match texSymbolMath '\\dot{F}' contained conceal cchar=Ḟ + syntax match texSymbolMath '\\dot{f}' contained conceal cchar=ḟ + syntax match texSymbolMath '\\dot{G}' contained conceal cchar=Ġ + syntax match texSymbolMath '\\dot{g}' contained conceal cchar=ġ + syntax match texSymbolMath '\\dot{H}' contained conceal cchar=Ḣ + syntax match texSymbolMath '\\dot{h}' contained conceal cchar=ḣ + syntax match texSymbolMath '\\dot{I}' contained conceal cchar=İ + syntax match texSymbolMath '\\dot{M}' contained conceal cchar=Ṁ + syntax match texSymbolMath '\\dot{m}' contained conceal cchar=ṁ + syntax match texSymbolMath '\\dot{N}' contained conceal cchar=Ṅ + syntax match texSymbolMath '\\dot{n}' contained conceal cchar=ṅ + syntax match texSymbolMath '\\dot{O}' contained conceal cchar=Ȯ + syntax match texSymbolMath '\\dot{o}' contained conceal cchar=ȯ + syntax match texSymbolMath '\\dot{P}' contained conceal cchar=Ṗ + syntax match texSymbolMath '\\dot{p}' contained conceal cchar=ṗ + syntax match texSymbolMath '\\dot{R}' contained conceal cchar=Ṙ + syntax match texSymbolMath '\\dot{r}' contained conceal cchar=ṙ + syntax match texSymbolMath '\\dot{S}' contained conceal cchar=Ṡ + syntax match texSymbolMath '\\dot{s}' contained conceal cchar=ṡ + syntax match texSymbolMath '\\dot{T}' contained conceal cchar=Ṫ + syntax match texSymbolMath '\\dot{t}' contained conceal cchar=ṫ + syntax match texSymbolMath '\\dot{W}' contained conceal cchar=Ẇ + syntax match texSymbolMath '\\dot{w}' contained conceal cchar=ẇ + syntax match texSymbolMath '\\dot{X}' contained conceal cchar=Ẋ + syntax match texSymbolMath '\\dot{x}' contained conceal cchar=ẋ + syntax match texSymbolMath '\\dot{Y}' contained conceal cchar=Ẏ + syntax match texSymbolMath '\\dot{y}' contained conceal cchar=ẏ + syntax match texSymbolMath '\\dot{Z}' contained conceal cchar=Ż + syntax match texSymbolMath '\\dot{z}' contained conceal cchar=ż + + syntax match texSymbolMath '\\hat{a}' contained conceal cchar=â + syntax match texSymbolMath '\\hat{A}' contained conceal cchar= + syntax match texSymbolMath '\\hat{c}' contained conceal cchar=ĉ + syntax match texSymbolMath '\\hat{C}' contained conceal cchar=Ĉ + syntax match texSymbolMath '\\hat{e}' contained conceal cchar=ê + syntax match texSymbolMath '\\hat{E}' contained conceal cchar=Ê + syntax match texSymbolMath '\\hat{g}' contained conceal cchar=ĝ + syntax match texSymbolMath '\\hat{G}' contained conceal cchar=Ĝ + syntax match texSymbolMath '\\hat{i}' contained conceal cchar=î + syntax match texSymbolMath '\\hat{I}' contained conceal cchar=Î + syntax match texSymbolMath '\\hat{o}' contained conceal cchar=ô + syntax match texSymbolMath '\\hat{O}' contained conceal cchar=Ô + syntax match texSymbolMath '\\hat{s}' contained conceal cchar=ŝ + syntax match texSymbolMath '\\hat{S}' contained conceal cchar=Ŝ + syntax match texSymbolMath '\\hat{u}' contained conceal cchar=û + syntax match texSymbolMath '\\hat{U}' contained conceal cchar=Û + syntax match texSymbolMath '\\hat{w}' contained conceal cchar=ŵ + syntax match texSymbolMath '\\hat{W}' contained conceal cchar=Ŵ + syntax match texSymbolMath '\\hat{y}' contained conceal cchar=ŷ + syntax match texSymbolMath '\\hat{Y}' contained conceal cchar=Ŷ endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/array.vim b/autoload/vimtex/syntax/p/array.vim index e118a1cb05..2517400bc4 100644 --- a/autoload/vimtex/syntax/p/array.vim +++ b/autoload/vimtex/syntax/p/array.vim @@ -10,24 +10,17 @@ function! vimtex#syntax#p#array#load() abort " {{{1 call vimtex#syntax#p#tabularx#load() - let l:concealends = &encoding ==# 'utf-8' - \ && g:vimtex_syntax_config.conceal.math_delimiters - \ ? 'concealends' : '' - " Change inline math to improve column specifiers, e.g. " " \begin{tabular}{*{3}{>{$}c<{$}}} " " See: https://en.wikibooks.org/wiki/LaTeX/Tables#Column_specification_using_.3E.7B.5Ccmd.7D_and_.3C.7B.5Ccmd.7D - syntax clear texRegionMathX - execute 'syntax region texRegionMathX' - \ 'matchgroup=Delimiter' - \ 'start="\([<>]{\)\@"' + execute 'syntax region texRegionMathX matchgroup=Delimiter' + \ 'start="\([<>]{\)\@ Date: Thu, 29 Oct 2020 23:44:44 +0100 Subject: [PATCH 25/99] wip: minor improvements --- autoload/vimtex/syntax/core.vim | 12 ++++-------- syntax/tex.vim | 5 +++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index c0c9ace1b9..547d5c0c9e 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -5,20 +5,16 @@ " function! vimtex#syntax#core#init() abort " {{{1 - " Syntax may be loaded without the main vimtex functionality, thus we need to - " ensure that the options are loaded! - call vimtex#options#init() + let l:cfg = deepcopy(g:vimtex_syntax_config) + let l:cfg.ext = expand('%:e') + let l:cfg.is_style_document = + \ index(['sty', 'cls', 'clo', 'dtx', 'ltx'], l:cfg.ext) >= 0 syntax spell toplevel syntax sync maxlines=500 syntax sync minlines=50 - let l:cfg = deepcopy(g:vimtex_syntax_config) - let l:cfg.ext = expand('%:e') - let l:cfg.is_style_document = - \ index(['sty', 'cls', 'clo', 'dtx', 'ltx'], l:cfg.ext) >= 0 - " {{{2 Primitives " Match TeX braces in general diff --git a/syntax/tex.vim b/syntax/tex.vim index 3ceb008494..94f2da0332 100644 --- a/syntax/tex.vim +++ b/syntax/tex.vim @@ -12,6 +12,11 @@ if !get(g:, 'vimtex_syntax_enabled', 1) | finish | endif if exists('b:current_syntax') | finish | endif +" Syntax may be loaded without the main vimtex functionality, thus we need to +" ensure that the options are loaded! +call vimtex#options#init() + + " Load core syntax (does not depend on vimtex state) call vimtex#syntax#core#init() From 0db1be9bb7a2b1329ef26d28131589ef1fc2e1cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sat, 31 Oct 2020 00:19:59 +0100 Subject: [PATCH 26/99] fix: allow option group for \author --- autoload/vimtex/syntax/core.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 547d5c0c9e..05559675cb 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -96,8 +96,9 @@ function! vimtex#syntax#core#init() abort " {{{1 " Author and title commands " TODO: Option groups here - syntax match texCmd nextgroup=texArgAuthor skipwhite skipnl "\\author\>" + syntax match texCmd nextgroup=texOptAuthor,texArgAuthor skipwhite skipnl "\\author\>" syntax match texCmd nextgroup=texArgTitle skipwhite skipnl "\\title\>" + call vimtex#syntax#core#new_cmd_opt('texOptAuthor', 'texArgAuthor') call vimtex#syntax#core#new_cmd_arg('texArgAuthor', '', 'texCmd,texComment,@NoSpell') call vimtex#syntax#core#new_cmd_arg('texArgTitle', '', 'texCmd,texComment') @@ -416,7 +417,6 @@ function! s:init_highlights(cfg) abort " {{{1 " Basic TeX highlighting groups highlight def link texArg Include - highlight def link texArgAuthor Identifier highlight def link texArgEnvMathName Delimiter highlight def link texArgEnvName PreCondit highlight def link texArgRef Special @@ -482,6 +482,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texErrorOnlyMath texError highlight def link texMatcherMath texMath highlight def link texSymbolMath texCmd + highlight def link texOptAuthor texOpt highlight def link texOptEqual texSymbol highlight def link texOptFile texOpt highlight def link texOptFiles texOpt From 646752178fe71914a97ac9f9f91e9f5d7f3973fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sat, 31 Oct 2020 01:12:12 +0100 Subject: [PATCH 27/99] wip: release candidate 1 --- autoload/vimtex/syntax/core.vim | 453 +++++++++++++++----------------- 1 file changed, 216 insertions(+), 237 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 05559675cb..6711ebe470 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -95,7 +95,6 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdTodo '\\todo\w*' " Author and title commands - " TODO: Option groups here syntax match texCmd nextgroup=texOptAuthor,texArgAuthor skipwhite skipnl "\\author\>" syntax match texCmd nextgroup=texArgTitle skipwhite skipnl "\\title\>" call vimtex#syntax#core#new_cmd_opt('texOptAuthor', 'texArgAuthor') @@ -284,7 +283,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " {{{2 Math " Math clusters for use in math regions - syntax cluster texClusterMath contains=texCmd,texCmdGreek,texCmdSize,texCmdStyle,texComment,texDelimMath,texDelimMathMod,texLength,texMatcherMath,texMathOper,texSymbolMath,texSpecialChar,texSubscript,texSuperscript,texSymbolAmp,texSymbolDash,@NoSpell + syntax cluster texClusterMath contains=texCmd,texCmdGreek,texCmdSize,texCmdStyle,texComment,texDelimMath,texDelimMathMod,texLength,texMatcherMath,texMathOper,texSymbolMath,texSpecialChar,texMathSub,texMathSuper,texSymbolAmp,texSymbolDash,@NoSpell syntax region texMatcherMath matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath " Math regions: environments @@ -322,7 +321,9 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmd "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texArgMathText call vimtex#syntax#core#new_cmd_arg('texArgMathText', '', 'TOP,@Spell') - " Math delimiters: \left... and \right... + + call s:match_math_sub_super(l:cfg) + call s:match_math_symbols(l:cfg) call s:match_math_delims(l:cfg) " }}}2 @@ -339,21 +340,11 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texSpecialChar '\\hyp\>' contained conceal cchar=- endif - " Many of these symbols were contributed by Björn Winckler - if l:cfg.conceal.math_delimiters - call s:match_conceal_math_symbols() - endif - " Conceal replace greek letters if l:cfg.conceal.greek call s:match_conceal_greek() endif - " Conceal replace superscripts and subscripts - if l:cfg.conceal.super_sub - call s:match_conceal_super_sub(l:cfg) - endif - " Conceal replace accented characters and ligatures if l:cfg.conceal.accents && !l:cfg.is_style_document call s:match_conceal_accents() @@ -473,15 +464,14 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdStyleItalBold texCmd highlight def link texCommentAcronym texComment highlight def link texCommentURL texComment - highlight def link texDelimMathKey texDelimMath - highlight def link texDelimMathSet1 texDelimMath - highlight def link texDelimMathSet2 texDelimMath highlight def link texDelimMathmode texDelim + highlight def link texDelimMathSet texDelimMath highlight def link texErrorMath texError highlight def link texErrorMathDelim texError highlight def link texErrorOnlyMath texError highlight def link texMatcherMath texMath - highlight def link texSymbolMath texCmd + highlight def link texMathSub texMath + highlight def link texMathSuper texMath highlight def link texOptAuthor texOpt highlight def link texOptEqual texSymbol highlight def link texOptFile texOpt @@ -501,12 +491,9 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texRegionMathXX texMath highlight def link texRegionVerb texRegion highlight def link texRegionVerbInline texRegionVerb - highlight def link texSubscript texCmd - highlight def link texSubscripts texSubscript - highlight def link texSuperscript texCmd - highlight def link texSuperscripts texSuperscript highlight def link texSymbolAmp texSymbol highlight def link texSymbolDash texSymbol + highlight def link texSymbolMath texCmd endfunction " }}}1 @@ -540,90 +527,149 @@ function! s:match_bold_italic(cfg) abort " {{{1 \ ['texCmdStyleItal', 'texttt'], \ ['texCmdStyleItal', 'textup'], \] - execute 'syntax match' l:group '"\\' . l:pattern . '\>\s*"' - \ 'skipwhite skipnl nextgroup=' . l:map[l:group] l:conceal + execute 'syntax match' l:group '"\\' . l:pattern . '\>\s*" skipwhite skipnl nextgroup=' . l:map[l:group] l:conceal endfor - execute 'syntax region texStyleBold matchgroup=texDelim start=/{/ end=/}/' - \ 'contained contains=@texClusterBold' l:concealends - execute 'syntax region texStyleItal matchgroup=texDelim start=/{/ end=/}/' - \ 'contained contains=@texClusterItal' l:concealends - execute 'syntax region texStyleBoth matchgroup=texDelim start=/{/ end=/}/' - \ 'contained contains=@texClusterItalBold' l:concealends + execute 'syntax region texStyleBold matchgroup=texDelim start=/{/ end=/}/ contained contains=@texClusterBold' l:concealends + execute 'syntax region texStyleItal matchgroup=texDelim start=/{/ end=/}/ contained contains=@texClusterItal' l:concealends + execute 'syntax region texStyleBoth matchgroup=texDelim start=/{/ end=/}/ contained contains=@texClusterItalBold' l:concealends endfunction " }}}1 -function! s:match_math_delims(cfg) abort " {{{1 - syntax match texDelimMathMod contained skipwhite nextgroup=texDelimMath "\\\(left\|right\)\>" - syntax match texDelimMathMod contained skipwhite nextgroup=texDelimMath "\\[bB]igg\?[lr]\?\>" - syntax match texDelimMath contained "[<>()[\]|/.]\|\\[{}|]" - syntax match texDelimMath contained "\\backslash" - syntax match texDelimMath contained "\\downarrow" - syntax match texDelimMath contained "\\Downarrow" - syntax match texDelimMath contained "\\lVert" - syntax match texDelimMath contained "\\langle" - syntax match texDelimMath contained "\\lbrace" - syntax match texDelimMath contained "\\lceil" - syntax match texDelimMath contained "\\lfloor" - syntax match texDelimMath contained "\\lgroup" - syntax match texDelimMath contained "\\lmoustache" - syntax match texDelimMath contained "\\lvert" - syntax match texDelimMath contained "\\rVert" - syntax match texDelimMath contained "\\rangle" - syntax match texDelimMath contained "\\rbrace" - syntax match texDelimMath contained "\\rceil" - syntax match texDelimMath contained "\\rfloor" - syntax match texDelimMath contained "\\rgroup" - syntax match texDelimMath contained "\\rmoustache" - syntax match texDelimMath contained "\\rvert" - syntax match texDelimMath contained "\\uparrow" - syntax match texDelimMath contained "\\Uparrow" - syntax match texDelimMath contained "\\updownarrow" - syntax match texDelimMath contained "\\Updownarrow" - if !a:cfg.conceal.math_delimiters || &encoding !=# 'utf-8' - return - endif +function! s:match_math_sub_super(cfg) " {{{1 + if !a:cfg.conceal.super_sub | return | endif - syntax match texDelimMath contained conceal cchar=< "\\\%([bB]igg\?l\|left\)<" - syntax match texDelimMath contained conceal cchar=> "\\\%([bB]igg\?r\|right\)>" - syntax match texDelimMath contained conceal cchar=( "\\\%([bB]igg\?l\|left\)(" - syntax match texDelimMath contained conceal cchar=) "\\\%([bB]igg\?r\|right\))" - syntax match texDelimMath contained conceal cchar=[ "\\\%([bB]igg\?l\|left\)\[" - syntax match texDelimMath contained conceal cchar=] "\\\%([bB]igg\?r\|right\)]" - syntax match texDelimMath contained conceal cchar={ "\\\%([bB]igg\?l\|left\)\\{" - syntax match texDelimMath contained conceal cchar=} "\\\%([bB]igg\?r\|right\)\\}" - syntax match texDelimMath contained conceal cchar=[ "\\\%([bB]igg\?l\|left\)\\lbrace" - syntax match texDelimMath contained conceal cchar=⌈ "\\\%([bB]igg\?l\|left\)\\lceil" - syntax match texDelimMath contained conceal cchar=⌊ "\\\%([bB]igg\?l\|left\)\\lfloor" - syntax match texDelimMath contained conceal cchar=⌊ "\\\%([bB]igg\?l\|left\)\\lgroup" - syntax match texDelimMath contained conceal cchar=⎛ "\\\%([bB]igg\?l\|left\)\\lmoustache" - syntax match texDelimMath contained conceal cchar=] "\\\%([bB]igg\?r\|right\)\\rbrace" - syntax match texDelimMath contained conceal cchar=⌉ "\\\%([bB]igg\?r\|right\)\\rceil" - syntax match texDelimMath contained conceal cchar=⌋ "\\\%([bB]igg\?r\|right\)\\rfloor" - syntax match texDelimMath contained conceal cchar=⌋ "\\\%([bB]igg\?r\|right\)\\rgroup" - syntax match texDelimMath contained conceal cchar=⎞ "\\\%([bB]igg\?r\|right\)\\rmoustache" - syntax match texDelimMath contained conceal cchar=| "\\\%([bB]igg\?[lr]\?\|left\|right\)|" - syntax match texDelimMath contained conceal cchar=‖ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\|" - syntax match texDelimMath contained conceal cchar=↓ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\downarrow" - syntax match texDelimMath contained conceal cchar=⇓ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Downarrow" - syntax match texDelimMath contained conceal cchar=↑ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\uparrow" - syntax match texDelimMath contained conceal cchar=↑ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Uparrow" - syntax match texDelimMath contained conceal cchar=↕ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\updownarrow" - syntax match texDelimMath contained conceal cchar=⇕ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Updownarrow" + for [l:from, l:to] in filter(copy(s:map_super), + \ {_, x -> x[0][0] ==# '\' || x[0] =~# '[0-9a-zA-W.,:;+-<>/()=]'}) + execute 'syntax match texMathSuper /\^' . l:from . '/ contained conceal cchar=' . l:to 'contains=texMathOper' + endfor - if &ambiwidth ==# 'double' - syntax match texDelimMath contained conceal cchar=〈 "\\\%([bB]igg\?l\|left\)\\langle" - syntax match texDelimMath contained conceal cchar=〉 "\\\%([bB]igg\?r\|right\)\\rangle" - else - syntax match texDelimMath contained conceal cchar=< "\\\%([bB]igg\?l\|left\)\\langle" - syntax match texDelimMath contained conceal cchar=> "\\\%([bB]igg\?r\|right\)\\rangle" - endif + for [l:from, l:to] in filter(copy(s:map_sub), + \ {_, x -> x[0][0] ==# '\' || x[0] =~# '[0-9aehijklmnoprstuvx,+-/().]'}) + execute 'syntax match texMathSub /_' . l:from . '/ contained conceal cchar=' . l:to 'contains=texMathOper' + endfor endfunction +let s:map_sub = [ + \ ['0', '₀'], + \ ['1', '₁'], + \ ['2', '₂'], + \ ['3', '₃'], + \ ['4', '₄'], + \ ['5', '₅'], + \ ['6', '₆'], + \ ['7', '₇'], + \ ['8', '₈'], + \ ['9', '₉'], + \ ['a', 'ₐ'], + \ ['e', 'ₑ'], + \ ['h', 'ₕ'], + \ ['i', 'ᵢ'], + \ ['j', 'ⱼ'], + \ ['k', 'ₖ'], + \ ['l', 'ₗ'], + \ ['m', 'ₘ'], + \ ['n', 'ₙ'], + \ ['o', 'ₒ'], + \ ['p', 'ₚ'], + \ ['r', 'ᵣ'], + \ ['s', 'ₛ'], + \ ['t', 'ₜ'], + \ ['u', 'ᵤ'], + \ ['v', 'ᵥ'], + \ ['x', 'ₓ'], + \ [',', '︐'], + \ ['+', '₊'], + \ ['-', '₋'], + \ ['\/', 'ˏ'], + \ ['(', '₍'], + \ [')', '₎'], + \ ['\.', '‸'], + \ ['r', 'ᵣ'], + \ ['v', 'ᵥ'], + \ ['x', 'ₓ'], + \ ['\\beta\>', 'ᵦ'], + \ ['\\delta\>', 'ᵨ'], + \ ['\\phi\>', 'ᵩ'], + \ ['\\gamma\>', 'ᵧ'], + \ ['\\chi\>', 'ᵪ'], + \] + +let s:map_super = [ + \ ['0', '⁰'], + \ ['1', '¹'], + \ ['2', '²'], + \ ['3', '³'], + \ ['4', '⁴'], + \ ['5', '⁵'], + \ ['6', '⁶'], + \ ['7', '⁷'], + \ ['8', '⁸'], + \ ['9', '⁹'], + \ ['a', 'ᵃ'], + \ ['b', 'ᵇ'], + \ ['c', 'ᶜ'], + \ ['d', 'ᵈ'], + \ ['e', 'ᵉ'], + \ ['f', 'ᶠ'], + \ ['g', 'ᵍ'], + \ ['h', 'ʰ'], + \ ['i', 'ⁱ'], + \ ['j', 'ʲ'], + \ ['k', 'ᵏ'], + \ ['l', 'ˡ'], + \ ['m', 'ᵐ'], + \ ['n', 'ⁿ'], + \ ['o', 'ᵒ'], + \ ['p', 'ᵖ'], + \ ['r', 'ʳ'], + \ ['s', 'ˢ'], + \ ['t', 'ᵗ'], + \ ['u', 'ᵘ'], + \ ['v', 'ᵛ'], + \ ['w', 'ʷ'], + \ ['x', 'ˣ'], + \ ['y', 'ʸ'], + \ ['z', 'ᶻ'], + \ ['A', 'ᴬ'], + \ ['B', 'ᴮ'], + \ ['D', 'ᴰ'], + \ ['E', 'ᴱ'], + \ ['G', 'ᴳ'], + \ ['H', 'ᴴ'], + \ ['I', 'ᴵ'], + \ ['J', 'ᴶ'], + \ ['K', 'ᴷ'], + \ ['L', 'ᴸ'], + \ ['M', 'ᴹ'], + \ ['N', 'ᴺ'], + \ ['O', 'ᴼ'], + \ ['P', 'ᴾ'], + \ ['R', 'ᴿ'], + \ ['T', 'ᵀ'], + \ ['U', 'ᵁ'], + \ ['V', 'ⱽ'], + \ ['W', 'ᵂ'], + \ [',', '︐'], + \ [':', '︓'], + \ [';', '︔'], + \ ['+', '⁺'], + \ ['-', '⁻'], + \ ['<', '˂'], + \ ['>', '˃'], + \ ['\/', 'ˊ'], + \ ['(', '⁽'], + \ [')', '⁾'], + \ ['\.', '˙'], + \ ['=', '˭'], + \] + " }}}1 +function! s:match_math_symbols(cfg) abort " {{{1 + " Many of these symbols were contributed by Björn Winckler + if !a:cfg.conceal.math_delimiters | return | endif -function! s:match_conceal_math_symbols() abort " {{{1 syntax match texSymbolMath "\\|" contained conceal cchar=‖ syntax match texSymbolMath "\\aleph\>" contained conceal cchar=ℵ syntax match texSymbolMath "\\amalg\>" contained conceal cchar=∐ @@ -795,13 +841,9 @@ function! s:match_conceal_math_symbols() abort " {{{1 syntax match texSymbolMath "\\wr\>" contained conceal cchar=≀ if &ambiwidth ==# 'double' - syntax match texSymbolMath "right\\rangle\>" contained conceal cchar=〉 - syntax match texSymbolMath "left\\langle\>" contained conceal cchar=〈 syntax match texSymbolMath '\\gg\>' contained conceal cchar=≫ syntax match texSymbolMath '\\ll\>' contained conceal cchar=≪ else - syntax match texSymbolMath "right\\rangle\>" contained conceal cchar=> - syntax match texSymbolMath "left\\langle\>" contained conceal cchar=< syntax match texSymbolMath '\\gg\>' contained conceal cchar=⟫ syntax match texSymbolMath '\\ll\>' contained conceal cchar=⟪ endif @@ -871,17 +913,86 @@ function! s:match_conceal_math_symbols() abort " {{{1 endfunction " }}}1 +function! s:match_math_delims(cfg) abort " {{{1 + syntax match texDelimMathMod contained skipwhite nextgroup=texDelimMathSet "\\\(left\|right\)\>" + syntax match texDelimMathMod contained skipwhite nextgroup=texDelimMathSet "\\[bB]igg\?[lr]\?\>" + syntax match texDelimMathSet contained "[<>()[\]|/.]\|\\[{}|]" + syntax match texDelimMathSet contained "\\backslash" + syntax match texDelimMathSet contained "\\downarrow" + syntax match texDelimMathSet contained "\\Downarrow" + syntax match texDelimMathSet contained "\\lVert" + syntax match texDelimMathSet contained "\\langle" + syntax match texDelimMathSet contained "\\lbrace" + syntax match texDelimMathSet contained "\\lceil" + syntax match texDelimMathSet contained "\\lfloor" + syntax match texDelimMathSet contained "\\lgroup" + syntax match texDelimMathSet contained "\\lmoustache" + syntax match texDelimMathSet contained "\\lvert" + syntax match texDelimMathSet contained "\\rVert" + syntax match texDelimMathSet contained "\\rangle" + syntax match texDelimMathSet contained "\\rbrace" + syntax match texDelimMathSet contained "\\rceil" + syntax match texDelimMathSet contained "\\rfloor" + syntax match texDelimMathSet contained "\\rgroup" + syntax match texDelimMathSet contained "\\rmoustache" + syntax match texDelimMathSet contained "\\rvert" + syntax match texDelimMathSet contained "\\uparrow" + syntax match texDelimMathSet contained "\\Uparrow" + syntax match texDelimMathSet contained "\\updownarrow" + syntax match texDelimMathSet contained "\\Updownarrow" + + if !a:cfg.conceal.math_delimiters || &encoding !=# 'utf-8' + return + endif + + syntax match texDelimMath contained conceal cchar=< "\\\%([bB]igg\?l\|left\)<" + syntax match texDelimMath contained conceal cchar=> "\\\%([bB]igg\?r\|right\)>" + syntax match texDelimMath contained conceal cchar=( "\\\%([bB]igg\?l\|left\)(" + syntax match texDelimMath contained conceal cchar=) "\\\%([bB]igg\?r\|right\))" + syntax match texDelimMath contained conceal cchar=[ "\\\%([bB]igg\?l\|left\)\[" + syntax match texDelimMath contained conceal cchar=] "\\\%([bB]igg\?r\|right\)]" + syntax match texDelimMath contained conceal cchar={ "\\\%([bB]igg\?l\|left\)\\{" + syntax match texDelimMath contained conceal cchar=} "\\\%([bB]igg\?r\|right\)\\}" + syntax match texDelimMath contained conceal cchar=[ "\\\%([bB]igg\?l\|left\)\\lbrace" + syntax match texDelimMath contained conceal cchar=⌈ "\\\%([bB]igg\?l\|left\)\\lceil" + syntax match texDelimMath contained conceal cchar=⌊ "\\\%([bB]igg\?l\|left\)\\lfloor" + syntax match texDelimMath contained conceal cchar=⌊ "\\\%([bB]igg\?l\|left\)\\lgroup" + syntax match texDelimMath contained conceal cchar=⎛ "\\\%([bB]igg\?l\|left\)\\lmoustache" + syntax match texDelimMath contained conceal cchar=] "\\\%([bB]igg\?r\|right\)\\rbrace" + syntax match texDelimMath contained conceal cchar=⌉ "\\\%([bB]igg\?r\|right\)\\rceil" + syntax match texDelimMath contained conceal cchar=⌋ "\\\%([bB]igg\?r\|right\)\\rfloor" + syntax match texDelimMath contained conceal cchar=⌋ "\\\%([bB]igg\?r\|right\)\\rgroup" + syntax match texDelimMath contained conceal cchar=⎞ "\\\%([bB]igg\?r\|right\)\\rmoustache" + syntax match texDelimMath contained conceal cchar=| "\\\%([bB]igg\?[lr]\?\|left\|right\)|" + syntax match texDelimMath contained conceal cchar=‖ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\|" + syntax match texDelimMath contained conceal cchar=↓ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\downarrow" + syntax match texDelimMath contained conceal cchar=⇓ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Downarrow" + syntax match texDelimMath contained conceal cchar=↑ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\uparrow" + syntax match texDelimMath contained conceal cchar=↑ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Uparrow" + syntax match texDelimMath contained conceal cchar=↕ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\updownarrow" + syntax match texDelimMath contained conceal cchar=⇕ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Updownarrow" + + if &ambiwidth ==# 'double' + syntax match texDelimMath contained conceal cchar=〈 "\\\%([bB]igg\?l\|left\)\\langle" + syntax match texDelimMath contained conceal cchar=〉 "\\\%([bB]igg\?r\|right\)\\rangle" + else + syntax match texDelimMath contained conceal cchar=< "\\\%([bB]igg\?l\|left\)\\langle" + syntax match texDelimMath contained conceal cchar=> "\\\%([bB]igg\?r\|right\)\\rangle" + endif +endfunction + +" }}}1 + function! s:match_conceal_accents() " {{{1 for [l:chr; l:targets] in s:map_accents for i in range(13) - if empty(l:targets[i]) | continue | endif - let l:accent = s:key_accents[i] - let l:target = l:targets[i] - if l:accent =~# '\a' - execute 'syntax match texCmdAccent /' . l:accent . '\%(\s*{' . l:chr . '}\|\s\+' . l:chr . '\)' . '/ conceal cchar=' . l:target - else - execute 'syntax match texCmdAccent /' . l:accent . '\s*\%({' . l:chr . '}\|' . l:chr . '\)' . '/ conceal cchar=' . l:target - endif + let l:target = l:targets[i] + let l:accent = s:key_accents[i] + if empty(l:target) | continue | endif + + let l:re = l:accent . '\%(\s*{' . l:chr . '}\|' + \ . (l:accent =~# '\a' ? '\s\+' : '\s*') . l:chr . '\)' + execute 'syntax match texCmdAccent /' . l:re . '/ conceal cchar=' . l:target endfor endfor @@ -1001,135 +1112,3 @@ function! s:match_conceal_greek() " {{{1 endfunction " }}}1 -function! s:match_conceal_super_sub(cfg) " {{{1 - syntax region texSuperscript matchgroup=texDelim start='\^{' skip="\\\\\|\\}" end='}' contained concealends contains=texSpecialChar,texSuperscripts,texCmd,texSubscript,texSuperscript,texMatcherMath - syntax region texSubscript matchgroup=texDelim start='_{' skip="\\\\\|\\}" end='}' contained concealends contains=texSpecialChar,texSubscripts,texCmd,texSubscript,texSuperscript,texMatcherMath - - for [l:from, l:to] in filter(copy(s:map_super), - \ {_, x -> x[0][0] ==# '\' || x[0] =~# '[0-9a-zA-W.,:;+-<>/()=]'}) - execute 'syntax match texSuperscript /\^' . l:from . '/ contained conceal cchar=' . l:to - execute 'syntax match texSuperscripts /' . l:from . '/ contained conceal cchar=' . l:to 'nextgroup=texSuperscripts' - endfor - - for [l:from, l:to] in filter(copy(s:map_sub), - \ {_, x -> x[0][0] ==# '\' || x[0] =~# '[0-9aehijklmnoprstuvx,+-/().]'}) - execute 'syntax match texSubscript /_' . l:from . '/ contained conceal cchar=' . l:to - execute 'syntax match texSubscripts /' . l:from . '/ contained conceal cchar=' . l:to . ' nextgroup=texSubscripts' - endfor -endfunction - -let s:map_sub = [ - \ ['0', '₀'], - \ ['1', '₁'], - \ ['2', '₂'], - \ ['3', '₃'], - \ ['4', '₄'], - \ ['5', '₅'], - \ ['6', '₆'], - \ ['7', '₇'], - \ ['8', '₈'], - \ ['9', '₉'], - \ ['a', 'ₐ'], - \ ['e', 'ₑ'], - \ ['h', 'ₕ'], - \ ['i', 'ᵢ'], - \ ['j', 'ⱼ'], - \ ['k', 'ₖ'], - \ ['l', 'ₗ'], - \ ['m', 'ₘ'], - \ ['n', 'ₙ'], - \ ['o', 'ₒ'], - \ ['p', 'ₚ'], - \ ['r', 'ᵣ'], - \ ['s', 'ₛ'], - \ ['t', 'ₜ'], - \ ['u', 'ᵤ'], - \ ['v', 'ᵥ'], - \ ['x', 'ₓ'], - \ [',', '︐'], - \ ['+', '₊'], - \ ['-', '₋'], - \ ['\/', 'ˏ'], - \ ['(', '₍'], - \ [')', '₎'], - \ ['\.', '‸'], - \ ['r', 'ᵣ'], - \ ['v', 'ᵥ'], - \ ['x', 'ₓ'], - \ ['\\beta\>', 'ᵦ'], - \ ['\\delta\>', 'ᵨ'], - \ ['\\phi\>', 'ᵩ'], - \ ['\\gamma\>', 'ᵧ'], - \ ['\\chi\>', 'ᵪ'], - \] - -let s:map_super = [ - \ ['0', '⁰'], - \ ['1', '¹'], - \ ['2', '²'], - \ ['3', '³'], - \ ['4', '⁴'], - \ ['5', '⁵'], - \ ['6', '⁶'], - \ ['7', '⁷'], - \ ['8', '⁸'], - \ ['9', '⁹'], - \ ['a', 'ᵃ'], - \ ['b', 'ᵇ'], - \ ['c', 'ᶜ'], - \ ['d', 'ᵈ'], - \ ['e', 'ᵉ'], - \ ['f', 'ᶠ'], - \ ['g', 'ᵍ'], - \ ['h', 'ʰ'], - \ ['i', 'ⁱ'], - \ ['j', 'ʲ'], - \ ['k', 'ᵏ'], - \ ['l', 'ˡ'], - \ ['m', 'ᵐ'], - \ ['n', 'ⁿ'], - \ ['o', 'ᵒ'], - \ ['p', 'ᵖ'], - \ ['r', 'ʳ'], - \ ['s', 'ˢ'], - \ ['t', 'ᵗ'], - \ ['u', 'ᵘ'], - \ ['v', 'ᵛ'], - \ ['w', 'ʷ'], - \ ['x', 'ˣ'], - \ ['y', 'ʸ'], - \ ['z', 'ᶻ'], - \ ['A', 'ᴬ'], - \ ['B', 'ᴮ'], - \ ['D', 'ᴰ'], - \ ['E', 'ᴱ'], - \ ['G', 'ᴳ'], - \ ['H', 'ᴴ'], - \ ['I', 'ᴵ'], - \ ['J', 'ᴶ'], - \ ['K', 'ᴷ'], - \ ['L', 'ᴸ'], - \ ['M', 'ᴹ'], - \ ['N', 'ᴺ'], - \ ['O', 'ᴼ'], - \ ['P', 'ᴾ'], - \ ['R', 'ᴿ'], - \ ['T', 'ᵀ'], - \ ['U', 'ᵁ'], - \ ['V', 'ⱽ'], - \ ['W', 'ᵂ'], - \ [',', '︐'], - \ [':', '︓'], - \ [';', '︔'], - \ ['+', '⁺'], - \ ['-', '⁻'], - \ ['<', '˂'], - \ ['>', '˃'], - \ ['\/', 'ˊ'], - \ ['(', '⁽'], - \ [')', '⁾'], - \ ['\.', '˙'], - \ ['=', '˭'], - \] - -" }}}1 From 1a137efc03e7cc5fa3e8dfad91829e792407be6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sat, 31 Oct 2020 09:28:42 +0100 Subject: [PATCH 28/99] wip: update tikz and pgfplots highlighting --- autoload/vimtex/syntax/p/pgfplots.vim | 34 +++++------ autoload/vimtex/syntax/p/tikz.vim | 34 ++++------- test/tests/test-syntax/test-large.tex | 85 -------------------------- test/tests/test-syntax/test-large.vim | 8 +-- test/tests/test-syntax/test-tikz.tex | 88 +++++++++++++++++++++++++++ test/tests/test-syntax/test-tikz.vim | 11 ++++ 6 files changed, 130 insertions(+), 130 deletions(-) create mode 100644 test/tests/test-syntax/test-tikz.tex create mode 100644 test/tests/test-syntax/test-tikz.vim diff --git a/autoload/vimtex/syntax/p/pgfplots.vim b/autoload/vimtex/syntax/p/pgfplots.vim index 1b8919d0ae..7af24e9a3c 100644 --- a/autoload/vimtex/syntax/p/pgfplots.vim +++ b/autoload/vimtex/syntax/p/pgfplots.vim @@ -4,31 +4,29 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#pgfplots#load() abort " {{{1 +function! vimtex#syntax#p#pgfplots#load() abort " if has_key(b:vimtex_syntax, 'pgfplots') | return | endif let b:vimtex_syntax.pgfplots = 1 - " Load Tikz first call vimtex#syntax#p#tikz#load() - " Add texAxisStatement to Tikz cluster - syntax cluster texTikz add=texAxisStatement + syntax cluster texClusterTikz add=texCmdAxis - " Match pgfplotsset and axis environments - syntax match texTikzSet /\\pgfplotsset\>/ - \ contains=texCmd skipwhite nextgroup=texTikzOptsCurly - syntax match texTikzEnv /\v\\begin\{%(log)*axis}/ - \ contains=texCmdEnv nextgroup=texTikzOpts skipwhite - syntax match texTikzEnv /\v\\begin\{groupplot}/ - \ contains=texCmdEnv nextgroup=texTikzOpts skipwhite + syntax match texCmd nextgroup=texArgTikzset skipwhite "\\pgfplotsset\>" - " Match some custom pgfplots macros - syntax match texAxisStatement /\\addplot3\>/ - \ contained skipwhite nextgroup=texTikzOpts - syntax match texAxisStatement /\\nextgroupplot\>/ - \ contained skipwhite nextgroup=texTikzOpts + syntax match texCmdAxis contained nextgroup=texOptTikzpic skipwhite "\\addplot3\?\>" + syntax match texCmdAxis contained nextgroup=texOptTikzpic skipwhite "\\nextgroupplot\>" - highlight def link texAxisStatement texCmd + syntax match texEnvBgnTikz contains=texCmdEnv nextgroup=texOptTikzpic skipwhite skipnl "\\begin{\%(log\)*axis}" + syntax match texEnvBgnTikz contains=texCmdEnv nextgroup=texOptTikzpic skipwhite skipnl "\\begin{groupplot}" + syntax region texRegionTikz + \ start="\\begin{\z(\%(log\)*axis\)}" end="\\end{\z1}" + \ keepend transparent contains=@texClusterTikz + syntax region texRegionTikz + \ start="\\begin{groupplot}" end="\\end{groupplot}" + \ keepend transparent contains=@texClusterTikz + + highlight def link texCmdAxis texCmd endfunction -" }}}1 +" diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index f7c9892aed..ceb33410ce 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -8,33 +8,23 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 if has_key(b:vimtex_syntax, 'tikz') | return | endif let b:vimtex_syntax.tikz = 1 - " Define clusters - syntax cluster texTikz contains=texTikzEnv,texCmdEnv,texCmd,texTikzSemicolon,texComment,@texVimtexGlobal - syntax cluster texTikzOS contains=texTikzOptsCurly,texTikzEqual,texRegionMathX,texTypeSize,texCmd,texLength,texComment + syntax cluster texClusterTikz contains=texEnvBgnTikz,texCmdEnv,texCmd,texTikzSemicolon,texComment,texMatcher + syntax cluster texClusterTikzset contains=texArgTikzset,texOptSep,texOptEqual,texRegionMathX,texTypeSize,texCmd,texLength,texComment - " Define tikz option groups - syntax match texTikzSet /\\tikzset\>/ - \ contains=texCmd skipwhite nextgroup=texTikzOptsCurly - syntax region texTikzOpts matchgroup=Delimiter - \ start='\[' end='\]' contained contains=@texTikzOS - syntax region texTikzOptsCurly matchgroup=Delimiter - \ start='{' end='}' contained contains=@texTikzOS + syntax match texCmd /\\tikzset\>/ skipwhite skipnl nextgroup=texArgTikzset + call vimtex#syntax#core#new_cmd_arg('texArgTikzset', '', '@texClusterTikzset') - syntax region texTikzpicture - \ start='\\begin{tikzpicture}'rs=s - \ end='\\end{tikzpicture}'re=e - \ keepend - \ transparent - \ contains=@texTikz - syntax match texTikzEnv /\v\\begin\{tikzpicture\}/ - \ contains=texCmdEnv nextgroup=texTikzOpts skipwhite + syntax match texEnvBgnTikz /\v\\begin\{tikzpicture\}/ + \ nextgroup=texOptTikzpic skipwhite skipnl contains=texCmdEnv + syntax region texRegionTikz + \ start='\\begin{tikzpicture}' + \ end='\\end{tikzpicture}' + \ keepend transparent contains=@texClusterTikz + call vimtex#syntax#core#new_cmd_opt('texOptTikzpic', '', '@texClusterTikzset') - syntax match texTikzEqual /=/ contained syntax match texTikzSemicolon /;/ contained - highlight def link texTikzEqual Operator - highlight def link texTikzSemicolon Delimiter + highlight def link texTikzSemicolon texDelim endfunction " }}}1 - diff --git a/test/tests/test-syntax/test-large.tex b/test/tests/test-syntax/test-large.tex index 5a9b646909..772dcffdce 100644 --- a/test/tests/test-syntax/test-large.tex +++ b/test/tests/test-syntax/test-large.tex @@ -18,8 +18,6 @@ \usepackage[inline]{asymptote} \usepackage{pythontex} \usepackage{listings} -\usepackage{tikz} -\usepackage{pgfplots} \begin{document} @@ -277,87 +275,4 @@ \section{Package: listings} } \end{lstlisting} -\section{Package: Tikz/pgfplots} - -\tikzset{ - a = b, -} - -\pgfplotsset{ - a = b, -} - -\begin{figure} - \centering - \begin{tikzpicture}[ - font = \small, - % A comment here - xlabel = $f(x)$, - very thick, - ] - - % A simple line - \draw (0,0) -- (1,0); - \end{tikzpicture} - \caption{A simple tikz example.} - \label{fig:tikz-example} -\end{figure} - -\begin{figure}[tbp] - \centering - \begin{tikzpicture} - \begin{groupplot}[ - height=0.35\textwidth, - width=0.375\textwidth, - xlabel={$V_0$ [\si{\meter\cubed}]}, - ylabel={$t$ [\si{\second}]}, - xmax=26, - ymax=90, - grid=both, - grid style={line width=.2pt, draw=gray!20}, - group style={ - group size=3 by 1, - horizontal sep=0.5cm, - x descriptions at=edge bottom, - y descriptions at=edge left, - }, - table/x = V0, - table/y = t_RPT, - domain=0.05:25.26, - ] - - \nextgroupplot[ - title={Composition $z_1$}, - legend columns=3, - transpose legend, - legend style={ - at={(0.05,1.20)}, - /tikz/column 2/.style={ - column sep=5pt, - }, - anchor=south west, - }, - ] - \addplot[cl3-1] {t_rpt(x, 437.0, 0.6*0.135294, 0.891)}; - \addplot[cl3-1, sim] table {data/instspill_m0_eps0.6.csv}; - \addlegendentry{$\epsilon = 1.2$} - \addlegendentry{Simulation} - - \nextgroupplot[ - title={Composition $z_2$}, - ] - \addplot[cl3-1] {t_rpt(x, 437.0, 0.6*0.135294, 0.781)}; - \addplot[cl3-3, sim] table {data/instspill_m1_eps1.2.csv}; - - \nextgroupplot[ - title={Composition $z_3$}, - ] - \addplot[cl3-1] {t_rpt(x, 437.0, 0.6*0.135294, 0.672)}; - \addplot[cl3-3, sim] table {data/instspill_m2_eps1.2.csv}; - \end{groupplot} - \end{tikzpicture} - \caption{This example will not compile!} - \label{fig:instspill-t} -\end{figure} - \end{document} diff --git a/test/tests/test-syntax/test-large.vim b/test/tests/test-syntax/test-large.vim index b3162b40c6..a3dfd96577 100644 --- a/test/tests/test-syntax/test-large.vim +++ b/test/tests/test-syntax/test-large.vim @@ -5,14 +5,12 @@ let g:vimtex_fold_enabled = 1 silent edit test-large.tex -syntax sync fromstart - if empty($INMAKE) | finish | endif -call vimtex#test#assert_equal(len(keys(b:vimtex_syntax)), 20) +call vimtex#test#assert_equal(len(keys(b:vimtex_syntax)), 18) " PythonTeX inside tikzpictures (#1563) -call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 243, 11)) -call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 248, 11)) +call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 241, 11)) +call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 246, 11)) quit! diff --git a/test/tests/test-syntax/test-tikz.tex b/test/tests/test-syntax/test-tikz.tex new file mode 100644 index 0000000000..87bc192357 --- /dev/null +++ b/test/tests/test-syntax/test-tikz.tex @@ -0,0 +1,88 @@ +\documentclass{article} +\usepackage{tikz} +\usepackage{pgfplots} + +\begin{document} + +\tikzset{ + a = b, +} + +\pgfplotsset{ + a = b, +} + +\begin{figure} + \centering + \begin{tikzpicture}[ + font = \small, + % A comment here + xlabel = $f(x)$, + very thick, + ] + + % A simple line + \draw (0,0) -- (1,0); + \end{tikzpicture} + \caption{A simple tikz example.} + \label{fig:tikz-example} +\end{figure} + +\begin{figure}[tbp] + \centering + \begin{tikzpicture} + \begin{groupplot}[ + height=0.35\textwidth, + width=0.375\textwidth, + xlabel={$V_0$ [\si{\meter\cubed}]}, + ylabel={$t$ [\si{\second}]}, + xmax=26, + ymax=90, + grid=both, + grid style={line width=.2pt, draw=gray!20}, + group style={ + group size=3 by 1, + horizontal sep=0.5cm, + x descriptions at=edge bottom, + y descriptions at=edge left, + }, + table/x = V0, + table/y = t_RPT, + domain=0.05:25.26, + ] + + \nextgroupplot[ + title={Composition $z_1$}, + legend columns=3, + transpose legend, + legend style={ + at={(0.05,1.20)}, + /tikz/column 2/.style={ + column sep=5pt, + }, + anchor=south west, + }, + ] + \addplot[cl3-1] {t_rpt(x, 437.0, 0.6*0.135294, 0.891)}; + \addplot[cl3-1, sim] table {data/instspill_m0_eps0.6.csv}; + \addlegendentry{$\epsilon = 1.2$} + \addlegendentry{Simulation} + + \nextgroupplot[ + title={Composition $z_2$}, + ] + \addplot[cl3-1] {t_rpt(x, 437.0, 0.6*0.135294, 0.781)}; + \addplot[cl3-3, sim] table {data/instspill_m1_eps1.2.csv}; + + \nextgroupplot[ + title={Composition $z_3$}, + ] + \addplot[cl3-1] {t_rpt(x, 437.0, 0.6*0.135294, 0.672)}; + \addplot[cl3-3, sim] table {data/instspill_m2_eps1.2.csv}; + \end{groupplot} + \end{tikzpicture} + \caption{This example will not compile!} + \label{fig:instspill-t} +\end{figure} + +\end{document} diff --git a/test/tests/test-syntax/test-tikz.vim b/test/tests/test-syntax/test-tikz.vim new file mode 100644 index 0000000000..357cfa8f5d --- /dev/null +++ b/test/tests/test-syntax/test-tikz.vim @@ -0,0 +1,11 @@ +source common.vim + +silent edit test-tikz.tex + +if empty($INMAKE) | finish | endif + +call vimtex#test#assert(vimtex#syntax#in('texTikzSemicolon', 66, 61)) +call vimtex#test#assert(vimtex#syntax#in('texRegionTikz', 66, 61)) +call vimtex#test#assert(vimtex#syntax#in('texCmdAxis', 71, 9)) + +quit! From c20f43da03529aaa172115da9216ac6df4d26975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 1 Nov 2020 15:48:39 +0100 Subject: [PATCH 29/99] wip: update tabularx syntax matching --- autoload/vimtex/syntax/p/array.vim | 2 +- autoload/vimtex/syntax/p/tabularx.vim | 80 +++++++----------------- test/tests/test-syntax/test-large.tex | 22 ------- test/tests/test-syntax/test-large.vim | 6 +- test/tests/test-syntax/test-tabularx.tex | 26 ++++++++ test/tests/test-syntax/test-tabularx.vim | 10 +++ 6 files changed, 63 insertions(+), 83 deletions(-) create mode 100644 test/tests/test-syntax/test-tabularx.tex create mode 100644 test/tests/test-syntax/test-tabularx.vim diff --git a/autoload/vimtex/syntax/p/array.vim b/autoload/vimtex/syntax/p/array.vim index 2517400bc4..3162e44ec4 100644 --- a/autoload/vimtex/syntax/p/array.vim +++ b/autoload/vimtex/syntax/p/array.vim @@ -15,7 +15,7 @@ function! vimtex#syntax#p#array#load() abort " {{{1 " \begin{tabular}{*{3}{>{$}c<{$}}} " " See: https://en.wikibooks.org/wiki/LaTeX/Tables#Column_specification_using_.3E.7B.5Ccmd.7D_and_.3C.7B.5Ccmd.7D - execute 'syntax region texRegionMathX matchgroup=Delimiter' + execute 'syntax region texRegionMathX matchgroup=texDelim' \ 'start="\([<>]{\)\@]/ - \ containedin=texTabularArg - \ nextgroup=texTabularPostPreArg - \ contained - - syntax region texTabularPostPreArg matchgroup=Delimiter - \ start='{' end='}' - \ containedin=texTabularArg - \ contains=texLength,texCmd,texMathDelimSingle - \ contained - - syntax region texTabularLength matchgroup=Delimiter - \ start='{' end='}' - \ containedin=texTabularArg - \ contains=texLength,texCmd - \ contained - - syntax match texMathDelimSingle /\$\$\?/ - \ containedin=texTabularPostPreArg - \ contained - - highlight def link texTabularCol Directory - highlight def link texTabularAtSep Type - highlight def link texTabularVertline Type - highlight def link texTabularPostPre Type - highlight def link texMathDelimSingle Delimiter + syntax match texTabularCol /[lcr]/ contained + syntax match texTabularCol /[pmb]/ contained nextgroup=texTabularLength + syntax match texTabularCol /\*/ contained nextgroup=texTabularMulti + syntax match texTabularAtSep /@/ contained nextgroup=texTabularLength + syntax match texTabularVertline /||\?/ contained + syntax match texTabularPostPre /[<>]/ contained nextgroup=texTabularPostPreArg + syntax match texDelimMathmodeTab /\$\$\?/ contained + + syntax match texCmdTabular '\\begin{tabular}' + \ nextgroup=texOptEnvModifierTab,texArgTabular skipwhite skipnl contains=texCmdEnv + call vimtex#syntax#core#new_cmd_opt('texOptEnvModifierTab', 'texArgTabular', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texArgTabular', '', 'texTabular.*') + + call vimtex#syntax#core#new_cmd_arg('texTabularMulti', 'texArgTabular') + call vimtex#syntax#core#new_cmd_arg('texTabularLength', '', 'texLength,texCmd') + call vimtex#syntax#core#new_cmd_arg('texTabularPostPreArg', '', 'texLength,texCmd,texDelimMathmodeTab') + + highlight def link texTabularCol texOpt + highlight def link texTabularAtSep texDelimMath + highlight def link texTabularVertline texDelimMath + highlight def link texTabularPostPre texDelimMath + highlight def link texOptEnvModifierTab texOptEnvModifier + highlight def link texDelimMathmodeTab texDelimMathmode endfunction " }}}1 diff --git a/test/tests/test-syntax/test-large.tex b/test/tests/test-syntax/test-large.tex index 772dcffdce..7d27691db9 100644 --- a/test/tests/test-syntax/test-large.tex +++ b/test/tests/test-syntax/test-large.tex @@ -7,8 +7,6 @@ \usepackage{biblatex} \usepackage{csquotes} \usepackage{cleveref} -\usepackage{tabularx} -\usepackage{array} \usepackage{varioref} \usepackage{amsmath} \usepackage{cases} @@ -92,26 +90,6 @@ \section{Package: cleveref} \cref{eq:test} \crefrange{eq:test}{eq:test2} -\section{Package: tabularx and array} -\begin{tabular}{*{3}{>{$}c<{$}}} - \hline - Hello world !\tabularnewline - \hline -\end{tabular} - -\begin{tabular}{l*{4}{m{1cm}}} - \hline - Hello world !\tabularnewline - \hline -\end{tabular} - -% Array specific math separators -\begin{tabular}[ht]{|>{\centering$}@{.}m{1cm}<{$}|} - \hline - Hello world !\tabularnewline - \hline -\end{tabular} - \section{Package: varioref} \Vref{sec_one} does what you need. Still \vref{sec_one} works. diff --git a/test/tests/test-syntax/test-large.vim b/test/tests/test-syntax/test-large.vim index a3dfd96577..feebe00ba5 100644 --- a/test/tests/test-syntax/test-large.vim +++ b/test/tests/test-syntax/test-large.vim @@ -7,10 +7,10 @@ silent edit test-large.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert_equal(len(keys(b:vimtex_syntax)), 18) +call vimtex#test#assert_equal(len(keys(b:vimtex_syntax)), 16) " PythonTeX inside tikzpictures (#1563) -call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 241, 11)) -call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 246, 11)) +call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 219, 11)) +call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 224, 11)) quit! diff --git a/test/tests/test-syntax/test-tabularx.tex b/test/tests/test-syntax/test-tabularx.tex new file mode 100644 index 0000000000..4d7c9f5827 --- /dev/null +++ b/test/tests/test-syntax/test-tabularx.tex @@ -0,0 +1,26 @@ +\documentclass{article} +\usepackage{tabularx} +\usepackage{array} + +\begin{document} + +\begin{tabular}{*{3}{>{$}c<{$}}} + \hline + Hello world !\tabularnewline + \hline +\end{tabular} + +\begin{tabular}{l*{4}{m{1cm}}} + \hline + Hello world !\tabularnewline + \hline +\end{tabular} + +% Array specific math separators +\begin{tabular}[ht]{|>{\centering$}@{.}m{1cm}<{$}|} + \hline + Hello world !\tabularnewline + \hline +\end{tabular} + +\end{document} diff --git a/test/tests/test-syntax/test-tabularx.vim b/test/tests/test-syntax/test-tabularx.vim new file mode 100644 index 0000000000..b8316860e7 --- /dev/null +++ b/test/tests/test-syntax/test-tabularx.vim @@ -0,0 +1,10 @@ +source common.vim + +silent edit test-tabularx.tex + +if empty($INMAKE) | finish | endif + +call vimtex#test#assert(vimtex#syntax#in('texTabularCol', 7, 17)) +call vimtex#test#assert(vimtex#syntax#in('texDelimMathmodeTab', 7, 24)) + +quit! From f0161c1ff157095ceaac82bdecdc1a0361fe88e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 1 Nov 2020 23:51:25 +0100 Subject: [PATCH 30/99] wip: updated a lot of packages --- autoload/vimtex/syntax/core.vim | 20 ++-- .../vimtex/syntax/{misc.vim => nested.vim} | 4 +- autoload/vimtex/syntax/p/amsmath.vim | 15 +-- autoload/vimtex/syntax/p/asymptote.vim | 16 ++-- autoload/vimtex/syntax/p/biblatex.vim | 95 ++++++------------- autoload/vimtex/syntax/p/cleveref.vim | 31 +++--- autoload/vimtex/syntax/p/csquotes.vim | 5 +- autoload/vimtex/syntax/p/dot2texi.vim | 10 +- autoload/vimtex/syntax/p/glossaries.vim | 7 +- autoload/vimtex/syntax/p/gnuplottex.vim | 6 +- autoload/vimtex/syntax/p/listings.vim | 16 ++-- autoload/vimtex/syntax/p/luacode.vim | 6 +- autoload/vimtex/syntax/p/markdown.vim | 2 +- autoload/vimtex/syntax/p/minted.vim | 14 +-- autoload/vimtex/syntax/p/pythontex.vim | 10 +- autoload/vimtex/syntax/p/wiki.vim | 4 +- syntax/tex.vim | 2 +- test/tests/test-syntax/test-large.tex | 2 +- 18 files changed, 107 insertions(+), 158 deletions(-) rename autoload/vimtex/syntax/{misc.vim => nested.vim} (89%) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 6711ebe470..a9f6212320 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -69,7 +69,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " Accents and ligatures syntax match texCmdAccent "\\[bcdvuH]$" syntax match texCmdAccent "\\[bcdvuH]\ze\A" - syntax match texCmdAccent /\\[=^.\~"`']/ + syntax match texCmdAccent /\\[=^.~"`']/ syntax match texCmdAccent /\\['=t'.c^ud"vb~Hr]{\a}/ syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)$" syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze\A" @@ -95,10 +95,10 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdTodo '\\todo\w*' " Author and title commands - syntax match texCmd nextgroup=texOptAuthor,texArgAuthor skipwhite skipnl "\\author\>" - syntax match texCmd nextgroup=texArgTitle skipwhite skipnl "\\title\>" + syntax match texCmdAuthor nextgroup=texOptAuthor,texArgAuthor skipwhite skipnl "\\author\>" + syntax match texCmdTitle nextgroup=texArgTitle skipwhite skipnl "\\title\>" call vimtex#syntax#core#new_cmd_opt('texOptAuthor', 'texArgAuthor') - call vimtex#syntax#core#new_cmd_arg('texArgAuthor', '', 'texCmd,texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texArgAuthor', '', 'texCmd,texCmdAccent,texCmdLigature,texSpecialChar,texComment,@NoSpell') call vimtex#syntax#core#new_cmd_arg('texArgTitle', '', 'texCmd,texComment') " Various commands that take a file argument (or similar) @@ -220,8 +220,8 @@ function! vimtex#syntax#core#init() abort " {{{1 " Add @NoSpell for commands per configuration for l:macro in g:vimtex_syntax_nospell_commands - execute 'syntax match texCmd skipwhite skipnl "\\' . l:macro . '"' - \ 'nextgroup=texArgNoSpell' + execute 'syntax match texCmd nextgroup=texArgNoSpell skipwhite skipnl' + \ '"\\' . l:macro . '"' endfor call vimtex#syntax#core#new_cmd_arg('texArgNoSpell', '', '@NoSpell') @@ -233,6 +233,9 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdParts nextgroup=texArgPartTitle "\\\(sub\)\?paragraph\>" call vimtex#syntax#core#new_cmd_arg('texArgPartTitle', '', 'TOP') + " Item elements in lists + syntax match texCmdItem "\\item\>" + " }}}2 " {{{2 Environments @@ -441,16 +444,18 @@ function! s:init_highlights(cfg) abort " {{{1 " Inherited groups highlight def link texArgDefName texCmd highlight def link texArgFile texArg - highlight def link texArgFiles texArg + highlight def link texArgFiles texArgFile highlight def link texArgNewcmdName texCmd highlight def link texArgNewenvName texArgEnvName highlight def link texArgPartTitle texTitle highlight def link texCmd texCmd highlight def link texCmdAccent texCmd + highlight def link texCmdAuthor texCmd highlight def link texCmdEnv texCmd highlight def link texCmdEnvMath texCmdEnv highlight def link texCmdError texError highlight def link texCmdGreek texCmd + highlight def link texCmdItem texArgEnvName highlight def link texCmdLigature texSpecialChar highlight def link texCmdParts texCmd highlight def link texCmdSize texType @@ -462,6 +467,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdStyleBoldItal texCmd highlight def link texCmdStyleItal texCmd highlight def link texCmdStyleItalBold texCmd + highlight def link texCmdTitle texCmd highlight def link texCommentAcronym texComment highlight def link texCommentURL texComment highlight def link texDelimMathmode texDelim diff --git a/autoload/vimtex/syntax/misc.vim b/autoload/vimtex/syntax/nested.vim similarity index 89% rename from autoload/vimtex/syntax/misc.vim rename to autoload/vimtex/syntax/nested.vim index bc7ed82b6b..5a403c585b 100644 --- a/autoload/vimtex/syntax/misc.vim +++ b/autoload/vimtex/syntax/nested.vim @@ -4,7 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#misc#include(name) abort " {{{1 +function! vimtex#syntax#nested#include(name) abort " {{{1 let l:inc_name = 'vimtex_nested_' . a:name if !has_key(s:included, l:inc_name) @@ -15,7 +15,7 @@ function! vimtex#syntax#misc#include(name) abort " {{{1 endfunction " }}}1 -function! vimtex#syntax#misc#include_reset() abort " {{{1 +function! vimtex#syntax#nested#reset() abort " {{{1 let s:included = {'vimtex_nested_tex': 0} endfunction diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index 5361dd1480..7e31be93e8 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -19,17 +19,12 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 call vimtex#syntax#core#new_math_region('xxalignat', 0) call vimtex#syntax#core#new_math_region('mathpar', 1) - " Amsmath [lr][vV]ert (Holger Mitschke) + " Amsmath [lr][vV]ert if &encoding ==# 'utf-8' && g:vimtex_syntax_config.conceal.math_delimiters - for l:texmath in [ - \ ['\\lvert', '|'] , - \ ['\\rvert', '|'] , - \ ['\\lVert', '‖'] , - \ ['\\rVert', '‖'] , - \ ] - execute "syntax match texDelimMath '\\\\[bB]igg\\=[lr]\\=" - \ . l:texmath[0] . "' contained conceal cchar=" . l:texmath[1] - endfor + syntax match texDelimMath contained conceal cchar=| "\\\%([bB]igg\?l\|left\)\\lvert" + syntax match texDelimMath contained conceal cchar=| "\\\%([bB]igg\?r\|right\)\\rvert" + syntax match texDelimMath contained conceal cchar=‖ "\\\%([bB]igg\?l\|left\)\\lVert" + syntax match texDelimMath contained conceal cchar=‖ "\\\%([bB]igg\?r\|right\)\\rVert" endif endfunction diff --git a/autoload/vimtex/syntax/p/asymptote.vim b/autoload/vimtex/syntax/p/asymptote.vim index 941e3d3cd6..f515882949 100644 --- a/autoload/vimtex/syntax/p/asymptote.vim +++ b/autoload/vimtex/syntax/p/asymptote.vim @@ -8,19 +8,17 @@ function! vimtex#syntax#p#asymptote#load() abort " {{{1 if has_key(b:vimtex_syntax, 'asymptote') | return | endif let b:vimtex_syntax.asymptote = 1 - if !empty(vimtex#syntax#misc#include('asy')) + if !empty(vimtex#syntax#nested#include('asy')) syntax region texRegionAsymptote - \ start='\\begin{asy\z(def\)\?}'rs=s - \ end='\\end{asy\z1}'re=e - \ keepend + \ start="\\begin{asy\z(def\)\?}" + \ end="\\end{asy\z1}" \ transparent - \ contains=texCmdEnv,@vimtex_nested_asy + \ keepend contains=texCmdEnv,@vimtex_nested_asy else syntax region texRegionAsymptote - \ start='\\begin{asy\z(def\)\?}'rs=s - \ end='\\end{asy\z1}'re=e - \ keepend - \ contains=texCmdEnv + \ start="\\begin{asy\z(def\)\?}" + \ end="\\end{asy\z1}" + \ keepend contains=texCmdEnv highlight def link texRegionAsymptote texRegion endif endfunction diff --git a/autoload/vimtex/syntax/p/biblatex.vim b/autoload/vimtex/syntax/p/biblatex.vim index cbe469b6e7..edf6f40583 100644 --- a/autoload/vimtex/syntax/p/biblatex.vim +++ b/autoload/vimtex/syntax/p/biblatex.vim @@ -8,73 +8,34 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 if has_key(b:vimtex_syntax, 'biblatex') | return | endif let b:vimtex_syntax.biblatex = 1 - syntax match texCmd "\\addbibresource\>" nextgroup=texArgFiles - - for l:pattern in [ - \ 'bibentry', - \ 'cite[pt]?\*?', - \ 'citeal[tp]\*?', - \ 'cite(num|text|url)', - \ '[Cc]ite%(title|author|year(par)?|date)\*?', - \ '[Pp]arencite\*?', - \ 'foot%(full)?cite%(text)?', - \ 'fullcite', - \ '[Tt]extcite', - \ '[Ss]martcite', - \ 'supercite', - \ '[Aa]utocite\*?', - \ '[Ppf]?[Nn]otecite', - \ '%(text|block)cquote\*?', - \] - execute 'syntax match texCmd' - \ '/\v\\' . l:pattern . '\ze\s*%(\[|\{)/' - \ 'nextgroup=texRefOption,texRefCite' - endfor - - for l:pattern in [ - \ '[Cc]ites', - \ '[Pp]arencites', - \ 'footcite%(s|texts)', - \ '[Tt]extcites', - \ '[Ss]martcites', - \ 'supercites', - \ '[Aa]utocites', - \ '[pPfFsStTaA]?[Vv]olcites?', - \ 'cite%(field|list|name)', - \] - execute 'syntax match texCmd' - \ '/\v\\' . l:pattern . '\ze\s*%(\[|\{)/' - \ 'nextgroup=texRefOptions,texRefCites' - endfor - - for l:pattern in [ - \ '%(foreign|hyphen)textcquote\*?', - \ '%(foreign|hyphen)blockcquote', - \ 'hybridblockcquote', - \] - execute 'syntax match texCmd' - \ '/\v\\' . l:pattern . '\ze\s*%(\[|\{)/' - \ 'nextgroup=texQuoteLang' - endfor - - syntax region texRefOptions contained matchgroup=Delimiter - \ start='\[' end=']' - \ contains=@texClusterRef,texRegionRef - \ nextgroup=texRefOptions,texRefCites - - syntax region texRefCites contained matchgroup=Delimiter - \ start='{' end='}' - \ contains=@texClusterRef,texRegionRef,texRefCites - \ nextgroup=texRefOptions,texRefCites - - syntax region texQuoteLang contained matchgroup=Delimiter - \ start='{' end='}' - \ transparent - \ contains=@texClusterMG - \ nextgroup=texRefOption,texRefCite - - highlight def link texRefOptions texRefOption - highlight def link texRefCites texRefCite + syntax match texCmd nextgroup=texArgFiles "\\addbibresource\>" + + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\bibentry\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\cite[pt]\?\*\?\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\citeal[tp]\*\?\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\cite\%(num\|text\|url\)\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\[Cc]ite\%(title\|author\|year\%(par\)\?\|date\)\*\?\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\[Pp]arencite\*\?\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\foot\%(full\)\?cite\%(text\)\?\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\fullcite\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\[Tt]extcite\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\[Ss]martcite\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\supercite\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\[Aa]utocite\*\?\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\[Ppf]\?[Nn]otecite\>" + syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\\%(text\|block\)cquote\*\?\>" + + syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\[Cc]ites\>" + syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\[Pp]arencites\>" + syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\footcite\%(s\|texts\)\>" + syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\[Tt]extcites\>" + syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\[Ss]martcites\>" + syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\supercites\>" + syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\[Aa]utocites\>" + syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\[pPfFsStTaA]\?[Vv]olcites\?\>" + syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\cite\%(field\|list\|name\)>" + call vimtex#syntax#core#new_cmd_arg('texArgRefs', 'texOptRefs,texArgRefs', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_opt('texOptRefs', 'texOptRef,texArgRef') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/cleveref.vim b/autoload/vimtex/syntax/p/cleveref.vim index f9df407d7a..2dd1347de4 100644 --- a/autoload/vimtex/syntax/p/cleveref.vim +++ b/autoload/vimtex/syntax/p/cleveref.vim @@ -8,32 +8,23 @@ function! vimtex#syntax#p#cleveref#load() abort " {{{1 if has_key(b:vimtex_syntax, 'cleveref') | return | endif let b:vimtex_syntax.cleveref = 1 - syntax match texCmd '\\\(\(label\)\?c\(page\)\?\|C\)ref\>' - \ nextgroup=texCRefZone + syntax match texCmd nextgroup=texArgCRef skipwhite skipnl + \ "\\\%(\%(label\)\?c\%(page\)\?\|C\)ref\>" " \crefrange, \cpagerefrange (these commands expect two arguments) - syntax match texCmd '\\c\(page\)\?refrange\>' - \ nextgroup=texCRefZoneRange skipwhite skipnl + syntax match texCmd nextgroup=texArgCRefRange skipwhite skipnl + \ "\\c\(page\)\?refrange\>" " \label[xxx]{asd} - syntax match texCmd '\\label\[.\{-}\]' - \ nextgroup=texCRefZone skipwhite skipnl - \ contains=texCRefLabelOpts + syntax match texCmd nextgroup=texOptCRef,texArgRef skipwhite skipnl "\\label\>" - syntax region texCRefZone contained matchgroup=Delimiter - \ start="{" end="}" - \ contains=@texClusterRef,texRegionRef - syntax region texCRefZoneRange contained matchgroup=Delimiter - \ start="{" end="}" - \ contains=@texClusterRef,texRegionRef - \ nextgroup=texCRefZone skipwhite skipnl - syntax region texCRefLabelOpts contained matchgroup=Delimiter - \ start='\[' end=']' - \ contains=@texClusterRef,texRegionRef + call vimtex#syntax#core#new_cmd_arg('texArgCRef', '', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texArgCRefRange', 'texArgCRef', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_opt('texOptCRef', 'texArgRef', '', 'oneline') - highlight link texCRefZone texRegionRef - highlight link texCRefZoneRange texRegionRef - highlight link texCRefLabelOpts texOptNewcmd + highlight link texArgCRef texArgRef + highlight link texArgCRefRange texArgRef + highlight link texOptCRef texOpt endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/csquotes.vim b/autoload/vimtex/syntax/p/csquotes.vim index 8b5a30b61b..1e6e1631be 100644 --- a/autoload/vimtex/syntax/p/csquotes.vim +++ b/autoload/vimtex/syntax/p/csquotes.vim @@ -8,7 +8,10 @@ function! vimtex#syntax#p#csquotes#load() abort " {{{1 if has_key(b:vimtex_syntax, 'csquotes') | return | endif let b:vimtex_syntax.csquotes = 1 - call vimtex#syntax#p#biblatex#load() + syntax match texCmd nextgroup=texCmdQuoteLang skipwhite skipnl "\\\%(foreign\|hyphen\)textcquote\*\?\>" + syntax match texCmd nextgroup=texCmdQuoteLang skipwhite skipnl "\\\%(foreign\|hyphen\)blockcquote\>" + syntax match texCmd nextgroup=texCmdQuoteLang skipwhite skipnl "\\hybridblockcquote\>" + call vimtex#syntax#core#new_cmd_arg('texCmdQuoteLang', 'texOptRef,texArgRef', 'TOP', 'transparent') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/dot2texi.vim b/autoload/vimtex/syntax/p/dot2texi.vim index 7271b4bbc4..0d2cd3099a 100644 --- a/autoload/vimtex/syntax/p/dot2texi.vim +++ b/autoload/vimtex/syntax/p/dot2texi.vim @@ -8,13 +8,11 @@ function! vimtex#syntax#p#dot2texi#load() abort " {{{1 if has_key(b:vimtex_syntax, 'dot2texi') | return | endif let b:vimtex_syntax.dot2texi = 1 - call vimtex#syntax#misc#include('dot') + call vimtex#syntax#nested#include('dot') syntax region texRegionDot - \ start="\\begin{dot2tex}"rs=s - \ end="\\end{dot2tex}"re=e - \ keepend - \ transparent - \ contains=texCmdEnv,@vimtex_nested_dot + \ start="\\begin{dot2tex}" + \ end="\\end{dot2tex}" + \ keepend transparent contains=texCmdEnv,@vimtex_nested_dot endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/glossaries.vim b/autoload/vimtex/syntax/p/glossaries.vim index dbe8a7d533..c306215345 100644 --- a/autoload/vimtex/syntax/p/glossaries.vim +++ b/autoload/vimtex/syntax/p/glossaries.vim @@ -10,11 +10,8 @@ function! vimtex#syntax#p#glossaries#load() abort " {{{1 if has_key(b:vimtex_syntax, 'glossaries') | return | endif let b:vimtex_syntax.glossaries = 1 - syntax match texCmd '\\gls\>' nextgroup=texGls - syntax region texGls matchgroup=Delimiter - \ start='{' end='}' - \ contained - \ contains=@NoSpell + syntax match texCmd nextgroup=texGls skipwhite skipnl "\\gls\>" + call vimtex#syntax#core#new_cmd_arg('texGls', '', '@NoSpell') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/gnuplottex.vim b/autoload/vimtex/syntax/p/gnuplottex.vim index 93f269f1c8..b54206699d 100644 --- a/autoload/vimtex/syntax/p/gnuplottex.vim +++ b/autoload/vimtex/syntax/p/gnuplottex.vim @@ -8,10 +8,10 @@ function! vimtex#syntax#p#gnuplottex#load() abort " {{{1 if has_key(b:vimtex_syntax, 'gnuplottex') | return | endif let b:vimtex_syntax.gnuplottex = 1 - call vimtex#syntax#misc#include('gnuplot') + call vimtex#syntax#nested#include('gnuplot') syntax region texRegionGnuplot - \ start='\\begin{gnuplot}\(\_s*\[\_[\]]\{-}\]\)\?'rs=s - \ end='\\end{gnuplot}'re=e + \ start='\\begin{gnuplot}' + \ end='\\end{gnuplot}' \ keepend \ transparent \ contains=texCmdEnv,texOptEnvModifier,@vimtex_nested_gnuplot diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index 183cc83f70..9c7a0273ef 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -10,20 +10,20 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 " First some general support syntax match texCmd "\\lstinputlisting\>" - \ nextgroup=texOptFile,texArgFile + \ nextgroup=texOptFile,texArgFile skipwhite skipnl syntax match texRegion "\\lstinline\s*\(\[.\{-}\]\)\={.\{-}}" " Set all listings environments to listings syntax cluster texFoldGroup add=texRegionListings syntax region texRegionListings - \ start="\\begin{lstlisting}\(\_s*\[\_[^\]]\{-}\]\)\?"rs=s - \ end="\\end{lstlisting}\|%stopzone\>"re=e + \ start="\\begin{lstlisting}\(\_s*\[\_[^\]]\{-}\]\)\?" + \ end="\\end{lstlisting}\|%stopzone\>" \ keepend \ contains=texCmdEnv " Next add nested syntax support for desired languages for l:nested in b:vimtex_syntax.listings - let l:cluster = vimtex#syntax#misc#include(l:nested) + let l:cluster = vimtex#syntax#nested#include(l:nested) if empty(l:cluster) | continue | endif let l:group_main = 'texRegionListings' . toupper(l:nested[0]) . l:nested[1:] @@ -34,8 +34,8 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 execute 'syntax region' l:group_main \ 'start="\c\\begin{lstlisting}\s*' - \ . '\[\_[^\]]\{-}language=' . l:nested . '\%(\s*,\_[^\]]\{-}\)\?\]"rs=s' - \ 'end="\\end{lstlisting}"re=e' + \ . '\[\_[^\]]\{-}language=' . l:nested . '\%(\s*,\_[^\]]\{-}\)\?\]"' + \ 'end="\\end{lstlisting}"' \ 'keepend' \ 'transparent' \ 'contains=texCmdEnv,@' . l:cluster @@ -48,8 +48,8 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 \ 'nextgroup=' . l:group_contained execute 'syntax region' l:group_contained - \ 'start="\\begin{lstlisting}"rs=s' - \ 'end="\\end{lstlisting}"re=e' + \ 'start="\\begin{lstlisting}"' + \ 'end="\\end{lstlisting}"' \ 'keepend' \ 'transparent' \ 'containedin=' . l:group_lstset diff --git a/autoload/vimtex/syntax/p/luacode.vim b/autoload/vimtex/syntax/p/luacode.vim index 4c5ecdb7f9..1cc36ce597 100644 --- a/autoload/vimtex/syntax/p/luacode.vim +++ b/autoload/vimtex/syntax/p/luacode.vim @@ -8,10 +8,10 @@ function! vimtex#syntax#p#luacode#load() abort " {{{1 if has_key(b:vimtex_syntax, 'luacode') | return | endif let b:vimtex_syntax.luacode = 1 - call vimtex#syntax#misc#include('lua') + call vimtex#syntax#nested#include('lua') syntax region texRegionLua - \ start='\\begin{luacode\*\?}'rs=s - \ end='\\end{luacode\*\?}'re=e + \ start='\\begin{luacode\*\?}' + \ end='\\end{luacode\*\?}' \ keepend \ transparent \ contains=texCmdEnv,@vimtex_nested_lua diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index 98ed02af5e..7030d8263f 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -8,7 +8,7 @@ function! vimtex#syntax#p#markdown#load() abort " {{{1 if has_key(b:vimtex_syntax, 'markdown') | return | endif let b:vimtex_syntax.markdown = 1 - call vimtex#syntax#misc#include('markdown') + call vimtex#syntax#nested#include('markdown') " Don't quite know why this is necessary, but it is syntax match texCmdEnv "\\\%(begin\|end\)\>\ze{markdown}" nextgroup=texArgEnvName diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index 0eea0cd24f..f882b4e127 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -44,8 +44,8 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " Match "unknown" environments syntax region texRegionMinted - \ start="\\begin{minted}\%(\_s*\[\_[^\]]\{-}\]\)\?\_s*{\w\+}"rs=s - \ end="\\end{minted}"re=e + \ start="\\begin{minted}\%(\_s*\[\_[^\]]\{-}\]\)\?\_s*{\w\+}" + \ end="\\end{minted}" \ keepend \ contains=texMintedBounds.* @@ -65,7 +65,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " Next add nested syntax support for desired languages for [l:nested, l:config] in items(b:vimtex.syntax.minted) - let l:cluster = vimtex#syntax#misc#include(l:nested) + let l:cluster = vimtex#syntax#nested#include(l:nested) let l:name = 'Minted' . toupper(l:nested[0]) . l:nested[1:] let l:group_main = 'texRegion' . l:name @@ -86,8 +86,8 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " Match minted environment execute 'syntax region' l:group_main - \ 'start="\\begin{minted}\%(\_s*\[\_[^\]]\{-}\]\)\?\_s*{' . l:nested . '}"rs=s' - \ 'end="\\end{minted}"re=e' + \ 'start="\\begin{minted}\%(\_s*\[\_[^\]]\{-}\]\)\?\_s*{' . l:nested . '}"' + \ 'end="\\end{minted}"' \ 'keepend' \ l:transparent \ 'contains=texMintedBounds.*' . l:contains_env @@ -95,8 +95,8 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " Match custom environment names for l:env in get(l:config, 'environments', []) execute 'syntax region' l:group_main - \ 'start="\\begin{\z(' . l:env . '\*\?\)}"rs=s' - \ 'end="\\end{\z1}"re=e' + \ 'start="\\begin{\z(' . l:env . '\*\?\)}"' + \ 'end="\\end{\z1}"' \ 'keepend' \ l:transparent \ 'contains=texMintedStarred,texCmdEnv' . l:contains_env diff --git a/autoload/vimtex/syntax/p/pythontex.vim b/autoload/vimtex/syntax/p/pythontex.vim index 0e191f3a70..2dd4f0595e 100644 --- a/autoload/vimtex/syntax/p/pythontex.vim +++ b/autoload/vimtex/syntax/p/pythontex.vim @@ -8,7 +8,7 @@ function! vimtex#syntax#p#pythontex#load() abort " {{{1 if has_key(b:vimtex_syntax, 'pythontex') | return | endif let b:vimtex_syntax.pythontex = 1 - call vimtex#syntax#misc#include('python') + call vimtex#syntax#nested#include('python') syntax match texCmd /\\py[bsc]\?/ contained nextgroup=texPythontexArg syntax region texPythontexArg matchgroup=Delimiter @@ -19,14 +19,14 @@ function! vimtex#syntax#p#pythontex#load() abort " {{{1 \ contained contains=@vimtex_nested_python syntax region texRegionPythontex - \ start='\\begin{pyblock}'rs=s - \ end='\\end{pyblock}'re=e + \ start='\\begin{pyblock}' + \ end='\\end{pyblock}' \ keepend \ transparent \ contains=texCmdEnv,@vimtex_nested_python syntax region texRegionPythontex - \ start='\\begin{pycode}'rs=s - \ end='\\end{pycode}'re=e + \ start='\\begin{pycode}' + \ end='\\end{pycode}' \ keepend \ transparent \ contains=texCmdEnv,@vimtex_nested_python diff --git a/autoload/vimtex/syntax/p/wiki.vim b/autoload/vimtex/syntax/p/wiki.vim index 286806cb55..f74fd20b99 100644 --- a/autoload/vimtex/syntax/p/wiki.vim +++ b/autoload/vimtex/syntax/p/wiki.vim @@ -8,11 +8,11 @@ function! vimtex#syntax#p#wiki#load() abort " {{{1 if has_key(b:vimtex_syntax, 'wiki') | return | endif let b:vimtex_syntax.wiki = 1 - call vimtex#syntax#misc#include('markdown') + call vimtex#syntax#nested#include('markdown') syntax region texRegionWiki \ start='\\wikimarkup\>' - \ end='\\nowikimarkup\>'re=e + \ end='\\nowikimarkup\>' \ keepend \ transparent \ contains=@vimtex_nested_markdown,@texFoldGroup,@texDocGroup diff --git a/syntax/tex.vim b/syntax/tex.vim index 94f2da0332..d83697a9f8 100644 --- a/syntax/tex.vim +++ b/syntax/tex.vim @@ -23,7 +23,7 @@ call vimtex#syntax#core#init() " Initialize buffer local syntax state let b:vimtex_syntax = {} -call vimtex#syntax#misc#include_reset() +call vimtex#syntax#nested#reset() " Load package specific syntax (may depend on vimtex state) diff --git a/test/tests/test-syntax/test-large.tex b/test/tests/test-syntax/test-large.tex index 7d27691db9..0c69dd897e 100644 --- a/test/tests/test-syntax/test-large.tex +++ b/test/tests/test-syntax/test-large.tex @@ -77,7 +77,7 @@ \section{Package: biblatex and csquotes} \citealp*{} \citenum{} \citetext{} -\citeauthor{} +\citeauthor{asd} \citeauthor*{} \citeyear{} \citeyearpar{} From 3ebe7ced9d319c487108a53b213b444416e30543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 2 Nov 2020 23:32:51 +0100 Subject: [PATCH 31/99] wip: more improvements --- autoload/vimtex/syntax/core.vim | 1 - autoload/vimtex/syntax/p/asymptote.vim | 1 + autoload/vimtex/syntax/p/luacode.vim | 15 +++++++-------- autoload/vimtex/syntax/p/markdown.vim | 7 ++----- autoload/vimtex/syntax/p/mathtools.vim | 1 - autoload/vimtex/syntax/p/moreverb.vim | 12 +++--------- autoload/vimtex/syntax/p/pdfpages.vim | 2 +- autoload/vimtex/syntax/p/pgfplots.vim | 4 ++-- autoload/vimtex/syntax/p/pythontex.vim | 10 ++++------ autoload/vimtex/syntax/p/subfile.vim | 4 ++-- autoload/vimtex/syntax/p/varioref.vim | 8 +------- autoload/vimtex/syntax/p/wiki.vim | 2 +- syntax/tex.vim | 4 ++++ 13 files changed, 28 insertions(+), 43 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index a9f6212320..9d48e98bb8 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -448,7 +448,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texArgNewcmdName texCmd highlight def link texArgNewenvName texArgEnvName highlight def link texArgPartTitle texTitle - highlight def link texCmd texCmd highlight def link texCmdAccent texCmd highlight def link texCmdAuthor texCmd highlight def link texCmdEnv texCmd diff --git a/autoload/vimtex/syntax/p/asymptote.vim b/autoload/vimtex/syntax/p/asymptote.vim index f515882949..71b715f0f2 100644 --- a/autoload/vimtex/syntax/p/asymptote.vim +++ b/autoload/vimtex/syntax/p/asymptote.vim @@ -12,6 +12,7 @@ function! vimtex#syntax#p#asymptote#load() abort " {{{1 syntax region texRegionAsymptote \ start="\\begin{asy\z(def\)\?}" \ end="\\end{asy\z1}" + \ keepend \ transparent \ keepend contains=texCmdEnv,@vimtex_nested_asy else diff --git a/autoload/vimtex/syntax/p/luacode.vim b/autoload/vimtex/syntax/p/luacode.vim index 1cc36ce597..a67e808950 100644 --- a/autoload/vimtex/syntax/p/luacode.vim +++ b/autoload/vimtex/syntax/p/luacode.vim @@ -9,18 +9,17 @@ function! vimtex#syntax#p#luacode#load() abort " {{{1 let b:vimtex_syntax.luacode = 1 call vimtex#syntax#nested#include('lua') + syntax region texRegionLua - \ start='\\begin{luacode\*\?}' - \ end='\\end{luacode\*\?}' + \ start="\\begin{luacode\*\?}" + \ end="\\end{luacode\*\?}" \ keepend \ transparent \ contains=texCmdEnv,@vimtex_nested_lua - syntax match texCmd '\\\(directlua\|luadirect\)' nextgroup=texRegionLuaArg - syntax region texRegionLuaArg matchgroup=Delimiter - \ start='{' - \ end='}' - \ contained - \ contains=@vimtex_nested_lua + + syntax match texCmd "\\\%(directlua\|luadirect\)\>" nextgroup=texRegionLuaArg skipwhite skipnl + call vimtex#syntax#core#new_cmd_arg( + \ 'texRegionLuaArg', '', '@vimtex_nested_lua', 'keepend') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index 7030d8263f..c7bd331c82 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -10,16 +10,13 @@ function! vimtex#syntax#p#markdown#load() abort " {{{1 call vimtex#syntax#nested#include('markdown') - " Don't quite know why this is necessary, but it is - syntax match texCmdEnv "\\\%(begin\|end\)\>\ze{markdown}" nextgroup=texArgEnvName - syntax region texRegionMarkdown \ start="\\begin{markdown}" \ end="\\end{markdown}" \ keepend transparent - \ contains=texCmdEnv,texArgEnvName,@vimtex_nested_markdown + \ contains=texCmd,texCmdEnv,texArgEnvName,@vimtex_nested_markdown - syntax match texCmd "\\markdownInput\>" nextgroup=texArgFile + syntax match texCmd "\\markdownInput\>" nextgroup=texArgFile skipwhite skipnl endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/mathtools.vim b/autoload/vimtex/syntax/p/mathtools.vim index 90d524ba35..9d9cb0c56d 100644 --- a/autoload/vimtex/syntax/p/mathtools.vim +++ b/autoload/vimtex/syntax/p/mathtools.vim @@ -10,7 +10,6 @@ function! vimtex#syntax#p#mathtools#load() abort " {{{1 if has_key(b:vimtex_syntax, 'mathtools') | return | endif let b:vimtex_syntax.mathtools = 1 - " Load amsmath call vimtex#syntax#p#amsmath#load() endfunction diff --git a/autoload/vimtex/syntax/p/moreverb.vim b/autoload/vimtex/syntax/p/moreverb.vim index 79daf24cb4..7ea8c471e5 100644 --- a/autoload/vimtex/syntax/p/moreverb.vim +++ b/autoload/vimtex/syntax/p/moreverb.vim @@ -8,15 +8,9 @@ function! vimtex#syntax#p#moreverb#load() abort " {{{1 if has_key(b:vimtex_syntax, 'moreverb') | return | endif let b:vimtex_syntax.moreverb = 1 - if exists('g:tex_verbspell') - syntax region texRegion start="\\begin{verbatimtab}" end="\\end{verbatimtab}\|%stopzone\>" contains=@Spell - syntax region texRegion start="\\begin{verbatimwrite}" end="\\end{verbatimwrite}\|%stopzone\>" contains=@Spell - syntax region texRegion start="\\begin{boxedverbatim}" end="\\end{boxedverbatim}\|%stopzone\>" contains=@Spell - else - syntax region texRegion start="\\begin{verbatimtab}" end="\\end{verbatimtab}\|%stopzone\>" - syntax region texRegion start="\\begin{verbatimwrite}" end="\\end{verbatimwrite}\|%stopzone\>" - syntax region texRegion start="\\begin{boxedverbatim}" end="\\end{boxedverbatim}\|%stopzone\>" - endif + syntax region texRegionVerb start="\\begin{verbatimtab}" end="\\end{verbatimtab}" keepend contains=texCmdEnv,texArgEnvName + syntax region texRegionVerb start="\\begin{verbatimwrite}" end="\\end{verbatimwrite}" keepend contains=texCmdEnv,texArgEnvName + syntax region texRegionVerb start="\\begin{boxedverbatim}" end="\\end{boxedverbatim}" keepend contains=texCmdEnv,texArgEnvName endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/pdfpages.vim b/autoload/vimtex/syntax/p/pdfpages.vim index 9716394952..e46fab9f5b 100644 --- a/autoload/vimtex/syntax/p/pdfpages.vim +++ b/autoload/vimtex/syntax/p/pdfpages.vim @@ -8,7 +8,7 @@ function! vimtex#syntax#p#pdfpages#load() abort " {{{1 if has_key(b:vimtex_syntax, 'pdfpages') | return | endif let b:vimtex_syntax.pdfpages = 1 - syntax match texCmd "\\includepdf\>" nextgroup=texOptFile,texArgFile + syntax match texCmd "\\includepdf\>" nextgroup=texOptFile,texArgFile skipwhite skipnl endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/pgfplots.vim b/autoload/vimtex/syntax/p/pgfplots.vim index 7af24e9a3c..842e140e99 100644 --- a/autoload/vimtex/syntax/p/pgfplots.vim +++ b/autoload/vimtex/syntax/p/pgfplots.vim @@ -4,7 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#pgfplots#load() abort " +function! vimtex#syntax#p#pgfplots#load() abort " {{{1 if has_key(b:vimtex_syntax, 'pgfplots') | return | endif let b:vimtex_syntax.pgfplots = 1 @@ -29,4 +29,4 @@ function! vimtex#syntax#p#pgfplots#load() abort " highlight def link texCmdAxis texCmd endfunction -" +" }}}1 diff --git a/autoload/vimtex/syntax/p/pythontex.vim b/autoload/vimtex/syntax/p/pythontex.vim index 2dd4f0595e..c66fef6855 100644 --- a/autoload/vimtex/syntax/p/pythontex.vim +++ b/autoload/vimtex/syntax/p/pythontex.vim @@ -10,13 +10,11 @@ function! vimtex#syntax#p#pythontex#load() abort " {{{1 call vimtex#syntax#nested#include('python') - syntax match texCmd /\\py[bsc]\?/ contained nextgroup=texPythontexArg - syntax region texPythontexArg matchgroup=Delimiter - \ start='{' end='}' - \ contained contains=@vimtex_nested_python - syntax region texPythontexArg matchgroup=Delimiter + syntax match texCmd /\\py[bsc]\?/ nextgroup=texPythontexArg skipwhite skipnl + call vimtex#syntax#core#new_cmd_arg('texPythontexArg', '', '@vimtex_nested_python', 'keepend') + syntax region texPythontexArg matchgroup=texDelim \ start='\z([#@]\)' end='\z1' - \ contained contains=@vimtex_nested_python + \ contained contains=@vimtex_nested_python keepend syntax region texRegionPythontex \ start='\\begin{pyblock}' diff --git a/autoload/vimtex/syntax/p/subfile.vim b/autoload/vimtex/syntax/p/subfile.vim index d1fba51b18..41d9a7cdc5 100644 --- a/autoload/vimtex/syntax/p/subfile.vim +++ b/autoload/vimtex/syntax/p/subfile.vim @@ -8,8 +8,8 @@ function! vimtex#syntax#p#subfile#load() abort " {{{1 if has_key(b:vimtex_syntax, 'subfile') | return | endif let b:vimtex_syntax.subfile = 1 - syntax match texCmd "\\subfile\>" nextgroup=texArgFile - syntax match texCmd "\\subfileinclude\>" nextgroup=texArgFile + syntax match texCmd "\\subfile\>" nextgroup=texArgFile skipwhite skipnl + syntax match texCmd "\\subfileinclude\>" nextgroup=texArgFile skipwhite skipnl endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/varioref.vim b/autoload/vimtex/syntax/p/varioref.vim index c12a85ef4e..4e6fc72bdf 100644 --- a/autoload/vimtex/syntax/p/varioref.vim +++ b/autoload/vimtex/syntax/p/varioref.vim @@ -8,13 +8,7 @@ function! vimtex#syntax#p#varioref#load() abort " {{{1 if has_key(b:vimtex_syntax, 'varioref') | return | endif let b:vimtex_syntax.varioref = 1 - syntax match texCmd '\\Vref\>' nextgroup=texRegionVarioref - - syntax region texRegionVarioref contained matchgroup=Delimiter - \ start="{" end="}" - \ contains=@texClusterRef,texRegionRef - - highlight link texRegionVarioref texRegionRef + syntax match texCmd '\\Vref\>' nextgroup=texArgRef skipwhite skipnl endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/wiki.vim b/autoload/vimtex/syntax/p/wiki.vim index f74fd20b99..e6475d2969 100644 --- a/autoload/vimtex/syntax/p/wiki.vim +++ b/autoload/vimtex/syntax/p/wiki.vim @@ -15,7 +15,7 @@ function! vimtex#syntax#p#wiki#load() abort " {{{1 \ end='\\nowikimarkup\>' \ keepend \ transparent - \ contains=@vimtex_nested_markdown,@texFoldGroup,@texDocGroup + \ contains=texCmd,@vimtex_nested_markdown endfunction " }}}1 diff --git a/syntax/tex.vim b/syntax/tex.vim index d83697a9f8..270978f517 100644 --- a/syntax/tex.vim +++ b/syntax/tex.vim @@ -11,6 +11,8 @@ if !get(g:, 'vimtex_syntax_enabled', 1) | finish | endif if exists('b:current_syntax') | finish | endif +if exists('s:is_loading') | finish | endif +let s:is_loading = 1 " Syntax may be loaded without the main vimtex functionality, thus we need to " ensure that the options are loaded! @@ -35,3 +37,5 @@ else autocmd User VimtexEventInitPost ++once call vimtex#syntax#packages#init() augroup END endif + +unlet s:is_loading From 946c884f4beca163d4fcf9e64b24795a7da0a393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Tue, 3 Nov 2020 00:10:46 +0100 Subject: [PATCH 32/99] wip: refactor new_region code --- autoload/vimtex/syntax/core.vim | 32 ++++++++++++++++------ autoload/vimtex/syntax/p/amsmath.vim | 16 +++++------ autoload/vimtex/syntax/p/asymptote.vim | 14 +++------- autoload/vimtex/syntax/p/breqn.vim | 8 +++--- autoload/vimtex/syntax/p/cases.vim | 2 +- autoload/vimtex/syntax/p/dot2texi.vim | 6 ++-- autoload/vimtex/syntax/p/gnuplottex.vim | 8 ++---- autoload/vimtex/syntax/p/ieeetrantools.vim | 8 +++--- autoload/vimtex/syntax/p/listings.vim | 6 +--- autoload/vimtex/syntax/p/luacode.vim | 8 ++---- autoload/vimtex/syntax/p/markdown.vim | 8 ++---- autoload/vimtex/syntax/p/moreverb.vim | 6 ++-- autoload/vimtex/syntax/p/pgfplots.vim | 10 +++---- autoload/vimtex/syntax/p/pythontex.vim | 14 ++-------- autoload/vimtex/syntax/p/tikz.vim | 6 ++-- 15 files changed, 64 insertions(+), 88 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 9d48e98bb8..15a511c0c9 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -250,9 +250,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " {{{2 Verbatim " Verbatim environment - syntax region texRegionVerb - \ start="\\begin{[vV]erbatim}" end="\\end{[vV]erbatim}" - \ keepend contains=texCmdEnv,texArgEnvName + call vimtex#syntax#core#new_region_env('texRegionVerb', '[vV]erbatim') " Verbatim inline syntax match texCmd "\\verb\>\*\?" nextgroup=texRegionVerbInline @@ -290,10 +288,10 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax region texMatcherMath matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath " Math regions: environments - call vimtex#syntax#core#new_math_region('displaymath', 1) - call vimtex#syntax#core#new_math_region('eqnarray', 1) - call vimtex#syntax#core#new_math_region('equation', 1) - call vimtex#syntax#core#new_math_region('math', 1) + call vimtex#syntax#core#new_region_math('displaymath', 1) + call vimtex#syntax#core#new_region_math('eqnarray', 1) + call vimtex#syntax#core#new_region_math('equation', 1) + call vimtex#syntax#core#new_region_math('math', 1) " Math regions: Inline Math Zones if l:cfg.conceal.math_bounds @@ -324,7 +322,6 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmd "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texArgMathText call vimtex#syntax#core#new_cmd_arg('texArgMathText', '', 'TOP,@Spell') - call s:match_math_sub_super(l:cfg) call s:match_math_symbols(l:cfg) call s:match_math_delims(l:cfg) @@ -387,7 +384,24 @@ function! vimtex#syntax#core#new_cmd_opt(grp, next, ...) abort " {{{1 endfunction " }}}1 -function! vimtex#syntax#core#new_math_region(mathzone, starred) abort " {{{1 +function! vimtex#syntax#core#new_region_env(grp, envname, ...) abort " {{{1 + let l:contains = 'texCmdEnv,texArgEnvName' + let l:options = 'keepend' + + if a:0 > 0 + let l:contains .= ',' . a:1 + let l:options .= ' transparent' + endif + + execute 'syntax region' a:grp + \ 'start="\\begin{' . a:envname .'}"' + \ 'end="\\end{' . a:envname .'}"' + \ (empty(l:contains) ? '' : 'contains=' . l:contains) + \ l:options +endfunction + +" }}}1 +function! vimtex#syntax#core#new_region_math(mathzone, starred) abort " {{{1 execute 'syntax match texErrorMath /\\end\s*{\s*' . a:mathzone . '\*\?\s*}/' execute 'syntax region texRegionMathEnv' diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index 7e31be93e8..07599ff9e7 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -10,14 +10,14 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 if has_key(b:vimtex_syntax, 'amsmath') | return | endif let b:vimtex_syntax.amsmath = 1 - call vimtex#syntax#core#new_math_region('align', 1) - call vimtex#syntax#core#new_math_region('alignat', 1) - call vimtex#syntax#core#new_math_region('flalign', 1) - call vimtex#syntax#core#new_math_region('gather', 1) - call vimtex#syntax#core#new_math_region('multline', 1) - call vimtex#syntax#core#new_math_region('xalignat', 1) - call vimtex#syntax#core#new_math_region('xxalignat', 0) - call vimtex#syntax#core#new_math_region('mathpar', 1) + call vimtex#syntax#core#new_region_math('align', 1) + call vimtex#syntax#core#new_region_math('alignat', 1) + call vimtex#syntax#core#new_region_math('flalign', 1) + call vimtex#syntax#core#new_region_math('gather', 1) + call vimtex#syntax#core#new_region_math('multline', 1) + call vimtex#syntax#core#new_region_math('xalignat', 1) + call vimtex#syntax#core#new_region_math('xxalignat', 0) + call vimtex#syntax#core#new_region_math('mathpar', 1) " Amsmath [lr][vV]ert if &encoding ==# 'utf-8' && g:vimtex_syntax_config.conceal.math_delimiters diff --git a/autoload/vimtex/syntax/p/asymptote.vim b/autoload/vimtex/syntax/p/asymptote.vim index 71b715f0f2..ccfd0dda82 100644 --- a/autoload/vimtex/syntax/p/asymptote.vim +++ b/autoload/vimtex/syntax/p/asymptote.vim @@ -9,17 +9,11 @@ function! vimtex#syntax#p#asymptote#load() abort " {{{1 let b:vimtex_syntax.asymptote = 1 if !empty(vimtex#syntax#nested#include('asy')) - syntax region texRegionAsymptote - \ start="\\begin{asy\z(def\)\?}" - \ end="\\end{asy\z1}" - \ keepend - \ transparent - \ keepend contains=texCmdEnv,@vimtex_nested_asy + call vimtex#syntax#core#new_region_env('texRegionAsymptote', 'asy', '@vimtex_nested_asy') + call vimtex#syntax#core#new_region_env('texRegionAsymptote', 'asydef', '@vimtex_nested_asy') else - syntax region texRegionAsymptote - \ start="\\begin{asy\z(def\)\?}" - \ end="\\end{asy\z1}" - \ keepend contains=texCmdEnv + call vimtex#syntax#core#new_region_env('texRegionAsymptote', 'asy') + call vimtex#syntax#core#new_region_env('texRegionAsymptote', 'asydef') highlight def link texRegionAsymptote texRegion endif endfunction diff --git a/autoload/vimtex/syntax/p/breqn.vim b/autoload/vimtex/syntax/p/breqn.vim index 655cd93268..9de083d736 100644 --- a/autoload/vimtex/syntax/p/breqn.vim +++ b/autoload/vimtex/syntax/p/breqn.vim @@ -10,10 +10,10 @@ function! vimtex#syntax#p#breqn#load() abort " {{{1 if has_key(b:vimtex_syntax, 'breqn') | return | endif let b:vimtex_syntax.breqn = 1 - call vimtex#syntax#core#new_math_region('dmath', 1) - call vimtex#syntax#core#new_math_region('dseries', 1) - call vimtex#syntax#core#new_math_region('dgroup', 1) - call vimtex#syntax#core#new_math_region('darray', 1) + call vimtex#syntax#core#new_region_math('dmath', 1) + call vimtex#syntax#core#new_region_math('dseries', 1) + call vimtex#syntax#core#new_region_math('dgroup', 1) + call vimtex#syntax#core#new_region_math('darray', 1) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/cases.vim b/autoload/vimtex/syntax/p/cases.vim index f8b4b843a2..c77bce6928 100644 --- a/autoload/vimtex/syntax/p/cases.vim +++ b/autoload/vimtex/syntax/p/cases.vim @@ -10,7 +10,7 @@ function! vimtex#syntax#p#cases#load() abort " {{{1 if has_key(b:vimtex_syntax, 'cases') | return | endif let b:vimtex_syntax.cases = 1 - call vimtex#syntax#core#new_math_region('\(sub\)\?numcases', 0) + call vimtex#syntax#core#new_region_math('\(sub\)\?numcases', 0) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/dot2texi.vim b/autoload/vimtex/syntax/p/dot2texi.vim index 0d2cd3099a..f460b376e3 100644 --- a/autoload/vimtex/syntax/p/dot2texi.vim +++ b/autoload/vimtex/syntax/p/dot2texi.vim @@ -9,10 +9,8 @@ function! vimtex#syntax#p#dot2texi#load() abort " {{{1 let b:vimtex_syntax.dot2texi = 1 call vimtex#syntax#nested#include('dot') - syntax region texRegionDot - \ start="\\begin{dot2tex}" - \ end="\\end{dot2tex}" - \ keepend transparent contains=texCmdEnv,@vimtex_nested_dot + call vimtex#syntax#core#new_region_env( + \ 'texRegionDot', 'dot2tex', '@vimtex_nested_dot') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/gnuplottex.vim b/autoload/vimtex/syntax/p/gnuplottex.vim index b54206699d..2435b6360b 100644 --- a/autoload/vimtex/syntax/p/gnuplottex.vim +++ b/autoload/vimtex/syntax/p/gnuplottex.vim @@ -9,12 +9,8 @@ function! vimtex#syntax#p#gnuplottex#load() abort " {{{1 let b:vimtex_syntax.gnuplottex = 1 call vimtex#syntax#nested#include('gnuplot') - syntax region texRegionGnuplot - \ start='\\begin{gnuplot}' - \ end='\\end{gnuplot}' - \ keepend - \ transparent - \ contains=texCmdEnv,texOptEnvModifier,@vimtex_nested_gnuplot + call vimtex#syntax#core#new_region_env( + \ 'texRegionGnuplot', 'gnuplot', '@vimtex_nested_gnuplot') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/ieeetrantools.vim b/autoload/vimtex/syntax/p/ieeetrantools.vim index 9631a1c7f1..339d734fff 100644 --- a/autoload/vimtex/syntax/p/ieeetrantools.vim +++ b/autoload/vimtex/syntax/p/ieeetrantools.vim @@ -10,14 +10,14 @@ function! vimtex#syntax#p#ieeetrantools#load() abort " {{{1 if has_key(b:vimtex_syntax, 'ieeetrantools') | return | endif let b:vimtex_syntax.ieeetrantools = 1 - call s:new_math_region('IEEEeqnarray') - call s:new_math_region('IEEEeqnarrayboxm') + call s:new_region_math('IEEEeqnarray') + call s:new_region_math('IEEEeqnarrayboxm') endfunction " }}}1 -function! s:new_math_region(mathzone) abort " {{{1 - " This needs to be slightly different than vimtex#syntax#core#new_math_region +function! s:new_region_math(mathzone) abort " {{{1 + " This needs to be slightly different than vimtex#syntax#core#new_region_math " to handle options for the environment. execute 'syntax match texErrorMath ''\\end\s*{\s*' . a:mathzone . '\*\?\s*}''' diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index 9c7a0273ef..7ada94733f 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -15,11 +15,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 " Set all listings environments to listings syntax cluster texFoldGroup add=texRegionListings - syntax region texRegionListings - \ start="\\begin{lstlisting}\(\_s*\[\_[^\]]\{-}\]\)\?" - \ end="\\end{lstlisting}\|%stopzone\>" - \ keepend - \ contains=texCmdEnv + call vimtex#syntax#core#new_region_env('texRegionListings', 'lstlisting') " Next add nested syntax support for desired languages for l:nested in b:vimtex_syntax.listings diff --git a/autoload/vimtex/syntax/p/luacode.vim b/autoload/vimtex/syntax/p/luacode.vim index a67e808950..8a9aa9e19f 100644 --- a/autoload/vimtex/syntax/p/luacode.vim +++ b/autoload/vimtex/syntax/p/luacode.vim @@ -10,12 +10,8 @@ function! vimtex#syntax#p#luacode#load() abort " {{{1 call vimtex#syntax#nested#include('lua') - syntax region texRegionLua - \ start="\\begin{luacode\*\?}" - \ end="\\end{luacode\*\?}" - \ keepend - \ transparent - \ contains=texCmdEnv,@vimtex_nested_lua + call vimtex#syntax#core#new_region_env( + \ 'texRegionLua', 'luacode\*\?', '@vimtex_nested_lua') syntax match texCmd "\\\%(directlua\|luadirect\)\>" nextgroup=texRegionLuaArg skipwhite skipnl call vimtex#syntax#core#new_cmd_arg( diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index c7bd331c82..414cb2af67 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -9,12 +9,8 @@ function! vimtex#syntax#p#markdown#load() abort " {{{1 let b:vimtex_syntax.markdown = 1 call vimtex#syntax#nested#include('markdown') - - syntax region texRegionMarkdown - \ start="\\begin{markdown}" - \ end="\\end{markdown}" - \ keepend transparent - \ contains=texCmd,texCmdEnv,texArgEnvName,@vimtex_nested_markdown + call vimtex#syntax#core#new_region_env( + \ 'texRegionMarkdown', 'markdown', 'texCmd,@vimtex_nested_markdown') syntax match texCmd "\\markdownInput\>" nextgroup=texArgFile skipwhite skipnl endfunction diff --git a/autoload/vimtex/syntax/p/moreverb.vim b/autoload/vimtex/syntax/p/moreverb.vim index 7ea8c471e5..55a499aae4 100644 --- a/autoload/vimtex/syntax/p/moreverb.vim +++ b/autoload/vimtex/syntax/p/moreverb.vim @@ -8,9 +8,9 @@ function! vimtex#syntax#p#moreverb#load() abort " {{{1 if has_key(b:vimtex_syntax, 'moreverb') | return | endif let b:vimtex_syntax.moreverb = 1 - syntax region texRegionVerb start="\\begin{verbatimtab}" end="\\end{verbatimtab}" keepend contains=texCmdEnv,texArgEnvName - syntax region texRegionVerb start="\\begin{verbatimwrite}" end="\\end{verbatimwrite}" keepend contains=texCmdEnv,texArgEnvName - syntax region texRegionVerb start="\\begin{boxedverbatim}" end="\\end{boxedverbatim}" keepend contains=texCmdEnv,texArgEnvName + call vimtex#syntax#core#new_region_env('texRegionVerb', 'verbatimtab') + call vimtex#syntax#core#new_region_env('texRegionVerb', 'verbatimwrite') + call vimtex#syntax#core#new_region_env('texRegionVerb', 'boxedverbatim') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/pgfplots.vim b/autoload/vimtex/syntax/p/pgfplots.vim index 842e140e99..2d651f831c 100644 --- a/autoload/vimtex/syntax/p/pgfplots.vim +++ b/autoload/vimtex/syntax/p/pgfplots.vim @@ -19,12 +19,10 @@ function! vimtex#syntax#p#pgfplots#load() abort " {{{1 syntax match texEnvBgnTikz contains=texCmdEnv nextgroup=texOptTikzpic skipwhite skipnl "\\begin{\%(log\)*axis}" syntax match texEnvBgnTikz contains=texCmdEnv nextgroup=texOptTikzpic skipwhite skipnl "\\begin{groupplot}" - syntax region texRegionTikz - \ start="\\begin{\z(\%(log\)*axis\)}" end="\\end{\z1}" - \ keepend transparent contains=@texClusterTikz - syntax region texRegionTikz - \ start="\\begin{groupplot}" end="\\end{groupplot}" - \ keepend transparent contains=@texClusterTikz + call vimtex#syntax#core#new_region_env('texRegionTikz', 'axis', '@texClusterTikz') + call vimtex#syntax#core#new_region_env('texRegionTikz', 'logaxis', '@texClusterTikz') + call vimtex#syntax#core#new_region_env('texRegionTikz', 'loglogaxis', '@texClusterTikz') + call vimtex#syntax#core#new_region_env('texRegionTikz', 'groupplot', '@texClusterTikz') highlight def link texCmdAxis texCmd endfunction diff --git a/autoload/vimtex/syntax/p/pythontex.vim b/autoload/vimtex/syntax/p/pythontex.vim index c66fef6855..f9c26cbd14 100644 --- a/autoload/vimtex/syntax/p/pythontex.vim +++ b/autoload/vimtex/syntax/p/pythontex.vim @@ -16,18 +16,8 @@ function! vimtex#syntax#p#pythontex#load() abort " {{{1 \ start='\z([#@]\)' end='\z1' \ contained contains=@vimtex_nested_python keepend - syntax region texRegionPythontex - \ start='\\begin{pyblock}' - \ end='\\end{pyblock}' - \ keepend - \ transparent - \ contains=texCmdEnv,@vimtex_nested_python - syntax region texRegionPythontex - \ start='\\begin{pycode}' - \ end='\\end{pycode}' - \ keepend - \ transparent - \ contains=texCmdEnv,@vimtex_nested_python + call vimtex#syntax#core#new_region_env('texRegionPythontex', 'pyblock', '@vimtex_nested_python') + call vimtex#syntax#core#new_region_env('texRegionPythontex', 'pycode', '@vimtex_nested_python') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index ceb33410ce..fcd09f82fc 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -16,10 +16,8 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 syntax match texEnvBgnTikz /\v\\begin\{tikzpicture\}/ \ nextgroup=texOptTikzpic skipwhite skipnl contains=texCmdEnv - syntax region texRegionTikz - \ start='\\begin{tikzpicture}' - \ end='\\end{tikzpicture}' - \ keepend transparent contains=@texClusterTikz + call vimtex#syntax#core#new_region_env( + \ 'texRegionTikz', 'tikzpicture', '@texClusterTikz') call vimtex#syntax#core#new_cmd_opt('texOptTikzpic', '', '@texClusterTikzset') syntax match texTikzSemicolon /;/ contained From 84bc06a2e27c380ec646d42dd8aff3670cda7f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Tue, 3 Nov 2020 00:16:49 +0100 Subject: [PATCH 33/99] wip: minor updates --- autoload/vimtex/syntax/core.vim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 15a511c0c9..e971fc0c8b 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -432,6 +432,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmd Statement highlight def link texCmdSpaceCodeChar Special highlight def link texCmdTodo Todo + highlight def link texCmdType Type highlight def link texComment Comment highlight def link texCommentTodo Todo highlight def link texDelim Delimiter @@ -448,8 +449,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texSpecialChar SpecialChar highlight def link texSymbol SpecialChar highlight def link texSymbolString String - highlight def link texTitle String - highlight def link texType Type + highlight def link texArgPartTitle String highlight def texStyleBold gui=bold cterm=bold highlight def texStyleItal gui=italic cterm=italic @@ -461,7 +461,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texArgFiles texArgFile highlight def link texArgNewcmdName texCmd highlight def link texArgNewenvName texArgEnvName - highlight def link texArgPartTitle texTitle highlight def link texCmdAccent texCmd highlight def link texCmdAuthor texCmd highlight def link texCmdEnv texCmd @@ -471,11 +470,11 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdItem texArgEnvName highlight def link texCmdLigature texSpecialChar highlight def link texCmdParts texCmd - highlight def link texCmdSize texType + highlight def link texCmdSize texCmdType highlight def link texCmdSpaceCode texCmd highlight def link texCmdSty texCmd highlight def link texCmdStyle texCmd - highlight def link texCmdStyle texType + highlight def link texCmdStyle texCmdType highlight def link texCmdStyleBold texCmd highlight def link texCmdStyleBoldItal texCmd highlight def link texCmdStyleItal texCmd From fef6987299d0e1b1d7f747627257cb66201712ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Tue, 3 Nov 2020 23:57:40 +0100 Subject: [PATCH 34/99] wip: more fixes plus initial latex3 support --- autoload/vimtex/syntax/core.vim | 33 ++++++++++++++++++++------ test/tests/test-syntax/test-core.tex | 4 ++++ test/tests/test-syntax/test-core.vim | 3 +++ test/tests/test-syntax/test-latex3.tex | 30 +++++++++++++++++++++++ test/tests/test-syntax/test-latex3.vim | 11 +++++++++ 5 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 test/tests/test-syntax/test-latex3.tex create mode 100644 test/tests/test-syntax/test-latex3.vim diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index e971fc0c8b..3da362a675 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -98,8 +98,8 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdAuthor nextgroup=texOptAuthor,texArgAuthor skipwhite skipnl "\\author\>" syntax match texCmdTitle nextgroup=texArgTitle skipwhite skipnl "\\title\>" call vimtex#syntax#core#new_cmd_opt('texOptAuthor', 'texArgAuthor') - call vimtex#syntax#core#new_cmd_arg('texArgAuthor', '', 'texCmd,texCmdAccent,texCmdLigature,texSpecialChar,texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texArgTitle', '', 'texCmd,texComment') + call vimtex#syntax#core#new_cmd_arg('texArgAuthor', '', 'texCmd,texMatcher,texCmdAccent,texCmdLigature,texSpecialChar,texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texArgTitle', '', 'texCmd,texMatcher,texComment') " Various commands that take a file argument (or similar) syntax match texCmd nextgroup=texArgFile skipwhite skipnl "\\input\>" @@ -228,8 +228,8 @@ function! vimtex#syntax#core#init() abort " {{{1 " Sections and parts syntax match texCmdParts "\\\(front\|main\|back\)matter\>" syntax match texCmdParts nextgroup=texArgPartTitle "\\part\>" - syntax match texCmdParts nextgroup=texArgPartTitle "\\chapter\>" - syntax match texCmdParts nextgroup=texArgPartTitle "\\\(sub\)*section\>" + syntax match texCmdParts nextgroup=texArgPartTitle "\\chapter\>\*\?" + syntax match texCmdParts nextgroup=texArgPartTitle "\\\(sub\)*section\>\*\?" syntax match texCmdParts nextgroup=texArgPartTitle "\\\(sub\)\?paragraph\>" call vimtex#syntax#core#new_cmd_arg('texArgPartTitle', '', 'TOP') @@ -280,6 +280,21 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texSpecialChar "\\\\" syntax match texSpecialChar "\^\^\%(\S\|[0-9a-f]\{2}\)" + " }}}2 + " {{{2 Expl3 + + syntax region texRegionExpl3 matchgroup=texCmdExpl3 + \ start='\\ExplSyntaxOn' end='\\ExplSyntaxOff' + \ transparent keepend contains=@texClusterExpl3 + + syntax match texE3Var contained "\\[a-zA-Z_]\+\>" + syntax match texE3Func contained "\\[a-zA-Z_]\+:[a-zA-Z]*" + syntax match texE3Parm contained "#\d\+" + syntax match texE3Delim contained "[{}]" + + syntax cluster texClusterExpl3 contains=TOP + syntax cluster texClusterExpl3 add=texE3Var,texE3Func,texE3Parm,texE3Delim + " }}}2 " {{{2 Math @@ -427,6 +442,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texArg Include highlight def link texArgEnvMathName Delimiter highlight def link texArgEnvName PreCondit + highlight def link texArgPartTitle String highlight def link texArgRef Special highlight def link texArgTitle Underlined highlight def link texCmd Statement @@ -449,7 +465,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texSpecialChar SpecialChar highlight def link texSymbol SpecialChar highlight def link texSymbolString String - highlight def link texArgPartTitle String highlight def texStyleBold gui=bold cterm=bold highlight def texStyleItal gui=italic cterm=italic @@ -466,6 +481,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdEnv texCmd highlight def link texCmdEnvMath texCmdEnv highlight def link texCmdError texError + highlight def link texCmdExpl3 texCmd highlight def link texCmdGreek texCmd highlight def link texCmdItem texArgEnvName highlight def link texCmdLigature texSpecialChar @@ -482,8 +498,12 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdTitle texCmd highlight def link texCommentAcronym texComment highlight def link texCommentURL texComment - highlight def link texDelimMathmode texDelim highlight def link texDelimMathSet texDelimMath + highlight def link texDelimMathmode texDelim + highlight def link texE3Delim texDelim + highlight def link texE3Func texCmdType + highlight def link texE3Parm texParm + highlight def link texE3Var texCmd highlight def link texErrorMath texError highlight def link texErrorMathDelim texError highlight def link texErrorOnlyMath texError @@ -500,7 +520,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texParmDef texParm highlight def link texParmNewcmd texParm highlight def link texParmNewenv texParm - highlight def link texRefCite texRegionRef highlight def link texRegionMath texMath highlight def link texRegionMathEnsured texMath highlight def link texRegionMathEnv texMath diff --git a/test/tests/test-syntax/test-core.tex b/test/tests/test-syntax/test-core.tex index e408dc8238..a68e786448 100644 --- a/test/tests/test-syntax/test-core.tex +++ b/test/tests/test-syntax/test-core.tex @@ -43,4 +43,8 @@ \section{First} \section{Second} \label{sec:second} +\author{A. Author\thanks{An Institute}} + +\section*{Acknowledgement} + \end{document} diff --git a/test/tests/test-syntax/test-core.vim b/test/tests/test-syntax/test-core.vim index 02a19172a3..d1758aa998 100644 --- a/test/tests/test-syntax/test-core.vim +++ b/test/tests/test-syntax/test-core.vim @@ -11,4 +11,7 @@ call vimtex#test#assert(vimtex#syntax#in('texParmNewenv', 20, 36)) call vimtex#test#assert(vimtex#syntax#in('texRegionVerbInline', 26, 36)) +call vimtex#test#assert(vimtex#syntax#in('texArgAuthor', 46, 20)) +call vimtex#test#assert(vimtex#syntax#in('texDelim', 46, 39)) + quit! diff --git a/test/tests/test-syntax/test-latex3.tex b/test/tests/test-syntax/test-latex3.tex new file mode 100644 index 0000000000..a6e7888518 --- /dev/null +++ b/test/tests/test-syntax/test-latex3.tex @@ -0,0 +1,30 @@ +\documentclass[fleqn]{article} +\usepackage{amsmath} +\usepackage{expl3} +\usepackage{xparse} + +\ExplSyntaxOn +\seq_new:N \l_test_A_seq +\seq_new:N \l_test_B_seq +\seq_new:N \l_test_C_seq + +\cs_new:Npn \fillmyseq #1 #2 { + \seq_set_split:Nnn #1 {,} {#2} +} + +\fillmyseq{\l_test_A_seq}{A_1, A_2, A_3} +\fillmyseq{\l_test_B_seq}{B_1, B_2, B_3} +\fillmyseq{\l_test_C_seq}{C_1, C_2, C_3} + +\cs_new:Nn \__test_do: { + \seq_show:N \l_test_A_seq + \seq_show:N \l_test_B_seq + \seq_show:N \l_test_C_seq +} + +\NewDocumentCommand\mydo {} {\__test_do:} +\ExplSyntaxOff + +\begin{document} +\mydo +\end{document} diff --git a/test/tests/test-syntax/test-latex3.vim b/test/tests/test-syntax/test-latex3.vim new file mode 100644 index 0000000000..ae7bccbe8c --- /dev/null +++ b/test/tests/test-syntax/test-latex3.vim @@ -0,0 +1,11 @@ +source common.vim + +silent edit test-latex3.tex + +if empty($INMAKE) | finish | endif + +call vimtex#test#assert(vimtex#syntax#in('texRegionExpl3', 7, 2)) +call vimtex#test#assert(vimtex#syntax#in('texE3Func', 7, 2)) +call vimtex#test#assert(vimtex#syntax#in('texE3Var', 7, 15)) + +quit! From 3bf0b74464320c82698fb088febf7847d7dc71ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 4 Nov 2020 00:11:48 +0100 Subject: [PATCH 35/99] wip: minor update --- autoload/vimtex/syntax/core.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 3da362a675..00ea069c37 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -483,7 +483,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdError texError highlight def link texCmdExpl3 texCmd highlight def link texCmdGreek texCmd - highlight def link texCmdItem texArgEnvName + highlight def link texCmdItem texCmdEnv highlight def link texCmdLigature texSpecialChar highlight def link texCmdParts texCmd highlight def link texCmdSize texCmdType From eabe0a3eaa28786b845b15425258d0cb7c734dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 5 Nov 2020 16:28:26 +0100 Subject: [PATCH 36/99] wip: don't match texLength at top level --- autoload/vimtex/syntax/core.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 00ea069c37..68edf4cf1c 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -17,8 +17,8 @@ function! vimtex#syntax#core#init() abort " {{{1 " {{{2 Primitives - " Match TeX braces in general - " TODO: Do we really need this?? + " Match unspecified TeX groups (this is necessary to always match the + " corresponding end brace for specific argument groups) syntax region texMatcher matchgroup=texDelim \ start="{" skip="\\\\\|\\}" end="}" contains=TOP @@ -53,7 +53,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax case match " TeX Lengths - syntax match texLength "\<\d\+\([.,]\d\+\)\?\s*\(true\)\?\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>" + syntax match texLength contained "\<\d\+\([.,]\d\+\)\?\s*\(true\)\?\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>" " }}}2 " {{{2 Commands @@ -298,7 +298,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " }}}2 " {{{2 Math - " Math clusters for use in math regions + " Syntax clusters for math regions syntax cluster texClusterMath contains=texCmd,texCmdGreek,texCmdSize,texCmdStyle,texComment,texDelimMath,texDelimMathMod,texLength,texMatcherMath,texMathOper,texSymbolMath,texSpecialChar,texMathSub,texMathSuper,texSymbolAmp,texSymbolDash,@NoSpell syntax region texMatcherMath matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath From 8742e0742f21a0553091aa2338fdda2f0a8a6f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 6 Nov 2020 22:07:48 +0100 Subject: [PATCH 37/99] wip: updated expl3 definitions --- autoload/vimtex/syntax/core.vim | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 68edf4cf1c..43a29141d2 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -287,13 +287,20 @@ function! vimtex#syntax#core#init() abort " {{{1 \ start='\\ExplSyntaxOn' end='\\ExplSyntaxOff' \ transparent keepend contains=@texClusterExpl3 - syntax match texE3Var contained "\\[a-zA-Z_]\+\>" - syntax match texE3Func contained "\\[a-zA-Z_]\+:[a-zA-Z]*" + syntax region texRegionExpl3 matchgroup=texCmdExpl3 + \ start='\\ProvidesExpl\%(Package\|Class\|File\)' + \ end='\\ExplSyntaxOff\|\%$' + \ transparent keepend contains=@texClusterExpl3 + + syntax region texE3Matcher matchgroup=texDelim + \ start="{" skip="\\\\\|\\}" end="}" + \ contains=@texClusterExpl3 + + syntax match texE3Var contained "\\\a*\%(_\+[a-zA-Z]\+\)\+\>" + syntax match texE3Func contained "\\\a*\%(_\+[a-zA-Z]\+\)\+:[a-zA-Z]*" syntax match texE3Parm contained "#\d\+" - syntax match texE3Delim contained "[{}]" - syntax cluster texClusterExpl3 contains=TOP - syntax cluster texClusterExpl3 add=texE3Var,texE3Func,texE3Parm,texE3Delim + syntax cluster texClusterExpl3 contains=texCmd,texE3Matcher,texE3Var,texE3Func,texE3Parm,texE3Delim " }}}2 " {{{2 Math From fa794ec806bbf7738cdb8185e43e6a7a17613a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 6 Nov 2020 22:11:29 +0100 Subject: [PATCH 38/99] wip: minor fix --- autoload/vimtex/syntax/core.vim | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 43a29141d2..65b584a023 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -284,16 +284,13 @@ function! vimtex#syntax#core#init() abort " {{{1 " {{{2 Expl3 syntax region texRegionExpl3 matchgroup=texCmdExpl3 - \ start='\\ExplSyntaxOn' end='\\ExplSyntaxOff' - \ transparent keepend contains=@texClusterExpl3 - - syntax region texRegionExpl3 matchgroup=texCmdExpl3 - \ start='\\ProvidesExpl\%(Package\|Class\|File\)' + \ start='\\\%(ExplSyntaxOn\|ProvidesExpl\%(Package\|Class\|File\)\)' \ end='\\ExplSyntaxOff\|\%$' \ transparent keepend contains=@texClusterExpl3 syntax region texE3Matcher matchgroup=texDelim \ start="{" skip="\\\\\|\\}" end="}" + \ contained \ contains=@texClusterExpl3 syntax match texE3Var contained "\\\a*\%(_\+[a-zA-Z]\+\)\+\>" From 5b7fd9ec6f5e230c2d4c12fdc53766b58c42bfbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 6 Nov 2020 22:38:00 +0100 Subject: [PATCH 39/99] wip: use texGroup instead of texMatcher --- autoload/vimtex/syntax/core.vim | 45 ++++++++++++------------- autoload/vimtex/syntax/p/listings.vim | 2 +- autoload/vimtex/syntax/p/tikz.vim | 2 +- test/tests/test-syntax/test-nospell.vim | 2 +- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 65b584a023..e5fda50cee 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -19,7 +19,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " Match unspecified TeX groups (this is necessary to always match the " corresponding end brace for specific argument groups) - syntax region texMatcher matchgroup=texDelim + syntax region texGroup matchgroup=texDelim \ start="{" skip="\\\\\|\\}" end="}" contains=TOP " Flag mismatching ending brace delimiter @@ -98,8 +98,8 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdAuthor nextgroup=texOptAuthor,texArgAuthor skipwhite skipnl "\\author\>" syntax match texCmdTitle nextgroup=texArgTitle skipwhite skipnl "\\title\>" call vimtex#syntax#core#new_cmd_opt('texOptAuthor', 'texArgAuthor') - call vimtex#syntax#core#new_cmd_arg('texArgAuthor', '', 'texCmd,texMatcher,texCmdAccent,texCmdLigature,texSpecialChar,texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texArgTitle', '', 'texCmd,texMatcher,texComment') + call vimtex#syntax#core#new_cmd_arg('texArgAuthor', '', 'texCmd,texGroup,texCmdAccent,texCmdLigature,texSpecialChar,texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texArgTitle', '', 'texCmd,texGroup,texComment') " Various commands that take a file argument (or similar) syntax match texCmd nextgroup=texArgFile skipwhite skipnl "\\input\>" @@ -286,25 +286,25 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax region texRegionExpl3 matchgroup=texCmdExpl3 \ start='\\\%(ExplSyntaxOn\|ProvidesExpl\%(Package\|Class\|File\)\)' \ end='\\ExplSyntaxOff\|\%$' - \ transparent keepend contains=@texClusterExpl3 + \ transparent keepend + \ contains=TOP - syntax region texE3Matcher matchgroup=texDelim + syntax region texGroupE3 matchgroup=texDelim \ start="{" skip="\\\\\|\\}" end="}" \ contained - \ contains=@texClusterExpl3 + \ containedin=texRegionExpl3,texGroupE3 + \ contains=TOP - syntax match texE3Var contained "\\\a*\%(_\+[a-zA-Z]\+\)\+\>" - syntax match texE3Func contained "\\\a*\%(_\+[a-zA-Z]\+\)\+:[a-zA-Z]*" - syntax match texE3Parm contained "#\d\+" - - syntax cluster texClusterExpl3 contains=texCmd,texE3Matcher,texE3Var,texE3Func,texE3Parm,texE3Delim + syntax match texE3Var contained containedin=texRegionExpl3,texGroupE3 "\\\a*\%(_\+[a-zA-Z]\+\)\+\>" + syntax match texE3Func contained containedin=texRegionExpl3,texGroupE3 "\\\a*\%(_\+[a-zA-Z]\+\)\+:[a-zA-Z]*" + syntax match texE3Parm contained containedin=texRegionExpl3,texGroupE3 "#\d\+" " }}}2 " {{{2 Math " Syntax clusters for math regions - syntax cluster texClusterMath contains=texCmd,texCmdGreek,texCmdSize,texCmdStyle,texComment,texDelimMath,texDelimMathMod,texLength,texMatcherMath,texMathOper,texSymbolMath,texSpecialChar,texMathSub,texMathSuper,texSymbolAmp,texSymbolDash,@NoSpell - syntax region texMatcherMath matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath + syntax cluster texClusterMath contains=texCmd,texCmdGreek,texCmdSize,texCmdStyle,texComment,texDelimMath,texDelimMathMod,texLength,texGroupMath,texMathOper,texSymbolMath,texSpecialChar,texMathSub,texMathSuper,texSymbolAmp,texSymbolDash,@NoSpell + syntax region texGroupMath matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath " Math regions: environments call vimtex#syntax#core#new_region_math('displaymath', 1) @@ -460,12 +460,12 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texDelimMathMod Statement highlight def link texError Error highlight def link texLength Number - highlight def link texMath Special highlight def link texMathOper Operator highlight def link texOpt Identifier highlight def link texOptSep NormalNC highlight def link texParm Special highlight def link texRegion PreCondit + highlight def link texRegionMath Special highlight def link texSpecialChar SpecialChar highlight def link texSymbol SpecialChar highlight def link texSymbolString String @@ -511,9 +511,9 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texErrorMath texError highlight def link texErrorMathDelim texError highlight def link texErrorOnlyMath texError - highlight def link texMatcherMath texMath - highlight def link texMathSub texMath - highlight def link texMathSuper texMath + highlight def link texGroupMath texRegionMath + highlight def link texMathSub texRegionMath + highlight def link texMathSuper texRegionMath highlight def link texOptAuthor texOpt highlight def link texOptEqual texSymbol highlight def link texOptFile texOpt @@ -524,12 +524,11 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texParmDef texParm highlight def link texParmNewcmd texParm highlight def link texParmNewenv texParm - highlight def link texRegionMath texMath - highlight def link texRegionMathEnsured texMath - highlight def link texRegionMathEnv texMath - highlight def link texRegionMathEnvStarred texMath - highlight def link texRegionMathX texMath - highlight def link texRegionMathXX texMath + highlight def link texRegionMathEnsured texRegionMath + highlight def link texRegionMathEnv texRegionMath + highlight def link texRegionMathEnvStarred texRegionMath + highlight def link texRegionMathX texRegionMath + highlight def link texRegionMathXX texRegionMath highlight def link texRegionVerb texRegion highlight def link texRegionVerbInline texRegionVerb highlight def link texSymbolAmp texSymbol diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index 7ada94733f..1d8ccfafed 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -39,7 +39,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 execute 'syntax match' l:group_lstset \ '"\c\\lstset{.*language=' . l:nested . '\%(\s*,\|}\)"' \ 'transparent' - \ 'contains=texCmd,texMatcher' + \ 'contains=texCmd,texGroup' \ 'skipwhite skipempty' \ 'nextgroup=' . l:group_contained diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index fcd09f82fc..4450e86512 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -8,7 +8,7 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 if has_key(b:vimtex_syntax, 'tikz') | return | endif let b:vimtex_syntax.tikz = 1 - syntax cluster texClusterTikz contains=texEnvBgnTikz,texCmdEnv,texCmd,texTikzSemicolon,texComment,texMatcher + syntax cluster texClusterTikz contains=texEnvBgnTikz,texCmdEnv,texCmd,texTikzSemicolon,texComment,texGroup syntax cluster texClusterTikzset contains=texArgTikzset,texOptSep,texOptEqual,texRegionMathX,texTypeSize,texCmd,texLength,texComment syntax match texCmd /\\tikzset\>/ skipwhite skipnl nextgroup=texArgTikzset diff --git a/test/tests/test-syntax/test-nospell.vim b/test/tests/test-syntax/test-nospell.vim index 1d4708b450..8559269009 100644 --- a/test/tests/test-syntax/test-nospell.vim +++ b/test/tests/test-syntax/test-nospell.vim @@ -7,7 +7,7 @@ silent edit test-nospell.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texMatcher', 7, 14)) +call vimtex#test#assert(vimtex#syntax#in('texGroup', 7, 14)) call vimtex#test#assert(vimtex#syntax#in('texArgNoSpell', 8, 14)) quit! From c00a41c6c663d7e71b8fe3b8a09c778306728c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sat, 7 Nov 2020 00:35:24 +0100 Subject: [PATCH 40/99] wip: change naming scheme --- autoload/vimtex/delim.vim | 2 +- autoload/vimtex/syntax.vim | 2 +- autoload/vimtex/syntax/core.vim | 986 +++++++++--------- autoload/vimtex/syntax/p/amsmath.vim | 8 +- autoload/vimtex/syntax/p/array.vim | 2 +- autoload/vimtex/syntax/p/asymptote.vim | 10 +- autoload/vimtex/syntax/p/beamer.vim | 14 +- autoload/vimtex/syntax/p/biblatex.vim | 52 +- autoload/vimtex/syntax/p/cleveref.vim | 19 +- autoload/vimtex/syntax/p/csquotes.vim | 10 +- autoload/vimtex/syntax/p/dot2texi.vim | 2 +- autoload/vimtex/syntax/p/glossaries.vim | 4 +- autoload/vimtex/syntax/p/gnuplottex.vim | 2 +- autoload/vimtex/syntax/p/hyperref.vim | 23 +- autoload/vimtex/syntax/p/ieeetrantools.vim | 6 +- autoload/vimtex/syntax/p/listings.vim | 2 +- autoload/vimtex/syntax/p/luacode.vim | 8 +- autoload/vimtex/syntax/p/markdown.vim | 4 +- autoload/vimtex/syntax/p/minted.vim | 2 +- autoload/vimtex/syntax/p/moreverb.vim | 6 +- autoload/vimtex/syntax/p/pdfpages.vim | 2 +- autoload/vimtex/syntax/p/pgfplots.vim | 18 +- autoload/vimtex/syntax/p/pythontex.vim | 8 +- autoload/vimtex/syntax/p/subfile.vim | 4 +- autoload/vimtex/syntax/p/tabularx.vim | 23 +- autoload/vimtex/syntax/p/tikz.vim | 17 +- autoload/vimtex/syntax/p/varioref.vim | 2 +- autoload/vimtex/syntax/p/wiki.vim | 2 +- test/tests/test-syntax/test-bold-italic.tex | 2 - test/tests/test-syntax/test-bold-italic.vim | 5 +- test/tests/test-syntax/test-breqn.vim | 2 +- test/tests/test-syntax/test-core.tex | 2 +- test/tests/test-syntax/test-core.vim | 6 +- test/tests/test-syntax/test-hyperref.vim | 4 +- test/tests/test-syntax/test-ieeetrantools.vim | 8 +- test/tests/test-syntax/test-markdown.vim | 2 +- test/tests/test-syntax/test-nospell.vim | 2 +- test/tests/test-syntax/test-tabularx.vim | 2 +- test/tests/test-syntax/test-tikz.vim | 2 +- 39 files changed, 651 insertions(+), 626 deletions(-) diff --git a/autoload/vimtex/delim.vim b/autoload/vimtex/delim.vim index ddc34ea0b0..8c9791e7a8 100644 --- a/autoload/vimtex/delim.vim +++ b/autoload/vimtex/delim.vim @@ -591,7 +591,7 @@ function! s:parser_tex(match, lnum, cnum, side, type, direction) abort " {{{1 \ 'close' : '\m' . escape(a:match, '$'), \} let result.side = vimtex#syntax#in( - \ (a:match ==# '$' ? 'texRegionMathX' : 'texRegionMathXX'), + \ (a:match ==# '$' ? 'texMathRegionX' : 'texMathRegionXX'), \ a:lnum, a:cnum+1) \ ? 'open' : 'close' let result.is_open = result.side ==# 'open' diff --git a/autoload/vimtex/syntax.vim b/autoload/vimtex/syntax.vim index de88477846..d0d4e68e67 100644 --- a/autoload/vimtex/syntax.vim +++ b/autoload/vimtex/syntax.vim @@ -26,7 +26,7 @@ endfunction " }}}1 function! vimtex#syntax#in_mathzone(...) abort " {{{1 - return call('vimtex#syntax#in', ['texRegionMath'] + a:000) + return call('vimtex#syntax#in', ['texMathRegion'] + a:000) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index e5fda50cee..044b842408 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -15,17 +15,8 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax sync maxlines=500 syntax sync minlines=50 - " {{{2 Primitives + " {{{2 Comments - " Match unspecified TeX groups (this is necessary to always match the - " corresponding end brace for specific argument groups) - syntax region texGroup matchgroup=texDelim - \ start="{" skip="\\\\\|\\}" end="}" contains=TOP - - " Flag mismatching ending brace delimiter - syntax match texError "}" - - " Comments " * In documented TeX Format, actual comments are defined by leading "^^A". " Almost all other lines start with one or more "%", which may be matched " as comment characters. The remaining part of the line can be interpreted @@ -52,32 +43,63 @@ function! vimtex#syntax#core#init() abort " {{{1 \ containedin=texComment contained syntax case match - " TeX Lengths - syntax match texLength contained "\<\d\+\([.,]\d\+\)\?\s*\(true\)\?\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>" + " }}}2 + " {{{2 TeX symbols and special characters + + syntax match texSymbolString "\v%(``|''|,,)" + syntax match texSymbolDash "--" + syntax match texSymbolDash "---" + syntax match texSymbolAmp "&" + syntax match texSymbolNewline "\\\\" + + " E.g.: \$ \& \% \# \{ \} \_ \S \P + syntax match texSpecialChar "\\[$&%#{}_]" + if l:cfg.is_style_document + syntax match texSpecialChar "\\[SP@]\ze[^a-zA-Z@]" + else + syntax match texSpecialChar "\\[SP@]\ze\A" + endif + syntax match texSpecialChar "\^\^\%(\S\|[0-9a-f]\{2}\)" " }}}2 - " {{{2 Commands + " {{{2 Commands: general + + " Match unspecified TeX groups + " Note: This is necessary to always match the corresponding end brace for + " specific argument groups. + syntax region texGroup matchgroup=texDelim + \ start="{" skip="\\\\\|\\}" end="}" contains=TOP + + " Flag mismatching ending brace delimiter + syntax match texGroupError "}" - " Most general version first + " Match general commands first + if l:cfg.is_style_document + syntax match texCmdSty "\\[a-zA-Z@]\+" + endif syntax match texCmd "\\\a\+" syntax match texCmdError "\\\a*@\a*" - " Add some standard contained stuff + " Add generic option elements contained in common option groups syntax match texOptEqual contained "=" syntax match texOptSep contained ",\s*" - " Accents and ligatures - syntax match texCmdAccent "\\[bcdvuH]$" - syntax match texCmdAccent "\\[bcdvuH]\ze\A" - syntax match texCmdAccent /\\[=^.~"`']/ - syntax match texCmdAccent /\\['=t'.c^ud"vb~Hr]{\a}/ - syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)$" - syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze\A" + " TeX Lengths (matched in options and some arguments) + syntax match texLength contained "\<\d\+\([.,]\d\+\)\?\s*\(true\)\?\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>" + " {{{2 Commands: core set + + " Accents and ligatures if l:cfg.is_style_document - syntax match texCmd "\\[a-zA-Z@]\+" syntax match texCmdAccent "\\[bcdvuH]\ze[^a-zA-Z@]" syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze[^a-zA-Z@]" + else + syntax match texCmdAccent "\\[bcdvuH]$" + syntax match texCmdAccent "\\[bcdvuH]\ze\A" + syntax match texCmdAccent /\\[=^.~"`']/ + syntax match texCmdAccent /\\['=t'.c^ud"vb~Hr]{\a}/ + syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)$" + syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze\A" endif " Spacecodes (TeX'isms) @@ -95,26 +117,30 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdTodo '\\todo\w*' " Author and title commands - syntax match texCmdAuthor nextgroup=texOptAuthor,texArgAuthor skipwhite skipnl "\\author\>" - syntax match texCmdTitle nextgroup=texArgTitle skipwhite skipnl "\\title\>" - call vimtex#syntax#core#new_cmd_opt('texOptAuthor', 'texArgAuthor') - call vimtex#syntax#core#new_cmd_arg('texArgAuthor', '', 'texCmd,texGroup,texCmdAccent,texCmdLigature,texSpecialChar,texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texArgTitle', '', 'texCmd,texGroup,texComment') + syntax match texCmdAuthor nextgroup=texAuthorOpt,texAuthorArg skipwhite skipnl "\\author\>" + syntax match texCmdTitle nextgroup=texTitleArg skipwhite skipnl "\\title\>" + call vimtex#syntax#core#new_cmd_opt('texAuthorOpt', 'texAuthorArg') + call vimtex#syntax#core#new_cmd_arg('texAuthorArg', '', '@texClusterTL,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texTitleArg', '', '@texClusterTL') + + " Footnotes + syntax match texCmdFootnote nextgroup=texFootnoteArg skipwhite skipnl "\\footnote\>" + call vimtex#syntax#core#new_cmd_arg('texFootnoteArg', '', '@texClusterTL') " Various commands that take a file argument (or similar) - syntax match texCmd nextgroup=texArgFile skipwhite skipnl "\\input\>" - syntax match texCmd nextgroup=texArgFile skipwhite skipnl "\\include\>" - syntax match texCmd nextgroup=texArgFiles skipwhite skipnl "\\includeonly\>" - syntax match texCmd nextgroup=texOptFile,texArgFile skipwhite skipnl "\\includegraphics\>" - syntax match texCmd nextgroup=texArgFiles skipwhite skipnl "\\bibliography\>" - syntax match texCmd nextgroup=texArgFile skipwhite skipnl "\\bibliographystyle\>" - syntax match texCmd nextgroup=texOptFile,texArgFile skipwhite skipnl "\\document\%(class\|style\)\>" - syntax match texCmd nextgroup=texOptFiles,texArgFiles skipwhite skipnl "\\usepackage\>" - syntax match texCmd nextgroup=texOptFiles,texArgFiles skipwhite skipnl "\\RequirePackage\>" - call vimtex#syntax#core#new_cmd_opt('texOptFile', 'texArgFile') - call vimtex#syntax#core#new_cmd_opt('texOptFiles', 'texArgFiles') - call vimtex#syntax#core#new_cmd_arg('texArgFile', '', 'texCmd,texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texArgFiles', '', 'texOptSep,texCmd,texComment,@NoSpell') + syntax match texCmdInput nextgroup=texFileArg skipwhite skipnl "\\input\>" + syntax match texCmdInput nextgroup=texFileArg skipwhite skipnl "\\include\>" + syntax match texCmdInput nextgroup=texFilesArg skipwhite skipnl "\\includeonly\>" + syntax match texCmdInput nextgroup=texFileOpt,texFileArg skipwhite skipnl "\\includegraphics\>" + syntax match texCmdBib nextgroup=texFilesArg skipwhite skipnl "\\bibliography\>" + syntax match texCmdBib nextgroup=texFileArg skipwhite skipnl "\\bibliographystyle\>" + syntax match texCmdClass nextgroup=texFileOpt,texFileArg skipwhite skipnl "\\document\%(class\|style\)\>" + syntax match texCmdPackage nextgroup=texFilesOpt,texFilesArg skipwhite skipnl "\\usepackage\>" + syntax match texCmdPackage nextgroup=texFilesOpt,texFilesArg skipwhite skipnl "\\RequirePackage\>" + call vimtex#syntax#core#new_cmd_opt('texFileOpt', 'texFileArg') + call vimtex#syntax#core#new_cmd_arg('texFileArg', '', '@NoSpell,texCmd,texComment') + call vimtex#syntax#core#new_cmd_opt('texFilesOpt', 'texFilesArg') + call vimtex#syntax#core#new_cmd_arg('texFilesArg', '', '@NoSpell,texCmd,texComment,texOptSep') " LaTeX 2.09 type styles syntax match texCmdStyle "\\rm\>" @@ -174,137 +200,122 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdSize "\\Huge\>" " \newcommand - syntax match texCmd nextgroup=texArgNewcmdName skipwhite skipnl "\\\%(re\)\?newcommand\>" - call vimtex#syntax#core#new_cmd_arg('texArgNewcmdName', 'texOptNewcmd,texArgNewcmdBody') - call vimtex#syntax#core#new_cmd_opt('texOptNewcmd', 'texOptNewcmd,texArgNewcmdBody', '', 'oneline') - call vimtex#syntax#core#new_cmd_arg('texArgNewcmdBody', '', 'TOP') - syntax match texParmNewcmd contained "#\d\+" containedin=texArgNewcmdBody + syntax match texCmdNewcmd nextgroup=texNewcmdArgName skipwhite skipnl "\\\%(re\)\?newcommand\>" + call vimtex#syntax#core#new_cmd_arg('texNewcmdArgName', 'texNewcmdOpt,texNewcmdArgBody') + call vimtex#syntax#core#new_cmd_opt('texNewcmdOpt', 'texNewcmdOpt,texNewcmdArgBody', '', 'oneline') + call vimtex#syntax#core#new_cmd_arg('texNewcmdArgBody', '', '@texClusterTL') + syntax match texNewcmdParm contained "#\d\+" containedin=texNewcmdArgBody " \newenvironment - syntax match texCmd nextgroup=texArgNewenvName skipwhite skipnl "\\\%(re\)\?newenvironment\>" - call vimtex#syntax#core#new_cmd_arg('texArgNewenvName', 'texArgNewenvBegin,texOptNewenv') - call vimtex#syntax#core#new_cmd_opt('texOptNewenv', 'texArgNewenvBegin,texOptNewenv', '', 'oneline') - call vimtex#syntax#core#new_cmd_arg('texArgNewenvBegin', 'texArgNewenvEnd', 'TOP') - call vimtex#syntax#core#new_cmd_arg('texArgNewenvEnd', '', 'TOP') - syntax match texParmNewenv contained "#\d\+" containedin=texArgNewenvBegin,texArgNewenvEnd + syntax match texCmdenv nextgroup=texNewenvArgName skipwhite skipnl "\\\%(re\)\?newenvironment\>" + call vimtex#syntax#core#new_cmd_arg('texNewenvArgName', 'texNewenvArgBegin,texNewenvOpt') + call vimtex#syntax#core#new_cmd_opt('texNewenvOpt', 'texNewenvArgBegin,texNewenvOpt', '', 'oneline') + call vimtex#syntax#core#new_cmd_arg('texNewenvArgBegin', 'texNewenvArgEnd', 'TOP') + call vimtex#syntax#core#new_cmd_arg('texNewenvArgEnd', '', '@texClusterTL') + syntax match texNewenvParm contained "#\d\+" containedin=texNewenvArgBegin,texNewenvArgEnd " Definitions/Commands " E.g. \def \foo #1#2 {foo #1 bar #2 baz} - syntax match texCmd "\\def\>" nextgroup=texArgDefName skipwhite skipnl + syntax match texCmdDef "\\def\>" nextgroup=texDefArgName skipwhite skipnl if l:cfg.is_style_document - syntax match texArgDefName contained nextgroup=texParmDefPre,texArgDefBody skipwhite skipnl "\\[a-zA-Z@]\+" - syntax match texArgDefName contained nextgroup=texParmDefPre,texArgDefBody skipwhite skipnl "\\[^a-zA-Z@]" + syntax match texDefArgName contained nextgroup=texDefParmPre,texDefArgBody skipwhite skipnl "\\[a-zA-Z@]\+" + syntax match texDefArgName contained nextgroup=texDefParmPre,texDefArgBody skipwhite skipnl "\\[^a-zA-Z@]" else - syntax match texArgDefName contained nextgroup=texParmDefPre,texArgDefBody skipwhite skipnl "\\\a\+" - syntax match texArgDefName contained nextgroup=texParmDefPre,texArgDefBody skipwhite skipnl "\\\A" + syntax match texDefArgName contained nextgroup=texDefParmPre,texDefArgBody skipwhite skipnl "\\\a\+" + syntax match texDefArgName contained nextgroup=texDefParmPre,texDefArgBody skipwhite skipnl "\\\A" endif - syntax match texParmDefPre contained nextgroup=texArgDefBody skipwhite skipnl "#[^{]*" - syntax match texParmDef contained "#\d\+" containedin=texParmDefPre,texArgDefBody - call vimtex#syntax#core#new_cmd_arg('texArgDefBody', '', 'TOP') + syntax match texDefParmPre contained nextgroup=texDefArgBody skipwhite skipnl "#[^{]*" + syntax match texDefParm contained "#\d\+" containedin=texDefParmPre,texDefArgBody + call vimtex#syntax#core#new_cmd_arg('texDefArgBody', '', '@texClusterTL') " Reference and cite commands - syntax match texCmd nextgroup=texArgRef skipwhite skipnl "\\nocite\>" - syntax match texCmd nextgroup=texArgRef skipwhite skipnl "\\label\>" - syntax match texCmd nextgroup=texArgRef skipwhite skipnl "\\\(page\|eq\)ref\>" - syntax match texCmd nextgroup=texArgRef skipwhite skipnl "\\v\?ref\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\cite\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\cite[tp]\>\*\?" - call vimtex#syntax#core#new_cmd_arg('texArgRef', '', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_opt('texOptRef', 'texOptRef,texArgRef') - - " \makeatletter ... \makeatother sections - " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do - " In short: allow @ in multicharacter macro name - syntax region texRegionSty matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP - syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=texRegionSty - - " Add @NoSpell for commands per configuration - for l:macro in g:vimtex_syntax_nospell_commands - execute 'syntax match texCmd nextgroup=texArgNoSpell skipwhite skipnl' - \ '"\\' . l:macro . '"' - endfor - call vimtex#syntax#core#new_cmd_arg('texArgNoSpell', '', '@NoSpell') + syntax match texCmdRef nextgroup=texRefArg skipwhite skipnl "\\nocite\>" + syntax match texCmdRef nextgroup=texRefArg skipwhite skipnl "\\label\>" + syntax match texCmdRef nextgroup=texRefArg skipwhite skipnl "\\\(page\|eq\)ref\>" + syntax match texCmdRef nextgroup=texRefArg skipwhite skipnl "\\v\?ref\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\cite\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\cite[tp]\>\*\?" + call vimtex#syntax#core#new_cmd_opt('texRefOpt', 'texRefOpt,texRefArg') + call vimtex#syntax#core#new_cmd_arg('texRefArg', '', 'texComment,@NoSpell') " Sections and parts syntax match texCmdParts "\\\(front\|main\|back\)matter\>" - syntax match texCmdParts nextgroup=texArgPartTitle "\\part\>" - syntax match texCmdParts nextgroup=texArgPartTitle "\\chapter\>\*\?" - syntax match texCmdParts nextgroup=texArgPartTitle "\\\(sub\)*section\>\*\?" - syntax match texCmdParts nextgroup=texArgPartTitle "\\\(sub\)\?paragraph\>" - call vimtex#syntax#core#new_cmd_arg('texArgPartTitle', '', 'TOP') + syntax match texCmdParts nextgroup=texPartArgTitle "\\part\>" + syntax match texCmdParts nextgroup=texPartArgTitle "\\chapter\>\*\?" + syntax match texCmdParts nextgroup=texPartArgTitle "\\\(sub\)*section\>\*\?" + syntax match texCmdParts nextgroup=texPartArgTitle "\\\(sub\)\?paragraph\>" + call vimtex#syntax#core#new_cmd_arg('texPartArgTitle', '', '@texClusterTL') " Item elements in lists syntax match texCmdItem "\\item\>" - " }}}2 - " {{{2 Environments + " Add @NoSpell for commands per configuration + for l:macro in g:vimtex_syntax_nospell_commands + execute 'syntax match texCmdNoSpell nextgroup=texNoSpellArg skipwhite skipnl "\\' . l:macro . '"' + endfor + call vimtex#syntax#core#new_cmd_arg('texNoSpellArg', '', '@texClusterTL,@NoSpell') - syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texArgEnvName - call vimtex#syntax#core#new_cmd_arg('texArgEnvName', 'texOptEnvModifier') - call vimtex#syntax#core#new_cmd_opt('texOptEnvModifier', '', 'texComment,@NoSpell') + " \begin \end environments + syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvArgName + call vimtex#syntax#core#new_cmd_arg('texEnvArgName', 'texEnvOpt') + call vimtex#syntax#core#new_cmd_opt('texEnvOpt', '', 'texComment,@NoSpell') - syntax match texCmdEnvMath "\v\\%(begin|end)>" contained nextgroup=texArgEnvMathName - call vimtex#syntax#core#new_cmd_arg('texArgEnvMathName', '') + " Specify clusters for use in regions + syntax cluster texClusterCmd contains=texCmd.*,texGroup.* + syntax cluster texClusterOpt contains=texOptEqual,texOptSep + syntax cluster texClusterTL contains=@texClusterCmd,texSpecialChar,texSymbol.*,texComment " }}}2 - " {{{2 Verbatim - - " Verbatim environment - call vimtex#syntax#core#new_region_env('texRegionVerb', '[vV]erbatim') + " {{{2 Region: \makeatletter ... \makeatother - " Verbatim inline - syntax match texCmd "\\verb\>\*\?" nextgroup=texRegionVerbInline - if l:cfg.is_style_document - syntax region texRegionVerbInline matchgroup=texDelim - \ start="\z([^\ta-zA-Z@]\)" end="\z1" contained - else - syntax region texRegionVerbInline matchgroup=texDelim - \ start="\z([^\ta-zA-Z]\)" end="\z1" contained - endif + " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do + " In short: allow @ in multicharacter macro name + syntax region texRegionSty matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP + syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=texRegionSty " }}}2 - " {{{2 Various TeX symbols + " {{{2 Region: Verbatim - syntax match texSymbolString "\v%(``|''|,,)" - syntax match texSymbolDash "--" - syntax match texSymbolDash "---" - syntax match texSymbolAmp "&" + " Verbatim environment + call vimtex#syntax#core#new_region_env('texVerbRegion', '[vV]erbatim') - " E.g.: \$ \& \% \# \{ \} \_ \S \P - syntax match texSpecialChar "\\[$&%#{}_]" + " Verbatim inline + syntax match texCmdVerb "\\verb\>\*\?" nextgroup=texVerbRegionInline + syntax cluster texClusterCmd add=texCmdVerb if l:cfg.is_style_document - syntax match texSpecialChar "\\[SP@]\ze[^a-zA-Z@]" + syntax region texVerbRegionInline matchgroup=texDelim start="\z([^\ta-zA-Z@]\)" end="\z1" contained else - syntax match texSpecialChar "\\[SP@]\ze\A" + syntax region texVerbRegionInline matchgroup=texDelim start="\z([^\ta-zA-Z]\)" end="\z1" contained endif - syntax match texSpecialChar "\\\\" - syntax match texSpecialChar "\^\^\%(\S\|[0-9a-f]\{2}\)" " }}}2 - " {{{2 Expl3 + " {{{2 Region: Expl3 - syntax region texRegionExpl3 matchgroup=texCmdExpl3 + syntax region texE3Region matchgroup=texCmdExpl3 \ start='\\\%(ExplSyntaxOn\|ProvidesExpl\%(Package\|Class\|File\)\)' \ end='\\ExplSyntaxOff\|\%$' \ transparent keepend \ contains=TOP - syntax region texGroupE3 matchgroup=texDelim + syntax region texE3Group matchgroup=texDelim \ start="{" skip="\\\\\|\\}" end="}" \ contained - \ containedin=texRegionExpl3,texGroupE3 + \ containedin=texE3Region,texE3Group \ contains=TOP - syntax match texE3Var contained containedin=texRegionExpl3,texGroupE3 "\\\a*\%(_\+[a-zA-Z]\+\)\+\>" - syntax match texE3Func contained containedin=texRegionExpl3,texGroupE3 "\\\a*\%(_\+[a-zA-Z]\+\)\+:[a-zA-Z]*" - syntax match texE3Parm contained containedin=texRegionExpl3,texGroupE3 "#\d\+" + syntax match texE3Var contained containedin=texE3Region,texE3Group "\\\a*\%(_\+[a-zA-Z]\+\)\+\>" + syntax match texE3Func contained containedin=texE3Region,texE3Group "\\\a*\%(_\+[a-zA-Z]\+\)\+:[a-zA-Z]*" + syntax match texE3Parm contained containedin=texE3Region,texE3Group "#\d\+" " }}}2 - " {{{2 Math + " {{{2 Region: Math + + syntax match texCmdMathenv "\v\\%(begin|end)>" contained nextgroup=texMathenvArgName + call vimtex#syntax#core#new_cmd_arg('texMathenvArgName', '') " Syntax clusters for math regions - syntax cluster texClusterMath contains=texCmd,texCmdGreek,texCmdSize,texCmdStyle,texComment,texDelimMath,texDelimMathMod,texLength,texGroupMath,texMathOper,texSymbolMath,texSpecialChar,texMathSub,texMathSuper,texSymbolAmp,texSymbolDash,@NoSpell - syntax region texGroupMath matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath + syntax cluster texClusterMath contains=texCmd,texCmdGreek,texCmdSize,texCmdStyle,texComment,texMathDelim,texMathDelimMod,texLength,texMathGroup,texMathOper,texMathSymbol,texSpecialChar,texMathSub,texMathSuper,texSymbolAmp,texSymbolDash,texSymbolNewline,@NoSpell + syntax region texMathGroup matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath " Math regions: environments call vimtex#syntax#core#new_region_math('displaymath', 1) @@ -314,32 +325,31 @@ function! vimtex#syntax#core#init() abort " {{{1 " Math regions: Inline Math Zones if l:cfg.conceal.math_bounds - syntax region texRegionMath matchgroup=texDelimMathmode concealends contains=@texClusterMath keepend start="\\(" end="\\)" - syntax region texRegionMath matchgroup=texDelimMathmode concealends contains=@texClusterMath keepend start="\\\[" end="\\]" - syntax region texRegionMathX matchgroup=texDelimMathmode concealends contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" - syntax region texRegionMathXX matchgroup=texDelimMathmode concealends contains=@texClusterMath keepend start="\$\$" end="\$\$" + syntax region texMathRegion matchgroup=texMathRegionDelim concealends contains=@texClusterMath keepend start="\\(" end="\\)" + syntax region texMathRegion matchgroup=texMathRegionDelim concealends contains=@texClusterMath keepend start="\\\[" end="\\]" + syntax region texMathRegionX matchgroup=texMathRegionDelim concealends contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" + syntax region texMathRegionXX matchgroup=texMathRegionDelim concealends contains=@texClusterMath keepend start="\$\$" end="\$\$" else - syntax region texRegionMath matchgroup=texDelimMathmode contains=@texClusterMath keepend start="\\(" end="\\)" - syntax region texRegionMath matchgroup=texDelimMathmode contains=@texClusterMath keepend start="\\\[" end="\\]" - syntax region texRegionMathX matchgroup=texDelimMathmode contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" - syntax region texRegionMathXX matchgroup=texDelimMathmode contains=@texClusterMath keepend start="\$\$" end="\$\$" + syntax region texMathRegion matchgroup=texMathRegionDelim contains=@texClusterMath keepend start="\\(" end="\\)" + syntax region texMathRegion matchgroup=texMathRegionDelim contains=@texClusterMath keepend start="\\\[" end="\\]" + syntax region texMathRegionX matchgroup=texMathRegionDelim contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" + syntax region texMathRegionXX matchgroup=texMathRegionDelim contains=@texClusterMath keepend start="\$\$" end="\$\$" endif " Math regions: \ensuremath{...} - syntax match texCmd "\\ensuremath\>" nextgroup=texRegionMathEnsured - call vimtex#syntax#core#new_cmd_arg('texRegionMathEnsured', '', '@texClusterMath') + syntax match texCmdMath "\\ensuremath\>" nextgroup=texMathRegionEnsured + call vimtex#syntax#core#new_cmd_arg('texMathRegionEnsured', '', '@texClusterMath') " Bad/Mismatched math - syntax match texErrorOnlyMath "[_^]" - syntax match texErrorMath "\\[\])]" - syntax match texErrorMath "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}" + syntax match texMathError "\\[\])]" + syntax match texMathError "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}" " Operators and similar syntax match texMathOper "[_^=]" contained " Text Inside Math regions - syntax match texCmd "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texArgMathText - call vimtex#syntax#core#new_cmd_arg('texArgMathText', '', 'TOP,@Spell') + syntax match texCmdMathtext "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texMathtextArg + call vimtex#syntax#core#new_cmd_arg('texMathtextArg', '', '@texClusterTL,@Spell') call s:match_math_sub_super(l:cfg) call s:match_math_symbols(l:cfg) @@ -404,7 +414,7 @@ endfunction " }}}1 function! vimtex#syntax#core#new_region_env(grp, envname, ...) abort " {{{1 - let l:contains = 'texCmdEnv,texArgEnvName' + let l:contains = 'texCmdEnv,texEnvArgName' let l:options = 'keepend' if a:0 > 0 @@ -421,19 +431,19 @@ endfunction " }}}1 function! vimtex#syntax#core#new_region_math(mathzone, starred) abort " {{{1 - execute 'syntax match texErrorMath /\\end\s*{\s*' . a:mathzone . '\*\?\s*}/' + execute 'syntax match texMathError /\\end\s*{\s*' . a:mathzone . '\*\?\s*}/' - execute 'syntax region texRegionMathEnv' + execute 'syntax region texMathRegionEnv' \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\s*}''' \ . ' end=''\\end\s*{\s*' . a:mathzone . '\s*}''' - \ . ' keepend contains=texCmdEnvMath,texArgEnvMathName,@texClusterMath' + \ . ' keepend contains=texCmdMathenv,texMathenvArgName,@texClusterMath' if !a:starred | return | endif - execute 'syntax region texRegionMathEnvStarred' + execute 'syntax region texMathRegionEnvStarred' \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\*\s*}''' \ . ' end=''\\end\s*{\s*' . a:mathzone . '\*\s*}''' - \ . ' keepend contains=texCmdEnvMath,texArgEnvMathName,@texClusterMath' + \ . ' keepend contains=texCmdMathenv,texMathenvArgName,@texClusterMath' endfunction " }}}1 @@ -444,11 +454,6 @@ function! s:init_highlights(cfg) abort " {{{1 " Basic TeX highlighting groups highlight def link texArg Include - highlight def link texArgEnvMathName Delimiter - highlight def link texArgEnvName PreCondit - highlight def link texArgPartTitle String - highlight def link texArgRef Special - highlight def link texArgTitle Underlined highlight def link texCmd Statement highlight def link texCmdSpaceCodeChar Special highlight def link texCmdTodo Todo @@ -456,40 +461,53 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texComment Comment highlight def link texCommentTodo Todo highlight def link texDelim Delimiter - highlight def link texDelimMath Type - highlight def link texDelimMathMod Statement + highlight def link texEnvArgName PreCondit highlight def link texError Error highlight def link texLength Number + highlight def link texMathDelim Type + highlight def link texMathDelimMod Statement highlight def link texMathOper Operator + highlight def link texMathRegion Special + highlight def link texMathenvArgName Delimiter highlight def link texOpt Identifier highlight def link texOptSep NormalNC highlight def link texParm Special + highlight def link texPartArgTitle String + highlight def link texRefArg Special highlight def link texRegion PreCondit - highlight def link texRegionMath Special highlight def link texSpecialChar SpecialChar highlight def link texSymbol SpecialChar highlight def link texSymbolString String + highlight def link texTitleArg Underlined highlight def texStyleBold gui=bold cterm=bold highlight def texStyleItal gui=italic cterm=italic highlight def texStyleBoth gui=bold,italic cterm=bold,italic " Inherited groups - highlight def link texArgDefName texCmd - highlight def link texArgFile texArg - highlight def link texArgFiles texArgFile - highlight def link texArgNewcmdName texCmd - highlight def link texArgNewenvName texArgEnvName + highlight def link texAuthorOpt texOpt highlight def link texCmdAccent texCmd highlight def link texCmdAuthor texCmd + highlight def link texCmdBib texCmd + highlight def link texCmdClass texCmd + highlight def link texCmdDef texCmd highlight def link texCmdEnv texCmd - highlight def link texCmdEnvMath texCmdEnv highlight def link texCmdError texError highlight def link texCmdExpl3 texCmd + highlight def link texCmdFootnote texCmd highlight def link texCmdGreek texCmd + highlight def link texCmdInput texCmd highlight def link texCmdItem texCmdEnv highlight def link texCmdLigature texSpecialChar + highlight def link texCmdMath texCmd + highlight def link texCmdMathenv texCmdEnv + highlight def link texCmdMathtext texCmd + highlight def link texCmdNewcmd texCmd + highlight def link texCmdNewenv texCmd + highlight def link texCmdNoSpell texCmd + highlight def link texCmdPackage texCmd highlight def link texCmdParts texCmd + highlight def link texCmdRef texCmd highlight def link texCmdSize texCmdType highlight def link texCmdSpaceCode texCmd highlight def link texCmdSty texCmd @@ -500,40 +518,46 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdStyleItal texCmd highlight def link texCmdStyleItalBold texCmd highlight def link texCmdTitle texCmd + highlight def link texCmdVerb texCmd highlight def link texCommentAcronym texComment highlight def link texCommentURL texComment - highlight def link texDelimMathSet texDelimMath - highlight def link texDelimMathmode texDelim + highlight def link texDefArgName texCmd + highlight def link texDefParm texParm highlight def link texE3Delim texDelim highlight def link texE3Func texCmdType highlight def link texE3Parm texParm highlight def link texE3Var texCmd - highlight def link texErrorMath texError - highlight def link texErrorMathDelim texError - highlight def link texErrorOnlyMath texError - highlight def link texGroupMath texRegionMath - highlight def link texMathSub texRegionMath - highlight def link texMathSuper texRegionMath - highlight def link texOptAuthor texOpt + highlight def link texFileArg texArg + highlight def link texFileOpt texOpt + highlight def link texFilesArg texFileArg + highlight def link texFilesOpt texOpt + highlight def link texGroupError texError + highlight def link texMathDelimSet texMathDelim + highlight def link texMathError texError + highlight def link texMathErrorDelim texError + highlight def link texMathGroup texMathRegion + highlight def link texMathRegionDelim texDelim + highlight def link texMathRegionEnsured texMathRegion + highlight def link texMathRegionEnv texMathRegion + highlight def link texMathRegionEnvStarred texMathRegion + highlight def link texMathRegionX texMathRegion + highlight def link texMathRegionXX texMathRegion + highlight def link texMathSub texMathRegion + highlight def link texMathSuper texMathRegion + highlight def link texMathSymbol texCmd + highlight def link texNewcmdArgName texCmd + highlight def link texNewcmdOpt texOpt + highlight def link texNewcmdParm texParm + highlight def link texNewenvArgName texEnvArgName + highlight def link texNewenvOpt texOpt + highlight def link texNewenvParm texParm highlight def link texOptEqual texSymbol - highlight def link texOptFile texOpt - highlight def link texOptFiles texOpt - highlight def link texOptNewcmd texOpt - highlight def link texOptNewenv texOpt - highlight def link texOptRef texOpt - highlight def link texParmDef texParm - highlight def link texParmNewcmd texParm - highlight def link texParmNewenv texParm - highlight def link texRegionMathEnsured texRegionMath - highlight def link texRegionMathEnv texRegionMath - highlight def link texRegionMathEnvStarred texRegionMath - highlight def link texRegionMathX texRegionMath - highlight def link texRegionMathXX texRegionMath - highlight def link texRegionVerb texRegion - highlight def link texRegionVerbInline texRegionVerb + highlight def link texRefOpt texOpt highlight def link texSymbolAmp texSymbol highlight def link texSymbolDash texSymbol - highlight def link texSymbolMath texCmd + highlight def link texSymbolNewline texSymbol + highlight def link texVerbRegion texRegion + highlight def link texVerbRegionInline texVerbRegion endfunction " }}}1 @@ -556,16 +580,10 @@ function! s:match_bold_italic(cfg) abort " {{{1 for [l:group, l:pattern] in [ \ ['texCmdStyleBoldItal', 'emph'], \ ['texCmdStyleBoldItal', 'textit'], - \ ['texCmdStyleBoldItal', 'texts[cfl]'], - \ ['texCmdStyleBoldItal', 'texttt'], - \ ['texCmdStyleBoldItal', 'textup'], \ ['texCmdStyleItalBold', 'textbf'], \ ['texCmdStyleBold', 'textbf'], \ ['texCmdStyleItal', 'emph'], \ ['texCmdStyleItal', 'textit'], - \ ['texCmdStyleItal', 'texts[cfl]'], - \ ['texCmdStyleItal', 'texttt'], - \ ['texCmdStyleItal', 'textup'], \] execute 'syntax match' l:group '"\\' . l:pattern . '\>\s*" skipwhite skipnl nextgroup=' . l:map[l:group] l:conceal endfor @@ -710,314 +728,314 @@ function! s:match_math_symbols(cfg) abort " {{{1 " Many of these symbols were contributed by Björn Winckler if !a:cfg.conceal.math_delimiters | return | endif - syntax match texSymbolMath "\\|" contained conceal cchar=‖ - syntax match texSymbolMath "\\aleph\>" contained conceal cchar=ℵ - syntax match texSymbolMath "\\amalg\>" contained conceal cchar=∐ - syntax match texSymbolMath "\\angle\>" contained conceal cchar=∠ - syntax match texSymbolMath "\\approx\>" contained conceal cchar=≈ - syntax match texSymbolMath "\\ast\>" contained conceal cchar=∗ - syntax match texSymbolMath "\\asymp\>" contained conceal cchar=≍ - syntax match texSymbolMath "\\backslash\>" contained conceal cchar=∖ - syntax match texSymbolMath "\\bigcap\>" contained conceal cchar=∩ - syntax match texSymbolMath "\\bigcirc\>" contained conceal cchar=○ - syntax match texSymbolMath "\\bigcup\>" contained conceal cchar=∪ - syntax match texSymbolMath "\\bigodot\>" contained conceal cchar=⊙ - syntax match texSymbolMath "\\bigoplus\>" contained conceal cchar=⊕ - syntax match texSymbolMath "\\bigotimes\>" contained conceal cchar=⊗ - syntax match texSymbolMath "\\bigsqcup\>" contained conceal cchar=⊔ - syntax match texSymbolMath "\\bigtriangledown\>" contained conceal cchar=∇ - syntax match texSymbolMath "\\bigtriangleup\>" contained conceal cchar=∆ - syntax match texSymbolMath "\\bigvee\>" contained conceal cchar=⋁ - syntax match texSymbolMath "\\bigwedge\>" contained conceal cchar=⋀ - syntax match texSymbolMath "\\bot\>" contained conceal cchar=⊥ - syntax match texSymbolMath "\\bowtie\>" contained conceal cchar=⋈ - syntax match texSymbolMath "\\bullet\>" contained conceal cchar=• - syntax match texSymbolMath "\\cap\>" contained conceal cchar=∩ - syntax match texSymbolMath "\\cdot\>" contained conceal cchar=· - syntax match texSymbolMath "\\cdots\>" contained conceal cchar=⋯ - syntax match texSymbolMath "\\circ\>" contained conceal cchar=∘ - syntax match texSymbolMath "\\clubsuit\>" contained conceal cchar=♣ - syntax match texSymbolMath "\\cong\>" contained conceal cchar=≅ - syntax match texSymbolMath "\\coprod\>" contained conceal cchar=∐ - syntax match texSymbolMath "\\copyright\>" contained conceal cchar=© - syntax match texSymbolMath "\\cup\>" contained conceal cchar=∪ - syntax match texSymbolMath "\\dagger\>" contained conceal cchar=† - syntax match texSymbolMath "\\dashv\>" contained conceal cchar=⊣ - syntax match texSymbolMath "\\ddagger\>" contained conceal cchar=‡ - syntax match texSymbolMath "\\ddots\>" contained conceal cchar=⋱ - syntax match texSymbolMath "\\diamond\>" contained conceal cchar=⋄ - syntax match texSymbolMath "\\diamondsuit\>" contained conceal cchar=♢ - syntax match texSymbolMath "\\div\>" contained conceal cchar=÷ - syntax match texSymbolMath "\\doteq\>" contained conceal cchar=≐ - syntax match texSymbolMath "\\dots\>" contained conceal cchar=… - syntax match texSymbolMath "\\downarrow\>" contained conceal cchar=↓ - syntax match texSymbolMath "\\Downarrow\>" contained conceal cchar=⇓ - syntax match texSymbolMath "\\ell\>" contained conceal cchar=ℓ - syntax match texSymbolMath "\\emptyset\>" contained conceal cchar=∅ - syntax match texSymbolMath "\\equiv\>" contained conceal cchar=≡ - syntax match texSymbolMath "\\exists\>" contained conceal cchar=∃ - syntax match texSymbolMath "\\flat\>" contained conceal cchar=♭ - syntax match texSymbolMath "\\forall\>" contained conceal cchar=∀ - syntax match texSymbolMath "\\frown\>" contained conceal cchar=⁔ - syntax match texSymbolMath "\\ge\>" contained conceal cchar=≥ - syntax match texSymbolMath "\\geq\>" contained conceal cchar=≥ - syntax match texSymbolMath "\\gets\>" contained conceal cchar=← - syntax match texSymbolMath "\\gg\>" contained conceal cchar=⟫ - syntax match texSymbolMath "\\hbar\>" contained conceal cchar=ℏ - syntax match texSymbolMath "\\heartsuit\>" contained conceal cchar=♡ - syntax match texSymbolMath "\\hookleftarrow\>" contained conceal cchar=↩ - syntax match texSymbolMath "\\hookrightarrow\>" contained conceal cchar=↪ - syntax match texSymbolMath "\\iff\>" contained conceal cchar=⇔ - syntax match texSymbolMath "\\Im\>" contained conceal cchar=ℑ - syntax match texSymbolMath "\\imath\>" contained conceal cchar=ɩ - syntax match texSymbolMath "\\in\>" contained conceal cchar=∈ - syntax match texSymbolMath "\\infty\>" contained conceal cchar=∞ - syntax match texSymbolMath "\\int\>" contained conceal cchar=∫ - syntax match texSymbolMath "\\jmath\>" contained conceal cchar=𝚥 - syntax match texSymbolMath "\\land\>" contained conceal cchar=∧ - syntax match texSymbolMath "\\lceil\>" contained conceal cchar=⌈ - syntax match texSymbolMath "\\ldots\>" contained conceal cchar=… - syntax match texSymbolMath "\\le\>" contained conceal cchar=≤ - syntax match texSymbolMath "\\left|" contained conceal cchar=| - syntax match texSymbolMath "\\left\\|" contained conceal cchar=‖ - syntax match texSymbolMath "\\left(" contained conceal cchar=( - syntax match texSymbolMath "\\left\[" contained conceal cchar=[ - syntax match texSymbolMath "\\left\\{" contained conceal cchar={ - syntax match texSymbolMath "\\leftarrow\>" contained conceal cchar=← - syntax match texSymbolMath "\\Leftarrow\>" contained conceal cchar=⇐ - syntax match texSymbolMath "\\leftharpoondown\>" contained conceal cchar=↽ - syntax match texSymbolMath "\\leftharpoonup\>" contained conceal cchar=↼ - syntax match texSymbolMath "\\leftrightarrow\>" contained conceal cchar=↔ - syntax match texSymbolMath "\\Leftrightarrow\>" contained conceal cchar=⇔ - syntax match texSymbolMath "\\leq\>" contained conceal cchar=≤ - syntax match texSymbolMath "\\leq\>" contained conceal cchar=≤ - syntax match texSymbolMath "\\lfloor\>" contained conceal cchar=⌊ - syntax match texSymbolMath "\\ll\>" contained conceal cchar=≪ - syntax match texSymbolMath "\\lmoustache\>" contained conceal cchar=╭ - syntax match texSymbolMath "\\lor\>" contained conceal cchar=∨ - syntax match texSymbolMath "\\mapsto\>" contained conceal cchar=↦ - syntax match texSymbolMath "\\mid\>" contained conceal cchar=∣ - syntax match texSymbolMath "\\models\>" contained conceal cchar=╞ - syntax match texSymbolMath "\\mp\>" contained conceal cchar=∓ - syntax match texSymbolMath "\\nabla\>" contained conceal cchar=∇ - syntax match texSymbolMath "\\natural\>" contained conceal cchar=♮ - syntax match texSymbolMath "\\ne\>" contained conceal cchar=≠ - syntax match texSymbolMath "\\nearrow\>" contained conceal cchar=↗ - syntax match texSymbolMath "\\neg\>" contained conceal cchar=¬ - syntax match texSymbolMath "\\neq\>" contained conceal cchar=≠ - syntax match texSymbolMath "\\ni\>" contained conceal cchar=∋ - syntax match texSymbolMath "\\notin\>" contained conceal cchar=∉ - syntax match texSymbolMath "\\nwarrow\>" contained conceal cchar=↖ - syntax match texSymbolMath "\\odot\>" contained conceal cchar=⊙ - syntax match texSymbolMath "\\oint\>" contained conceal cchar=∮ - syntax match texSymbolMath "\\ominus\>" contained conceal cchar=⊖ - syntax match texSymbolMath "\\oplus\>" contained conceal cchar=⊕ - syntax match texSymbolMath "\\oslash\>" contained conceal cchar=⊘ - syntax match texSymbolMath "\\otimes\>" contained conceal cchar=⊗ - syntax match texSymbolMath "\\owns\>" contained conceal cchar=∋ - syntax match texSymbolMath "\\P\>" contained conceal cchar=¶ - syntax match texSymbolMath "\\parallel\>" contained conceal cchar=║ - syntax match texSymbolMath "\\partial\>" contained conceal cchar=∂ - syntax match texSymbolMath "\\perp\>" contained conceal cchar=⊥ - syntax match texSymbolMath "\\pm\>" contained conceal cchar=± - syntax match texSymbolMath "\\prec\>" contained conceal cchar=≺ - syntax match texSymbolMath "\\preceq\>" contained conceal cchar=⪯ - syntax match texSymbolMath "\\prime\>" contained conceal cchar=′ - syntax match texSymbolMath "\\prod\>" contained conceal cchar=∏ - syntax match texSymbolMath "\\propto\>" contained conceal cchar=∝ - syntax match texSymbolMath "\\rceil\>" contained conceal cchar=⌉ - syntax match texSymbolMath "\\Re\>" contained conceal cchar=ℜ - syntax match texSymbolMath "\\quad\>" contained conceal cchar=  - syntax match texSymbolMath "\\qquad\>" contained conceal cchar=  - syntax match texSymbolMath "\\rfloor\>" contained conceal cchar=⌋ - syntax match texSymbolMath "\\right|" contained conceal cchar=| - syntax match texSymbolMath "\\right\\|" contained conceal cchar=‖ - syntax match texSymbolMath "\\right)" contained conceal cchar=) - syntax match texSymbolMath "\\right]" contained conceal cchar=] - syntax match texSymbolMath "\\right\\}" contained conceal cchar=} - syntax match texSymbolMath "\\rightarrow\>" contained conceal cchar=→ - syntax match texSymbolMath "\\Rightarrow\>" contained conceal cchar=⇒ - syntax match texSymbolMath "\\rightleftharpoons\>" contained conceal cchar=⇌ - syntax match texSymbolMath "\\rmoustache\>" contained conceal cchar=╮ - syntax match texSymbolMath "\\S\>" contained conceal cchar=§ - syntax match texSymbolMath "\\searrow\>" contained conceal cchar=↘ - syntax match texSymbolMath "\\setminus\>" contained conceal cchar=∖ - syntax match texSymbolMath "\\sharp\>" contained conceal cchar=♯ - syntax match texSymbolMath "\\sim\>" contained conceal cchar=∼ - syntax match texSymbolMath "\\simeq\>" contained conceal cchar=⋍ - syntax match texSymbolMath "\\smile\>" contained conceal cchar=‿ - syntax match texSymbolMath "\\spadesuit\>" contained conceal cchar=♠ - syntax match texSymbolMath "\\sqcap\>" contained conceal cchar=⊓ - syntax match texSymbolMath "\\sqcup\>" contained conceal cchar=⊔ - syntax match texSymbolMath "\\sqsubset\>" contained conceal cchar=⊏ - syntax match texSymbolMath "\\sqsubseteq\>" contained conceal cchar=⊑ - syntax match texSymbolMath "\\sqsupset\>" contained conceal cchar=⊐ - syntax match texSymbolMath "\\sqsupseteq\>" contained conceal cchar=⊒ - syntax match texSymbolMath "\\star\>" contained conceal cchar=✫ - syntax match texSymbolMath "\\subset\>" contained conceal cchar=⊂ - syntax match texSymbolMath "\\subseteq\>" contained conceal cchar=⊆ - syntax match texSymbolMath "\\succ\>" contained conceal cchar=≻ - syntax match texSymbolMath "\\succeq\>" contained conceal cchar=⪰ - syntax match texSymbolMath "\\sum\>" contained conceal cchar=∑ - syntax match texSymbolMath "\\supset\>" contained conceal cchar=⊃ - syntax match texSymbolMath "\\supseteq\>" contained conceal cchar=⊇ - syntax match texSymbolMath "\\surd\>" contained conceal cchar=√ - syntax match texSymbolMath "\\swarrow\>" contained conceal cchar=↙ - syntax match texSymbolMath "\\times\>" contained conceal cchar=× - syntax match texSymbolMath "\\to\>" contained conceal cchar=→ - syntax match texSymbolMath "\\top\>" contained conceal cchar=⊤ - syntax match texSymbolMath "\\triangle\>" contained conceal cchar=∆ - syntax match texSymbolMath "\\triangleleft\>" contained conceal cchar=⊲ - syntax match texSymbolMath "\\triangleright\>" contained conceal cchar=⊳ - syntax match texSymbolMath "\\uparrow\>" contained conceal cchar=↑ - syntax match texSymbolMath "\\Uparrow\>" contained conceal cchar=⇑ - syntax match texSymbolMath "\\updownarrow\>" contained conceal cchar=↕ - syntax match texSymbolMath "\\Updownarrow\>" contained conceal cchar=⇕ - syntax match texSymbolMath "\\vdash\>" contained conceal cchar=⊢ - syntax match texSymbolMath "\\vdots\>" contained conceal cchar=⋮ - syntax match texSymbolMath "\\vee\>" contained conceal cchar=∨ - syntax match texSymbolMath "\\wedge\>" contained conceal cchar=∧ - syntax match texSymbolMath "\\wp\>" contained conceal cchar=℘ - syntax match texSymbolMath "\\wr\>" contained conceal cchar=≀ + syntax match texMathSymbol "\\|" contained conceal cchar=‖ + syntax match texMathSymbol "\\aleph\>" contained conceal cchar=ℵ + syntax match texMathSymbol "\\amalg\>" contained conceal cchar=∐ + syntax match texMathSymbol "\\angle\>" contained conceal cchar=∠ + syntax match texMathSymbol "\\approx\>" contained conceal cchar=≈ + syntax match texMathSymbol "\\ast\>" contained conceal cchar=∗ + syntax match texMathSymbol "\\asymp\>" contained conceal cchar=≍ + syntax match texMathSymbol "\\backslash\>" contained conceal cchar=∖ + syntax match texMathSymbol "\\bigcap\>" contained conceal cchar=∩ + syntax match texMathSymbol "\\bigcirc\>" contained conceal cchar=○ + syntax match texMathSymbol "\\bigcup\>" contained conceal cchar=∪ + syntax match texMathSymbol "\\bigodot\>" contained conceal cchar=⊙ + syntax match texMathSymbol "\\bigoplus\>" contained conceal cchar=⊕ + syntax match texMathSymbol "\\bigotimes\>" contained conceal cchar=⊗ + syntax match texMathSymbol "\\bigsqcup\>" contained conceal cchar=⊔ + syntax match texMathSymbol "\\bigtriangledown\>" contained conceal cchar=∇ + syntax match texMathSymbol "\\bigtriangleup\>" contained conceal cchar=∆ + syntax match texMathSymbol "\\bigvee\>" contained conceal cchar=⋁ + syntax match texMathSymbol "\\bigwedge\>" contained conceal cchar=⋀ + syntax match texMathSymbol "\\bot\>" contained conceal cchar=⊥ + syntax match texMathSymbol "\\bowtie\>" contained conceal cchar=⋈ + syntax match texMathSymbol "\\bullet\>" contained conceal cchar=• + syntax match texMathSymbol "\\cap\>" contained conceal cchar=∩ + syntax match texMathSymbol "\\cdot\>" contained conceal cchar=· + syntax match texMathSymbol "\\cdots\>" contained conceal cchar=⋯ + syntax match texMathSymbol "\\circ\>" contained conceal cchar=∘ + syntax match texMathSymbol "\\clubsuit\>" contained conceal cchar=♣ + syntax match texMathSymbol "\\cong\>" contained conceal cchar=≅ + syntax match texMathSymbol "\\coprod\>" contained conceal cchar=∐ + syntax match texMathSymbol "\\copyright\>" contained conceal cchar=© + syntax match texMathSymbol "\\cup\>" contained conceal cchar=∪ + syntax match texMathSymbol "\\dagger\>" contained conceal cchar=† + syntax match texMathSymbol "\\dashv\>" contained conceal cchar=⊣ + syntax match texMathSymbol "\\ddagger\>" contained conceal cchar=‡ + syntax match texMathSymbol "\\ddots\>" contained conceal cchar=⋱ + syntax match texMathSymbol "\\diamond\>" contained conceal cchar=⋄ + syntax match texMathSymbol "\\diamondsuit\>" contained conceal cchar=♢ + syntax match texMathSymbol "\\div\>" contained conceal cchar=÷ + syntax match texMathSymbol "\\doteq\>" contained conceal cchar=≐ + syntax match texMathSymbol "\\dots\>" contained conceal cchar=… + syntax match texMathSymbol "\\downarrow\>" contained conceal cchar=↓ + syntax match texMathSymbol "\\Downarrow\>" contained conceal cchar=⇓ + syntax match texMathSymbol "\\ell\>" contained conceal cchar=ℓ + syntax match texMathSymbol "\\emptyset\>" contained conceal cchar=∅ + syntax match texMathSymbol "\\equiv\>" contained conceal cchar=≡ + syntax match texMathSymbol "\\exists\>" contained conceal cchar=∃ + syntax match texMathSymbol "\\flat\>" contained conceal cchar=♭ + syntax match texMathSymbol "\\forall\>" contained conceal cchar=∀ + syntax match texMathSymbol "\\frown\>" contained conceal cchar=⁔ + syntax match texMathSymbol "\\ge\>" contained conceal cchar=≥ + syntax match texMathSymbol "\\geq\>" contained conceal cchar=≥ + syntax match texMathSymbol "\\gets\>" contained conceal cchar=← + syntax match texMathSymbol "\\gg\>" contained conceal cchar=⟫ + syntax match texMathSymbol "\\hbar\>" contained conceal cchar=ℏ + syntax match texMathSymbol "\\heartsuit\>" contained conceal cchar=♡ + syntax match texMathSymbol "\\hookleftarrow\>" contained conceal cchar=↩ + syntax match texMathSymbol "\\hookrightarrow\>" contained conceal cchar=↪ + syntax match texMathSymbol "\\iff\>" contained conceal cchar=⇔ + syntax match texMathSymbol "\\Im\>" contained conceal cchar=ℑ + syntax match texMathSymbol "\\imath\>" contained conceal cchar=ɩ + syntax match texMathSymbol "\\in\>" contained conceal cchar=∈ + syntax match texMathSymbol "\\infty\>" contained conceal cchar=∞ + syntax match texMathSymbol "\\int\>" contained conceal cchar=∫ + syntax match texMathSymbol "\\jmath\>" contained conceal cchar=𝚥 + syntax match texMathSymbol "\\land\>" contained conceal cchar=∧ + syntax match texMathSymbol "\\lceil\>" contained conceal cchar=⌈ + syntax match texMathSymbol "\\ldots\>" contained conceal cchar=… + syntax match texMathSymbol "\\le\>" contained conceal cchar=≤ + syntax match texMathSymbol "\\left|" contained conceal cchar=| + syntax match texMathSymbol "\\left\\|" contained conceal cchar=‖ + syntax match texMathSymbol "\\left(" contained conceal cchar=( + syntax match texMathSymbol "\\left\[" contained conceal cchar=[ + syntax match texMathSymbol "\\left\\{" contained conceal cchar={ + syntax match texMathSymbol "\\leftarrow\>" contained conceal cchar=← + syntax match texMathSymbol "\\Leftarrow\>" contained conceal cchar=⇐ + syntax match texMathSymbol "\\leftharpoondown\>" contained conceal cchar=↽ + syntax match texMathSymbol "\\leftharpoonup\>" contained conceal cchar=↼ + syntax match texMathSymbol "\\leftrightarrow\>" contained conceal cchar=↔ + syntax match texMathSymbol "\\Leftrightarrow\>" contained conceal cchar=⇔ + syntax match texMathSymbol "\\leq\>" contained conceal cchar=≤ + syntax match texMathSymbol "\\leq\>" contained conceal cchar=≤ + syntax match texMathSymbol "\\lfloor\>" contained conceal cchar=⌊ + syntax match texMathSymbol "\\ll\>" contained conceal cchar=≪ + syntax match texMathSymbol "\\lmoustache\>" contained conceal cchar=╭ + syntax match texMathSymbol "\\lor\>" contained conceal cchar=∨ + syntax match texMathSymbol "\\mapsto\>" contained conceal cchar=↦ + syntax match texMathSymbol "\\mid\>" contained conceal cchar=∣ + syntax match texMathSymbol "\\models\>" contained conceal cchar=╞ + syntax match texMathSymbol "\\mp\>" contained conceal cchar=∓ + syntax match texMathSymbol "\\nabla\>" contained conceal cchar=∇ + syntax match texMathSymbol "\\natural\>" contained conceal cchar=♮ + syntax match texMathSymbol "\\ne\>" contained conceal cchar=≠ + syntax match texMathSymbol "\\nearrow\>" contained conceal cchar=↗ + syntax match texMathSymbol "\\neg\>" contained conceal cchar=¬ + syntax match texMathSymbol "\\neq\>" contained conceal cchar=≠ + syntax match texMathSymbol "\\ni\>" contained conceal cchar=∋ + syntax match texMathSymbol "\\notin\>" contained conceal cchar=∉ + syntax match texMathSymbol "\\nwarrow\>" contained conceal cchar=↖ + syntax match texMathSymbol "\\odot\>" contained conceal cchar=⊙ + syntax match texMathSymbol "\\oint\>" contained conceal cchar=∮ + syntax match texMathSymbol "\\ominus\>" contained conceal cchar=⊖ + syntax match texMathSymbol "\\oplus\>" contained conceal cchar=⊕ + syntax match texMathSymbol "\\oslash\>" contained conceal cchar=⊘ + syntax match texMathSymbol "\\otimes\>" contained conceal cchar=⊗ + syntax match texMathSymbol "\\owns\>" contained conceal cchar=∋ + syntax match texMathSymbol "\\P\>" contained conceal cchar=¶ + syntax match texMathSymbol "\\parallel\>" contained conceal cchar=║ + syntax match texMathSymbol "\\partial\>" contained conceal cchar=∂ + syntax match texMathSymbol "\\perp\>" contained conceal cchar=⊥ + syntax match texMathSymbol "\\pm\>" contained conceal cchar=± + syntax match texMathSymbol "\\prec\>" contained conceal cchar=≺ + syntax match texMathSymbol "\\preceq\>" contained conceal cchar=⪯ + syntax match texMathSymbol "\\prime\>" contained conceal cchar=′ + syntax match texMathSymbol "\\prod\>" contained conceal cchar=∏ + syntax match texMathSymbol "\\propto\>" contained conceal cchar=∝ + syntax match texMathSymbol "\\rceil\>" contained conceal cchar=⌉ + syntax match texMathSymbol "\\Re\>" contained conceal cchar=ℜ + syntax match texMathSymbol "\\quad\>" contained conceal cchar=  + syntax match texMathSymbol "\\qquad\>" contained conceal cchar=  + syntax match texMathSymbol "\\rfloor\>" contained conceal cchar=⌋ + syntax match texMathSymbol "\\right|" contained conceal cchar=| + syntax match texMathSymbol "\\right\\|" contained conceal cchar=‖ + syntax match texMathSymbol "\\right)" contained conceal cchar=) + syntax match texMathSymbol "\\right]" contained conceal cchar=] + syntax match texMathSymbol "\\right\\}" contained conceal cchar=} + syntax match texMathSymbol "\\rightarrow\>" contained conceal cchar=→ + syntax match texMathSymbol "\\Rightarrow\>" contained conceal cchar=⇒ + syntax match texMathSymbol "\\rightleftharpoons\>" contained conceal cchar=⇌ + syntax match texMathSymbol "\\rmoustache\>" contained conceal cchar=╮ + syntax match texMathSymbol "\\S\>" contained conceal cchar=§ + syntax match texMathSymbol "\\searrow\>" contained conceal cchar=↘ + syntax match texMathSymbol "\\setminus\>" contained conceal cchar=∖ + syntax match texMathSymbol "\\sharp\>" contained conceal cchar=♯ + syntax match texMathSymbol "\\sim\>" contained conceal cchar=∼ + syntax match texMathSymbol "\\simeq\>" contained conceal cchar=⋍ + syntax match texMathSymbol "\\smile\>" contained conceal cchar=‿ + syntax match texMathSymbol "\\spadesuit\>" contained conceal cchar=♠ + syntax match texMathSymbol "\\sqcap\>" contained conceal cchar=⊓ + syntax match texMathSymbol "\\sqcup\>" contained conceal cchar=⊔ + syntax match texMathSymbol "\\sqsubset\>" contained conceal cchar=⊏ + syntax match texMathSymbol "\\sqsubseteq\>" contained conceal cchar=⊑ + syntax match texMathSymbol "\\sqsupset\>" contained conceal cchar=⊐ + syntax match texMathSymbol "\\sqsupseteq\>" contained conceal cchar=⊒ + syntax match texMathSymbol "\\star\>" contained conceal cchar=✫ + syntax match texMathSymbol "\\subset\>" contained conceal cchar=⊂ + syntax match texMathSymbol "\\subseteq\>" contained conceal cchar=⊆ + syntax match texMathSymbol "\\succ\>" contained conceal cchar=≻ + syntax match texMathSymbol "\\succeq\>" contained conceal cchar=⪰ + syntax match texMathSymbol "\\sum\>" contained conceal cchar=∑ + syntax match texMathSymbol "\\supset\>" contained conceal cchar=⊃ + syntax match texMathSymbol "\\supseteq\>" contained conceal cchar=⊇ + syntax match texMathSymbol "\\surd\>" contained conceal cchar=√ + syntax match texMathSymbol "\\swarrow\>" contained conceal cchar=↙ + syntax match texMathSymbol "\\times\>" contained conceal cchar=× + syntax match texMathSymbol "\\to\>" contained conceal cchar=→ + syntax match texMathSymbol "\\top\>" contained conceal cchar=⊤ + syntax match texMathSymbol "\\triangle\>" contained conceal cchar=∆ + syntax match texMathSymbol "\\triangleleft\>" contained conceal cchar=⊲ + syntax match texMathSymbol "\\triangleright\>" contained conceal cchar=⊳ + syntax match texMathSymbol "\\uparrow\>" contained conceal cchar=↑ + syntax match texMathSymbol "\\Uparrow\>" contained conceal cchar=⇑ + syntax match texMathSymbol "\\updownarrow\>" contained conceal cchar=↕ + syntax match texMathSymbol "\\Updownarrow\>" contained conceal cchar=⇕ + syntax match texMathSymbol "\\vdash\>" contained conceal cchar=⊢ + syntax match texMathSymbol "\\vdots\>" contained conceal cchar=⋮ + syntax match texMathSymbol "\\vee\>" contained conceal cchar=∨ + syntax match texMathSymbol "\\wedge\>" contained conceal cchar=∧ + syntax match texMathSymbol "\\wp\>" contained conceal cchar=℘ + syntax match texMathSymbol "\\wr\>" contained conceal cchar=≀ if &ambiwidth ==# 'double' - syntax match texSymbolMath '\\gg\>' contained conceal cchar=≫ - syntax match texSymbolMath '\\ll\>' contained conceal cchar=≪ + syntax match texMathSymbol '\\gg\>' contained conceal cchar=≫ + syntax match texMathSymbol '\\ll\>' contained conceal cchar=≪ else - syntax match texSymbolMath '\\gg\>' contained conceal cchar=⟫ - syntax match texSymbolMath '\\ll\>' contained conceal cchar=⟪ + syntax match texMathSymbol '\\gg\>' contained conceal cchar=⟫ + syntax match texMathSymbol '\\ll\>' contained conceal cchar=⟪ endif - syntax match texSymbolMath '\\bar{a}' contained conceal cchar=a̅ - - syntax match texSymbolMath '\\dot{A}' contained conceal cchar=Ȧ - syntax match texSymbolMath '\\dot{a}' contained conceal cchar=ȧ - syntax match texSymbolMath '\\dot{B}' contained conceal cchar=Ḃ - syntax match texSymbolMath '\\dot{b}' contained conceal cchar=ḃ - syntax match texSymbolMath '\\dot{C}' contained conceal cchar=Ċ - syntax match texSymbolMath '\\dot{c}' contained conceal cchar=ċ - syntax match texSymbolMath '\\dot{D}' contained conceal cchar=Ḋ - syntax match texSymbolMath '\\dot{d}' contained conceal cchar=ḋ - syntax match texSymbolMath '\\dot{E}' contained conceal cchar=Ė - syntax match texSymbolMath '\\dot{e}' contained conceal cchar=ė - syntax match texSymbolMath '\\dot{F}' contained conceal cchar=Ḟ - syntax match texSymbolMath '\\dot{f}' contained conceal cchar=ḟ - syntax match texSymbolMath '\\dot{G}' contained conceal cchar=Ġ - syntax match texSymbolMath '\\dot{g}' contained conceal cchar=ġ - syntax match texSymbolMath '\\dot{H}' contained conceal cchar=Ḣ - syntax match texSymbolMath '\\dot{h}' contained conceal cchar=ḣ - syntax match texSymbolMath '\\dot{I}' contained conceal cchar=İ - syntax match texSymbolMath '\\dot{M}' contained conceal cchar=Ṁ - syntax match texSymbolMath '\\dot{m}' contained conceal cchar=ṁ - syntax match texSymbolMath '\\dot{N}' contained conceal cchar=Ṅ - syntax match texSymbolMath '\\dot{n}' contained conceal cchar=ṅ - syntax match texSymbolMath '\\dot{O}' contained conceal cchar=Ȯ - syntax match texSymbolMath '\\dot{o}' contained conceal cchar=ȯ - syntax match texSymbolMath '\\dot{P}' contained conceal cchar=Ṗ - syntax match texSymbolMath '\\dot{p}' contained conceal cchar=ṗ - syntax match texSymbolMath '\\dot{R}' contained conceal cchar=Ṙ - syntax match texSymbolMath '\\dot{r}' contained conceal cchar=ṙ - syntax match texSymbolMath '\\dot{S}' contained conceal cchar=Ṡ - syntax match texSymbolMath '\\dot{s}' contained conceal cchar=ṡ - syntax match texSymbolMath '\\dot{T}' contained conceal cchar=Ṫ - syntax match texSymbolMath '\\dot{t}' contained conceal cchar=ṫ - syntax match texSymbolMath '\\dot{W}' contained conceal cchar=Ẇ - syntax match texSymbolMath '\\dot{w}' contained conceal cchar=ẇ - syntax match texSymbolMath '\\dot{X}' contained conceal cchar=Ẋ - syntax match texSymbolMath '\\dot{x}' contained conceal cchar=ẋ - syntax match texSymbolMath '\\dot{Y}' contained conceal cchar=Ẏ - syntax match texSymbolMath '\\dot{y}' contained conceal cchar=ẏ - syntax match texSymbolMath '\\dot{Z}' contained conceal cchar=Ż - syntax match texSymbolMath '\\dot{z}' contained conceal cchar=ż - - syntax match texSymbolMath '\\hat{a}' contained conceal cchar=â - syntax match texSymbolMath '\\hat{A}' contained conceal cchar= - syntax match texSymbolMath '\\hat{c}' contained conceal cchar=ĉ - syntax match texSymbolMath '\\hat{C}' contained conceal cchar=Ĉ - syntax match texSymbolMath '\\hat{e}' contained conceal cchar=ê - syntax match texSymbolMath '\\hat{E}' contained conceal cchar=Ê - syntax match texSymbolMath '\\hat{g}' contained conceal cchar=ĝ - syntax match texSymbolMath '\\hat{G}' contained conceal cchar=Ĝ - syntax match texSymbolMath '\\hat{i}' contained conceal cchar=î - syntax match texSymbolMath '\\hat{I}' contained conceal cchar=Î - syntax match texSymbolMath '\\hat{o}' contained conceal cchar=ô - syntax match texSymbolMath '\\hat{O}' contained conceal cchar=Ô - syntax match texSymbolMath '\\hat{s}' contained conceal cchar=ŝ - syntax match texSymbolMath '\\hat{S}' contained conceal cchar=Ŝ - syntax match texSymbolMath '\\hat{u}' contained conceal cchar=û - syntax match texSymbolMath '\\hat{U}' contained conceal cchar=Û - syntax match texSymbolMath '\\hat{w}' contained conceal cchar=ŵ - syntax match texSymbolMath '\\hat{W}' contained conceal cchar=Ŵ - syntax match texSymbolMath '\\hat{y}' contained conceal cchar=ŷ - syntax match texSymbolMath '\\hat{Y}' contained conceal cchar=Ŷ + syntax match texMathSymbol '\\bar{a}' contained conceal cchar=a̅ + + syntax match texMathSymbol '\\dot{A}' contained conceal cchar=Ȧ + syntax match texMathSymbol '\\dot{a}' contained conceal cchar=ȧ + syntax match texMathSymbol '\\dot{B}' contained conceal cchar=Ḃ + syntax match texMathSymbol '\\dot{b}' contained conceal cchar=ḃ + syntax match texMathSymbol '\\dot{C}' contained conceal cchar=Ċ + syntax match texMathSymbol '\\dot{c}' contained conceal cchar=ċ + syntax match texMathSymbol '\\dot{D}' contained conceal cchar=Ḋ + syntax match texMathSymbol '\\dot{d}' contained conceal cchar=ḋ + syntax match texMathSymbol '\\dot{E}' contained conceal cchar=Ė + syntax match texMathSymbol '\\dot{e}' contained conceal cchar=ė + syntax match texMathSymbol '\\dot{F}' contained conceal cchar=Ḟ + syntax match texMathSymbol '\\dot{f}' contained conceal cchar=ḟ + syntax match texMathSymbol '\\dot{G}' contained conceal cchar=Ġ + syntax match texMathSymbol '\\dot{g}' contained conceal cchar=ġ + syntax match texMathSymbol '\\dot{H}' contained conceal cchar=Ḣ + syntax match texMathSymbol '\\dot{h}' contained conceal cchar=ḣ + syntax match texMathSymbol '\\dot{I}' contained conceal cchar=İ + syntax match texMathSymbol '\\dot{M}' contained conceal cchar=Ṁ + syntax match texMathSymbol '\\dot{m}' contained conceal cchar=ṁ + syntax match texMathSymbol '\\dot{N}' contained conceal cchar=Ṅ + syntax match texMathSymbol '\\dot{n}' contained conceal cchar=ṅ + syntax match texMathSymbol '\\dot{O}' contained conceal cchar=Ȯ + syntax match texMathSymbol '\\dot{o}' contained conceal cchar=ȯ + syntax match texMathSymbol '\\dot{P}' contained conceal cchar=Ṗ + syntax match texMathSymbol '\\dot{p}' contained conceal cchar=ṗ + syntax match texMathSymbol '\\dot{R}' contained conceal cchar=Ṙ + syntax match texMathSymbol '\\dot{r}' contained conceal cchar=ṙ + syntax match texMathSymbol '\\dot{S}' contained conceal cchar=Ṡ + syntax match texMathSymbol '\\dot{s}' contained conceal cchar=ṡ + syntax match texMathSymbol '\\dot{T}' contained conceal cchar=Ṫ + syntax match texMathSymbol '\\dot{t}' contained conceal cchar=ṫ + syntax match texMathSymbol '\\dot{W}' contained conceal cchar=Ẇ + syntax match texMathSymbol '\\dot{w}' contained conceal cchar=ẇ + syntax match texMathSymbol '\\dot{X}' contained conceal cchar=Ẋ + syntax match texMathSymbol '\\dot{x}' contained conceal cchar=ẋ + syntax match texMathSymbol '\\dot{Y}' contained conceal cchar=Ẏ + syntax match texMathSymbol '\\dot{y}' contained conceal cchar=ẏ + syntax match texMathSymbol '\\dot{Z}' contained conceal cchar=Ż + syntax match texMathSymbol '\\dot{z}' contained conceal cchar=ż + + syntax match texMathSymbol '\\hat{a}' contained conceal cchar=â + syntax match texMathSymbol '\\hat{A}' contained conceal cchar= + syntax match texMathSymbol '\\hat{c}' contained conceal cchar=ĉ + syntax match texMathSymbol '\\hat{C}' contained conceal cchar=Ĉ + syntax match texMathSymbol '\\hat{e}' contained conceal cchar=ê + syntax match texMathSymbol '\\hat{E}' contained conceal cchar=Ê + syntax match texMathSymbol '\\hat{g}' contained conceal cchar=ĝ + syntax match texMathSymbol '\\hat{G}' contained conceal cchar=Ĝ + syntax match texMathSymbol '\\hat{i}' contained conceal cchar=î + syntax match texMathSymbol '\\hat{I}' contained conceal cchar=Î + syntax match texMathSymbol '\\hat{o}' contained conceal cchar=ô + syntax match texMathSymbol '\\hat{O}' contained conceal cchar=Ô + syntax match texMathSymbol '\\hat{s}' contained conceal cchar=ŝ + syntax match texMathSymbol '\\hat{S}' contained conceal cchar=Ŝ + syntax match texMathSymbol '\\hat{u}' contained conceal cchar=û + syntax match texMathSymbol '\\hat{U}' contained conceal cchar=Û + syntax match texMathSymbol '\\hat{w}' contained conceal cchar=ŵ + syntax match texMathSymbol '\\hat{W}' contained conceal cchar=Ŵ + syntax match texMathSymbol '\\hat{y}' contained conceal cchar=ŷ + syntax match texMathSymbol '\\hat{Y}' contained conceal cchar=Ŷ endfunction " }}}1 function! s:match_math_delims(cfg) abort " {{{1 - syntax match texDelimMathMod contained skipwhite nextgroup=texDelimMathSet "\\\(left\|right\)\>" - syntax match texDelimMathMod contained skipwhite nextgroup=texDelimMathSet "\\[bB]igg\?[lr]\?\>" - syntax match texDelimMathSet contained "[<>()[\]|/.]\|\\[{}|]" - syntax match texDelimMathSet contained "\\backslash" - syntax match texDelimMathSet contained "\\downarrow" - syntax match texDelimMathSet contained "\\Downarrow" - syntax match texDelimMathSet contained "\\lVert" - syntax match texDelimMathSet contained "\\langle" - syntax match texDelimMathSet contained "\\lbrace" - syntax match texDelimMathSet contained "\\lceil" - syntax match texDelimMathSet contained "\\lfloor" - syntax match texDelimMathSet contained "\\lgroup" - syntax match texDelimMathSet contained "\\lmoustache" - syntax match texDelimMathSet contained "\\lvert" - syntax match texDelimMathSet contained "\\rVert" - syntax match texDelimMathSet contained "\\rangle" - syntax match texDelimMathSet contained "\\rbrace" - syntax match texDelimMathSet contained "\\rceil" - syntax match texDelimMathSet contained "\\rfloor" - syntax match texDelimMathSet contained "\\rgroup" - syntax match texDelimMathSet contained "\\rmoustache" - syntax match texDelimMathSet contained "\\rvert" - syntax match texDelimMathSet contained "\\uparrow" - syntax match texDelimMathSet contained "\\Uparrow" - syntax match texDelimMathSet contained "\\updownarrow" - syntax match texDelimMathSet contained "\\Updownarrow" + syntax match texMathDelimMod contained skipwhite nextgroup=texMathDelimSet "\\\(left\|right\)\>" + syntax match texMathDelimMod contained skipwhite nextgroup=texMathDelimSet "\\[bB]igg\?[lr]\?\>" + syntax match texMathDelimSet contained "[<>()[\]|/.]\|\\[{}|]" + syntax match texMathDelimSet contained "\\backslash" + syntax match texMathDelimSet contained "\\downarrow" + syntax match texMathDelimSet contained "\\Downarrow" + syntax match texMathDelimSet contained "\\lVert" + syntax match texMathDelimSet contained "\\langle" + syntax match texMathDelimSet contained "\\lbrace" + syntax match texMathDelimSet contained "\\lceil" + syntax match texMathDelimSet contained "\\lfloor" + syntax match texMathDelimSet contained "\\lgroup" + syntax match texMathDelimSet contained "\\lmoustache" + syntax match texMathDelimSet contained "\\lvert" + syntax match texMathDelimSet contained "\\rVert" + syntax match texMathDelimSet contained "\\rangle" + syntax match texMathDelimSet contained "\\rbrace" + syntax match texMathDelimSet contained "\\rceil" + syntax match texMathDelimSet contained "\\rfloor" + syntax match texMathDelimSet contained "\\rgroup" + syntax match texMathDelimSet contained "\\rmoustache" + syntax match texMathDelimSet contained "\\rvert" + syntax match texMathDelimSet contained "\\uparrow" + syntax match texMathDelimSet contained "\\Uparrow" + syntax match texMathDelimSet contained "\\updownarrow" + syntax match texMathDelimSet contained "\\Updownarrow" if !a:cfg.conceal.math_delimiters || &encoding !=# 'utf-8' return endif - syntax match texDelimMath contained conceal cchar=< "\\\%([bB]igg\?l\|left\)<" - syntax match texDelimMath contained conceal cchar=> "\\\%([bB]igg\?r\|right\)>" - syntax match texDelimMath contained conceal cchar=( "\\\%([bB]igg\?l\|left\)(" - syntax match texDelimMath contained conceal cchar=) "\\\%([bB]igg\?r\|right\))" - syntax match texDelimMath contained conceal cchar=[ "\\\%([bB]igg\?l\|left\)\[" - syntax match texDelimMath contained conceal cchar=] "\\\%([bB]igg\?r\|right\)]" - syntax match texDelimMath contained conceal cchar={ "\\\%([bB]igg\?l\|left\)\\{" - syntax match texDelimMath contained conceal cchar=} "\\\%([bB]igg\?r\|right\)\\}" - syntax match texDelimMath contained conceal cchar=[ "\\\%([bB]igg\?l\|left\)\\lbrace" - syntax match texDelimMath contained conceal cchar=⌈ "\\\%([bB]igg\?l\|left\)\\lceil" - syntax match texDelimMath contained conceal cchar=⌊ "\\\%([bB]igg\?l\|left\)\\lfloor" - syntax match texDelimMath contained conceal cchar=⌊ "\\\%([bB]igg\?l\|left\)\\lgroup" - syntax match texDelimMath contained conceal cchar=⎛ "\\\%([bB]igg\?l\|left\)\\lmoustache" - syntax match texDelimMath contained conceal cchar=] "\\\%([bB]igg\?r\|right\)\\rbrace" - syntax match texDelimMath contained conceal cchar=⌉ "\\\%([bB]igg\?r\|right\)\\rceil" - syntax match texDelimMath contained conceal cchar=⌋ "\\\%([bB]igg\?r\|right\)\\rfloor" - syntax match texDelimMath contained conceal cchar=⌋ "\\\%([bB]igg\?r\|right\)\\rgroup" - syntax match texDelimMath contained conceal cchar=⎞ "\\\%([bB]igg\?r\|right\)\\rmoustache" - syntax match texDelimMath contained conceal cchar=| "\\\%([bB]igg\?[lr]\?\|left\|right\)|" - syntax match texDelimMath contained conceal cchar=‖ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\|" - syntax match texDelimMath contained conceal cchar=↓ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\downarrow" - syntax match texDelimMath contained conceal cchar=⇓ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Downarrow" - syntax match texDelimMath contained conceal cchar=↑ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\uparrow" - syntax match texDelimMath contained conceal cchar=↑ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Uparrow" - syntax match texDelimMath contained conceal cchar=↕ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\updownarrow" - syntax match texDelimMath contained conceal cchar=⇕ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Updownarrow" + syntax match texMathDelim contained conceal cchar=< "\\\%([bB]igg\?l\|left\)<" + syntax match texMathDelim contained conceal cchar=> "\\\%([bB]igg\?r\|right\)>" + syntax match texMathDelim contained conceal cchar=( "\\\%([bB]igg\?l\|left\)(" + syntax match texMathDelim contained conceal cchar=) "\\\%([bB]igg\?r\|right\))" + syntax match texMathDelim contained conceal cchar=[ "\\\%([bB]igg\?l\|left\)\[" + syntax match texMathDelim contained conceal cchar=] "\\\%([bB]igg\?r\|right\)]" + syntax match texMathDelim contained conceal cchar={ "\\\%([bB]igg\?l\|left\)\\{" + syntax match texMathDelim contained conceal cchar=} "\\\%([bB]igg\?r\|right\)\\}" + syntax match texMathDelim contained conceal cchar=[ "\\\%([bB]igg\?l\|left\)\\lbrace" + syntax match texMathDelim contained conceal cchar=⌈ "\\\%([bB]igg\?l\|left\)\\lceil" + syntax match texMathDelim contained conceal cchar=⌊ "\\\%([bB]igg\?l\|left\)\\lfloor" + syntax match texMathDelim contained conceal cchar=⌊ "\\\%([bB]igg\?l\|left\)\\lgroup" + syntax match texMathDelim contained conceal cchar=⎛ "\\\%([bB]igg\?l\|left\)\\lmoustache" + syntax match texMathDelim contained conceal cchar=] "\\\%([bB]igg\?r\|right\)\\rbrace" + syntax match texMathDelim contained conceal cchar=⌉ "\\\%([bB]igg\?r\|right\)\\rceil" + syntax match texMathDelim contained conceal cchar=⌋ "\\\%([bB]igg\?r\|right\)\\rfloor" + syntax match texMathDelim contained conceal cchar=⌋ "\\\%([bB]igg\?r\|right\)\\rgroup" + syntax match texMathDelim contained conceal cchar=⎞ "\\\%([bB]igg\?r\|right\)\\rmoustache" + syntax match texMathDelim contained conceal cchar=| "\\\%([bB]igg\?[lr]\?\|left\|right\)|" + syntax match texMathDelim contained conceal cchar=‖ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\|" + syntax match texMathDelim contained conceal cchar=↓ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\downarrow" + syntax match texMathDelim contained conceal cchar=⇓ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Downarrow" + syntax match texMathDelim contained conceal cchar=↑ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\uparrow" + syntax match texMathDelim contained conceal cchar=↑ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Uparrow" + syntax match texMathDelim contained conceal cchar=↕ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\updownarrow" + syntax match texMathDelim contained conceal cchar=⇕ "\\\%([bB]igg\?[lr]\?\|left\|right\)\\Updownarrow" if &ambiwidth ==# 'double' - syntax match texDelimMath contained conceal cchar=〈 "\\\%([bB]igg\?l\|left\)\\langle" - syntax match texDelimMath contained conceal cchar=〉 "\\\%([bB]igg\?r\|right\)\\rangle" + syntax match texMathDelim contained conceal cchar=〈 "\\\%([bB]igg\?l\|left\)\\langle" + syntax match texMathDelim contained conceal cchar=〉 "\\\%([bB]igg\?r\|right\)\\rangle" else - syntax match texDelimMath contained conceal cchar=< "\\\%([bB]igg\?l\|left\)\\langle" - syntax match texDelimMath contained conceal cchar=> "\\\%([bB]igg\?r\|right\)\\rangle" + syntax match texMathDelim contained conceal cchar=< "\\\%([bB]igg\?l\|left\)\\langle" + syntax match texMathDelim contained conceal cchar=> "\\\%([bB]igg\?r\|right\)\\rangle" endif endfunction diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index 07599ff9e7..62d266eeb6 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -21,10 +21,10 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 " Amsmath [lr][vV]ert if &encoding ==# 'utf-8' && g:vimtex_syntax_config.conceal.math_delimiters - syntax match texDelimMath contained conceal cchar=| "\\\%([bB]igg\?l\|left\)\\lvert" - syntax match texDelimMath contained conceal cchar=| "\\\%([bB]igg\?r\|right\)\\rvert" - syntax match texDelimMath contained conceal cchar=‖ "\\\%([bB]igg\?l\|left\)\\lVert" - syntax match texDelimMath contained conceal cchar=‖ "\\\%([bB]igg\?r\|right\)\\rVert" + syntax match texMathDelim contained conceal cchar=| "\\\%([bB]igg\?l\|left\)\\lvert" + syntax match texMathDelim contained conceal cchar=| "\\\%([bB]igg\?r\|right\)\\rvert" + syntax match texMathDelim contained conceal cchar=‖ "\\\%([bB]igg\?l\|left\)\\lVert" + syntax match texMathDelim contained conceal cchar=‖ "\\\%([bB]igg\?r\|right\)\\rVert" endif endfunction diff --git a/autoload/vimtex/syntax/p/array.vim b/autoload/vimtex/syntax/p/array.vim index 3162e44ec4..9929da3a2d 100644 --- a/autoload/vimtex/syntax/p/array.vim +++ b/autoload/vimtex/syntax/p/array.vim @@ -15,7 +15,7 @@ function! vimtex#syntax#p#array#load() abort " {{{1 " \begin{tabular}{*{3}{>{$}c<{$}}} " " See: https://en.wikibooks.org/wiki/LaTeX/Tables#Column_specification_using_.3E.7B.5Ccmd.7D_and_.3C.7B.5Ccmd.7D - execute 'syntax region texRegionMathX matchgroup=texDelim' + execute 'syntax region texMathRegionX matchgroup=texDelim' \ 'start="\([<>]{\)\@' contained - syntax match texBeamerOpt '<[^>]*>' contained contains=texBeamerDelimiter + syntax match texBeamerDelim '<\|>' contained + syntax match texBeamerOpt '<[^>]*>' contained contains=texBeamerDelim syntax match texCmdBeamer '\\only\(<[^>]*>\)\?' contains=texBeamerOpt - syntax match texCmdBeamer '\\item<[^>]*>' contains=texBeamerOpt + syntax match texCmdItem '\\item<[^>]*>' contains=texBeamerOpt - syntax match texCmd "\\includegraphics<[^>]*>" + syntax match texCmdInput "\\includegraphics<[^>]*>" \ contains=texBeamerOpt - \ nextgroup=texOptFile,texArgFile + \ nextgroup=texFileOpt,texFileArg highlight link texCmdBeamer texCmd - highlight link texBeamerOpt texOptNewcmd - highlight link texBeamerDelimiter texDelimiter + highlight link texBeamerOpt texOpt + highlight link texBeamerDelim texDelim endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/biblatex.vim b/autoload/vimtex/syntax/p/biblatex.vim index edf6f40583..e0830250c0 100644 --- a/autoload/vimtex/syntax/p/biblatex.vim +++ b/autoload/vimtex/syntax/p/biblatex.vim @@ -8,34 +8,34 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 if has_key(b:vimtex_syntax, 'biblatex') | return | endif let b:vimtex_syntax.biblatex = 1 - syntax match texCmd nextgroup=texArgFiles "\\addbibresource\>" + syntax match texCmdBib nextgroup=texFilesArg "\\addbibresource\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\bibentry\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\cite[pt]\?\*\?\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\citeal[tp]\*\?\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\cite\%(num\|text\|url\)\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\[Cc]ite\%(title\|author\|year\%(par\)\?\|date\)\*\?\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\[Pp]arencite\*\?\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\foot\%(full\)\?cite\%(text\)\?\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\fullcite\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\[Tt]extcite\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\[Ss]martcite\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\supercite\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\[Aa]utocite\*\?\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\[Ppf]\?[Nn]otecite\>" - syntax match texCmd nextgroup=texOptRef,texArgRef skipwhite skipnl "\\\%(text\|block\)cquote\*\?\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\bibentry\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\cite[pt]\?\*\?\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\citeal[tp]\*\?\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\cite\%(num\|text\|url\)\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\[Cc]ite\%(title\|author\|year\%(par\)\?\|date\)\*\?\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\[Pp]arencite\*\?\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\foot\%(full\)\?cite\%(text\)\?\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\fullcite\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\[Tt]extcite\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\[Ss]martcite\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\supercite\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\[Aa]utocite\*\?\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\[Ppf]\?[Nn]otecite\>" + syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\\%(text\|block\)cquote\*\?\>" - syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\[Cc]ites\>" - syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\[Pp]arencites\>" - syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\footcite\%(s\|texts\)\>" - syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\[Tt]extcites\>" - syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\[Ss]martcites\>" - syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\supercites\>" - syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\[Aa]utocites\>" - syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\[pPfFsStTaA]\?[Vv]olcites\?\>" - syntax match texCmd nextgroup=texOptRefs,texArgRefs skipwhite skipnl "\\cite\%(field\|list\|name\)>" - call vimtex#syntax#core#new_cmd_arg('texArgRefs', 'texOptRefs,texArgRefs', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_opt('texOptRefs', 'texOptRef,texArgRef') + syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\[Cc]ites\>" + syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\[Pp]arencites\>" + syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\footcite\%(s\|texts\)\>" + syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\[Tt]extcites\>" + syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\[Ss]martcites\>" + syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\supercites\>" + syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\[Aa]utocites\>" + syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\[pPfFsStTaA]\?[Vv]olcites\?\>" + syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\cite\%(field\|list\|name\)>" + call vimtex#syntax#core#new_cmd_arg('texRefArgs', 'texRefOpts,texRefArgs', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_opt('texRefOpts', 'texRefOpt,texRefArg') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/cleveref.vim b/autoload/vimtex/syntax/p/cleveref.vim index 2dd1347de4..3c01483478 100644 --- a/autoload/vimtex/syntax/p/cleveref.vim +++ b/autoload/vimtex/syntax/p/cleveref.vim @@ -8,23 +8,24 @@ function! vimtex#syntax#p#cleveref#load() abort " {{{1 if has_key(b:vimtex_syntax, 'cleveref') | return | endif let b:vimtex_syntax.cleveref = 1 - syntax match texCmd nextgroup=texArgCRef skipwhite skipnl + syntax match texCmdCRef nextgroup=texCRefArg skipwhite skipnl \ "\\\%(\%(label\)\?c\%(page\)\?\|C\)ref\>" " \crefrange, \cpagerefrange (these commands expect two arguments) - syntax match texCmd nextgroup=texArgCRefRange skipwhite skipnl + syntax match texCmdCRef nextgroup=texCRefRangeArg skipwhite skipnl \ "\\c\(page\)\?refrange\>" " \label[xxx]{asd} - syntax match texCmd nextgroup=texOptCRef,texArgRef skipwhite skipnl "\\label\>" + syntax match texCmdCRef nextgroup=texCRefOpt,texRefArg skipwhite skipnl "\\label\>" - call vimtex#syntax#core#new_cmd_arg('texArgCRef', '', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texArgCRefRange', 'texArgCRef', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_opt('texOptCRef', 'texArgRef', '', 'oneline') + call vimtex#syntax#core#new_cmd_arg('texCRefArg', '', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texCRefRangeArg', 'texCRefArg', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_opt('texCRefOpt', 'texRefArg', '', 'oneline') - highlight link texArgCRef texArgRef - highlight link texArgCRefRange texArgRef - highlight link texOptCRef texOpt + highlight def link texCRefArg texRefArg + highlight def link texCRefOpt texOpt + highlight def link texCRefRangeArg texRefArg + highlight def link texCmdCRef texCmd endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/csquotes.vim b/autoload/vimtex/syntax/p/csquotes.vim index 1e6e1631be..1685d43aac 100644 --- a/autoload/vimtex/syntax/p/csquotes.vim +++ b/autoload/vimtex/syntax/p/csquotes.vim @@ -8,10 +8,12 @@ function! vimtex#syntax#p#csquotes#load() abort " {{{1 if has_key(b:vimtex_syntax, 'csquotes') | return | endif let b:vimtex_syntax.csquotes = 1 - syntax match texCmd nextgroup=texCmdQuoteLang skipwhite skipnl "\\\%(foreign\|hyphen\)textcquote\*\?\>" - syntax match texCmd nextgroup=texCmdQuoteLang skipwhite skipnl "\\\%(foreign\|hyphen\)blockcquote\>" - syntax match texCmd nextgroup=texCmdQuoteLang skipwhite skipnl "\\hybridblockcquote\>" - call vimtex#syntax#core#new_cmd_arg('texCmdQuoteLang', 'texOptRef,texArgRef', 'TOP', 'transparent') + syntax match texCmdQuote nextgroup=texQuoteArg skipwhite skipnl "\\\%(foreign\|hyphen\)textcquote\*\?\>" + syntax match texCmdQuote nextgroup=texQuoteArg skipwhite skipnl "\\\%(foreign\|hyphen\)blockcquote\>" + syntax match texCmdQuote nextgroup=texQuoteArg skipwhite skipnl "\\hybridblockcquote\>" + call vimtex#syntax#core#new_cmd_arg('texQuoteArg', 'texRefOpt,texRefArg', '@texClusterTL', 'transparent') + + highlight def link texCmdQuote texCmd endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/dot2texi.vim b/autoload/vimtex/syntax/p/dot2texi.vim index f460b376e3..28461102c6 100644 --- a/autoload/vimtex/syntax/p/dot2texi.vim +++ b/autoload/vimtex/syntax/p/dot2texi.vim @@ -10,7 +10,7 @@ function! vimtex#syntax#p#dot2texi#load() abort " {{{1 call vimtex#syntax#nested#include('dot') call vimtex#syntax#core#new_region_env( - \ 'texRegionDot', 'dot2tex', '@vimtex_nested_dot') + \ 'texDotRegion', 'dot2tex', '@vimtex_nested_dot') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/glossaries.vim b/autoload/vimtex/syntax/p/glossaries.vim index c306215345..545645bea7 100644 --- a/autoload/vimtex/syntax/p/glossaries.vim +++ b/autoload/vimtex/syntax/p/glossaries.vim @@ -10,8 +10,8 @@ function! vimtex#syntax#p#glossaries#load() abort " {{{1 if has_key(b:vimtex_syntax, 'glossaries') | return | endif let b:vimtex_syntax.glossaries = 1 - syntax match texCmd nextgroup=texGls skipwhite skipnl "\\gls\>" - call vimtex#syntax#core#new_cmd_arg('texGls', '', '@NoSpell') + syntax match texCmd nextgroup=texGlsArg skipwhite skipnl "\\gls\>" + call vimtex#syntax#core#new_cmd_arg('texGlsArg', '', '@NoSpell') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/gnuplottex.vim b/autoload/vimtex/syntax/p/gnuplottex.vim index 2435b6360b..48fc13a4d1 100644 --- a/autoload/vimtex/syntax/p/gnuplottex.vim +++ b/autoload/vimtex/syntax/p/gnuplottex.vim @@ -10,7 +10,7 @@ function! vimtex#syntax#p#gnuplottex#load() abort " {{{1 call vimtex#syntax#nested#include('gnuplot') call vimtex#syntax#core#new_region_env( - \ 'texRegionGnuplot', 'gnuplot', '@vimtex_nested_gnuplot') + \ 'texGnuplotRegion', 'gnuplot', '@vimtex_nested_gnuplot') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/hyperref.vim b/autoload/vimtex/syntax/p/hyperref.vim index 96b1a1650a..ab81479099 100644 --- a/autoload/vimtex/syntax/p/hyperref.vim +++ b/autoload/vimtex/syntax/p/hyperref.vim @@ -8,21 +8,22 @@ function! vimtex#syntax#p#hyperref#load() abort " {{{1 if has_key(b:vimtex_syntax, 'hyperref') | return | endif let b:vimtex_syntax.hyperref = 1 - syntax match texCmd "\\url\>" nextgroup=texArgUrl skipwhite - syntax region texArgUrl matchgroup=texDelim + syntax match texCmdHyperref '\\autoref\>' nextgroup=texRefOpt,texRefArg + syntax match texCmdHyperref '\\hyperref\>' nextgroup=texRefOpt,texRefArg + syntax match texCmdHyperref '\\href\>' nextgroup=texHrefArgLink skipwhite + call vimtex#syntax#core#new_cmd_arg('texHrefArgLink', 'texHrefArgText', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texHrefArgText', '', '@texClusterTL') + + syntax match texCmdHyperref "\\url\>" nextgroup=texUrlArg skipwhite + syntax region texUrlArg matchgroup=texDelim \ contained contains=@NoSpell,texComment \ start="\z([^\ta-zA-Z]\)" end="\z1" - call vimtex#syntax#core#new_cmd_arg('texArgUrl', '', 'texComment,@NoSpell') - - syntax match texCmd '\\href\>' nextgroup=texArgHrefLink - call vimtex#syntax#core#new_cmd_arg('texArgHrefLink', 'texArgHrefText', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texArgHrefText', '', 'TOP') + call vimtex#syntax#core#new_cmd_arg('texUrlArg', '', 'texComment,@NoSpell') - syntax match texCmd '\\hyperref\>' nextgroup=texOptRef,texArgRef - syntax match texCmd '\\autoref\>' nextgroup=texOptRef,texArgRef - highlight link texArgUrl texOpt - highlight link texArgHrefLink texOpt + highlight def link texCmdHyperref texCmd + highlight def link texHrefArgLink texOpt + highlight def link texUrlArg texOpt endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/ieeetrantools.vim b/autoload/vimtex/syntax/p/ieeetrantools.vim index 339d734fff..6e9794db3d 100644 --- a/autoload/vimtex/syntax/p/ieeetrantools.vim +++ b/autoload/vimtex/syntax/p/ieeetrantools.vim @@ -20,13 +20,13 @@ function! s:new_region_math(mathzone) abort " {{{1 " This needs to be slightly different than vimtex#syntax#core#new_region_math " to handle options for the environment. - execute 'syntax match texErrorMath ''\\end\s*{\s*' . a:mathzone . '\*\?\s*}''' + execute 'syntax match texMathError ''\\end\s*{\s*' . a:mathzone . '\*\?\s*}''' - execute 'syntax region texRegionMathEnv' + execute 'syntax region texMathRegionEnv' \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\z(\*\?\)\s*}' \ . '\(\[.\{-}\]\)\?{\w*}''' \ . ' end=''\\end\s*{\s*' . a:mathzone . '\z1\s*}''' - \ . ' keepend contains=texCmdEnvMath,texArgEnvMathName,@texClusterMath' + \ . ' keepend contains=texCmdMathenv,texMathenvArgName,@texClusterMath' endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index 1d8ccfafed..57f4048526 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -10,7 +10,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 " First some general support syntax match texCmd "\\lstinputlisting\>" - \ nextgroup=texOptFile,texArgFile skipwhite skipnl + \ nextgroup=texFileOpt,texFileArg skipwhite skipnl syntax match texRegion "\\lstinline\s*\(\[.\{-}\]\)\={.\{-}}" " Set all listings environments to listings diff --git a/autoload/vimtex/syntax/p/luacode.vim b/autoload/vimtex/syntax/p/luacode.vim index 8a9aa9e19f..60beb713c0 100644 --- a/autoload/vimtex/syntax/p/luacode.vim +++ b/autoload/vimtex/syntax/p/luacode.vim @@ -11,11 +11,13 @@ function! vimtex#syntax#p#luacode#load() abort " {{{1 call vimtex#syntax#nested#include('lua') call vimtex#syntax#core#new_region_env( - \ 'texRegionLua', 'luacode\*\?', '@vimtex_nested_lua') + \ 'texLuaRegion', 'luacode\*\?', '@vimtex_nested_lua') - syntax match texCmd "\\\%(directlua\|luadirect\)\>" nextgroup=texRegionLuaArg skipwhite skipnl + syntax match texCmdLua "\\\%(directlua\|luadirect\)\>" nextgroup=texLuaArg skipwhite skipnl call vimtex#syntax#core#new_cmd_arg( - \ 'texRegionLuaArg', '', '@vimtex_nested_lua', 'keepend') + \ 'texLuaArg', '', '@vimtex_nested_lua', 'keepend') + + highlight def link texCmdLua texCmd endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index 414cb2af67..01a059b66e 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -10,9 +10,9 @@ function! vimtex#syntax#p#markdown#load() abort " {{{1 call vimtex#syntax#nested#include('markdown') call vimtex#syntax#core#new_region_env( - \ 'texRegionMarkdown', 'markdown', 'texCmd,@vimtex_nested_markdown') + \ 'texMarkdownRegion', 'markdown', 'texCmd,@vimtex_nested_markdown') - syntax match texCmd "\\markdownInput\>" nextgroup=texArgFile skipwhite skipnl + syntax match texCmdInput "\\markdownInput\>" nextgroup=texFileArg skipwhite skipnl endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index f882b4e127..4fd3da4c84 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -142,7 +142,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 highlight link texRegionMinted texRegion highlight link texRegionMintedCmd texRegion - highlight link texMintedName texOptNewcmd + highlight link texMintedName texOpt highlight link texMintedNameOpt texMintedName endfunction diff --git a/autoload/vimtex/syntax/p/moreverb.vim b/autoload/vimtex/syntax/p/moreverb.vim index 55a499aae4..4b56c208d0 100644 --- a/autoload/vimtex/syntax/p/moreverb.vim +++ b/autoload/vimtex/syntax/p/moreverb.vim @@ -8,9 +8,9 @@ function! vimtex#syntax#p#moreverb#load() abort " {{{1 if has_key(b:vimtex_syntax, 'moreverb') | return | endif let b:vimtex_syntax.moreverb = 1 - call vimtex#syntax#core#new_region_env('texRegionVerb', 'verbatimtab') - call vimtex#syntax#core#new_region_env('texRegionVerb', 'verbatimwrite') - call vimtex#syntax#core#new_region_env('texRegionVerb', 'boxedverbatim') + call vimtex#syntax#core#new_region_env('texVerbRegion', 'verbatimtab') + call vimtex#syntax#core#new_region_env('texVerbRegion', 'verbatimwrite') + call vimtex#syntax#core#new_region_env('texVerbRegion', 'boxedverbatim') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/pdfpages.vim b/autoload/vimtex/syntax/p/pdfpages.vim index e46fab9f5b..f4e2c82ccb 100644 --- a/autoload/vimtex/syntax/p/pdfpages.vim +++ b/autoload/vimtex/syntax/p/pdfpages.vim @@ -8,7 +8,7 @@ function! vimtex#syntax#p#pdfpages#load() abort " {{{1 if has_key(b:vimtex_syntax, 'pdfpages') | return | endif let b:vimtex_syntax.pdfpages = 1 - syntax match texCmd "\\includepdf\>" nextgroup=texOptFile,texArgFile skipwhite skipnl + syntax match texCmdInput "\\includepdf\>" nextgroup=texFileOpt,texFileArg skipwhite skipnl endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/pgfplots.vim b/autoload/vimtex/syntax/p/pgfplots.vim index 2d651f831c..f5cf904ee4 100644 --- a/autoload/vimtex/syntax/p/pgfplots.vim +++ b/autoload/vimtex/syntax/p/pgfplots.vim @@ -12,17 +12,17 @@ function! vimtex#syntax#p#pgfplots#load() abort " {{{1 syntax cluster texClusterTikz add=texCmdAxis - syntax match texCmd nextgroup=texArgTikzset skipwhite "\\pgfplotsset\>" + syntax match texCmdTikzset nextgroup=texTikzsetArg skipwhite "\\pgfplotsset\>" - syntax match texCmdAxis contained nextgroup=texOptTikzpic skipwhite "\\addplot3\?\>" - syntax match texCmdAxis contained nextgroup=texOptTikzpic skipwhite "\\nextgroupplot\>" + syntax match texCmdAxis contained nextgroup=texTikzOpt skipwhite "\\addplot3\?\>" + syntax match texCmdAxis contained nextgroup=texTikzOpt skipwhite "\\nextgroupplot\>" - syntax match texEnvBgnTikz contains=texCmdEnv nextgroup=texOptTikzpic skipwhite skipnl "\\begin{\%(log\)*axis}" - syntax match texEnvBgnTikz contains=texCmdEnv nextgroup=texOptTikzpic skipwhite skipnl "\\begin{groupplot}" - call vimtex#syntax#core#new_region_env('texRegionTikz', 'axis', '@texClusterTikz') - call vimtex#syntax#core#new_region_env('texRegionTikz', 'logaxis', '@texClusterTikz') - call vimtex#syntax#core#new_region_env('texRegionTikz', 'loglogaxis', '@texClusterTikz') - call vimtex#syntax#core#new_region_env('texRegionTikz', 'groupplot', '@texClusterTikz') + syntax match texTikzEnvBgn contains=texCmdEnv nextgroup=texTikzOpt skipwhite skipnl "\\begin{\%(log\)*axis}" + syntax match texTikzEnvBgn contains=texCmdEnv nextgroup=texTikzOpt skipwhite skipnl "\\begin{groupplot}" + call vimtex#syntax#core#new_region_env('texTikzRegion', 'axis', '@texClusterTikz') + call vimtex#syntax#core#new_region_env('texTikzRegion', 'logaxis', '@texClusterTikz') + call vimtex#syntax#core#new_region_env('texTikzRegion', 'loglogaxis', '@texClusterTikz') + call vimtex#syntax#core#new_region_env('texTikzRegion', 'groupplot', '@texClusterTikz') highlight def link texCmdAxis texCmd endfunction diff --git a/autoload/vimtex/syntax/p/pythontex.vim b/autoload/vimtex/syntax/p/pythontex.vim index f9c26cbd14..828be3b4bd 100644 --- a/autoload/vimtex/syntax/p/pythontex.vim +++ b/autoload/vimtex/syntax/p/pythontex.vim @@ -10,14 +10,16 @@ function! vimtex#syntax#p#pythontex#load() abort " {{{1 call vimtex#syntax#nested#include('python') - syntax match texCmd /\\py[bsc]\?/ nextgroup=texPythontexArg skipwhite skipnl + syntax match texCmdPythontex /\\py[bsc]\?/ nextgroup=texPythontexArg skipwhite skipnl call vimtex#syntax#core#new_cmd_arg('texPythontexArg', '', '@vimtex_nested_python', 'keepend') syntax region texPythontexArg matchgroup=texDelim \ start='\z([#@]\)' end='\z1' \ contained contains=@vimtex_nested_python keepend - call vimtex#syntax#core#new_region_env('texRegionPythontex', 'pyblock', '@vimtex_nested_python') - call vimtex#syntax#core#new_region_env('texRegionPythontex', 'pycode', '@vimtex_nested_python') + call vimtex#syntax#core#new_region_env('texPythontexRegion', 'pyblock', '@vimtex_nested_python') + call vimtex#syntax#core#new_region_env('texPythontexRegion', 'pycode', '@vimtex_nested_python') + + highlight def link texCmdPythontex texCmd endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/subfile.vim b/autoload/vimtex/syntax/p/subfile.vim index 41d9a7cdc5..ddf85e6373 100644 --- a/autoload/vimtex/syntax/p/subfile.vim +++ b/autoload/vimtex/syntax/p/subfile.vim @@ -8,8 +8,8 @@ function! vimtex#syntax#p#subfile#load() abort " {{{1 if has_key(b:vimtex_syntax, 'subfile') | return | endif let b:vimtex_syntax.subfile = 1 - syntax match texCmd "\\subfile\>" nextgroup=texArgFile skipwhite skipnl - syntax match texCmd "\\subfileinclude\>" nextgroup=texArgFile skipwhite skipnl + syntax match texCmdInput nextgroup=texFileArg skipwhite skipnl "\\subfile\>" + syntax match texCmdInput nextgroup=texFileArg skipwhite skipnl "\\subfileinclude\>" endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/tabularx.vim b/autoload/vimtex/syntax/p/tabularx.vim index b2b92289ce..d1a1a01d9f 100644 --- a/autoload/vimtex/syntax/p/tabularx.vim +++ b/autoload/vimtex/syntax/p/tabularx.vim @@ -14,23 +14,24 @@ function! vimtex#syntax#p#tabularx#load() abort " {{{1 syntax match texTabularAtSep /@/ contained nextgroup=texTabularLength syntax match texTabularVertline /||\?/ contained syntax match texTabularPostPre /[<>]/ contained nextgroup=texTabularPostPreArg - syntax match texDelimMathmodeTab /\$\$\?/ contained + syntax match texTabularMathdelim /\$\$\?/ contained + syntax cluster texClusterTabular contains=texTabular.* syntax match texCmdTabular '\\begin{tabular}' - \ nextgroup=texOptEnvModifierTab,texArgTabular skipwhite skipnl contains=texCmdEnv - call vimtex#syntax#core#new_cmd_opt('texOptEnvModifierTab', 'texArgTabular', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texArgTabular', '', 'texTabular.*') + \ nextgroup=texTabularOpt,texTabularArg skipwhite skipnl contains=texCmdEnv + call vimtex#syntax#core#new_cmd_opt('texTabularOpt', 'texTabularArg', 'texComment,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texTabularArg', '', '@texClusterTabular') - call vimtex#syntax#core#new_cmd_arg('texTabularMulti', 'texArgTabular') + call vimtex#syntax#core#new_cmd_arg('texTabularMulti', 'texTabularArg') call vimtex#syntax#core#new_cmd_arg('texTabularLength', '', 'texLength,texCmd') - call vimtex#syntax#core#new_cmd_arg('texTabularPostPreArg', '', 'texLength,texCmd,texDelimMathmodeTab') + call vimtex#syntax#core#new_cmd_arg('texTabularPostPreArg', '', 'texLength,texCmd,texTabularMathdelim') highlight def link texTabularCol texOpt - highlight def link texTabularAtSep texDelimMath - highlight def link texTabularVertline texDelimMath - highlight def link texTabularPostPre texDelimMath - highlight def link texOptEnvModifierTab texOptEnvModifier - highlight def link texDelimMathmodeTab texDelimMathmode + highlight def link texTabularAtSep texMathDelim + highlight def link texTabularVertline texMathDelim + highlight def link texTabularPostPre texMathDelim + highlight def link texTabularMathdelim texMathRegionDelim + highlight def link texTabularOpt texEnvOpt endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index 4450e86512..4471903f75 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -8,20 +8,21 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 if has_key(b:vimtex_syntax, 'tikz') | return | endif let b:vimtex_syntax.tikz = 1 - syntax cluster texClusterTikz contains=texEnvBgnTikz,texCmdEnv,texCmd,texTikzSemicolon,texComment,texGroup - syntax cluster texClusterTikzset contains=texArgTikzset,texOptSep,texOptEqual,texRegionMathX,texTypeSize,texCmd,texLength,texComment + syntax cluster texClusterTikz contains=texTikzEnvBgn,texTikzSemicolon,texCmd,texCmdEnv,texGroup,texComment + syntax cluster texClusterTikzset contains=texTikzsetArg,texOptSep,texOptEqual,texMathRegionX,texTypeSize,texCmd,texLength,texComment - syntax match texCmd /\\tikzset\>/ skipwhite skipnl nextgroup=texArgTikzset - call vimtex#syntax#core#new_cmd_arg('texArgTikzset', '', '@texClusterTikzset') + syntax match texCmdTikzset /\\tikzset\>/ skipwhite skipnl nextgroup=texTikzsetArg + call vimtex#syntax#core#new_cmd_arg('texTikzsetArg', '', '@texClusterTikzset') - syntax match texEnvBgnTikz /\v\\begin\{tikzpicture\}/ - \ nextgroup=texOptTikzpic skipwhite skipnl contains=texCmdEnv + syntax match texTikzEnvBgn /\v\\begin\{tikzpicture\}/ + \ nextgroup=texTikzOpt skipwhite skipnl contains=texCmdEnv call vimtex#syntax#core#new_region_env( - \ 'texRegionTikz', 'tikzpicture', '@texClusterTikz') - call vimtex#syntax#core#new_cmd_opt('texOptTikzpic', '', '@texClusterTikzset') + \ 'texTikzRegion', 'tikzpicture', '@texClusterTikz') + call vimtex#syntax#core#new_cmd_opt('texTikzOpt', '', '@texClusterTikzset') syntax match texTikzSemicolon /;/ contained + highlight def link texCmdTikzset texCmd highlight def link texTikzSemicolon texDelim endfunction diff --git a/autoload/vimtex/syntax/p/varioref.vim b/autoload/vimtex/syntax/p/varioref.vim index 4e6fc72bdf..669ccd82f0 100644 --- a/autoload/vimtex/syntax/p/varioref.vim +++ b/autoload/vimtex/syntax/p/varioref.vim @@ -8,7 +8,7 @@ function! vimtex#syntax#p#varioref#load() abort " {{{1 if has_key(b:vimtex_syntax, 'varioref') | return | endif let b:vimtex_syntax.varioref = 1 - syntax match texCmd '\\Vref\>' nextgroup=texArgRef skipwhite skipnl + syntax match texCmdRef '\\Vref\>' nextgroup=texRefArg skipwhite skipnl endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/wiki.vim b/autoload/vimtex/syntax/p/wiki.vim index e6475d2969..8dc3330a8d 100644 --- a/autoload/vimtex/syntax/p/wiki.vim +++ b/autoload/vimtex/syntax/p/wiki.vim @@ -10,7 +10,7 @@ function! vimtex#syntax#p#wiki#load() abort " {{{1 call vimtex#syntax#nested#include('markdown') - syntax region texRegionWiki + syntax region texWikiRegion \ start='\\wikimarkup\>' \ end='\\nowikimarkup\>' \ keepend diff --git a/test/tests/test-syntax/test-bold-italic.tex b/test/tests/test-syntax/test-bold-italic.tex index 3b0f258cf8..29660891c9 100644 --- a/test/tests/test-syntax/test-bold-italic.tex +++ b/test/tests/test-syntax/test-bold-italic.tex @@ -4,9 +4,7 @@ \textit {\textbf {This is bold-italic, but it looks italic}} \textbf{\textit{This is bold-italic, but it looks italic}} -\textbf{\texttt{This is bold-italic, but it looks italic}} \textbf{\textbf{This is bold-italic, but it looks italic}} -\textit{\textit{This is bold-italic, but it looks italic}} \textbf{\emph{This is bold-italic, but it looks italic}} \textit{\emph{This is bold-italic, but it looks italic}} \emph{\textbf{This is bold-italic, but it looks italic}} diff --git a/test/tests/test-syntax/test-bold-italic.vim b/test/tests/test-syntax/test-bold-italic.vim index 94017922cc..e7f20a6a95 100644 --- a/test/tests/test-syntax/test-bold-italic.vim +++ b/test/tests/test-syntax/test-bold-italic.vim @@ -9,8 +9,7 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texStyleBoth', 5, 50)) call vimtex#test#assert(vimtex#syntax#in('texStyleBoth', 6, 50)) -call vimtex#test#assert(vimtex#syntax#in('texStyleBoth', 7, 50)) -call vimtex#test#assert(vimtex#syntax#in('texStyleBoth', 10, 50)) -call vimtex#test#assert(vimtex#syntax#in('texCmdStyle', 8, 14)) +call vimtex#test#assert(vimtex#syntax#in('texStyleBoth', 8, 50)) +call vimtex#test#assert(vimtex#syntax#in('texCmdStyle', 7, 14)) quit! diff --git a/test/tests/test-syntax/test-breqn.vim b/test/tests/test-syntax/test-breqn.vim index 70ca346c21..4d1aab3221 100644 --- a/test/tests/test-syntax/test-breqn.vim +++ b/test/tests/test-syntax/test-breqn.vim @@ -4,7 +4,7 @@ silent edit test-breqn.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texRegionMathEnv', 9, 1)) +call vimtex#test#assert(vimtex#syntax#in('texMathRegionEnv', 9, 1)) quit! diff --git a/test/tests/test-syntax/test-core.tex b/test/tests/test-syntax/test-core.tex index a68e786448..4f1e003e1c 100644 --- a/test/tests/test-syntax/test-core.tex +++ b/test/tests/test-syntax/test-core.tex @@ -26,7 +26,7 @@ Line with inline verbatim: \verb+verb+ Line with inline verbatim: \verb*+verb+ -Line with $inline math$ here. +Line with $inline math$ here.\footnote{here {asd} with \cmd also}. \section{First} \label{sec:first} diff --git a/test/tests/test-syntax/test-core.vim b/test/tests/test-syntax/test-core.vim index d1758aa998..ebf796e9ff 100644 --- a/test/tests/test-syntax/test-core.vim +++ b/test/tests/test-syntax/test-core.vim @@ -7,11 +7,11 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texCmdError', 5, 3)) call vimtex#test#assert(vimtex#syntax#in('texCmdSty', 8, 3)) -call vimtex#test#assert(vimtex#syntax#in('texParmNewenv', 20, 36)) +call vimtex#test#assert(vimtex#syntax#in('texNewenvParm', 20, 36)) -call vimtex#test#assert(vimtex#syntax#in('texRegionVerbInline', 26, 36)) +call vimtex#test#assert(vimtex#syntax#in('texVerbRegionInline', 26, 36)) -call vimtex#test#assert(vimtex#syntax#in('texArgAuthor', 46, 20)) +call vimtex#test#assert(vimtex#syntax#in('texAuthorArg', 46, 20)) call vimtex#test#assert(vimtex#syntax#in('texDelim', 46, 39)) quit! diff --git a/test/tests/test-syntax/test-hyperref.vim b/test/tests/test-syntax/test-hyperref.vim index 497fef5908..2fec85e991 100644 --- a/test/tests/test-syntax/test-hyperref.vim +++ b/test/tests/test-syntax/test-hyperref.vim @@ -4,7 +4,7 @@ silent edit test-hyperref.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texArgUrl', 6, 25)) -call vimtex#test#assert(vimtex#syntax#in('texArgRef', 16, 35)) +call vimtex#test#assert(vimtex#syntax#in('texUrlArg', 6, 25)) +call vimtex#test#assert(vimtex#syntax#in('texRefArg', 16, 35)) quit! diff --git a/test/tests/test-syntax/test-ieeetrantools.vim b/test/tests/test-syntax/test-ieeetrantools.vim index bf79c9e71d..0e8ad3839f 100644 --- a/test/tests/test-syntax/test-ieeetrantools.vim +++ b/test/tests/test-syntax/test-ieeetrantools.vim @@ -4,9 +4,9 @@ silent edit test-ieeetrantools.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texRegionMathEnv', 8, 1)) -call vimtex#test#assert(vimtex#syntax#in('texRegionMathEnv', 13, 1)) -call vimtex#test#assert(vimtex#syntax#in('texRegionMathEnv', 24, 1)) -call vimtex#test#assert(vimtex#syntax#in('texRegionMathEnv', 31, 1)) +call vimtex#test#assert(vimtex#syntax#in('texMathRegionEnv', 8, 1)) +call vimtex#test#assert(vimtex#syntax#in('texMathRegionEnv', 13, 1)) +call vimtex#test#assert(vimtex#syntax#in('texMathRegionEnv', 24, 1)) +call vimtex#test#assert(vimtex#syntax#in('texMathRegionEnv', 31, 1)) quit! diff --git a/test/tests/test-syntax/test-markdown.vim b/test/tests/test-syntax/test-markdown.vim index 6a20b2dd21..13f5019106 100644 --- a/test/tests/test-syntax/test-markdown.vim +++ b/test/tests/test-syntax/test-markdown.vim @@ -7,6 +7,6 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texRegionMarkdown', 7, 1)) call vimtex#test#assert(vimtex#syntax#in('markdownItalic', 7, 1)) call vimtex#test#assert(vimtex#syntax#in('markdownLink', 11, 12)) -call vimtex#test#assert(vimtex#syntax#in('texArgFile', 16, 16)) +call vimtex#test#assert(vimtex#syntax#in('texFileArg', 16, 16)) quit! diff --git a/test/tests/test-syntax/test-nospell.vim b/test/tests/test-syntax/test-nospell.vim index 8559269009..3d82022a52 100644 --- a/test/tests/test-syntax/test-nospell.vim +++ b/test/tests/test-syntax/test-nospell.vim @@ -8,6 +8,6 @@ silent edit test-nospell.tex if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texGroup', 7, 14)) -call vimtex#test#assert(vimtex#syntax#in('texArgNoSpell', 8, 14)) +call vimtex#test#assert(vimtex#syntax#in('texNoSpellArg', 8, 14)) quit! diff --git a/test/tests/test-syntax/test-tabularx.vim b/test/tests/test-syntax/test-tabularx.vim index b8316860e7..94c7b97e60 100644 --- a/test/tests/test-syntax/test-tabularx.vim +++ b/test/tests/test-syntax/test-tabularx.vim @@ -5,6 +5,6 @@ silent edit test-tabularx.tex if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texTabularCol', 7, 17)) -call vimtex#test#assert(vimtex#syntax#in('texDelimMathmodeTab', 7, 24)) +call vimtex#test#assert(vimtex#syntax#in('texMathRegionDelimTab', 7, 24)) quit! diff --git a/test/tests/test-syntax/test-tikz.vim b/test/tests/test-syntax/test-tikz.vim index 357cfa8f5d..e0e6b0953f 100644 --- a/test/tests/test-syntax/test-tikz.vim +++ b/test/tests/test-syntax/test-tikz.vim @@ -5,7 +5,7 @@ silent edit test-tikz.tex if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texTikzSemicolon', 66, 61)) -call vimtex#test#assert(vimtex#syntax#in('texRegionTikz', 66, 61)) +call vimtex#test#assert(vimtex#syntax#in('texTikzRegion', 66, 61)) call vimtex#test#assert(vimtex#syntax#in('texCmdAxis', 71, 9)) quit! From 49d1504061e4e8cf2fd0e813b499c6667a33522f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sat, 7 Nov 2020 00:46:40 +0100 Subject: [PATCH 41/99] wip: updated tests --- test/tests/test-syntax/test-latex3.vim | 2 +- test/tests/test-syntax/test-markdown.vim | 2 +- test/tests/test-syntax/test-tabularx.vim | 2 +- test/tests/test-syntax/test-wiki.vim | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/tests/test-syntax/test-latex3.vim b/test/tests/test-syntax/test-latex3.vim index ae7bccbe8c..cdcf71709e 100644 --- a/test/tests/test-syntax/test-latex3.vim +++ b/test/tests/test-syntax/test-latex3.vim @@ -4,7 +4,7 @@ silent edit test-latex3.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texRegionExpl3', 7, 2)) +call vimtex#test#assert(vimtex#syntax#in('texE3Region', 7, 2)) call vimtex#test#assert(vimtex#syntax#in('texE3Func', 7, 2)) call vimtex#test#assert(vimtex#syntax#in('texE3Var', 7, 15)) diff --git a/test/tests/test-syntax/test-markdown.vim b/test/tests/test-syntax/test-markdown.vim index 13f5019106..03a88bff27 100644 --- a/test/tests/test-syntax/test-markdown.vim +++ b/test/tests/test-syntax/test-markdown.vim @@ -4,7 +4,7 @@ silent edit test-markdown.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texRegionMarkdown', 7, 1)) +call vimtex#test#assert(vimtex#syntax#in('texMarkdownRegion', 7, 1)) call vimtex#test#assert(vimtex#syntax#in('markdownItalic', 7, 1)) call vimtex#test#assert(vimtex#syntax#in('markdownLink', 11, 12)) call vimtex#test#assert(vimtex#syntax#in('texFileArg', 16, 16)) diff --git a/test/tests/test-syntax/test-tabularx.vim b/test/tests/test-syntax/test-tabularx.vim index 94c7b97e60..964cebdbb4 100644 --- a/test/tests/test-syntax/test-tabularx.vim +++ b/test/tests/test-syntax/test-tabularx.vim @@ -5,6 +5,6 @@ silent edit test-tabularx.tex if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texTabularCol', 7, 17)) -call vimtex#test#assert(vimtex#syntax#in('texMathRegionDelimTab', 7, 24)) +call vimtex#test#assert(vimtex#syntax#in('texTabularMathdelim', 7, 24)) quit! diff --git a/test/tests/test-syntax/test-wiki.vim b/test/tests/test-syntax/test-wiki.vim index c0868b40e8..5e130a1bab 100644 --- a/test/tests/test-syntax/test-wiki.vim +++ b/test/tests/test-syntax/test-wiki.vim @@ -4,7 +4,7 @@ silent edit test-wiki.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texRegionWiki', 6, 1)) +call vimtex#test#assert(vimtex#syntax#in('texWikiRegion', 6, 1)) " call vimtex#test#assert(vimtex#syntax#in('markdownHeader', 7, 1)) quit! From 236bf5c5544cf4c3b9c980a81c87f3e79776b4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sat, 7 Nov 2020 00:55:41 +0100 Subject: [PATCH 42/99] wip: fix minor bug --- autoload/vimtex/syntax/core.vim | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 044b842408..be90a5b66e 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -325,15 +325,15 @@ function! vimtex#syntax#core#init() abort " {{{1 " Math regions: Inline Math Zones if l:cfg.conceal.math_bounds - syntax region texMathRegion matchgroup=texMathRegionDelim concealends contains=@texClusterMath keepend start="\\(" end="\\)" - syntax region texMathRegion matchgroup=texMathRegionDelim concealends contains=@texClusterMath keepend start="\\\[" end="\\]" - syntax region texMathRegionX matchgroup=texMathRegionDelim concealends contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" - syntax region texMathRegionXX matchgroup=texMathRegionDelim concealends contains=@texClusterMath keepend start="\$\$" end="\$\$" + syntax region texMathRegion matchgroup=texMathDelimRegion concealends contains=@texClusterMath keepend start="\\(" end="\\)" + syntax region texMathRegion matchgroup=texMathDelimRegion concealends contains=@texClusterMath keepend start="\\\[" end="\\]" + syntax region texMathRegionX matchgroup=texMathDelimRegion concealends contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" + syntax region texMathRegionXX matchgroup=texMathDelimRegion concealends contains=@texClusterMath keepend start="\$\$" end="\$\$" else - syntax region texMathRegion matchgroup=texMathRegionDelim contains=@texClusterMath keepend start="\\(" end="\\)" - syntax region texMathRegion matchgroup=texMathRegionDelim contains=@texClusterMath keepend start="\\\[" end="\\]" - syntax region texMathRegionX matchgroup=texMathRegionDelim contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" - syntax region texMathRegionXX matchgroup=texMathRegionDelim contains=@texClusterMath keepend start="\$\$" end="\$\$" + syntax region texMathRegion matchgroup=texMathDelimRegion contains=@texClusterMath keepend start="\\(" end="\\)" + syntax region texMathRegion matchgroup=texMathDelimRegion contains=@texClusterMath keepend start="\\\[" end="\\]" + syntax region texMathRegionX matchgroup=texMathDelimRegion contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" + syntax region texMathRegionXX matchgroup=texMathDelimRegion contains=@texClusterMath keepend start="\$\$" end="\$\$" endif " Math regions: \ensuremath{...} @@ -532,11 +532,11 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texFilesArg texFileArg highlight def link texFilesOpt texOpt highlight def link texGroupError texError + highlight def link texMathDelimRegion texDelim highlight def link texMathDelimSet texMathDelim highlight def link texMathError texError highlight def link texMathErrorDelim texError highlight def link texMathGroup texMathRegion - highlight def link texMathRegionDelim texDelim highlight def link texMathRegionEnsured texMathRegion highlight def link texMathRegionEnv texMathRegion highlight def link texMathRegionEnvStarred texMathRegion From eaea9c97e418deb0c4eee7fbe1d9ef145139c654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sat, 7 Nov 2020 09:48:14 +0100 Subject: [PATCH 43/99] wip: minor fixes --- autoload/vimtex/syntax/core.vim | 2 +- autoload/vimtex/syntax/p/tikz.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index be90a5b66e..519be5881e 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -414,7 +414,7 @@ endfunction " }}}1 function! vimtex#syntax#core#new_region_env(grp, envname, ...) abort " {{{1 - let l:contains = 'texCmdEnv,texEnvArgName' + let l:contains = 'texCmdEnv' let l:options = 'keepend' if a:0 > 0 diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index 4471903f75..323e4ee2a4 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -8,7 +8,7 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 if has_key(b:vimtex_syntax, 'tikz') | return | endif let b:vimtex_syntax.tikz = 1 - syntax cluster texClusterTikz contains=texTikzEnvBgn,texTikzSemicolon,texCmd,texCmdEnv,texGroup,texComment + syntax cluster texClusterTikz contains=texTikzEnvBgn,texTikzSemicolon,texCmd,texGroup,texComment syntax cluster texClusterTikzset contains=texTikzsetArg,texOptSep,texOptEqual,texMathRegionX,texTypeSize,texCmd,texLength,texComment syntax match texCmdTikzset /\\tikzset\>/ skipwhite skipnl nextgroup=texTikzsetArg From 56e150650efa1a6b0bb72a91ea44fb4902a01dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sat, 7 Nov 2020 17:39:05 +0100 Subject: [PATCH 44/99] wip: minor fix --- autoload/vimtex/syntax/core.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 519be5881e..9470d101d4 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -314,7 +314,7 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_cmd_arg('texMathenvArgName', '') " Syntax clusters for math regions - syntax cluster texClusterMath contains=texCmd,texCmdGreek,texCmdSize,texCmdStyle,texComment,texMathDelim,texMathDelimMod,texLength,texMathGroup,texMathOper,texMathSymbol,texSpecialChar,texMathSub,texMathSuper,texSymbolAmp,texSymbolDash,texSymbolNewline,@NoSpell + syntax cluster texClusterMath contains=texCmd,texCmdRef,texCmdGreek,texCmdSize,texCmdStyle,texComment,texMathDelim,texMathDelimMod,texLength,texMathGroup,texMathOper,texMathSymbol,texSpecialChar,texMathSub,texMathSuper,texSymbolAmp,texSymbolDash,texSymbolNewline,@NoSpell syntax region texMathGroup matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath " Math regions: environments From 1cdaf632aab646d1486395a124e074da8995b0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 9 Nov 2020 21:39:23 +0100 Subject: [PATCH 45/99] wip: minor adjustments --- autoload/vimtex/syntax/core.vim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 9470d101d4..c8ab4892d8 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -314,7 +314,7 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_cmd_arg('texMathenvArgName', '') " Syntax clusters for math regions - syntax cluster texClusterMath contains=texCmd,texCmdRef,texCmdGreek,texCmdSize,texCmdStyle,texComment,texMathDelim,texMathDelimMod,texLength,texMathGroup,texMathOper,texMathSymbol,texSpecialChar,texMathSub,texMathSuper,texSymbolAmp,texSymbolDash,texSymbolNewline,@NoSpell + syntax cluster texClusterMath contains=texCmd,texCmdRef,texCmdGreek,texCmdSize,texCmdStyle,texCmdMathtext,texComment,texMathDelim,texMathDelimMod,texLength,texMathGroup,texMathOper,texMathSymbol,texSpecialChar,texMathSub,texMathSuper,texSymbolAmp,texSymbolDash,texSymbolNewline,@NoSpell syntax region texMathGroup matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath " Math regions: environments @@ -452,7 +452,7 @@ endfunction function! s:init_highlights(cfg) abort " {{{1 " See :help group-name for list of conventional group names - " Basic TeX highlighting groups + " Primitive TeX highlighting groups highlight def link texArg Include highlight def link texCmd Statement highlight def link texCmdSpaceCodeChar Special @@ -479,10 +479,9 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texSymbol SpecialChar highlight def link texSymbolString String highlight def link texTitleArg Underlined - highlight def texStyleBold gui=bold cterm=bold - highlight def texStyleItal gui=italic cterm=italic highlight def texStyleBoth gui=bold,italic cterm=bold,italic + highlight def texStyleItal gui=italic cterm=italic " Inherited groups highlight def link texAuthorOpt texOpt From 7b93801db225d5c96d859a2f8c9567e62da280f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 9 Nov 2020 21:58:10 +0100 Subject: [PATCH 46/99] wip: add texTabularChar for & and \\ --- autoload/vimtex/syntax/core.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index c8ab4892d8..9da3f94834 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -49,8 +49,8 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texSymbolString "\v%(``|''|,,)" syntax match texSymbolDash "--" syntax match texSymbolDash "---" - syntax match texSymbolAmp "&" - syntax match texSymbolNewline "\\\\" + syntax match texTabularChar "&" + syntax match texTabularChar "\\\\" " E.g.: \$ \& \% \# \{ \} \_ \S \P syntax match texSpecialChar "\\[$&%#{}_]" @@ -60,6 +60,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texSpecialChar "\\[SP@]\ze\A" endif syntax match texSpecialChar "\^\^\%(\S\|[0-9a-f]\{2}\)" + syntax match texSpecialChar "\\[,;:!]" " }}}2 " {{{2 Commands: general @@ -314,7 +315,7 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_cmd_arg('texMathenvArgName', '') " Syntax clusters for math regions - syntax cluster texClusterMath contains=texCmd,texCmdRef,texCmdGreek,texCmdSize,texCmdStyle,texCmdMathtext,texComment,texMathDelim,texMathDelimMod,texLength,texMathGroup,texMathOper,texMathSymbol,texSpecialChar,texMathSub,texMathSuper,texSymbolAmp,texSymbolDash,texSymbolNewline,@NoSpell + syntax cluster texClusterMath contains=texCmd,texCmdRef,texCmdGreek,texCmdSize,texCmdStyle,texCmdMathtext,texComment,texMathDelim,texMathDelimMod,texLength,texMathGroup,texMathOper,texMathSymbol,texSpecialChar,texMathSub,texMathSuper,texTabularChar,texSymbolDash,@NoSpell syntax region texMathGroup matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath " Math regions: environments @@ -552,9 +553,8 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texNewenvParm texParm highlight def link texOptEqual texSymbol highlight def link texRefOpt texOpt - highlight def link texSymbolAmp texSymbol highlight def link texSymbolDash texSymbol - highlight def link texSymbolNewline texSymbol + highlight def link texTabularChar texSymbol highlight def link texVerbRegion texRegion highlight def link texVerbRegionInline texVerbRegion endfunction From aebd6f6d86e2ed800d385e46de614abe4da329de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 9 Nov 2020 22:07:22 +0100 Subject: [PATCH 47/99] wip: improve math delim matching --- autoload/vimtex/syntax/core.vim | 55 ++++++++++++++-------------- test/tests/test-syntax/test-core.tex | 13 +++++++ 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 9da3f94834..bcbca036c1 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -466,7 +466,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texError Error highlight def link texLength Number highlight def link texMathDelim Type - highlight def link texMathDelimMod Statement highlight def link texMathOper Operator highlight def link texMathRegion Special highlight def link texMathenvArgName Delimiter @@ -533,7 +532,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texFilesOpt texOpt highlight def link texGroupError texError highlight def link texMathDelimRegion texDelim - highlight def link texMathDelimSet texMathDelim + highlight def link texMathDelimMod texMathDelim highlight def link texMathError texError highlight def link texMathErrorDelim texError highlight def link texMathGroup texMathRegion @@ -971,32 +970,32 @@ endfunction " }}}1 function! s:match_math_delims(cfg) abort " {{{1 - syntax match texMathDelimMod contained skipwhite nextgroup=texMathDelimSet "\\\(left\|right\)\>" - syntax match texMathDelimMod contained skipwhite nextgroup=texMathDelimSet "\\[bB]igg\?[lr]\?\>" - syntax match texMathDelimSet contained "[<>()[\]|/.]\|\\[{}|]" - syntax match texMathDelimSet contained "\\backslash" - syntax match texMathDelimSet contained "\\downarrow" - syntax match texMathDelimSet contained "\\Downarrow" - syntax match texMathDelimSet contained "\\lVert" - syntax match texMathDelimSet contained "\\langle" - syntax match texMathDelimSet contained "\\lbrace" - syntax match texMathDelimSet contained "\\lceil" - syntax match texMathDelimSet contained "\\lfloor" - syntax match texMathDelimSet contained "\\lgroup" - syntax match texMathDelimSet contained "\\lmoustache" - syntax match texMathDelimSet contained "\\lvert" - syntax match texMathDelimSet contained "\\rVert" - syntax match texMathDelimSet contained "\\rangle" - syntax match texMathDelimSet contained "\\rbrace" - syntax match texMathDelimSet contained "\\rceil" - syntax match texMathDelimSet contained "\\rfloor" - syntax match texMathDelimSet contained "\\rgroup" - syntax match texMathDelimSet contained "\\rmoustache" - syntax match texMathDelimSet contained "\\rvert" - syntax match texMathDelimSet contained "\\uparrow" - syntax match texMathDelimSet contained "\\Uparrow" - syntax match texMathDelimSet contained "\\updownarrow" - syntax match texMathDelimSet contained "\\Updownarrow" + syntax match texMathDelimMod contained "\\\(left\|right\)\>" + syntax match texMathDelimMod contained "\\[bB]igg\?[lr]\?\>" + syntax match texMathDelim contained "[<>()[\]|/.]\|\\[{}|]" + syntax match texMathDelim contained "\\backslash" + syntax match texMathDelim contained "\\downarrow" + syntax match texMathDelim contained "\\Downarrow" + syntax match texMathDelim contained "\\lVert" + syntax match texMathDelim contained "\\langle" + syntax match texMathDelim contained "\\lbrace" + syntax match texMathDelim contained "\\lceil" + syntax match texMathDelim contained "\\lfloor" + syntax match texMathDelim contained "\\lgroup" + syntax match texMathDelim contained "\\lmoustache" + syntax match texMathDelim contained "\\lvert" + syntax match texMathDelim contained "\\rVert" + syntax match texMathDelim contained "\\rangle" + syntax match texMathDelim contained "\\rbrace" + syntax match texMathDelim contained "\\rceil" + syntax match texMathDelim contained "\\rfloor" + syntax match texMathDelim contained "\\rgroup" + syntax match texMathDelim contained "\\rmoustache" + syntax match texMathDelim contained "\\rvert" + syntax match texMathDelim contained "\\uparrow" + syntax match texMathDelim contained "\\Uparrow" + syntax match texMathDelim contained "\\updownarrow" + syntax match texMathDelim contained "\\Updownarrow" if !a:cfg.conceal.math_delimiters || &encoding !=# 'utf-8' return diff --git a/test/tests/test-syntax/test-core.tex b/test/tests/test-syntax/test-core.tex index 4f1e003e1c..7f11ab4903 100644 --- a/test/tests/test-syntax/test-core.tex +++ b/test/tests/test-syntax/test-core.tex @@ -45,6 +45,19 @@ \section{Second} \author{A. Author\thanks{An Institute}} +\section{Math} +\label{sec:math} + +\begin{equation} + ( ) + [ ] + + \left( \right) + \left\{ \right\} + \left\lvert \right\rvert + \left] \right[ +\end{equation} + \section*{Acknowledgement} \end{document} From 3200f3f0e6a5bb056b3beee2abe7843aa5d0b5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 9 Nov 2020 22:26:55 +0100 Subject: [PATCH 48/99] wip: separate listings syntax tests --- test/tests/test-syntax/test-large.vim | 16 -------- test/tests/test-syntax/test-listings.tex | 40 +++++++++++++++++++ test/tests/test-syntax/test-listings.vim | 20 ++++++++++ ...st-large.tex => test-various-packages.tex} | 29 -------------- .../test-syntax/test-various-packages.vim | 16 ++++++++ 5 files changed, 76 insertions(+), 45 deletions(-) delete mode 100644 test/tests/test-syntax/test-large.vim create mode 100644 test/tests/test-syntax/test-listings.tex create mode 100644 test/tests/test-syntax/test-listings.vim rename test/tests/test-syntax/{test-large.tex => test-various-packages.tex} (88%) create mode 100644 test/tests/test-syntax/test-various-packages.vim diff --git a/test/tests/test-syntax/test-large.vim b/test/tests/test-syntax/test-large.vim deleted file mode 100644 index feebe00ba5..0000000000 --- a/test/tests/test-syntax/test-large.vim +++ /dev/null @@ -1,16 +0,0 @@ -source common.vim - -let &rtp = '.,' . &rtp -let g:vimtex_fold_enabled = 1 - -silent edit test-large.tex - -if empty($INMAKE) | finish | endif - -call vimtex#test#assert_equal(len(keys(b:vimtex_syntax)), 16) - -" PythonTeX inside tikzpictures (#1563) -call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 219, 11)) -call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 224, 11)) - -quit! diff --git a/test/tests/test-syntax/test-listings.tex b/test/tests/test-syntax/test-listings.tex new file mode 100644 index 0000000000..ec0c00daf5 --- /dev/null +++ b/test/tests/test-syntax/test-listings.tex @@ -0,0 +1,40 @@ +\documentclass{article} +\usepackage{listings} + +\begin{document} + +% Comment out to compile! +\lstinputlisting[options]{file} + +\lstinline|asdasd| + +\begin{lstlisting} +testing +\end{lstlisting} + +\begin{lstlisting}[directivestyle={\color{black}}, + language=C, + emph={int,char,double,float,unsigned}, + emphstyle={\color{blue}}] +#include +main() { + int i = 0; + printf("Hello World"); +} +\end{lstlisting} + +\begin{lstlisting}[language=python] +def function(arg): + pass +\end{lstlisting} + +\lstset{language=rust,numbers=none} +\begin{lstlisting} +fn main() { + println!("Hello World!"); +} +\end{lstlisting} + +\lstset{language=x,numbers=none} + +\end{document} diff --git a/test/tests/test-syntax/test-listings.vim b/test/tests/test-syntax/test-listings.vim new file mode 100644 index 0000000000..d5ec7c056a --- /dev/null +++ b/test/tests/test-syntax/test-listings.vim @@ -0,0 +1,20 @@ +source common.vim + +let &rtp = '.,' . &rtp +let g:vimtex_fold_enabled = 1 + +silent edit test-listings.tex + +if empty($INMAKE) | finish | endif + +call vimtex#test#assert(vimtex#syntax#in('texFileArg', 7, 28)) +call vimtex#test#assert(vimtex#syntax#in('texVerbRegionInline', 9, 14)) + +call vimtex#test#assert(vimtex#syntax#in('texLstRegion', 12, 1)) +call vimtex#test#assert(vimtex#syntax#in('texLstRegionC', 20, 1)) +call vimtex#test#assert(vimtex#syntax#in('texLstRegionPython', 27, 1)) +call vimtex#test#assert(vimtex#syntax#in('texLstRegionRust', 33, 1)) + +call vimtex#test#assert(vimtex#syntax#in('texLstsetGroup', 38, 10)) + +quit! diff --git a/test/tests/test-syntax/test-large.tex b/test/tests/test-syntax/test-various-packages.tex similarity index 88% rename from test/tests/test-syntax/test-large.tex rename to test/tests/test-syntax/test-various-packages.tex index 0c69dd897e..8c005b85db 100644 --- a/test/tests/test-syntax/test-large.tex +++ b/test/tests/test-syntax/test-various-packages.tex @@ -15,7 +15,6 @@ \usepackage{gnuplottex} \usepackage[inline]{asymptote} \usepackage{pythontex} -\usepackage{listings} \begin{document} @@ -225,32 +224,4 @@ \section{Package: pythontex} \end{pycode} \end{tikzpicture} -\section{Package: listings} -\begin{lstlisting} -testing -\end{lstlisting} - -\begin{lstlisting}[directivestyle={\color{black}}, - language=C, - emph={int,char,double,float,unsigned}, - emphstyle={\color{blue}}] -#include -main() { - int i = 0; - printf("Hello World"); -} -\end{lstlisting} - -\begin{lstlisting}[language=python] -def function(arg): - pass -\end{lstlisting} - -\lstset{language=rust,numbers=none} -\begin{lstlisting} -fn main() { - println!("Hello World!"); -} -\end{lstlisting} - \end{document} diff --git a/test/tests/test-syntax/test-various-packages.vim b/test/tests/test-syntax/test-various-packages.vim new file mode 100644 index 0000000000..756bf9d0f4 --- /dev/null +++ b/test/tests/test-syntax/test-various-packages.vim @@ -0,0 +1,16 @@ +source common.vim + +let &rtp = '.,' . &rtp +let g:vimtex_fold_enabled = 1 + +silent edit test-various-packages.tex + +if empty($INMAKE) | finish | endif + +call vimtex#test#assert_equal(15, len(keys(b:vimtex_syntax))) + +" PythonTeX inside tikzpictures (#1563) +call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 218, 11)) +call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 223, 11)) + +quit! From 464ef909f953df586dfd236eb2273248cfb08628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 9 Nov 2020 23:27:19 +0100 Subject: [PATCH 49/99] wip: improve listings support --- autoload/vimtex/syntax/core.vim | 6 +- autoload/vimtex/syntax/p/listings.vim | 84 ++++++++++++++------------- autoload/vimtex/syntax/p/tikz.vim | 4 +- 3 files changed, 50 insertions(+), 44 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index bcbca036c1..c4af0f9ec5 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -208,7 +208,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texNewcmdParm contained "#\d\+" containedin=texNewcmdArgBody " \newenvironment - syntax match texCmdenv nextgroup=texNewenvArgName skipwhite skipnl "\\\%(re\)\?newenvironment\>" + syntax match texCmdNewenv nextgroup=texNewenvArgName skipwhite skipnl "\\\%(re\)\?newenvironment\>" call vimtex#syntax#core#new_cmd_arg('texNewenvArgName', 'texNewenvArgBegin,texNewenvOpt') call vimtex#syntax#core#new_cmd_opt('texNewenvOpt', 'texNewenvArgBegin,texNewenvOpt', '', 'oneline') call vimtex#syntax#core#new_cmd_arg('texNewenvArgBegin', 'texNewenvArgEnd', 'TOP') @@ -271,8 +271,8 @@ function! vimtex#syntax#core#init() abort " {{{1 " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do " In short: allow @ in multicharacter macro name - syntax region texRegionSty matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP - syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=texRegionSty + syntax region texStyRegion matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP + syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=texStyRegion " }}}2 " {{{2 Region: Verbatim diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index 57f4048526..189459374c 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -6,61 +6,67 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 if has_key(b:vimtex_syntax, 'listings') | return | endif - let b:vimtex_syntax.listings = s:get_nested_languages() - " First some general support + let b:vimtex_syntax.listings = map( + \ filter(getline(1, '$'), "v:val =~# 'language='"), + \ {_, x -> matchstr(x, 'language=\zs\w\+')}) + + " Match inline listings + syntax match texCmdVerb "\\lstinline\>" nextgroup=texVerbRegionInline + + " Match input file commands syntax match texCmd "\\lstinputlisting\>" \ nextgroup=texFileOpt,texFileArg skipwhite skipnl - syntax match texRegion "\\lstinline\s*\(\[.\{-}\]\)\={.\{-}}" - " Set all listings environments to listings - syntax cluster texFoldGroup add=texRegionListings - call vimtex#syntax#core#new_region_env('texRegionListings', 'lstlisting') + " Match \lstset + syntax match texCmdLstset "\\lstset\>" + \ skipwhite skipempty nextgroup=texLstsetArg,texLstsetGroup + syntax region texLstsetGroup matchgroup=texDelim + \ start="{" skip="\\\\\|\\}" end="}" + \ contained + \ contains=texComment,texLength,texOptSep,texOptEqual + + " Match unspecified lstlisting environment + syntax match texLstEnvBgn "\\begin{lstlisting}" + \ nextgroup=texLstOpt skipwhite skipnl contains=texCmdEnv + call vimtex#syntax#core#new_cmd_opt('texLstOpt', '') + syntax region texLstRegion + \ start="\\begin{lstlisting}" + \ end="\\end{lstlisting}" + \ keepend + \ contains=texLstEnvBgn,texCmdEnv - " Next add nested syntax support for desired languages + " Add nested syntax support for desired languages for l:nested in b:vimtex_syntax.listings let l:cluster = vimtex#syntax#nested#include(l:nested) if empty(l:cluster) | continue | endif - let l:group_main = 'texRegionListings' . toupper(l:nested[0]) . l:nested[1:] - let l:group_lstset = l:group_main . 'Lstset' - let l:group_contained = l:group_main . 'Contained' - execute 'syntax cluster texFoldGroup add=' . l:group_main - execute 'syntax cluster texFoldGroup add=' . l:group_lstset + let l:groupname = 'texLstRegion' . toupper(l:nested[0]) . l:nested[1:] - execute 'syntax region' l:group_main - \ 'start="\c\\begin{lstlisting}\s*' - \ . '\[\_[^\]]\{-}language=' . l:nested . '\%(\s*,\_[^\]]\{-}\)\?\]"' - \ 'end="\\end{lstlisting}"' - \ 'keepend' + execute 'syntax match texLstsetArg' + \ '"\c{\_[^}]*language=' . l:nested . '\%(\s*,\|}\)"' + \ 'skipwhite skipempty nextgroup=' . l:groupname \ 'transparent' - \ 'contains=texCmdEnv,@' . l:cluster + \ 'contains=texLstsetGroup' - execute 'syntax match' l:group_lstset - \ '"\c\\lstset{.*language=' . l:nested . '\%(\s*,\|}\)"' - \ 'transparent' - \ 'contains=texCmd,texGroup' - \ 'skipwhite skipempty' - \ 'nextgroup=' . l:group_contained - - execute 'syntax region' l:group_contained + execute 'syntax region' l:groupname \ 'start="\\begin{lstlisting}"' \ 'end="\\end{lstlisting}"' - \ 'keepend' - \ 'transparent' - \ 'containedin=' . l:group_lstset - \ 'contains=texCmd,texCmdEnv,@' . l:cluster - endfor - - highlight link texRegionListings texRegion -endfunction + \ 'keepend contained' + \ 'contains=texLstEnvBgn,texCmdEnv,@' . l:cluster -" }}}1 + execute 'syntax region' l:groupname + \ 'start="\c\\begin{lstlisting}\s*' + \ . '\[\_[^\]]\{-}language=' . l:nested . '\%(\s*,\_[^\]]\{-}\)\?\]"' + \ 'end="\\end{lstlisting}"' + \ 'keepend transparent' + \ 'contains=texCmdEnv,texLstEnvBgn,@' . l:cluster + endfor -function! s:get_nested_languages() abort " {{{1 - return map( - \ filter(getline(1, '$'), "v:val =~# 'language='"), - \ {_, x -> matchstr(x, 'language=\zs\w\+')}) + highlight def link texCmdLstset texCmd + highlight def link texLstsetGroup texOpt + highlight def link texLstRegion texRegion + highlight def link texLstOpt texOpt endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index 323e4ee2a4..c2e72b4fd4 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -11,10 +11,10 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 syntax cluster texClusterTikz contains=texTikzEnvBgn,texTikzSemicolon,texCmd,texGroup,texComment syntax cluster texClusterTikzset contains=texTikzsetArg,texOptSep,texOptEqual,texMathRegionX,texTypeSize,texCmd,texLength,texComment - syntax match texCmdTikzset /\\tikzset\>/ skipwhite skipnl nextgroup=texTikzsetArg + syntax match texCmdTikzset "\\tikzset\>" skipwhite skipnl nextgroup=texTikzsetArg call vimtex#syntax#core#new_cmd_arg('texTikzsetArg', '', '@texClusterTikzset') - syntax match texTikzEnvBgn /\v\\begin\{tikzpicture\}/ + syntax match texTikzEnvBgn "\\begin{tikzpicture}" \ nextgroup=texTikzOpt skipwhite skipnl contains=texCmdEnv call vimtex#syntax#core#new_region_env( \ 'texTikzRegion', 'tikzpicture', '@texClusterTikz') From 4499fd7cb43985489696c98c827d7bea2992c4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 9 Nov 2020 23:33:00 +0100 Subject: [PATCH 50/99] wip: minor update --- autoload/vimtex/syntax/p/minted.vim | 35 +++++++++++++------------- test/tests/test-syntax/test-minted.vim | 4 +-- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index 4fd3da4c84..55739425b4 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -12,8 +12,8 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 call s:parse_minted_constructs() " Match minted language names - syntax region texMintedName matchgroup=Delimiter start="{" end="}" contained - syntax region texMintedNameOpt matchgroup=Delimiter start="\[" end="\]" contained + syntax region texMintedName matchgroup=texDelim start="{" end="}" contained + syntax region texMintedNameOpt matchgroup=texDelim start="\[" end="\]" contained " Match boundaries of minted environments syntax match texMintedBounds '\\end{minted}' @@ -23,7 +23,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 \ contained \ contains=texCmdEnv \ nextgroup=texMintedBoundsOpts,texMintedName - syntax region texMintedBoundsOpts matchgroup=Delimiter + syntax region texMintedBoundsOpts matchgroup=texDelim \ start="\[" end="\]" \ contained \ nextgroup=texMintedName @@ -33,17 +33,17 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 \ contained \ contains=texCmdEnv \ nextgroup=texMintedStarredOpts - syntax region texMintedStarredOpts matchgroup=Delimiter + syntax region texMintedStarredOpts matchgroup=texDelim \ start='{' \ end='}' \ contained \ containedin=texMintedStarred " Match \newminted type macros - syntax match texCmd '\\newmint\%(ed\|inline\)\?' nextgroup=texMintedName,texMintedNameOpt + syntax match texCmd '\\newmint\%(ed\|inline\)\?\>' skipwhite skipnl nextgroup=texMintedName,texMintedNameOpt " Match "unknown" environments - syntax region texRegionMinted + syntax region texMintedRegion \ start="\\begin{minted}\%(\_s*\[\_[^\]]\{-}\]\)\?\_s*{\w\+}" \ end="\\end{minted}" \ keepend @@ -53,12 +53,12 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 syntax match texArgMinted "{\w\+}" \ contained \ contains=texMintedName - \ nextgroup=texRegionMintedCmd - syntax region texRegionMintedCmd matchgroup=Delimiter + \ nextgroup=texMintedRegionArg + syntax region texMintedRegionArg matchgroup=texDelim \ start='\z([|+/]\)' \ end='\z1' \ contained - syntax region texRegionMintedCmd matchgroup=Delimiter + syntax region texMintedRegionArg matchgroup=texDelim \ start='{' \ end='}' \ contained @@ -76,8 +76,8 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 let l:transparent = '' let l:contains_env = '' let l:contains_macro = '' - execute 'highlight link' l:group_main 'texRegionMinted' - execute 'highlight link' l:group_arg_zone 'texRegionMinted' + execute 'highlight link' l:group_main 'texMintedRegion' + execute 'highlight link' l:group_arg_zone 'texMintedRegion' else let l:transparent = 'transparent' let l:contains_env = ',@' . l:cluster @@ -112,13 +112,13 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 \ 'contains=texMintedName' \ 'nextgroup=' . l:group_arg_zone execute 'syntax region' l:group_arg_zone - \ 'matchgroup=Delimiter' + \ 'matchgroup=texDelim' \ 'start=''\z([|+/]\)''' \ 'end=''\z1''' \ 'contained' \ l:contains_macro execute 'syntax region' l:group_arg_zone - \ 'matchgroup=Delimiter' + \ 'matchgroup=texDelim' \ 'start=''{''' \ 'end=''}''' \ 'contained' @@ -134,14 +134,13 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " Main matcher for the minted statements/commands " - Note: This comes last to allow the nextgroup pattern syntax match texCmd '\\mint\(inline\)\?' nextgroup=texArgOptMinted,texArgMinted.* - syntax region texArgOptMinted matchgroup=Delimiter - \ start='\[' - \ end='\]' + syntax region texArgOptMinted matchgroup=texDelim + \ start='\[' end='\]' \ contained \ nextgroup=texArgMinted.* - highlight link texRegionMinted texRegion - highlight link texRegionMintedCmd texRegion + highlight link texMintedRegion texRegion + highlight link texMintedRegionArg texRegion highlight link texMintedName texOpt highlight link texMintedNameOpt texMintedName endfunction diff --git a/test/tests/test-syntax/test-minted.vim b/test/tests/test-syntax/test-minted.vim index bfc0beb8fe..f3732723a0 100644 --- a/test/tests/test-syntax/test-minted.vim +++ b/test/tests/test-syntax/test-minted.vim @@ -8,8 +8,8 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('javaScopeDecl', 72, 3)) " Newminted on unrecognized languages (#1616) -call vimtex#test#assert(vimtex#syntax#in('texRegionMintedLog', 112, 1)) -call vimtex#test#assert(vimtex#syntax#in('texRegionMintedShellsession', 116, 1)) +call vimtex#test#assert(vimtex#syntax#in('texMintedRegionLog', 112, 1)) +call vimtex#test#assert(vimtex#syntax#in('texMintedRegionShellsession', 116, 1)) " Doing :e should not destroy nested syntax and similar call vimtex#test#assert(vimtex#syntax#in('pythonFunction', 38, 5)) From bd7fb5bf0a217d67780afbeb9f64c2d52a232240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 9 Nov 2020 23:45:16 +0100 Subject: [PATCH 51/99] wip: minor fix --- autoload/vimtex/syntax/p/minted.vim | 14 +++++++------- test/tests/test-syntax/test-minted.vim | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index 55739425b4..fb67f5198f 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -50,7 +50,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 \ contains=texMintedBounds.* " Match "unknown" commands - syntax match texArgMinted "{\w\+}" + syntax match texMintedArg "{\w\+}" \ contained \ contains=texMintedName \ nextgroup=texMintedRegionArg @@ -67,10 +67,10 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 for [l:nested, l:config] in items(b:vimtex.syntax.minted) let l:cluster = vimtex#syntax#nested#include(l:nested) - let l:name = 'Minted' . toupper(l:nested[0]) . l:nested[1:] - let l:group_main = 'texRegion' . l:name - let l:group_arg = 'texArg' . l:name - let l:group_arg_zone = 'texArgZone' . l:name + let l:name = toupper(l:nested[0]) . l:nested[1:] + let l:group_main = 'texMintedRegion' . l:name + let l:group_arg = 'texMintedArg' . l:name + let l:group_arg_zone = 'texMintedRegion' . l:name . 'Inline' if empty(l:cluster) let l:transparent = '' @@ -133,11 +133,11 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " Main matcher for the minted statements/commands " - Note: This comes last to allow the nextgroup pattern - syntax match texCmd '\\mint\(inline\)\?' nextgroup=texArgOptMinted,texArgMinted.* + syntax match texCmd '\\mint\(inline\)\?' nextgroup=texArgOptMinted,texMintedArg.* syntax region texArgOptMinted matchgroup=texDelim \ start='\[' end='\]' \ contained - \ nextgroup=texArgMinted.* + \ nextgroup=texMintedArg.* highlight link texMintedRegion texRegion highlight link texMintedRegionArg texRegion diff --git a/test/tests/test-syntax/test-minted.vim b/test/tests/test-syntax/test-minted.vim index f3732723a0..4a9442e241 100644 --- a/test/tests/test-syntax/test-minted.vim +++ b/test/tests/test-syntax/test-minted.vim @@ -11,9 +11,9 @@ call vimtex#test#assert(vimtex#syntax#in('javaScopeDecl', 72, 3)) call vimtex#test#assert(vimtex#syntax#in('texMintedRegionLog', 112, 1)) call vimtex#test#assert(vimtex#syntax#in('texMintedRegionShellsession', 116, 1)) -" Doing :e should not destroy nested syntax and similar -call vimtex#test#assert(vimtex#syntax#in('pythonFunction', 38, 5)) -edit -call vimtex#test#assert(vimtex#syntax#in('pythonFunction', 38, 5)) +" " Doing :e should not destroy nested syntax and similar +" call vimtex#test#assert(vimtex#syntax#in('pythonFunction', 38, 5)) +" edit +" call vimtex#test#assert(vimtex#syntax#in('pythonFunction', 38, 5)) quit! From 0a5f8617c61fb0b63769b0f434c9dfb2fd4b7d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Tue, 10 Nov 2020 22:36:56 +0100 Subject: [PATCH 52/99] wip: add g:vimtex_syntax_conceal as a short option --- autoload/vimtex/options.vim | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index d6eed8e8c4..5048464a33 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -261,15 +261,16 @@ function! vimtex#options#init() abort " {{{1 call s:init_option('vimtex_subfile_start_local', 0) + call s:init_option('vimtex_syntax_conceal', 1) call s:init_option('vimtex_syntax_config', { \ 'conceal': { - \ 'accents': 1, - \ 'greek': 1, - \ 'math_bounds': 1, - \ 'math_delimiters': 1, - \ 'special_chars': 1, - \ 'styles': 1, - \ 'super_sub': 1, + \ 'accents': g:vimtex_syntax_conceal, + \ 'greek': g:vimtex_syntax_conceal, + \ 'math_bounds': g:vimtex_syntax_conceal, + \ 'math_delimiters': g:vimtex_syntax_conceal, + \ 'special_chars': g:vimtex_syntax_conceal, + \ 'styles': g:vimtex_syntax_conceal, + \ 'super_sub': g:vimtex_syntax_conceal, \ }, \}) From 6739e0865f269d64ab194a672920182ce5598f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Tue, 10 Nov 2020 23:22:02 +0100 Subject: [PATCH 53/99] wip: improved minted highlighting --- autoload/vimtex/syntax/p/minted.vim | 108 +++++++++++++++------------- 1 file changed, 58 insertions(+), 50 deletions(-) diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index fb67f5198f..c35d2123d5 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -11,57 +11,54 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " Parse minted macros in the current project call s:parse_minted_constructs() - " Match minted language names - syntax region texMintedName matchgroup=texDelim start="{" end="}" contained - syntax region texMintedNameOpt matchgroup=texDelim start="\[" end="\]" contained - - " Match boundaries of minted environments - syntax match texMintedBounds '\\end{minted}' - \ contained - \ contains=texCmdEnv - syntax match texMintedBounds '\\begin{minted}' - \ contained + " Match \newminted type macros + syntax match texCmdNewmint '\\newmint\%(ed\|inline\)\?\>' + \ skipwhite skipnl nextgroup=texNewmintOpt,texNewmintArgX + syntax region texNewmintOpt contained matchgroup=texDelim + \ start="\[" end="\]" + \ skipwhite skipnl nextgroup=texNewmintArgY + syntax region texNewmintArgX contained matchgroup=texDelim + \ start="{" end="}" + \ skipwhite skipnl nextgroup=texNewmintArgOpts + syntax region texNewmintArgY contained matchgroup=texDelim + \ start="{" end="}" + \ skipwhite skipnl nextgroup=texNewmintArgOpts + syntax region texNewmintArgOpts contained matchgroup=texDelim + \ start="{" end="}" + + " Match minted environment boundaries + syntax match texMintedEnvBgn contained '\\begin{minted}' \ contains=texCmdEnv - \ nextgroup=texMintedBoundsOpts,texMintedName - syntax region texMintedBoundsOpts matchgroup=texDelim + \ skipwhite skipnl nextgroup=texMintedEnvOpt,texMintedEnvArg + syntax region texMintedEnvOpt contained matchgroup=texDelim \ start="\[" end="\]" - \ contained - \ nextgroup=texMintedName + \ skipwhite skipnl nextgroup=texMintedEnvArg + syntax region texMintedEnvArg contained matchgroup=texDelim + \ start="{" end="}" - " Match starred custom minted environments with options - syntax match texMintedStarred "\\begin{\w\+\*}" + " Match custom starred minted environments and their options + syntax match texMintedEnvBgn "\\begin{\w\+\*}" \ contained \ contains=texCmdEnv - \ nextgroup=texMintedStarredOpts - syntax region texMintedStarredOpts matchgroup=texDelim - \ start='{' - \ end='}' - \ contained - \ containedin=texMintedStarred - - " Match \newminted type macros - syntax match texCmd '\\newmint\%(ed\|inline\)\?\>' skipwhite skipnl nextgroup=texMintedName,texMintedNameOpt + \ nextgroup=texMintedEnvOptStarred + syntax region texMintedEnvOptStarred contained matchgroup=texDelim + \ start='{' end='}' " Match "unknown" environments syntax region texMintedRegion \ start="\\begin{minted}\%(\_s*\[\_[^\]]\{-}\]\)\?\_s*{\w\+}" \ end="\\end{minted}" \ keepend - \ contains=texMintedBounds.* + \ contains=texCmdEnv,texMintedEnvBgn " Match "unknown" commands - syntax match texMintedArg "{\w\+}" - \ contained - \ contains=texMintedName - \ nextgroup=texMintedRegionArg - syntax region texMintedRegionArg matchgroup=texDelim - \ start='\z([|+/]\)' - \ end='\z1' - \ contained - syntax region texMintedRegionArg matchgroup=texDelim - \ start='{' - \ end='}' - \ contained + syntax region texMintedArg contained matchgroup=texDelim + \ start='{' end='}' + \ skipwhite skipnl nextgroup=texMintedRegionArg + syntax region texMintedRegionArg contained matchgroup=texDelim + \ start='\z([|+/]\)' end='\z1' + syntax region texMintedRegionArg contained matchgroup=texDelim + \ start='{' end='}' " Next add nested syntax support for desired languages for [l:nested, l:config] in items(b:vimtex.syntax.minted) @@ -90,7 +87,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 \ 'end="\\end{minted}"' \ 'keepend' \ l:transparent - \ 'contains=texMintedBounds.*' . l:contains_env + \ 'contains=texCmdEnv,texMintedEnvBgn' . l:contains_env " Match custom environment names for l:env in get(l:config, 'environments', []) @@ -99,7 +96,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 \ 'end="\\end{\z1}"' \ 'keepend' \ l:transparent - \ 'contains=texMintedStarred,texCmdEnv' . l:contains_env + \ 'contains=texCmdEnv,texMintedEnvBgn' . l:contains_env endfor " Match minted macros @@ -109,7 +106,7 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " - \mintinline[]{lang}{...} execute 'syntax match' l:group_arg '''{' . l:nested . '}''' \ 'contained' - \ 'contains=texMintedName' + \ 'contains=texMintedArg' \ 'nextgroup=' . l:group_arg_zone execute 'syntax region' l:group_arg_zone \ 'matchgroup=texDelim' @@ -133,16 +130,27 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " Main matcher for the minted statements/commands " - Note: This comes last to allow the nextgroup pattern - syntax match texCmd '\\mint\(inline\)\?' nextgroup=texArgOptMinted,texMintedArg.* - syntax region texArgOptMinted matchgroup=texDelim + syntax match texCmdMinted '\\mint\(inline\)\?' + \ skipwhite skipnl nextgroup=texMintedOpt,texMintedArg.* + syntax region texMintedOpt contained matchgroup=texDelim \ start='\[' end='\]' - \ contained - \ nextgroup=texMintedArg.* - - highlight link texMintedRegion texRegion - highlight link texMintedRegionArg texRegion - highlight link texMintedName texOpt - highlight link texMintedNameOpt texMintedName + \ skipwhite skipnl nextgroup=texMintedArg.* + + highlight def link texCmdMinted texCmd + highlight def link texMintedOpt texOpt + highlight def link texMintedArg texSymbol + + highlight def link texMintedRegion texRegion + highlight def link texMintedRegionArg texRegion + highlight def link texMintedEnvOpt texOpt + highlight def link texMintedEnvOptStarred texOpt + highlight def link texMintedEnvArg texSymbol + + highlight def link texCmdNewmint texCmd + highlight def link texNewmintOpt texSymbol + highlight def link texNewmintArgX texSymbol + highlight def link texNewmintArgY texComment + highlight def link texNewmintArgOpts texOpt endfunction " }}}1 From 1609ea8bc61f7bd0eef08e8f708bebded830cc08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 11 Nov 2020 23:04:57 +0100 Subject: [PATCH 54/99] wip: fix the main clusters --- autoload/vimtex/syntax/core.vim | 104 +++++++++++++++++++++----- autoload/vimtex/syntax/p/csquotes.vim | 2 +- autoload/vimtex/syntax/p/hyperref.vim | 2 +- 3 files changed, 89 insertions(+), 19 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index c4af0f9ec5..62c14185c8 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -15,6 +15,84 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax sync maxlines=500 syntax sync minlines=50 + " {{{2 Define main syntax clusters + + " Note: These clusters can be updated for specific package syntax if + " a package defines items that should be available at top level. + + syntax cluster texClusterMain contains= + \texGroup, + \texGroupError, + \@texClusterCmds, + \@texClusterOther + + syntax cluster texClusterCmds contains= + \texCmd, + \texCmdAccent, + \texCmdAuthor, + \texCmdBib, + \texCmdClass, + \texCmdDef, + \texCmdEnv, + \texCmdError, + \texCmdFootnote, + \texCmdGreek, + \texCmdInput, + \texCmdItem, + \texCmdLigature, + \texCmdNewcmd, + \texCmdNewenv, + \texCmdPackage, + \texCmdParts, + \texCmdRef, + \texCmdSize, + \texCmdSpaceCode, + \texCmdSpaceCodeChar, + \texCmdStyle, + \texCmdStyleBold, + \texCmdStyleBoldItal, + \texCmdStyleItal, + \texCmdStyleItalBold, + \texCmdTitle, + \texCmdTodo, + \texCmdVerb + + syntax cluster texClusterOther contains= + \texComment, + \texSpecialChar, + \texSymbolDash, + \texSymbolString, + \texTabularChar + + syntax cluster texClusterOpt contains=texOptEqual,texOptSep + + syntax cluster texClusterMath contains= + \texCmd, + \texCmdEnv, + \texCmdError, + \texCmdFootnote, + \texCmdGreek, + \texCmdMathtext, + \texCmdRef, + \texCmdSize, + \texCmdStyle, + \texCmdTodo, + \texCmdVerb, + \texComment, + \texGroupError, + \texMathDelim, + \texMathDelimMod, + \texMathGroup, + \texMathOper, + \texMathSub, + \texMathSuper, + \texMathSymbol, + \texSpecialChar, + \texTabularChar, + \@NoSpell + + " }}}2 + " {{{2 Comments " * In documented TeX Format, actual comments are defined by leading "^^A". @@ -121,12 +199,12 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdAuthor nextgroup=texAuthorOpt,texAuthorArg skipwhite skipnl "\\author\>" syntax match texCmdTitle nextgroup=texTitleArg skipwhite skipnl "\\title\>" call vimtex#syntax#core#new_cmd_opt('texAuthorOpt', 'texAuthorArg') - call vimtex#syntax#core#new_cmd_arg('texAuthorArg', '', '@texClusterTL,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texTitleArg', '', '@texClusterTL') + call vimtex#syntax#core#new_cmd_arg('texAuthorArg', '', '@texClusterMain,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texTitleArg', '', '@texClusterMain') " Footnotes syntax match texCmdFootnote nextgroup=texFootnoteArg skipwhite skipnl "\\footnote\>" - call vimtex#syntax#core#new_cmd_arg('texFootnoteArg', '', '@texClusterTL') + call vimtex#syntax#core#new_cmd_arg('texFootnoteArg', '', '@texClusterMain') " Various commands that take a file argument (or similar) syntax match texCmdInput nextgroup=texFileArg skipwhite skipnl "\\input\>" @@ -204,7 +282,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdNewcmd nextgroup=texNewcmdArgName skipwhite skipnl "\\\%(re\)\?newcommand\>" call vimtex#syntax#core#new_cmd_arg('texNewcmdArgName', 'texNewcmdOpt,texNewcmdArgBody') call vimtex#syntax#core#new_cmd_opt('texNewcmdOpt', 'texNewcmdOpt,texNewcmdArgBody', '', 'oneline') - call vimtex#syntax#core#new_cmd_arg('texNewcmdArgBody', '', '@texClusterTL') + call vimtex#syntax#core#new_cmd_arg('texNewcmdArgBody', '', '@texClusterMain') syntax match texNewcmdParm contained "#\d\+" containedin=texNewcmdArgBody " \newenvironment @@ -212,7 +290,7 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_cmd_arg('texNewenvArgName', 'texNewenvArgBegin,texNewenvOpt') call vimtex#syntax#core#new_cmd_opt('texNewenvOpt', 'texNewenvArgBegin,texNewenvOpt', '', 'oneline') call vimtex#syntax#core#new_cmd_arg('texNewenvArgBegin', 'texNewenvArgEnd', 'TOP') - call vimtex#syntax#core#new_cmd_arg('texNewenvArgEnd', '', '@texClusterTL') + call vimtex#syntax#core#new_cmd_arg('texNewenvArgEnd', '', '@texClusterMain') syntax match texNewenvParm contained "#\d\+" containedin=texNewenvArgBegin,texNewenvArgEnd " Definitions/Commands @@ -227,7 +305,7 @@ function! vimtex#syntax#core#init() abort " {{{1 endif syntax match texDefParmPre contained nextgroup=texDefArgBody skipwhite skipnl "#[^{]*" syntax match texDefParm contained "#\d\+" containedin=texDefParmPre,texDefArgBody - call vimtex#syntax#core#new_cmd_arg('texDefArgBody', '', '@texClusterTL') + call vimtex#syntax#core#new_cmd_arg('texDefArgBody', '', '@texClusterMain') " Reference and cite commands syntax match texCmdRef nextgroup=texRefArg skipwhite skipnl "\\nocite\>" @@ -245,7 +323,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdParts nextgroup=texPartArgTitle "\\chapter\>\*\?" syntax match texCmdParts nextgroup=texPartArgTitle "\\\(sub\)*section\>\*\?" syntax match texCmdParts nextgroup=texPartArgTitle "\\\(sub\)\?paragraph\>" - call vimtex#syntax#core#new_cmd_arg('texPartArgTitle', '', '@texClusterTL') + call vimtex#syntax#core#new_cmd_arg('texPartArgTitle', '', '@texClusterMain') " Item elements in lists syntax match texCmdItem "\\item\>" @@ -254,18 +332,13 @@ function! vimtex#syntax#core#init() abort " {{{1 for l:macro in g:vimtex_syntax_nospell_commands execute 'syntax match texCmdNoSpell nextgroup=texNoSpellArg skipwhite skipnl "\\' . l:macro . '"' endfor - call vimtex#syntax#core#new_cmd_arg('texNoSpellArg', '', '@texClusterTL,@NoSpell') + call vimtex#syntax#core#new_cmd_arg('texNoSpellArg', '', '@texClusterMain,@NoSpell') " \begin \end environments syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvArgName call vimtex#syntax#core#new_cmd_arg('texEnvArgName', 'texEnvOpt') call vimtex#syntax#core#new_cmd_opt('texEnvOpt', '', 'texComment,@NoSpell') - " Specify clusters for use in regions - syntax cluster texClusterCmd contains=texCmd.*,texGroup.* - syntax cluster texClusterOpt contains=texOptEqual,texOptSep - syntax cluster texClusterTL contains=@texClusterCmd,texSpecialChar,texSymbol.*,texComment - " }}}2 " {{{2 Region: \makeatletter ... \makeatother @@ -282,7 +355,6 @@ function! vimtex#syntax#core#init() abort " {{{1 " Verbatim inline syntax match texCmdVerb "\\verb\>\*\?" nextgroup=texVerbRegionInline - syntax cluster texClusterCmd add=texCmdVerb if l:cfg.is_style_document syntax region texVerbRegionInline matchgroup=texDelim start="\z([^\ta-zA-Z@]\)" end="\z1" contained else @@ -314,8 +386,6 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdMathenv "\v\\%(begin|end)>" contained nextgroup=texMathenvArgName call vimtex#syntax#core#new_cmd_arg('texMathenvArgName', '') - " Syntax clusters for math regions - syntax cluster texClusterMath contains=texCmd,texCmdRef,texCmdGreek,texCmdSize,texCmdStyle,texCmdMathtext,texComment,texMathDelim,texMathDelimMod,texLength,texMathGroup,texMathOper,texMathSymbol,texSpecialChar,texMathSub,texMathSuper,texTabularChar,texSymbolDash,@NoSpell syntax region texMathGroup matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath " Math regions: environments @@ -350,7 +420,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " Text Inside Math regions syntax match texCmdMathtext "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texMathtextArg - call vimtex#syntax#core#new_cmd_arg('texMathtextArg', '', '@texClusterTL,@Spell') + call vimtex#syntax#core#new_cmd_arg('texMathtextArg', '', '@texClusterMain,@Spell') call s:match_math_sub_super(l:cfg) call s:match_math_symbols(l:cfg) diff --git a/autoload/vimtex/syntax/p/csquotes.vim b/autoload/vimtex/syntax/p/csquotes.vim index 1685d43aac..a43064a9d3 100644 --- a/autoload/vimtex/syntax/p/csquotes.vim +++ b/autoload/vimtex/syntax/p/csquotes.vim @@ -11,7 +11,7 @@ function! vimtex#syntax#p#csquotes#load() abort " {{{1 syntax match texCmdQuote nextgroup=texQuoteArg skipwhite skipnl "\\\%(foreign\|hyphen\)textcquote\*\?\>" syntax match texCmdQuote nextgroup=texQuoteArg skipwhite skipnl "\\\%(foreign\|hyphen\)blockcquote\>" syntax match texCmdQuote nextgroup=texQuoteArg skipwhite skipnl "\\hybridblockcquote\>" - call vimtex#syntax#core#new_cmd_arg('texQuoteArg', 'texRefOpt,texRefArg', '@texClusterTL', 'transparent') + call vimtex#syntax#core#new_cmd_arg('texQuoteArg', 'texRefOpt,texRefArg', '@texClusterMain', 'transparent') highlight def link texCmdQuote texCmd endfunction diff --git a/autoload/vimtex/syntax/p/hyperref.vim b/autoload/vimtex/syntax/p/hyperref.vim index ab81479099..028c1e7f4d 100644 --- a/autoload/vimtex/syntax/p/hyperref.vim +++ b/autoload/vimtex/syntax/p/hyperref.vim @@ -12,7 +12,7 @@ function! vimtex#syntax#p#hyperref#load() abort " {{{1 syntax match texCmdHyperref '\\hyperref\>' nextgroup=texRefOpt,texRefArg syntax match texCmdHyperref '\\href\>' nextgroup=texHrefArgLink skipwhite call vimtex#syntax#core#new_cmd_arg('texHrefArgLink', 'texHrefArgText', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texHrefArgText', '', '@texClusterTL') + call vimtex#syntax#core#new_cmd_arg('texHrefArgText', '', '@texClusterMain') syntax match texCmdHyperref "\\url\>" nextgroup=texUrlArg skipwhite syntax region texUrlArg matchgroup=texDelim From 8fd6ee6c8c49bf67046cfdb17cdb9ebb00484a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 11 Nov 2020 23:08:27 +0100 Subject: [PATCH 55/99] wip: change texSymbol(String|Dash) -> texLigature --- autoload/vimtex/syntax/core.vim | 37 +++++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 62c14185c8..3468693024 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -59,9 +59,8 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax cluster texClusterOther contains= \texComment, + \texLigature, \texSpecialChar, - \texSymbolDash, - \texSymbolString, \texTabularChar syntax cluster texClusterOpt contains=texOptEqual,texOptSep @@ -124,9 +123,9 @@ function! vimtex#syntax#core#init() abort " {{{1 " }}}2 " {{{2 TeX symbols and special characters - syntax match texSymbolString "\v%(``|''|,,)" - syntax match texSymbolDash "--" - syntax match texSymbolDash "---" + syntax match texLigature "--" + syntax match texLigature "---" + syntax match texLigature "\v%(``|''|,,)" syntax match texTabularChar "&" syntax match texTabularChar "\\\\" @@ -547,7 +546,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texRegion PreCondit highlight def link texSpecialChar SpecialChar highlight def link texSymbol SpecialChar - highlight def link texSymbolString String highlight def link texTitleArg Underlined highlight def texStyleBold gui=bold cterm=bold highlight def texStyleBoth gui=bold,italic cterm=bold,italic @@ -622,7 +620,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texNewenvParm texParm highlight def link texOptEqual texSymbol highlight def link texRefOpt texOpt - highlight def link texSymbolDash texSymbol + highlight def link texLigature texSymbol highlight def link texTabularChar texSymbol highlight def link texVerbRegion texRegion highlight def link texVerbRegionInline texVerbRegion @@ -1122,17 +1120,20 @@ function! s:match_conceal_accents() " {{{1 endfor endfor - syntax match texCmdAccent '\\aa\>' conceal cchar=å - syntax match texCmdAccent '\\AA\>' conceal cchar=Å - syntax match texCmdAccent '\\o\>' conceal cchar=ø - syntax match texCmdAccent '\\O\>' conceal cchar=Ø - syntax match texCmdLigature '\\AE\>' conceal cchar=Æ - syntax match texCmdLigature '\\ae\>' conceal cchar=æ - syntax match texCmdLigature '\\oe\>' conceal cchar=œ - syntax match texCmdLigature '\\OE\>' conceal cchar=Œ - syntax match texCmdLigature '\\ss\>' conceal cchar=ß - syntax match texSymbolDash '--' conceal cchar=– - syntax match texSymbolDash '---' conceal cchar=— + syntax match texCmdAccent "\\aa\>" conceal cchar=å + syntax match texCmdAccent "\\AA\>" conceal cchar=Å + syntax match texCmdAccent "\\o\>" conceal cchar=ø + syntax match texCmdAccent "\\O\>" conceal cchar=Ø + syntax match texCmdLigature "\\AE\>" conceal cchar=Æ + syntax match texCmdLigature "\\ae\>" conceal cchar=æ + syntax match texCmdLigature "\\oe\>" conceal cchar=œ + syntax match texCmdLigature "\\OE\>" conceal cchar=Œ + syntax match texCmdLigature "\\ss\>" conceal cchar=ß + syntax match texLigature "--" conceal cchar=– + syntax match texLigature "---" conceal cchar=— + syntax match texLigature "``" conceal cchar=“ + syntax match texLigature "''" conceal cchar=” + syntax match texLigature ",," conceal cchar=„ endfunction let s:key_accents = [ From d401be0d17ccb61316848793991b23a7af7f7768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 12 Nov 2020 00:13:53 +0100 Subject: [PATCH 56/99] wip: improved cmd, arg and opt matchers --- autoload/vimtex/syntax/core.vim | 143 ++++++++++++++---------- autoload/vimtex/syntax/p/biblatex.vim | 4 +- autoload/vimtex/syntax/p/cleveref.vim | 6 +- autoload/vimtex/syntax/p/csquotes.vim | 2 +- autoload/vimtex/syntax/p/glossaries.vim | 2 +- autoload/vimtex/syntax/p/hyperref.vim | 9 +- autoload/vimtex/syntax/p/listings.vim | 2 +- autoload/vimtex/syntax/p/luacode.vim | 9 +- autoload/vimtex/syntax/p/pythontex.vim | 2 +- autoload/vimtex/syntax/p/tabularx.vim | 10 +- autoload/vimtex/syntax/p/tikz.vim | 6 +- test/tests/test-syntax/test-nospell.vim | 2 +- 12 files changed, 112 insertions(+), 85 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 3468693024..be36260ae6 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -63,7 +63,13 @@ function! vimtex#syntax#core#init() abort " {{{1 \texSpecialChar, \texTabularChar - syntax cluster texClusterOpt contains=texOptEqual,texOptSep + syntax cluster texClusterOpt contains= + \texCmd, + \texComment, + \texLength, + \texOptEqual, + \texOptSep, + \@NoSpell syntax cluster texClusterMath contains= \texCmd, @@ -142,22 +148,13 @@ function! vimtex#syntax#core#init() abort " {{{1 " }}}2 " {{{2 Commands: general - " Match unspecified TeX groups - " Note: This is necessary to always match the corresponding end brace for - " specific argument groups. - syntax region texGroup matchgroup=texDelim - \ start="{" skip="\\\\\|\\}" end="}" contains=TOP + " Unspecified TeX groups + " Note: This is necessary to keep track of all nested braces + syntax region texGroup matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contains=TOP,@NoSpell " Flag mismatching ending brace delimiter syntax match texGroupError "}" - " Match general commands first - if l:cfg.is_style_document - syntax match texCmdSty "\\[a-zA-Z@]\+" - endif - syntax match texCmd "\\\a\+" - syntax match texCmdError "\\\a*@\a*" - " Add generic option elements contained in common option groups syntax match texOptEqual contained "=" syntax match texOptSep contained ",\s*" @@ -165,6 +162,15 @@ function! vimtex#syntax#core#init() abort " {{{1 " TeX Lengths (matched in options and some arguments) syntax match texLength contained "\<\d\+\([.,]\d\+\)\?\s*\(true\)\?\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>" + " Match general commands first + if l:cfg.is_style_document + syntax match texCmdSty "\\[a-zA-Z@]\+" + endif + syntax match texCmd nextgroup=texOpt,texArg skipwhite skipnl "\\\a\+" + call vimtex#syntax#core#new_opt('texOpt', {'next': 'texArg'}) + call vimtex#syntax#core#new_arg('texArg', {'next': 'texArg', 'opts': 'contained transparent'}) + syntax match texCmdError "\\\a*@\a*" + " {{{2 Commands: core set " Accents and ligatures @@ -194,16 +200,18 @@ function! vimtex#syntax#core#init() abort " {{{1 " Todo commands syntax match texCmdTodo '\\todo\w*' - " Author and title commands + " \author syntax match texCmdAuthor nextgroup=texAuthorOpt,texAuthorArg skipwhite skipnl "\\author\>" + call vimtex#syntax#core#new_opt('texAuthorOpt', {'next': 'texAuthorArg'}) + call vimtex#syntax#core#new_arg('texAuthorArg', {'contains': 'TOP,@Spell'}) + + " \title syntax match texCmdTitle nextgroup=texTitleArg skipwhite skipnl "\\title\>" - call vimtex#syntax#core#new_cmd_opt('texAuthorOpt', 'texAuthorArg') - call vimtex#syntax#core#new_cmd_arg('texAuthorArg', '', '@texClusterMain,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texTitleArg', '', '@texClusterMain') + call vimtex#syntax#core#new_arg('texTitleArg') - " Footnotes + " \footnote syntax match texCmdFootnote nextgroup=texFootnoteArg skipwhite skipnl "\\footnote\>" - call vimtex#syntax#core#new_cmd_arg('texFootnoteArg', '', '@texClusterMain') + call vimtex#syntax#core#new_arg('texFootnoteArg') " Various commands that take a file argument (or similar) syntax match texCmdInput nextgroup=texFileArg skipwhite skipnl "\\input\>" @@ -215,10 +223,10 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdClass nextgroup=texFileOpt,texFileArg skipwhite skipnl "\\document\%(class\|style\)\>" syntax match texCmdPackage nextgroup=texFilesOpt,texFilesArg skipwhite skipnl "\\usepackage\>" syntax match texCmdPackage nextgroup=texFilesOpt,texFilesArg skipwhite skipnl "\\RequirePackage\>" - call vimtex#syntax#core#new_cmd_opt('texFileOpt', 'texFileArg') - call vimtex#syntax#core#new_cmd_arg('texFileArg', '', '@NoSpell,texCmd,texComment') - call vimtex#syntax#core#new_cmd_opt('texFilesOpt', 'texFilesArg') - call vimtex#syntax#core#new_cmd_arg('texFilesArg', '', '@NoSpell,texCmd,texComment,texOptSep') + call vimtex#syntax#core#new_arg('texFileArg', {'contains': '@NoSpell,texCmd,texComment'}) + call vimtex#syntax#core#new_arg('texFilesArg', {'contains': '@NoSpell,texCmd,texComment,texOptSep'}) + call vimtex#syntax#core#new_opt('texFileOpt', {'next': 'texFileArg'}) + call vimtex#syntax#core#new_opt('texFilesOpt', {'next': 'texFilesArg'}) " LaTeX 2.09 type styles syntax match texCmdStyle "\\rm\>" @@ -279,17 +287,23 @@ function! vimtex#syntax#core#init() abort " {{{1 " \newcommand syntax match texCmdNewcmd nextgroup=texNewcmdArgName skipwhite skipnl "\\\%(re\)\?newcommand\>" - call vimtex#syntax#core#new_cmd_arg('texNewcmdArgName', 'texNewcmdOpt,texNewcmdArgBody') - call vimtex#syntax#core#new_cmd_opt('texNewcmdOpt', 'texNewcmdOpt,texNewcmdArgBody', '', 'oneline') - call vimtex#syntax#core#new_cmd_arg('texNewcmdArgBody', '', '@texClusterMain') + call vimtex#syntax#core#new_arg('texNewcmdArgName', {'next': 'texNewcmdOpt,texNewcmdArgBody'}) + call vimtex#syntax#core#new_opt('texNewcmdOpt', { + \ 'next': 'texNewcmdOpt,texNewcmdArgBody', + \ 'opts': 'oneline', + \}) + call vimtex#syntax#core#new_arg('texNewcmdArgBody') syntax match texNewcmdParm contained "#\d\+" containedin=texNewcmdArgBody " \newenvironment syntax match texCmdNewenv nextgroup=texNewenvArgName skipwhite skipnl "\\\%(re\)\?newenvironment\>" - call vimtex#syntax#core#new_cmd_arg('texNewenvArgName', 'texNewenvArgBegin,texNewenvOpt') - call vimtex#syntax#core#new_cmd_opt('texNewenvOpt', 'texNewenvArgBegin,texNewenvOpt', '', 'oneline') - call vimtex#syntax#core#new_cmd_arg('texNewenvArgBegin', 'texNewenvArgEnd', 'TOP') - call vimtex#syntax#core#new_cmd_arg('texNewenvArgEnd', '', '@texClusterMain') + call vimtex#syntax#core#new_arg('texNewenvArgName', {'next': 'texNewenvArgBegin,texNewenvOpt'}) + call vimtex#syntax#core#new_opt('texNewenvOpt', { + \ 'next': 'texNewenvArgBegin,texNewenvOpt', + \ 'opts': 'oneline' + \}) + call vimtex#syntax#core#new_arg('texNewenvArgBegin', {'next': 'texNewenvArgEnd'}) + call vimtex#syntax#core#new_arg('texNewenvArgEnd') syntax match texNewenvParm contained "#\d\+" containedin=texNewenvArgBegin,texNewenvArgEnd " Definitions/Commands @@ -304,7 +318,7 @@ function! vimtex#syntax#core#init() abort " {{{1 endif syntax match texDefParmPre contained nextgroup=texDefArgBody skipwhite skipnl "#[^{]*" syntax match texDefParm contained "#\d\+" containedin=texDefParmPre,texDefArgBody - call vimtex#syntax#core#new_cmd_arg('texDefArgBody', '', '@texClusterMain') + call vimtex#syntax#core#new_arg('texDefArgBody') " Reference and cite commands syntax match texCmdRef nextgroup=texRefArg skipwhite skipnl "\\nocite\>" @@ -313,8 +327,8 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdRef nextgroup=texRefArg skipwhite skipnl "\\v\?ref\>" syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\cite\>" syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\cite[tp]\>\*\?" - call vimtex#syntax#core#new_cmd_opt('texRefOpt', 'texRefOpt,texRefArg') - call vimtex#syntax#core#new_cmd_arg('texRefArg', '', 'texComment,@NoSpell') + call vimtex#syntax#core#new_opt('texRefOpt', {'next': 'texRefOpt,texRefArg'}) + call vimtex#syntax#core#new_arg('texRefArg', {'contains': 'texComment,@NoSpell'}) " Sections and parts syntax match texCmdParts "\\\(front\|main\|back\)matter\>" @@ -322,21 +336,21 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdParts nextgroup=texPartArgTitle "\\chapter\>\*\?" syntax match texCmdParts nextgroup=texPartArgTitle "\\\(sub\)*section\>\*\?" syntax match texCmdParts nextgroup=texPartArgTitle "\\\(sub\)\?paragraph\>" - call vimtex#syntax#core#new_cmd_arg('texPartArgTitle', '', '@texClusterMain') + call vimtex#syntax#core#new_arg('texPartArgTitle') " Item elements in lists syntax match texCmdItem "\\item\>" - " Add @NoSpell for commands per configuration + " Add @NoSpell for commands per configuration (TOP,@Spell implies NoSpell!) for l:macro in g:vimtex_syntax_nospell_commands execute 'syntax match texCmdNoSpell nextgroup=texNoSpellArg skipwhite skipnl "\\' . l:macro . '"' endfor - call vimtex#syntax#core#new_cmd_arg('texNoSpellArg', '', '@texClusterMain,@NoSpell') + call vimtex#syntax#core#new_arg('texNoSpellArg', {'contains': 'TOP,@Spell'}) " \begin \end environments syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvArgName - call vimtex#syntax#core#new_cmd_arg('texEnvArgName', 'texEnvOpt') - call vimtex#syntax#core#new_cmd_opt('texEnvOpt', '', 'texComment,@NoSpell') + call vimtex#syntax#core#new_arg('texEnvArgName', {'next': 'texEnvOpt'}) + call vimtex#syntax#core#new_opt('texEnvOpt', {'contains': 'texComment,@NoSpell'}) " }}}2 " {{{2 Region: \makeatletter ... \makeatother @@ -367,13 +381,13 @@ function! vimtex#syntax#core#init() abort " {{{1 \ start='\\\%(ExplSyntaxOn\|ProvidesExpl\%(Package\|Class\|File\)\)' \ end='\\ExplSyntaxOff\|\%$' \ transparent keepend - \ contains=TOP + \ contains=TOP,@NoSpell syntax region texE3Group matchgroup=texDelim \ start="{" skip="\\\\\|\\}" end="}" \ contained \ containedin=texE3Region,texE3Group - \ contains=TOP + \ contains=TOP,@NoSpell syntax match texE3Var contained containedin=texE3Region,texE3Group "\\\a*\%(_\+[a-zA-Z]\+\)\+\>" syntax match texE3Func contained containedin=texE3Region,texE3Group "\\\a*\%(_\+[a-zA-Z]\+\)\+:[a-zA-Z]*" @@ -383,7 +397,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " {{{2 Region: Math syntax match texCmdMathenv "\v\\%(begin|end)>" contained nextgroup=texMathenvArgName - call vimtex#syntax#core#new_cmd_arg('texMathenvArgName', '') + call vimtex#syntax#core#new_arg('texMathenvArgName') syntax region texMathGroup matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath @@ -408,7 +422,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " Math regions: \ensuremath{...} syntax match texCmdMath "\\ensuremath\>" nextgroup=texMathRegionEnsured - call vimtex#syntax#core#new_cmd_arg('texMathRegionEnsured', '', '@texClusterMath') + call vimtex#syntax#core#new_arg('texMathRegionEnsured', {'contains': '@texClusterMath'}) " Bad/Mismatched math syntax match texMathError "\\[\])]" @@ -419,7 +433,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " Text Inside Math regions syntax match texCmdMathtext "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texMathtextArg - call vimtex#syntax#core#new_cmd_arg('texMathtextArg', '', '@texClusterMain,@Spell') + call vimtex#syntax#core#new_arg('texMathtextArg') call s:match_math_sub_super(l:cfg) call s:match_math_symbols(l:cfg) @@ -459,30 +473,39 @@ endfunction " }}}1 -function! vimtex#syntax#core#new_cmd_arg(grp, next, ...) abort " {{{1 - let l:contains = a:0 >= 1 ? a:1 : 'texComment' - let l:options = a:0 >= 2 ? a:2 : '' +function! vimtex#syntax#core#new_arg(grp, ...) abort " {{{1 + let l:cfg = extend({ + \ 'opts': 'contained', + \ 'next': '', + \ 'contains': 'TOP,@NoSpell', + \}, a:0 > 0 ? a:1 : {}) execute 'syntax region' a:grp - \ 'contained matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}"' - \ (empty(l:contains) ? '' : 'contains=' . l:contains) - \ (empty(a:next) ? '' : 'nextgroup=' . a:next . ' skipwhite skipnl') - \ l:options + \ 'matchgroup=texDelim' + \ 'start="{" skip="\\\\\|\\}" end="}"' + \ l:cfg.opts + \ (empty(l:cfg.contains) ? '' : 'contains=' . l:cfg.contains) + \ (empty(l:cfg.next) ? '' : 'nextgroup=' . l:cfg.next . ' skipwhite skipnl') endfunction " }}}1 -function! vimtex#syntax#core#new_cmd_opt(grp, next, ...) abort " {{{1 - let l:contains = a:0 > 0 ? a:1 : 'texComment,texCmd,texLength,texOptSep,texOptEqual' - let l:options = a:0 >= 2 ? a:2 : '' +function! vimtex#syntax#core#new_opt(grp, ...) abort " {{{1 + let l:cfg = extend({ + \ 'opts': '', + \ 'next': '', + \ 'contains': '@texClusterOpt', + \}, a:0 > 0 ? a:1 : {}) execute 'syntax region' a:grp - \ 'contained matchgroup=texDelim start="\[" skip="\\\\\|\\\]" end="\]"' - \ (empty(l:contains) ? '' : 'contains=' . l:contains) - \ (empty(a:next) ? '' : 'nextgroup=' . a:next . ' skipwhite skipnl') - \ l:options + \ 'contained matchgroup=texDelim' + \ 'start="\[" skip="\\\\\|\\\]" end="\]"' + \ l:cfg.opts + \ (empty(l:cfg.contains) ? '' : 'contains=' . l:cfg.contains) + \ (empty(l:cfg.next) ? '' : 'nextgroup=' . l:cfg.next . ' skipwhite skipnl') endfunction " }}}1 + function! vimtex#syntax#core#new_region_env(grp, envname, ...) abort " {{{1 let l:contains = 'texCmdEnv' let l:options = 'keepend' @@ -632,9 +655,9 @@ function! s:match_bold_italic(cfg) abort " {{{1 let [l:conceal, l:concealends] = \ (a:cfg.conceal.styles ? ['conceal', 'concealends'] : ['', '']) - syntax cluster texClusterBold contains=TOP,texCmdStyleItal,texCmdStyleBold,texCmdStyleItalBold - syntax cluster texClusterItal contains=TOP,texCmdStyleItal,texCmdStyleBold,texCmdStyleBoldItal - syntax cluster texClusterItalBold contains=TOP,texCmdStyleItal,texCmdStyleBold,texCmdStyleItalBold,texCmdStyleBoldItal + syntax cluster texClusterBold contains=TOP,@NoSpell,texCmdStyleItal,texCmdStyleBold,texCmdStyleItalBold + syntax cluster texClusterItal contains=TOP,@NoSpell,texCmdStyleItal,texCmdStyleBold,texCmdStyleBoldItal + syntax cluster texClusterItalBold contains=TOP,@NoSpell,texCmdStyleItal,texCmdStyleBold,texCmdStyleItalBold,texCmdStyleBoldItal let l:map = { \ 'texCmdStyleBold': 'texStyleBold', diff --git a/autoload/vimtex/syntax/p/biblatex.vim b/autoload/vimtex/syntax/p/biblatex.vim index e0830250c0..fca97e0e10 100644 --- a/autoload/vimtex/syntax/p/biblatex.vim +++ b/autoload/vimtex/syntax/p/biblatex.vim @@ -34,8 +34,8 @@ function! vimtex#syntax#p#biblatex#load() abort " {{{1 syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\[Aa]utocites\>" syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\[pPfFsStTaA]\?[Vv]olcites\?\>" syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\cite\%(field\|list\|name\)>" - call vimtex#syntax#core#new_cmd_arg('texRefArgs', 'texRefOpts,texRefArgs', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_opt('texRefOpts', 'texRefOpt,texRefArg') + call vimtex#syntax#core#new_arg('texRefArgs', {'next': 'texRefOpts,texRefArgs', 'contains': 'texComment,@NoSpell'}) + call vimtex#syntax#core#new_opt('texRefOpts', {'next': 'texRefOpt,texRefArg'}) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/cleveref.vim b/autoload/vimtex/syntax/p/cleveref.vim index 3c01483478..c9e9010226 100644 --- a/autoload/vimtex/syntax/p/cleveref.vim +++ b/autoload/vimtex/syntax/p/cleveref.vim @@ -18,9 +18,9 @@ function! vimtex#syntax#p#cleveref#load() abort " {{{1 " \label[xxx]{asd} syntax match texCmdCRef nextgroup=texCRefOpt,texRefArg skipwhite skipnl "\\label\>" - call vimtex#syntax#core#new_cmd_arg('texCRefArg', '', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texCRefRangeArg', 'texCRefArg', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_opt('texCRefOpt', 'texRefArg', '', 'oneline') + call vimtex#syntax#core#new_arg('texCRefArg', {'contains': 'texComment,@NoSpell'}) + call vimtex#syntax#core#new_arg('texCRefRangeArg', {'next': 'texCRefArg', 'contains': 'texComment,@NoSpell'}) + call vimtex#syntax#core#new_opt('texCRefOpt', {'next': 'texRefArg', 'opts': 'oneline'}) highlight def link texCRefArg texRefArg highlight def link texCRefOpt texOpt diff --git a/autoload/vimtex/syntax/p/csquotes.vim b/autoload/vimtex/syntax/p/csquotes.vim index a43064a9d3..923471a248 100644 --- a/autoload/vimtex/syntax/p/csquotes.vim +++ b/autoload/vimtex/syntax/p/csquotes.vim @@ -11,7 +11,7 @@ function! vimtex#syntax#p#csquotes#load() abort " {{{1 syntax match texCmdQuote nextgroup=texQuoteArg skipwhite skipnl "\\\%(foreign\|hyphen\)textcquote\*\?\>" syntax match texCmdQuote nextgroup=texQuoteArg skipwhite skipnl "\\\%(foreign\|hyphen\)blockcquote\>" syntax match texCmdQuote nextgroup=texQuoteArg skipwhite skipnl "\\hybridblockcquote\>" - call vimtex#syntax#core#new_cmd_arg('texQuoteArg', 'texRefOpt,texRefArg', '@texClusterMain', 'transparent') + call vimtex#syntax#core#new_arg('texQuoteArg', {'next': 'texRefOpt,texRefArg', 'opts': 'contained transparent'}) highlight def link texCmdQuote texCmd endfunction diff --git a/autoload/vimtex/syntax/p/glossaries.vim b/autoload/vimtex/syntax/p/glossaries.vim index 545645bea7..63f103bd54 100644 --- a/autoload/vimtex/syntax/p/glossaries.vim +++ b/autoload/vimtex/syntax/p/glossaries.vim @@ -11,7 +11,7 @@ function! vimtex#syntax#p#glossaries#load() abort " {{{1 let b:vimtex_syntax.glossaries = 1 syntax match texCmd nextgroup=texGlsArg skipwhite skipnl "\\gls\>" - call vimtex#syntax#core#new_cmd_arg('texGlsArg', '', '@NoSpell') + call vimtex#syntax#core#new_arg('texGlsArg', {'contains': '@NoSpell'}) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/hyperref.vim b/autoload/vimtex/syntax/p/hyperref.vim index 028c1e7f4d..d51d1788b5 100644 --- a/autoload/vimtex/syntax/p/hyperref.vim +++ b/autoload/vimtex/syntax/p/hyperref.vim @@ -11,14 +11,17 @@ function! vimtex#syntax#p#hyperref#load() abort " {{{1 syntax match texCmdHyperref '\\autoref\>' nextgroup=texRefOpt,texRefArg syntax match texCmdHyperref '\\hyperref\>' nextgroup=texRefOpt,texRefArg syntax match texCmdHyperref '\\href\>' nextgroup=texHrefArgLink skipwhite - call vimtex#syntax#core#new_cmd_arg('texHrefArgLink', 'texHrefArgText', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texHrefArgText', '', '@texClusterMain') + call vimtex#syntax#core#new_arg('texHrefArgLink', { + \ 'next': 'texHrefArgText', + \ 'contains': 'texComment,@NoSpell', + \}) + call vimtex#syntax#core#new_arg('texHrefArgText') syntax match texCmdHyperref "\\url\>" nextgroup=texUrlArg skipwhite syntax region texUrlArg matchgroup=texDelim \ contained contains=@NoSpell,texComment \ start="\z([^\ta-zA-Z]\)" end="\z1" - call vimtex#syntax#core#new_cmd_arg('texUrlArg', '', 'texComment,@NoSpell') + call vimtex#syntax#core#new_arg('texUrlArg', {'contains': 'texComment,@NoSpell'}) highlight def link texCmdHyperref texCmd diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index 189459374c..2c8a2456c4 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -29,7 +29,7 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 " Match unspecified lstlisting environment syntax match texLstEnvBgn "\\begin{lstlisting}" \ nextgroup=texLstOpt skipwhite skipnl contains=texCmdEnv - call vimtex#syntax#core#new_cmd_opt('texLstOpt', '') + call vimtex#syntax#core#new_opt('texLstOpt') syntax region texLstRegion \ start="\\begin{lstlisting}" \ end="\\end{lstlisting}" diff --git a/autoload/vimtex/syntax/p/luacode.vim b/autoload/vimtex/syntax/p/luacode.vim index 60beb713c0..c164acd615 100644 --- a/autoload/vimtex/syntax/p/luacode.vim +++ b/autoload/vimtex/syntax/p/luacode.vim @@ -10,12 +10,13 @@ function! vimtex#syntax#p#luacode#load() abort " {{{1 call vimtex#syntax#nested#include('lua') - call vimtex#syntax#core#new_region_env( - \ 'texLuaRegion', 'luacode\*\?', '@vimtex_nested_lua') + call vimtex#syntax#core#new_region_env('texLuaRegion', 'luacode\*\?', '@vimtex_nested_lua') syntax match texCmdLua "\\\%(directlua\|luadirect\)\>" nextgroup=texLuaArg skipwhite skipnl - call vimtex#syntax#core#new_cmd_arg( - \ 'texLuaArg', '', '@vimtex_nested_lua', 'keepend') + call vimtex#syntax#core#new_arg('texLuaArg', { + \ 'contains': '@vimtex_nested_lua', + \ 'opts': 'contained keepend', + \}) highlight def link texCmdLua texCmd endfunction diff --git a/autoload/vimtex/syntax/p/pythontex.vim b/autoload/vimtex/syntax/p/pythontex.vim index 828be3b4bd..5e6351c2d4 100644 --- a/autoload/vimtex/syntax/p/pythontex.vim +++ b/autoload/vimtex/syntax/p/pythontex.vim @@ -11,7 +11,7 @@ function! vimtex#syntax#p#pythontex#load() abort " {{{1 call vimtex#syntax#nested#include('python') syntax match texCmdPythontex /\\py[bsc]\?/ nextgroup=texPythontexArg skipwhite skipnl - call vimtex#syntax#core#new_cmd_arg('texPythontexArg', '', '@vimtex_nested_python', 'keepend') + call vimtex#syntax#core#new_arg('texPythontexArg', {'contains': '@vimtex_nested_python', 'opts': 'contained keepend'}) syntax region texPythontexArg matchgroup=texDelim \ start='\z([#@]\)' end='\z1' \ contained contains=@vimtex_nested_python keepend diff --git a/autoload/vimtex/syntax/p/tabularx.vim b/autoload/vimtex/syntax/p/tabularx.vim index d1a1a01d9f..e215afc6ba 100644 --- a/autoload/vimtex/syntax/p/tabularx.vim +++ b/autoload/vimtex/syntax/p/tabularx.vim @@ -19,12 +19,12 @@ function! vimtex#syntax#p#tabularx#load() abort " {{{1 syntax match texCmdTabular '\\begin{tabular}' \ nextgroup=texTabularOpt,texTabularArg skipwhite skipnl contains=texCmdEnv - call vimtex#syntax#core#new_cmd_opt('texTabularOpt', 'texTabularArg', 'texComment,@NoSpell') - call vimtex#syntax#core#new_cmd_arg('texTabularArg', '', '@texClusterTabular') + call vimtex#syntax#core#new_opt('texTabularOpt', {'next': 'texTabularArg', 'contains': 'texComment,@NoSpell'}) + call vimtex#syntax#core#new_arg('texTabularArg', {'contains': '@texClusterTabular'}) - call vimtex#syntax#core#new_cmd_arg('texTabularMulti', 'texTabularArg') - call vimtex#syntax#core#new_cmd_arg('texTabularLength', '', 'texLength,texCmd') - call vimtex#syntax#core#new_cmd_arg('texTabularPostPreArg', '', 'texLength,texCmd,texTabularMathdelim') + call vimtex#syntax#core#new_arg('texTabularMulti', {'next': 'texTabularArg'}) + call vimtex#syntax#core#new_arg('texTabularLength', {'contains': 'texLength,texCmd'}) + call vimtex#syntax#core#new_arg('texTabularPostPreArg', {'contains': 'texLength,texCmd,texTabularMathdelim'}) highlight def link texTabularCol texOpt highlight def link texTabularAtSep texMathDelim diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index c2e72b4fd4..47d94cd9c4 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -9,16 +9,16 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 let b:vimtex_syntax.tikz = 1 syntax cluster texClusterTikz contains=texTikzEnvBgn,texTikzSemicolon,texCmd,texGroup,texComment - syntax cluster texClusterTikzset contains=texTikzsetArg,texOptSep,texOptEqual,texMathRegionX,texTypeSize,texCmd,texLength,texComment + syntax cluster texClusterTikzset contains=texTikzsetArg,texMathRegionX,texTypeSize,@texClusterOpt syntax match texCmdTikzset "\\tikzset\>" skipwhite skipnl nextgroup=texTikzsetArg - call vimtex#syntax#core#new_cmd_arg('texTikzsetArg', '', '@texClusterTikzset') + call vimtex#syntax#core#new_arg('texTikzsetArg', {'contains': '@texClusterTikzset'}) syntax match texTikzEnvBgn "\\begin{tikzpicture}" \ nextgroup=texTikzOpt skipwhite skipnl contains=texCmdEnv call vimtex#syntax#core#new_region_env( \ 'texTikzRegion', 'tikzpicture', '@texClusterTikz') - call vimtex#syntax#core#new_cmd_opt('texTikzOpt', '', '@texClusterTikzset') + call vimtex#syntax#core#new_opt('texTikzOpt', {'contains': '@texClusterTikzset'}) syntax match texTikzSemicolon /;/ contained diff --git a/test/tests/test-syntax/test-nospell.vim b/test/tests/test-syntax/test-nospell.vim index 3d82022a52..5e1b6621d1 100644 --- a/test/tests/test-syntax/test-nospell.vim +++ b/test/tests/test-syntax/test-nospell.vim @@ -7,7 +7,7 @@ silent edit test-nospell.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texGroup', 7, 14)) +call vimtex#test#assert(vimtex#syntax#in('texArg', 7, 14)) call vimtex#test#assert(vimtex#syntax#in('texNoSpellArg', 8, 14)) quit! From 2d0955ef3211302068bbcc2c6920c7867f1ef589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 12 Nov 2020 00:19:00 +0100 Subject: [PATCH 57/99] wip: minor rebase --- autoload/vimtex/syntax/core.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index be36260ae6..d8ad725615 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -150,7 +150,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " Unspecified TeX groups " Note: This is necessary to keep track of all nested braces - syntax region texGroup matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contains=TOP,@NoSpell + call vimtex#syntax#core#new_arg('texGroup', {'opts': ''}) " Flag mismatching ending brace delimiter syntax match texGroupError "}" From 0c6c69dc0c4630f532792045bc2ce8f172b38e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 12 Nov 2020 00:20:29 +0100 Subject: [PATCH 58/99] wip: remove unused clusters --- autoload/vimtex/syntax/core.vim | 46 --------------------------------- 1 file changed, 46 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index d8ad725615..8adb071adc 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -17,52 +17,6 @@ function! vimtex#syntax#core#init() abort " {{{1 " {{{2 Define main syntax clusters - " Note: These clusters can be updated for specific package syntax if - " a package defines items that should be available at top level. - - syntax cluster texClusterMain contains= - \texGroup, - \texGroupError, - \@texClusterCmds, - \@texClusterOther - - syntax cluster texClusterCmds contains= - \texCmd, - \texCmdAccent, - \texCmdAuthor, - \texCmdBib, - \texCmdClass, - \texCmdDef, - \texCmdEnv, - \texCmdError, - \texCmdFootnote, - \texCmdGreek, - \texCmdInput, - \texCmdItem, - \texCmdLigature, - \texCmdNewcmd, - \texCmdNewenv, - \texCmdPackage, - \texCmdParts, - \texCmdRef, - \texCmdSize, - \texCmdSpaceCode, - \texCmdSpaceCodeChar, - \texCmdStyle, - \texCmdStyleBold, - \texCmdStyleBoldItal, - \texCmdStyleItal, - \texCmdStyleItalBold, - \texCmdTitle, - \texCmdTodo, - \texCmdVerb - - syntax cluster texClusterOther contains= - \texComment, - \texLigature, - \texSpecialChar, - \texTabularChar - syntax cluster texClusterOpt contains= \texCmd, \texComment, From 88277bc42e3f20919357dd4ae000c6f6d5997995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 13 Nov 2020 12:47:41 +0100 Subject: [PATCH 59/99] wip: more consistent matching of math envs --- autoload/vimtex/syntax/core.vim | 53 ++++++++++++---------- autoload/vimtex/syntax/p/amsmath.vim | 16 +++---- autoload/vimtex/syntax/p/breqn.vim | 8 ++-- autoload/vimtex/syntax/p/cases.vim | 2 +- autoload/vimtex/syntax/p/ieeetrantools.vim | 28 +++++------- 5 files changed, 53 insertions(+), 54 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 8adb071adc..192424459c 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -31,7 +31,7 @@ function! vimtex#syntax#core#init() abort " {{{1 \texCmdError, \texCmdFootnote, \texCmdGreek, - \texCmdMathtext, + \texCmdMathText, \texCmdRef, \texCmdSize, \texCmdStyle, @@ -350,16 +350,18 @@ function! vimtex#syntax#core#init() abort " {{{1 " }}}2 " {{{2 Region: Math - syntax match texCmdMathenv "\v\\%(begin|end)>" contained nextgroup=texMathenvArgName - call vimtex#syntax#core#new_arg('texMathenvArgName') + " Define math region group + call vimtex#syntax#core#new_arg('texMathGroup', {'contains': '@texClusterMath'}) - syntax region texMathGroup matchgroup=texDelim start="{" skip="\\\\\|\\}" end="}" contained contains=@texClusterMath + " Define math environment boundaries + syntax match texCmdMathEnv "\v\\%(begin|end)>" contained nextgroup=texMathEnvArgName + call vimtex#syntax#core#new_arg('texMathEnvArgName') " Math regions: environments - call vimtex#syntax#core#new_region_math('displaymath', 1) - call vimtex#syntax#core#new_region_math('eqnarray', 1) - call vimtex#syntax#core#new_region_math('equation', 1) - call vimtex#syntax#core#new_region_math('math', 1) + call vimtex#syntax#core#new_region_math('displaymath') + call vimtex#syntax#core#new_region_math('eqnarray') + call vimtex#syntax#core#new_region_math('equation') + call vimtex#syntax#core#new_region_math('math') " Math regions: Inline Math Zones if l:cfg.conceal.math_bounds @@ -386,7 +388,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texMathOper "[_^=]" contained " Text Inside Math regions - syntax match texCmdMathtext "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texMathtextArg + syntax match texCmdMathText "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texMathtextArg call vimtex#syntax#core#new_arg('texMathtextArg') call s:match_math_sub_super(l:cfg) @@ -477,20 +479,23 @@ function! vimtex#syntax#core#new_region_env(grp, envname, ...) abort " {{{1 endfunction " }}}1 -function! vimtex#syntax#core#new_region_math(mathzone, starred) abort " {{{1 - execute 'syntax match texMathError /\\end\s*{\s*' . a:mathzone . '\*\?\s*}/' - - execute 'syntax region texMathRegionEnv' - \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\s*}''' - \ . ' end=''\\end\s*{\s*' . a:mathzone . '\s*}''' - \ . ' keepend contains=texCmdMathenv,texMathenvArgName,@texClusterMath' +function! vimtex#syntax#core#new_region_math(mathzone, ...) abort " {{{1 + let l:cfg = extend({ + \ 'starred': 1, + \ 'next': '', + \}, a:0 > 0 ? a:1 : {}) - if !a:starred | return | endif + let l:envname = a:mathzone . (l:cfg.starred ? '\*\?' : '') - execute 'syntax region texMathRegionEnvStarred' - \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\*\s*}''' - \ . ' end=''\\end\s*{\s*' . a:mathzone . '\*\s*}''' - \ . ' keepend contains=texCmdMathenv,texMathenvArgName,@texClusterMath' + execute 'syntax match texMathEnvBgnEnd "\\\%(begin\|end\)\>{' . l:envname . '}"' + \ 'contained contains=texCmdMathEnv' + \ (empty(l:cfg.next) ? '' : 'nextgroup=' . l:cfg.next . ' skipwhite skipnl') + execute 'syntax match texMathError "\\end{' . l:envname . '}"' + execute 'syntax region texMathRegionEnv' + \ 'start="\\begin{\z(' . l:envname . '\)}"' + \ 'end="\\end{\z1}"' + \ 'contains=texMathEnvBgnEnd,@texClusterMath' + \ 'keepend' endfunction " }}}1 @@ -514,7 +519,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texMathDelim Type highlight def link texMathOper Operator highlight def link texMathRegion Special - highlight def link texMathenvArgName Delimiter + highlight def link texMathEnvArgName Delimiter highlight def link texOpt Identifier highlight def link texOptSep NormalNC highlight def link texParm Special @@ -544,8 +549,8 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdItem texCmdEnv highlight def link texCmdLigature texSpecialChar highlight def link texCmdMath texCmd - highlight def link texCmdMathenv texCmdEnv - highlight def link texCmdMathtext texCmd + highlight def link texCmdMathEnv texCmdEnv + highlight def link texCmdMathText texCmd highlight def link texCmdNewcmd texCmd highlight def link texCmdNewenv texCmd highlight def link texCmdNoSpell texCmd diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index 62d266eeb6..24855f85ed 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -10,14 +10,14 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 if has_key(b:vimtex_syntax, 'amsmath') | return | endif let b:vimtex_syntax.amsmath = 1 - call vimtex#syntax#core#new_region_math('align', 1) - call vimtex#syntax#core#new_region_math('alignat', 1) - call vimtex#syntax#core#new_region_math('flalign', 1) - call vimtex#syntax#core#new_region_math('gather', 1) - call vimtex#syntax#core#new_region_math('multline', 1) - call vimtex#syntax#core#new_region_math('xalignat', 1) - call vimtex#syntax#core#new_region_math('xxalignat', 0) - call vimtex#syntax#core#new_region_math('mathpar', 1) + call vimtex#syntax#core#new_region_math('align') + call vimtex#syntax#core#new_region_math('alignat') + call vimtex#syntax#core#new_region_math('flalign') + call vimtex#syntax#core#new_region_math('gather') + call vimtex#syntax#core#new_region_math('multline') + call vimtex#syntax#core#new_region_math('xalignat') + call vimtex#syntax#core#new_region_math('xxalignat', {'starred': 0}) + call vimtex#syntax#core#new_region_math('mathpar') " Amsmath [lr][vV]ert if &encoding ==# 'utf-8' && g:vimtex_syntax_config.conceal.math_delimiters diff --git a/autoload/vimtex/syntax/p/breqn.vim b/autoload/vimtex/syntax/p/breqn.vim index 9de083d736..11449353e2 100644 --- a/autoload/vimtex/syntax/p/breqn.vim +++ b/autoload/vimtex/syntax/p/breqn.vim @@ -10,10 +10,10 @@ function! vimtex#syntax#p#breqn#load() abort " {{{1 if has_key(b:vimtex_syntax, 'breqn') | return | endif let b:vimtex_syntax.breqn = 1 - call vimtex#syntax#core#new_region_math('dmath', 1) - call vimtex#syntax#core#new_region_math('dseries', 1) - call vimtex#syntax#core#new_region_math('dgroup', 1) - call vimtex#syntax#core#new_region_math('darray', 1) + call vimtex#syntax#core#new_region_math('dmath') + call vimtex#syntax#core#new_region_math('dseries') + call vimtex#syntax#core#new_region_math('dgroup') + call vimtex#syntax#core#new_region_math('darray') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/cases.vim b/autoload/vimtex/syntax/p/cases.vim index c77bce6928..38c63c557e 100644 --- a/autoload/vimtex/syntax/p/cases.vim +++ b/autoload/vimtex/syntax/p/cases.vim @@ -10,7 +10,7 @@ function! vimtex#syntax#p#cases#load() abort " {{{1 if has_key(b:vimtex_syntax, 'cases') | return | endif let b:vimtex_syntax.cases = 1 - call vimtex#syntax#core#new_region_math('\(sub\)\?numcases', 0) + call vimtex#syntax#core#new_region_math('\(sub\)\?numcases', {'starred': 0}) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/ieeetrantools.vim b/autoload/vimtex/syntax/p/ieeetrantools.vim index 6e9794db3d..ef989cdcf3 100644 --- a/autoload/vimtex/syntax/p/ieeetrantools.vim +++ b/autoload/vimtex/syntax/p/ieeetrantools.vim @@ -10,23 +10,17 @@ function! vimtex#syntax#p#ieeetrantools#load() abort " {{{1 if has_key(b:vimtex_syntax, 'ieeetrantools') | return | endif let b:vimtex_syntax.ieeetrantools = 1 - call s:new_region_math('IEEEeqnarray') - call s:new_region_math('IEEEeqnarrayboxm') -endfunction - -" }}}1 - -function! s:new_region_math(mathzone) abort " {{{1 - " This needs to be slightly different than vimtex#syntax#core#new_region_math - " to handle options for the environment. - - execute 'syntax match texMathError ''\\end\s*{\s*' . a:mathzone . '\*\?\s*}''' - - execute 'syntax region texMathRegionEnv' - \ . ' start=''\\begin\s*{\s*' . a:mathzone . '\z(\*\?\)\s*}' - \ . '\(\[.\{-}\]\)\?{\w*}''' - \ . ' end=''\\end\s*{\s*' . a:mathzone . '\z1\s*}''' - \ . ' keepend contains=texCmdMathenv,texMathenvArgName,@texClusterMath' + call vimtex#syntax#core#new_arg('texMathEnvIEEEArg') + call vimtex#syntax#core#new_opt('texMathEnvIEEEOpt', + \ {'next': 'texMathEnvIEEEArg'}) + for l:env in ['IEEEeqnarray', 'IEEEeqnarrayboxm'] + call vimtex#syntax#core#new_region_math(l:env, { + \ 'next': 'texMathEnvIEEEOpt,texMathEnvIEEEArg', + \}) + endfor + + highlight def link texMathEnvIEEEArg texArg + highlight def link texMathEnvIEEEOpt texOpt endfunction " }}}1 From 4868be5f057c08efd4abaa2bc66c22f25fa77bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 13 Nov 2020 14:55:14 +0100 Subject: [PATCH 60/99] wip: better cmds in math regions --- autoload/vimtex/syntax/core.vim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 192424459c..009cce65b9 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -26,7 +26,6 @@ function! vimtex#syntax#core#init() abort " {{{1 \@NoSpell syntax cluster texClusterMath contains= - \texCmd, \texCmdEnv, \texCmdError, \texCmdFootnote, @@ -39,6 +38,7 @@ function! vimtex#syntax#core#init() abort " {{{1 \texCmdVerb, \texComment, \texGroupError, + \texMathCmd, \texMathDelim, \texMathDelimMod, \texMathGroup, @@ -357,6 +357,10 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdMathEnv "\v\\%(begin|end)>" contained nextgroup=texMathEnvArgName call vimtex#syntax#core#new_arg('texMathEnvArgName') + " Define separate "generic" commands inside math regions + syntax match texMathCmd nextgroup=texMathArg skipwhite skipnl "\\\a\+" + call vimtex#syntax#core#new_arg('texMathArg', {'contains': '@texClusterMath'}) + " Math regions: environments call vimtex#syntax#core#new_region_math('displaymath') call vimtex#syntax#core#new_region_math('eqnarray') @@ -581,6 +585,8 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texFilesArg texFileArg highlight def link texFilesOpt texOpt highlight def link texGroupError texError + highlight def link texMathArg texMathRegion + highlight def link texMathCmd texCmd highlight def link texMathDelimRegion texDelim highlight def link texMathDelimMod texMathDelim highlight def link texMathError texError From 031f63856a295fcec9cbe1bf29da2ee41de572d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 13 Nov 2020 14:57:51 +0100 Subject: [PATCH 61/99] wip: fixed silly bug --- autoload/vimtex/syntax/core.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 009cce65b9..a05c5cdabe 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -358,7 +358,7 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_arg('texMathEnvArgName') " Define separate "generic" commands inside math regions - syntax match texMathCmd nextgroup=texMathArg skipwhite skipnl "\\\a\+" + syntax match texMathCmd contained nextgroup=texMathArg skipwhite skipnl "\\\a\+" call vimtex#syntax#core#new_arg('texMathArg', {'contains': '@texClusterMath'}) " Math regions: environments From 735e590425b96680587d782b447857286fe064d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 13 Nov 2020 15:11:24 +0100 Subject: [PATCH 62/99] wip: generic commands must be defined early --- autoload/vimtex/syntax/core.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index a05c5cdabe..0e70240a69 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -125,6 +125,10 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_arg('texArg', {'next': 'texArg', 'opts': 'contained transparent'}) syntax match texCmdError "\\\a*@\a*" + " Define separate "generic" commands inside math regions + syntax match texMathCmd contained nextgroup=texMathArg skipwhite skipnl "\\\a\+" + call vimtex#syntax#core#new_arg('texMathArg', {'contains': '@texClusterMath'}) + " {{{2 Commands: core set " Accents and ligatures @@ -357,10 +361,6 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdMathEnv "\v\\%(begin|end)>" contained nextgroup=texMathEnvArgName call vimtex#syntax#core#new_arg('texMathEnvArgName') - " Define separate "generic" commands inside math regions - syntax match texMathCmd contained nextgroup=texMathArg skipwhite skipnl "\\\a\+" - call vimtex#syntax#core#new_arg('texMathArg', {'contains': '@texClusterMath'}) - " Math regions: environments call vimtex#syntax#core#new_region_math('displaymath') call vimtex#syntax#core#new_region_math('eqnarray') From 1636f50ce64127844703c080961ed6e23db8a4e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 13 Nov 2020 15:33:28 +0100 Subject: [PATCH 63/99] wip: improve new_region_env --- autoload/vimtex/syntax/core.vim | 15 ++++++++------- autoload/vimtex/syntax/p/asymptote.vim | 9 +++++---- autoload/vimtex/syntax/p/dot2texi.vim | 4 ++-- autoload/vimtex/syntax/p/gnuplottex.vim | 4 ++-- autoload/vimtex/syntax/p/luacode.vim | 3 ++- autoload/vimtex/syntax/p/markdown.vim | 4 ++-- autoload/vimtex/syntax/p/pgfplots.vim | 8 ++++---- autoload/vimtex/syntax/p/pythontex.vim | 6 ++++-- autoload/vimtex/syntax/p/tikz.vim | 4 ++-- 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 0e70240a69..a355895c3a 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -467,19 +467,20 @@ endfunction " }}}1 function! vimtex#syntax#core#new_region_env(grp, envname, ...) abort " {{{1 - let l:contains = 'texCmdEnv' - let l:options = 'keepend' + let l:cfg = extend({ + \ 'contains': '', + \}, a:0 > 0 ? a:1 : {}) - if a:0 > 0 - let l:contains .= ',' . a:1 - let l:options .= ' transparent' + let l:contains = 'contains=texCmdEnv' + if !empty(l:cfg.contains) + let l:contains .= ',' . l:cfg.contains endif execute 'syntax region' a:grp \ 'start="\\begin{' . a:envname .'}"' \ 'end="\\end{' . a:envname .'}"' - \ (empty(l:contains) ? '' : 'contains=' . l:contains) - \ l:options + \ l:contains + \ 'keepend transparent' endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/asymptote.vim b/autoload/vimtex/syntax/p/asymptote.vim index e5740d640a..4775fa6c05 100644 --- a/autoload/vimtex/syntax/p/asymptote.vim +++ b/autoload/vimtex/syntax/p/asymptote.vim @@ -9,13 +9,14 @@ function! vimtex#syntax#p#asymptote#load() abort " {{{1 let b:vimtex_syntax.asymptote = 1 if !empty(vimtex#syntax#nested#include('asy')) - call vimtex#syntax#core#new_region_env('texAsymptoteRegion', 'asy', '@vimtex_nested_asy') - call vimtex#syntax#core#new_region_env('texAsymptoteRegion', 'asydef', '@vimtex_nested_asy') + let l:opts = {'contains': '@vimtex_nested_asy'} else - call vimtex#syntax#core#new_region_env('texAsymptoteRegion', 'asy') - call vimtex#syntax#core#new_region_env('texAsymptoteRegion', 'asydef') + let l:opts = {} highlight def link texAsymptoteRegion texRegion endif + + call vimtex#syntax#core#new_region_env('texAsymptoteRegion', 'asy', l:opts) + call vimtex#syntax#core#new_region_env('texAsymptoteRegion', 'asydef', l:opts) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/dot2texi.vim b/autoload/vimtex/syntax/p/dot2texi.vim index 28461102c6..58c517744e 100644 --- a/autoload/vimtex/syntax/p/dot2texi.vim +++ b/autoload/vimtex/syntax/p/dot2texi.vim @@ -9,8 +9,8 @@ function! vimtex#syntax#p#dot2texi#load() abort " {{{1 let b:vimtex_syntax.dot2texi = 1 call vimtex#syntax#nested#include('dot') - call vimtex#syntax#core#new_region_env( - \ 'texDotRegion', 'dot2tex', '@vimtex_nested_dot') + call vimtex#syntax#core#new_region_env('texDotRegion', 'dot2tex', + \ {'contains': '@vimtex_nested_dot'}) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/gnuplottex.vim b/autoload/vimtex/syntax/p/gnuplottex.vim index 48fc13a4d1..25807059c1 100644 --- a/autoload/vimtex/syntax/p/gnuplottex.vim +++ b/autoload/vimtex/syntax/p/gnuplottex.vim @@ -9,8 +9,8 @@ function! vimtex#syntax#p#gnuplottex#load() abort " {{{1 let b:vimtex_syntax.gnuplottex = 1 call vimtex#syntax#nested#include('gnuplot') - call vimtex#syntax#core#new_region_env( - \ 'texGnuplotRegion', 'gnuplot', '@vimtex_nested_gnuplot') + call vimtex#syntax#core#new_region_env('texGnuplotRegion', 'gnuplot', + \ {'contains': '@vimtex_nested_gnuplot'}) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/luacode.vim b/autoload/vimtex/syntax/p/luacode.vim index c164acd615..d9591457d5 100644 --- a/autoload/vimtex/syntax/p/luacode.vim +++ b/autoload/vimtex/syntax/p/luacode.vim @@ -10,7 +10,8 @@ function! vimtex#syntax#p#luacode#load() abort " {{{1 call vimtex#syntax#nested#include('lua') - call vimtex#syntax#core#new_region_env('texLuaRegion', 'luacode\*\?', '@vimtex_nested_lua') + call vimtex#syntax#core#new_region_env('texLuaRegion', 'luacode\*\?', + \ {'contains': '@vimtex_nested_lua'}) syntax match texCmdLua "\\\%(directlua\|luadirect\)\>" nextgroup=texLuaArg skipwhite skipnl call vimtex#syntax#core#new_arg('texLuaArg', { diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index 01a059b66e..f5babe9a01 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -9,8 +9,8 @@ function! vimtex#syntax#p#markdown#load() abort " {{{1 let b:vimtex_syntax.markdown = 1 call vimtex#syntax#nested#include('markdown') - call vimtex#syntax#core#new_region_env( - \ 'texMarkdownRegion', 'markdown', 'texCmd,@vimtex_nested_markdown') + call vimtex#syntax#core#new_region_env('texMarkdownRegion', 'markdown', + \ {'contains': 'texCmd,@vimtex_nested_markdown'}) syntax match texCmdInput "\\markdownInput\>" nextgroup=texFileArg skipwhite skipnl endfunction diff --git a/autoload/vimtex/syntax/p/pgfplots.vim b/autoload/vimtex/syntax/p/pgfplots.vim index f5cf904ee4..f1e355cb2d 100644 --- a/autoload/vimtex/syntax/p/pgfplots.vim +++ b/autoload/vimtex/syntax/p/pgfplots.vim @@ -19,10 +19,10 @@ function! vimtex#syntax#p#pgfplots#load() abort " {{{1 syntax match texTikzEnvBgn contains=texCmdEnv nextgroup=texTikzOpt skipwhite skipnl "\\begin{\%(log\)*axis}" syntax match texTikzEnvBgn contains=texCmdEnv nextgroup=texTikzOpt skipwhite skipnl "\\begin{groupplot}" - call vimtex#syntax#core#new_region_env('texTikzRegion', 'axis', '@texClusterTikz') - call vimtex#syntax#core#new_region_env('texTikzRegion', 'logaxis', '@texClusterTikz') - call vimtex#syntax#core#new_region_env('texTikzRegion', 'loglogaxis', '@texClusterTikz') - call vimtex#syntax#core#new_region_env('texTikzRegion', 'groupplot', '@texClusterTikz') + call vimtex#syntax#core#new_region_env('texTikzRegion', 'axis', {'contains': '@texClusterTikz'}) + call vimtex#syntax#core#new_region_env('texTikzRegion', 'logaxis', {'contains': '@texClusterTikz'}) + call vimtex#syntax#core#new_region_env('texTikzRegion', 'loglogaxis', {'contains': '@texClusterTikz'}) + call vimtex#syntax#core#new_region_env('texTikzRegion', 'groupplot', {'contains': '@texClusterTikz'}) highlight def link texCmdAxis texCmd endfunction diff --git a/autoload/vimtex/syntax/p/pythontex.vim b/autoload/vimtex/syntax/p/pythontex.vim index 5e6351c2d4..b41a4cbce2 100644 --- a/autoload/vimtex/syntax/p/pythontex.vim +++ b/autoload/vimtex/syntax/p/pythontex.vim @@ -16,8 +16,10 @@ function! vimtex#syntax#p#pythontex#load() abort " {{{1 \ start='\z([#@]\)' end='\z1' \ contained contains=@vimtex_nested_python keepend - call vimtex#syntax#core#new_region_env('texPythontexRegion', 'pyblock', '@vimtex_nested_python') - call vimtex#syntax#core#new_region_env('texPythontexRegion', 'pycode', '@vimtex_nested_python') + call vimtex#syntax#core#new_region_env('texPythontexRegion', 'pyblock', + \ {'contains': '@vimtex_nested_python'}) + call vimtex#syntax#core#new_region_env('texPythontexRegion', 'pycode', + \ {'contains': '@vimtex_nested_python'}) highlight def link texCmdPythontex texCmd endfunction diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index 47d94cd9c4..7cb4c31b44 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -16,8 +16,8 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 syntax match texTikzEnvBgn "\\begin{tikzpicture}" \ nextgroup=texTikzOpt skipwhite skipnl contains=texCmdEnv - call vimtex#syntax#core#new_region_env( - \ 'texTikzRegion', 'tikzpicture', '@texClusterTikz') + call vimtex#syntax#core#new_region_env('texTikzRegion', 'tikzpicture', + \ {'contains': '@texClusterTikz'}) call vimtex#syntax#core#new_opt('texTikzOpt', {'contains': '@texClusterTikzset'}) syntax match texTikzSemicolon /;/ contained From cfa95392f6ce3b0c6f7480b8b9b5349777e1ab90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 13 Nov 2020 15:38:22 +0100 Subject: [PATCH 64/99] wip: remove transparency for verb like envs --- autoload/vimtex/syntax/core.vim | 14 ++++++++++++-- autoload/vimtex/syntax/p/asymptote.vim | 2 +- autoload/vimtex/syntax/p/moreverb.vim | 6 +++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index a355895c3a..855d80aa7d 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -322,7 +322,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " {{{2 Region: Verbatim " Verbatim environment - call vimtex#syntax#core#new_region_env('texVerbRegion', '[vV]erbatim') + call vimtex#syntax#core#new_region_env('texVerbRegion', '[vV]erbatim', {'transparent': 0}) " Verbatim inline syntax match texCmdVerb "\\verb\>\*\?" nextgroup=texVerbRegionInline @@ -469,6 +469,8 @@ endfunction function! vimtex#syntax#core#new_region_env(grp, envname, ...) abort " {{{1 let l:cfg = extend({ \ 'contains': '', + \ 'opts': '', + \ 'transparent': 1, \}, a:0 > 0 ? a:1 : {}) let l:contains = 'contains=texCmdEnv' @@ -476,11 +478,19 @@ function! vimtex#syntax#core#new_region_env(grp, envname, ...) abort " {{{1 let l:contains .= ',' . l:cfg.contains endif + let l:options = 'keepend' + if l:cfg.transparent + let l:options .= ' transparent' + endif + if !empty(l:cfg.opts) + let l:options .= ' ' . l:cfg.opts + endif + execute 'syntax region' a:grp \ 'start="\\begin{' . a:envname .'}"' \ 'end="\\end{' . a:envname .'}"' \ l:contains - \ 'keepend transparent' + \ l:options endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/asymptote.vim b/autoload/vimtex/syntax/p/asymptote.vim index 4775fa6c05..d1d6a6474c 100644 --- a/autoload/vimtex/syntax/p/asymptote.vim +++ b/autoload/vimtex/syntax/p/asymptote.vim @@ -11,7 +11,7 @@ function! vimtex#syntax#p#asymptote#load() abort " {{{1 if !empty(vimtex#syntax#nested#include('asy')) let l:opts = {'contains': '@vimtex_nested_asy'} else - let l:opts = {} + let l:opts = {'transparent': 0} highlight def link texAsymptoteRegion texRegion endif diff --git a/autoload/vimtex/syntax/p/moreverb.vim b/autoload/vimtex/syntax/p/moreverb.vim index 4b56c208d0..f19b117dc4 100644 --- a/autoload/vimtex/syntax/p/moreverb.vim +++ b/autoload/vimtex/syntax/p/moreverb.vim @@ -8,9 +8,9 @@ function! vimtex#syntax#p#moreverb#load() abort " {{{1 if has_key(b:vimtex_syntax, 'moreverb') | return | endif let b:vimtex_syntax.moreverb = 1 - call vimtex#syntax#core#new_region_env('texVerbRegion', 'verbatimtab') - call vimtex#syntax#core#new_region_env('texVerbRegion', 'verbatimwrite') - call vimtex#syntax#core#new_region_env('texVerbRegion', 'boxedverbatim') + call vimtex#syntax#core#new_region_env('texVerbRegion', 'verbatimtab', {'transparent': 0}) + call vimtex#syntax#core#new_region_env('texVerbRegion', 'verbatimwrite', {'transparent': 0}) + call vimtex#syntax#core#new_region_env('texVerbRegion', 'boxedverbatim', {'transparent': 0}) endfunction " }}}1 From 3397a76da1bd535040707562c005175d0bedc07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 13 Nov 2020 21:25:22 +0100 Subject: [PATCH 65/99] wip: consistent minted and listings support --- autoload/vimtex/syntax/core.vim | 18 ++- autoload/vimtex/syntax/p/listings.vim | 33 ++--- autoload/vimtex/syntax/p/minted.vim | 198 +++++++++++-------------- test/tests/test-syntax/test-minted.tex | 2 +- 4 files changed, 115 insertions(+), 136 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 855d80aa7d..c443b3d4b9 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -326,11 +326,12 @@ function! vimtex#syntax#core#init() abort " {{{1 " Verbatim inline syntax match texCmdVerb "\\verb\>\*\?" nextgroup=texVerbRegionInline - if l:cfg.is_style_document - syntax region texVerbRegionInline matchgroup=texDelim start="\z([^\ta-zA-Z@]\)" end="\z1" contained - else - syntax region texVerbRegionInline matchgroup=texDelim start="\z([^\ta-zA-Z]\)" end="\z1" contained - endif + call vimtex#syntax#core#new_arg('texVerbRegionInline', { + \ 'contains': '', + \ 'matcher': (l:cfg.is_style_document + \ ? 'start="\z([^\ta-zA-Z@]\)" end="\z1"' + \ : 'start="\z([^\ta-zA-Z]\)" end="\z1"'), + \}) " }}}2 " {{{2 Region: Expl3 @@ -435,14 +436,15 @@ endfunction function! vimtex#syntax#core#new_arg(grp, ...) abort " {{{1 let l:cfg = extend({ - \ 'opts': 'contained', - \ 'next': '', \ 'contains': 'TOP,@NoSpell', + \ 'matcher': 'start="{" skip="\\\\\|\\}" end="}"', + \ 'next': '', + \ 'opts': 'contained', \}, a:0 > 0 ? a:1 : {}) execute 'syntax region' a:grp \ 'matchgroup=texDelim' - \ 'start="{" skip="\\\\\|\\}" end="}"' + \ l:cfg.matcher \ l:cfg.opts \ (empty(l:cfg.contains) ? '' : 'contains=' . l:cfg.contains) \ (empty(l:cfg.next) ? '' : 'nextgroup=' . l:cfg.next . ' skipwhite skipnl') diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index 2c8a2456c4..6ae3f4e01f 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -20,42 +20,39 @@ function! vimtex#syntax#p#listings#load() abort " {{{1 " Match \lstset syntax match texCmdLstset "\\lstset\>" - \ skipwhite skipempty nextgroup=texLstsetArg,texLstsetGroup - syntax region texLstsetGroup matchgroup=texDelim - \ start="{" skip="\\\\\|\\}" end="}" - \ contained - \ contains=texComment,texLength,texOptSep,texOptEqual + \ nextgroup=texLstsetArg,texLstsetGroup skipwhite skipnl + call vimtex#syntax#core#new_arg('texLstsetGroup', { + \ 'contains': 'texComment,texLength,texOptSep,texOptEqual' + \}) " Match unspecified lstlisting environment syntax match texLstEnvBgn "\\begin{lstlisting}" \ nextgroup=texLstOpt skipwhite skipnl contains=texCmdEnv call vimtex#syntax#core#new_opt('texLstOpt') - syntax region texLstRegion - \ start="\\begin{lstlisting}" - \ end="\\end{lstlisting}" - \ keepend - \ contains=texLstEnvBgn,texCmdEnv + call vimtex#syntax#core#new_region_env('texLstRegion', 'lstlisting', { + \ 'contains': 'texLstEnvBgn', + \ 'transparent': 0, + \}) " Add nested syntax support for desired languages for l:nested in b:vimtex_syntax.listings let l:cluster = vimtex#syntax#nested#include(l:nested) if empty(l:cluster) | continue | endif - let l:groupname = 'texLstRegion' . toupper(l:nested[0]) . l:nested[1:] + let l:grp = 'texLstRegion' . toupper(l:nested[0]) . l:nested[1:] execute 'syntax match texLstsetArg' \ '"\c{\_[^}]*language=' . l:nested . '\%(\s*,\|}\)"' - \ 'skipwhite skipempty nextgroup=' . l:groupname + \ 'nextgroup=' . l:grp 'skipwhite skipnl' \ 'transparent' \ 'contains=texLstsetGroup' - execute 'syntax region' l:groupname - \ 'start="\\begin{lstlisting}"' - \ 'end="\\end{lstlisting}"' - \ 'keepend contained' - \ 'contains=texLstEnvBgn,texCmdEnv,@' . l:cluster + call vimtex#syntax#core#new_region_env(l:grp, 'lstlisting', { + \ 'contains': 'texLstEnvBgn,@' . l:cluster, + \ 'opts': 'contained', + \}) - execute 'syntax region' l:groupname + execute 'syntax region' l:grp \ 'start="\c\\begin{lstlisting}\s*' \ . '\[\_[^\]]\{-}language=' . l:nested . '\%(\s*,\_[^\]]\{-}\)\?\]"' \ 'end="\\end{lstlisting}"' diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index c35d2123d5..1fba3505f6 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -14,143 +14,123 @@ function! vimtex#syntax#p#minted#load() abort " {{{1 " Match \newminted type macros syntax match texCmdNewmint '\\newmint\%(ed\|inline\)\?\>' \ skipwhite skipnl nextgroup=texNewmintOpt,texNewmintArgX - syntax region texNewmintOpt contained matchgroup=texDelim - \ start="\[" end="\]" - \ skipwhite skipnl nextgroup=texNewmintArgY - syntax region texNewmintArgX contained matchgroup=texDelim - \ start="{" end="}" - \ skipwhite skipnl nextgroup=texNewmintArgOpts - syntax region texNewmintArgY contained matchgroup=texDelim - \ start="{" end="}" - \ skipwhite skipnl nextgroup=texNewmintArgOpts - syntax region texNewmintArgOpts contained matchgroup=texDelim - \ start="{" end="}" + call vimtex#syntax#core#new_opt('texNewmintOpt', {'next': 'texNewmintArgY'}) + call vimtex#syntax#core#new_arg('texNewmintArgX', {'contains': '', 'next': 'texNewmintArgOpts'}) + call vimtex#syntax#core#new_arg('texNewmintArgY', {'contains': '', 'next': 'texNewmintArgOpts'}) + call vimtex#syntax#core#new_arg('texNewmintArgOpts', {'contains': ''}) " Match minted environment boundaries syntax match texMintedEnvBgn contained '\\begin{minted}' + \ nextgroup=texMintedEnvOpt,texMintedEnvArg skipwhite \ contains=texCmdEnv - \ skipwhite skipnl nextgroup=texMintedEnvOpt,texMintedEnvArg - syntax region texMintedEnvOpt contained matchgroup=texDelim - \ start="\[" end="\]" - \ skipwhite skipnl nextgroup=texMintedEnvArg - syntax region texMintedEnvArg contained matchgroup=texDelim - \ start="{" end="}" - - " Match custom starred minted environments and their options - syntax match texMintedEnvBgn "\\begin{\w\+\*}" - \ contained + call vimtex#syntax#core#new_opt('texMintedEnvOpt', {'next': 'texMintedEnvArg'}) + call vimtex#syntax#core#new_arg('texMintedEnvArg', {'contains': ''}) + + " Match starred custom minted environments and the option group + syntax match texMintedEnvBgn contained "\\begin{\w\+\*}" + \ nextgroup=texMintedEnvArgOpt skipwhite \ contains=texCmdEnv - \ nextgroup=texMintedEnvOptStarred - syntax region texMintedEnvOptStarred contained matchgroup=texDelim - \ start='{' end='}' - - " Match "unknown" environments - syntax region texMintedRegion - \ start="\\begin{minted}\%(\_s*\[\_[^\]]\{-}\]\)\?\_s*{\w\+}" - \ end="\\end{minted}" - \ keepend - \ contains=texCmdEnv,texMintedEnvBgn - - " Match "unknown" commands - syntax region texMintedArg contained matchgroup=texDelim - \ start='{' end='}' - \ skipwhite skipnl nextgroup=texMintedRegionArg - syntax region texMintedRegionArg contained matchgroup=texDelim - \ start='\z([|+/]\)' end='\z1' - syntax region texMintedRegionArg contained matchgroup=texDelim - \ start='{' end='}' + call vimtex#syntax#core#new_arg('texMintedEnvArgOpt', {'contains': ''}) + + " Match generic minted environment regions + call vimtex#syntax#core#new_region_env('texMintedRegion', 'minted', { + \ 'contains': 'texCmdEnv,texMintedEnvBgn', + \ 'transparent': 0, + \}) + + " Match generic minted command regions + call vimtex#syntax#core#new_arg('texMintedArg', {'contains': '', 'next': 'texMintedRegionInline'}) + call vimtex#syntax#core#new_arg('texMintedRegionInline', {'contains': ''}) + call vimtex#syntax#core#new_arg('texMintedRegionInline', { + \ 'contains': '', + \ 'matcher': 'start="\z([|+/]\)" end="\z1"', + \}) " Next add nested syntax support for desired languages for [l:nested, l:config] in items(b:vimtex.syntax.minted) let l:cluster = vimtex#syntax#nested#include(l:nested) let l:name = toupper(l:nested[0]) . l:nested[1:] - let l:group_main = 'texMintedRegion' . l:name - let l:group_arg = 'texMintedArg' . l:name - let l:group_arg_zone = 'texMintedRegion' . l:name . 'Inline' - - if empty(l:cluster) - let l:transparent = '' - let l:contains_env = '' - let l:contains_macro = '' - execute 'highlight link' l:group_main 'texMintedRegion' - execute 'highlight link' l:group_arg_zone 'texMintedRegion' + let l:grp_env = 'texMintedRegion' . l:name + let l:grp_inline = 'texMintedRegionInline' . l:name + let l:grp_inline_matcher = 'texMintedArg' . l:name + + let l:options = 'keepend' + let l:contains = 'contains=texCmdEnv,texMintedEnvBgn' + let l:contains_inline = '' + + if !empty(l:cluster) + let l:options .= ' transparent' + let l:contains .= ',@' . l:cluster + let l:contains_inline = '@' . l:cluster else - let l:transparent = 'transparent' - let l:contains_env = ',@' . l:cluster - let l:contains_macro = 'contains=@' . l:cluster + execute 'highlight def link' l:grp_env 'texMintedRegion' + execute 'highlight def link' l:grp_inline 'texMintedRegionInline' endif - " Match minted environment - execute 'syntax region' l:group_main + " Match normal minted environments + execute 'syntax region' l:grp_env \ 'start="\\begin{minted}\%(\_s*\[\_[^\]]\{-}\]\)\?\_s*{' . l:nested . '}"' \ 'end="\\end{minted}"' - \ 'keepend' - \ l:transparent - \ 'contains=texCmdEnv,texMintedEnvBgn' . l:contains_env + \ l:options + \ l:contains - " Match custom environment names + " Match custom minted environments for l:env in get(l:config, 'environments', []) - execute 'syntax region' l:group_main + execute 'syntax region' l:grp_env \ 'start="\\begin{\z(' . l:env . '\*\?\)}"' \ 'end="\\end{\z1}"' - \ 'keepend' - \ l:transparent - \ 'contains=texCmdEnv,texMintedEnvBgn' . l:contains_env + \ l:options + \ l:contains endfor - " Match minted macros - " - \mint[]{lang}|...| - " - \mint[]{lang}{...} - " - \mintinline[]{lang}|...| - " - \mintinline[]{lang}{...} - execute 'syntax match' l:group_arg '''{' . l:nested . '}''' + " Match normal inline minted command regions + " Note: These are the language specific arguments for the commands + " \mint and \mintinline + execute 'syntax match' l:grp_inline_matcher '"{' . l:nested . '}"' \ 'contained' \ 'contains=texMintedArg' - \ 'nextgroup=' . l:group_arg_zone - execute 'syntax region' l:group_arg_zone - \ 'matchgroup=texDelim' - \ 'start=''\z([|+/]\)''' - \ 'end=''\z1''' - \ 'contained' - \ l:contains_macro - execute 'syntax region' l:group_arg_zone - \ 'matchgroup=texDelim' - \ 'start=''{''' - \ 'end=''}''' - \ 'contained' - \ l:contains_macro - - " Match minted custom macros + \ 'nextgroup=' . l:grp_inline 'skipwhite skipnl' + call vimtex#syntax#core#new_arg(l:grp_inline, { + \ 'contains': l:contains_inline, + \ 'matcher': 'start="\z([|+/]\)" end="\z1"', + \}) + call vimtex#syntax#core#new_arg(l:grp_inline, { + \ 'contains': l:contains_inline + \}) + + " Match custom inline minted commands for l:cmd in sort(get(l:config, 'commands', [])) - execute printf('syntax match texCmd ''\\%s'' nextgroup=%s', - \ l:cmd, l:group_arg_zone) + execute 'syntax match texCmdMinted' + \ '"\\' . l:cmd . '\>"' + \ 'nextgroup=' . l:grp_inline 'skipwhite skipnl' endfor endfor - " Main matcher for the minted statements/commands - " - Note: This comes last to allow the nextgroup pattern - syntax match texCmdMinted '\\mint\(inline\)\?' - \ skipwhite skipnl nextgroup=texMintedOpt,texMintedArg.* - syntax region texMintedOpt contained matchgroup=texDelim - \ start='\[' end='\]' - \ skipwhite skipnl nextgroup=texMintedArg.* - - highlight def link texCmdMinted texCmd - highlight def link texMintedOpt texOpt - highlight def link texMintedArg texSymbol - - highlight def link texMintedRegion texRegion - highlight def link texMintedRegionArg texRegion - highlight def link texMintedEnvOpt texOpt - highlight def link texMintedEnvOptStarred texOpt - highlight def link texMintedEnvArg texSymbol - - highlight def link texCmdNewmint texCmd - highlight def link texNewmintOpt texSymbol - highlight def link texNewmintArgX texSymbol - highlight def link texNewmintArgY texComment - highlight def link texNewmintArgOpts texOpt + " Match inline minted commands + " - \mint[]{lang}|...| + " - \mint[]{lang}{...} + " - \mintinline[]{lang}|...| + " - \mintinline[]{lang}{...} + " Note: This comes last to allow the nextgroup pattern + syntax match texCmdMinted "\\mint\%(inline\)\?" + \ nextgroup=texMintedOpt,texMintedArg.* skipwhite skipnl + call vimtex#syntax#core#new_opt('texMintedOpt', {'next': 'texMintedArg.*'}) + + " Specify default highlight groups + highlight def link texCmdMinted texCmd + highlight def link texCmdNewmint texCmd + highlight def link texMintedArg texSymbol + highlight def link texMintedEnvArg texSymbol + highlight def link texMintedEnvArgOpt texOpt + highlight def link texMintedEnvOpt texOpt + highlight def link texMintedOpt texOpt + highlight def link texMintedRegion texRegion + highlight def link texMintedRegionInline texRegion + highlight def link texNewmintArgOpts texOpt + highlight def link texNewmintArgX texSymbol + highlight def link texNewmintArgY texComment + highlight def link texNewmintOpt texSymbol endfunction " }}}1 diff --git a/test/tests/test-syntax/test-minted.tex b/test/tests/test-syntax/test-minted.tex index 1a475135a2..8a880866f3 100644 --- a/test/tests/test-syntax/test-minted.tex +++ b/test/tests/test-syntax/test-minted.tex @@ -20,7 +20,7 @@ L985 +++$+++ u0 +++$+++ m0 +++$+++ BIANCA +++$+++ I hope so.! \end{minted} -% This is not valid and should not be highlighted in any special way! +% This is not valid, but let's still highlight it as a texRegion \begin{minted} L1045 +++$+++ u0 +++$+++ m0 +++$+++ BIANCA +++$+++ They do not! L1044 +++$+++ u0 +++$+++ m0 +++$+++ CAMERON +++$+++ They do to! From ef89e549fce55cb5fb665b25194234a2bf8bd577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 15 Nov 2020 13:37:12 +0100 Subject: [PATCH 66/99] test: refactor 'various-packages' tests --- test/tests/test-syntax/test-amsmath.tex | 11 ++ test/tests/test-syntax/test-amsmath.vim | 8 ++ test/tests/test-syntax/test-asymptote.tex | 57 +++++++++ test/tests/test-syntax/test-asymptote.vim | 10 ++ test/tests/test-syntax/test-booktabs.tex | 17 +++ test/tests/test-syntax/test-booktabs.vim | 8 ++ test/tests/test-syntax/test-cases.tex | 16 +++ test/tests/test-syntax/test-cases.vim | 7 ++ test/tests/test-syntax/test-core.tex | 18 +++ test/tests/test-syntax/test-pythontex.tex | 37 ++++++ test/tests/test-syntax/test-pythontex.vim | 10 ++ .../test-syntax/test-various-packages.tex | 108 ------------------ .../test-syntax/test-various-packages.vim | 9 +- 13 files changed, 200 insertions(+), 116 deletions(-) create mode 100644 test/tests/test-syntax/test-amsmath.tex create mode 100644 test/tests/test-syntax/test-amsmath.vim create mode 100644 test/tests/test-syntax/test-asymptote.tex create mode 100644 test/tests/test-syntax/test-asymptote.vim create mode 100644 test/tests/test-syntax/test-booktabs.tex create mode 100644 test/tests/test-syntax/test-booktabs.vim create mode 100644 test/tests/test-syntax/test-cases.tex create mode 100644 test/tests/test-syntax/test-cases.vim create mode 100644 test/tests/test-syntax/test-pythontex.tex create mode 100644 test/tests/test-syntax/test-pythontex.vim diff --git a/test/tests/test-syntax/test-amsmath.tex b/test/tests/test-syntax/test-amsmath.tex new file mode 100644 index 0000000000..de1a076f15 --- /dev/null +++ b/test/tests/test-syntax/test-amsmath.tex @@ -0,0 +1,11 @@ +\documentclass{article} +\usepackage{amsmath} + +\begin{document} + +\begin{align} + f(x) &= \bigg\lvert 0 \bigg\rvert \\ + f(x) &= \Bigg\lVert 0 \Bigg\rVert \\ +\end{align} + +\end{document} diff --git a/test/tests/test-syntax/test-amsmath.vim b/test/tests/test-syntax/test-amsmath.vim new file mode 100644 index 0000000000..4821e708a9 --- /dev/null +++ b/test/tests/test-syntax/test-amsmath.vim @@ -0,0 +1,8 @@ +source common.vim + +silent edit test-amsmath.tex + +if empty($INMAKE) | finish | endif + + +quit! diff --git a/test/tests/test-syntax/test-asymptote.tex b/test/tests/test-syntax/test-asymptote.tex new file mode 100644 index 0000000000..ec2906076f --- /dev/null +++ b/test/tests/test-syntax/test-asymptote.tex @@ -0,0 +1,57 @@ +\documentclass{article} +\usepackage[inline]{asymptote} + +\begin{document} + +Here is a venn diagram produced with Asymptote, drawn to width 4cm: + +\begin{asy} + size(4cm,0); + pen colour1=red; + pen colour2=green; + + pair z0=(0,0); + pair z1=(-1,0); + pair z2=(1,0); + real r=1.5; + path c1=circle(z1,r); + path c2=circle(z2,r); + fill(c1,colour1); + fill(c2,colour2); + + picture intersection=new picture; + fill(intersection,c1,colour1+colour2); + clip(intersection,c2); + + add(intersection); + + draw(c1); + draw(c2); + + // draw("$\A$",box,z1); // Requires [inline] package option. + // draw(Label("$\B$","$B$"),box,z2); // Requires [inline] package option. + draw("$A$",box,z1); + draw("$\V{B}$",box,z2); + + pair z=(0,-2); + real m=3; + margin BigMargin=Margin(0,m*dot(unit(z1-z),unit(z0-z))); + + draw(Label("$A\cap B$",0),conj(z)--z0,Arrow,BigMargin); + draw(Label("$A\cup B$",0),z--z0,Arrow,BigMargin); + draw(z--z1,Arrow,Margin(0,m)); + draw(z--z2,Arrow,Margin(0,m)); + + shipout(bbox(0.25cm)); +\end{asy} + +\begin{asydef} + // Global Asymptote definitions can be put here. + import three; + usepackage("bm"); + texpreamble("\def\V#1{\bm{#1}}"); + // One can globally override the default toolbar settings here: + // settings.toolbar=true; +\end{asydef} + +\end{document} diff --git a/test/tests/test-syntax/test-asymptote.vim b/test/tests/test-syntax/test-asymptote.vim new file mode 100644 index 0000000000..c3de5a8ba4 --- /dev/null +++ b/test/tests/test-syntax/test-asymptote.vim @@ -0,0 +1,10 @@ +source common.vim + +let &rtp = '.,' . &rtp + +silent edit test-asymptote.tex + +if empty($INMAKE) | finish | endif + + +quit! diff --git a/test/tests/test-syntax/test-booktabs.tex b/test/tests/test-syntax/test-booktabs.tex new file mode 100644 index 0000000000..37c6fbc546 --- /dev/null +++ b/test/tests/test-syntax/test-booktabs.tex @@ -0,0 +1,17 @@ +\documentclass{article} +\usepackage{booktabs} + +\begin{document} + +\begin{table} + \centering + \begin{tabular}{cr} + \toprule + 1234 \\ + \midrule + 2345 \\ + \bottomrule + \end{tabular} +\end{table} + +\end{document} diff --git a/test/tests/test-syntax/test-booktabs.vim b/test/tests/test-syntax/test-booktabs.vim new file mode 100644 index 0000000000..3fc8b170e4 --- /dev/null +++ b/test/tests/test-syntax/test-booktabs.vim @@ -0,0 +1,8 @@ +source common.vim + +silent edit test-booktabs.tex + +if empty($INMAKE) | finish | endif + + +quit! diff --git a/test/tests/test-syntax/test-cases.tex b/test/tests/test-syntax/test-cases.tex new file mode 100644 index 0000000000..8bc5cabd20 --- /dev/null +++ b/test/tests/test-syntax/test-cases.tex @@ -0,0 +1,16 @@ +\documentclass{article} +\usepackage{cases} + +\begin{document} + +\begin{numcases}{y_1 = } + f_1(x) & $x > 0$\\ + f_2(x) & $x \leqslant 0$ +\end{numcases} + +\begin{subnumcases}{y_1 = } + f_1(x) & $x > 0$\\ + f_2(x) & $x \leqslant 0$ +\end{subnumcases} + +\end{document} diff --git a/test/tests/test-syntax/test-cases.vim b/test/tests/test-syntax/test-cases.vim new file mode 100644 index 0000000000..dd92ccd2f9 --- /dev/null +++ b/test/tests/test-syntax/test-cases.vim @@ -0,0 +1,7 @@ +source common.vim + +silent edit test-cases.tex + +if empty($INMAKE) | finish | endif + +quit! diff --git a/test/tests/test-syntax/test-core.tex b/test/tests/test-syntax/test-core.tex index 7f11ab4903..833c8b4967 100644 --- a/test/tests/test-syntax/test-core.tex +++ b/test/tests/test-syntax/test-core.tex @@ -58,6 +58,24 @@ \section{Math} \left] \right[ \end{equation} +\begin{table} + \centering + \caption{asdfasdf} + \label{tab:} + \begin{tabular}{cr} + 1234 \\ + 2345 \\ + \end{tabular} +\end{table} + +\begin{equation} + \begin{array}{ccc} + asd & \left( f \right] & c \\ + asd & f & c \\ + asd & f & c + \end{array} +\end{equation} + \section*{Acknowledgement} \end{document} diff --git a/test/tests/test-syntax/test-pythontex.tex b/test/tests/test-syntax/test-pythontex.tex new file mode 100644 index 0000000000..266e17fcf3 --- /dev/null +++ b/test/tests/test-syntax/test-pythontex.tex @@ -0,0 +1,37 @@ +\documentclass{article} +\usepackage{pythontex} + +\begin{document} + +\py{1+1} +\pyb#1+1# +\pyc@1+1@ +\pys#1+1# + +\pyb{print('Python says hi!')} + +\begin{pycode} + print(r'\begin{center}') + print(r'\textit{A message from Python!}') + print(r'\end{center}') +\end{pycode} + +\begin{pyblock} + mytext = '$1 + 1 = {0}$'.format(1 + 1) + + def myfunction(arg1, arg2): + """docstring""" + pass +\end{pyblock} + +\begin{pycode} +print(r'\node {This is python};') +\end{pycode} + +\begin{tikzpicture} + \begin{pycode} + print(r'\node {This is python};') + \end{pycode} +\end{tikzpicture} + +\end{document} diff --git a/test/tests/test-syntax/test-pythontex.vim b/test/tests/test-syntax/test-pythontex.vim new file mode 100644 index 0000000000..9d10a5ac81 --- /dev/null +++ b/test/tests/test-syntax/test-pythontex.vim @@ -0,0 +1,10 @@ +source common.vim + +silent edit test-pythontex.tex + +if empty($INMAKE) | finish | endif + +call vimtex#test#assert(vimtex#syntax#in('pythonString', 11, 13)) +call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 16, 13)) + +quit! diff --git a/test/tests/test-syntax/test-various-packages.tex b/test/tests/test-syntax/test-various-packages.tex index 8c005b85db..24eb94bd2f 100644 --- a/test/tests/test-syntax/test-various-packages.tex +++ b/test/tests/test-syntax/test-various-packages.tex @@ -8,13 +8,9 @@ \usepackage{csquotes} \usepackage{cleveref} \usepackage{varioref} -\usepackage{amsmath} -\usepackage{cases} \usepackage{dot2texi} \usepackage{luacode} \usepackage{gnuplottex} -\usepackage[inline]{asymptote} -\usepackage{pythontex} \begin{document} @@ -92,26 +88,6 @@ \section{Package: cleveref} \section{Package: varioref} \Vref{sec_one} does what you need. Still \vref{sec_one} works. -\section{Package: amsmath and cases} -\begin{equation} - f(x) = 0 -\end{equation} - -\begin{align} - f(x) &= \bigg\lvert 0 \bigg\rvert \\ - f(x) &= \Bigg\lVert 0 \Bigg\rVert \\ -\end{align} - -\begin{numcases}{y_1 = } - f_1(x) & $x > 0$\\ - f_2(x) & $x \leqslant 0$ -\end{numcases} - -\begin{subnumcases}{y_1 = } - f_1(x) & $x > 0$\\ - f_2(x) & $x \leqslant 0$ -\end{subnumcases} - \section{Package: dot2texi} \begin{dot2tex} graph graphname { @@ -140,88 +116,4 @@ \section{Package: gnuplottex} plot file using 1:2 with lines \end{gnuplot} -\section{Package: asymptote} -Here is a venn diagram produced with Asymptote, drawn to width 4cm: - -\begin{asy} - size(4cm,0); - pen colour1=red; - pen colour2=green; - - pair z0=(0,0); - pair z1=(-1,0); - pair z2=(1,0); - real r=1.5; - path c1=circle(z1,r); - path c2=circle(z2,r); - fill(c1,colour1); - fill(c2,colour2); - - picture intersection=new picture; - fill(intersection,c1,colour1+colour2); - clip(intersection,c2); - - add(intersection); - - draw(c1); - draw(c2); - - // draw("$\A$",box,z1); // Requires [inline] package option. - // draw(Label("$\B$","$B$"),box,z2); // Requires [inline] package option. - draw("$A$",box,z1); - draw("$\V{B}$",box,z2); - - pair z=(0,-2); - real m=3; - margin BigMargin=Margin(0,m*dot(unit(z1-z),unit(z0-z))); - - draw(Label("$A\cap B$",0),conj(z)--z0,Arrow,BigMargin); - draw(Label("$A\cup B$",0),z--z0,Arrow,BigMargin); - draw(z--z1,Arrow,Margin(0,m)); - draw(z--z2,Arrow,Margin(0,m)); - - shipout(bbox(0.25cm)); -\end{asy} - -\begin{asydef} - // Global Asymptote definitions can be put here. - import three; - usepackage("bm"); - texpreamble("\def\V#1{\bm{#1}}"); - // One can globally override the default toolbar settings here: - // settings.toolbar=true; -\end{asydef} - -\section{Package: pythontex} -\py{1+1} -\pyb#1+1# -\pyc@1+1@ -\pys#1+1# - -\pyb{print('Python says hi!')} - -\begin{pycode} - print(r'\begin{center}') - print(r'\textit{A message from Python!}') - print(r'\end{center}') -\end{pycode} - -\begin{pyblock} - mytext = '$1 + 1 = {0}$'.format(1 + 1) - - def myfunction(arg1, arg2): - """docstring""" - pass -\end{pyblock} - -\begin{pycode} -print(r'\node {This is python};') -\end{pycode} - -\begin{tikzpicture} - \begin{pycode} - print(r'\node {This is python};') - \end{pycode} -\end{tikzpicture} - \end{document} diff --git a/test/tests/test-syntax/test-various-packages.vim b/test/tests/test-syntax/test-various-packages.vim index 756bf9d0f4..32bd6df8a0 100644 --- a/test/tests/test-syntax/test-various-packages.vim +++ b/test/tests/test-syntax/test-various-packages.vim @@ -1,16 +1,9 @@ source common.vim -let &rtp = '.,' . &rtp -let g:vimtex_fold_enabled = 1 - silent edit test-various-packages.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert_equal(15, len(keys(b:vimtex_syntax))) - -" PythonTeX inside tikzpictures (#1563) -call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 218, 11)) -call vimtex#test#assert(vimtex#syntax#in('pythonRawString', 223, 11)) +call vimtex#test#assert_equal(12, len(keys(b:vimtex_syntax))) quit! From d151ea2e15af5fc7b2427aa1cccd800f4f12d683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 15 Nov 2020 13:37:51 +0100 Subject: [PATCH 67/99] feat: added basic booktabs support --- autoload/vimtex/syntax/p/booktabs.vim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 autoload/vimtex/syntax/p/booktabs.vim diff --git a/autoload/vimtex/syntax/p/booktabs.vim b/autoload/vimtex/syntax/p/booktabs.vim new file mode 100644 index 0000000000..d6cc97dc22 --- /dev/null +++ b/autoload/vimtex/syntax/p/booktabs.vim @@ -0,0 +1,17 @@ +" vimtex - LaTeX plugin for Vim +" +" Maintainer: Karl Yngve Lervåg +" Email: karl.yngve@gmail.com +" + +function! vimtex#syntax#p#booktabs#load() abort " {{{1 + if has_key(b:vimtex_syntax, 'booktabs') | return | endif + let b:vimtex_syntax.booktabs = 1 + + syntax match texCmdBooktabs "\\\%(top\|mid\|bottom\)rule\>" + + highlight def link texCmdBooktabs texMathDelim +endfunction + +" }}}1 + From c1d6a8f4e7cac6d4fb2c85068f4fc27c4794d870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 15 Nov 2020 13:38:43 +0100 Subject: [PATCH 68/99] feat: support for tabular and array args --- autoload/vimtex/syntax/core.vim | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index c443b3d4b9..e7e3e33516 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -39,6 +39,7 @@ function! vimtex#syntax#core#init() abort " {{{1 \texComment, \texGroupError, \texMathCmd, + \texMathCmdEnv, \texMathDelim, \texMathDelimMod, \texMathGroup, @@ -310,6 +311,10 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_arg('texEnvArgName', {'next': 'texEnvOpt'}) call vimtex#syntax#core#new_opt('texEnvOpt', {'contains': 'texComment,@NoSpell'}) + " Tabular arguments + syntax match texCmdEnv "\\begin{tabular}" contains=texCmdEnv nextgroup=texTabularArg skipwhite skipnl + call vimtex#syntax#core#new_arg('texTabularArg', {'contains': ''}) + " }}}2 " {{{2 Region: \makeatletter ... \makeatother @@ -393,13 +398,17 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texMathOper "[_^=]" contained " Text Inside Math regions - syntax match texCmdMathText "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texMathtextArg - call vimtex#syntax#core#new_arg('texMathtextArg') + syntax match texCmdMathText "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texMathTextArg + call vimtex#syntax#core#new_arg('texMathTextArg') call s:match_math_sub_super(l:cfg) call s:match_math_symbols(l:cfg) call s:match_math_delims(l:cfg) + " Support for array environment + syntax match texMathCmdEnv "\\begin{array}" contained contains=texCmdEnv nextgroup=texMathArrayArg skipwhite skipnl + call vimtex#syntax#core#new_arg('texMathArrayArg', {'contains': ''}) + " }}}2 " {{{2 Conceal mode support @@ -600,6 +609,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texGroupError texError highlight def link texMathArg texMathRegion highlight def link texMathCmd texCmd + highlight def link texMathArrayArg texOpt highlight def link texMathDelimRegion texDelim highlight def link texMathDelimMod texMathDelim highlight def link texMathError texError @@ -622,6 +632,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texOptEqual texSymbol highlight def link texRefOpt texOpt highlight def link texLigature texSymbol + highlight def link texTabularArg texOpt highlight def link texTabularChar texSymbol highlight def link texVerbRegion texRegion highlight def link texVerbRegionInline texVerbRegion From 918ece1b38ec23b03adced0abd4d53f92f660830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 15 Nov 2020 13:54:20 +0100 Subject: [PATCH 69/99] feat: better amsmath support --- autoload/vimtex/syntax/p/amsmath.vim | 6 ++++- test/tests/test-syntax/test-amsmath.tex | 29 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index 24855f85ed..3cf12ef39e 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -14,10 +14,10 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 call vimtex#syntax#core#new_region_math('alignat') call vimtex#syntax#core#new_region_math('flalign') call vimtex#syntax#core#new_region_math('gather') + call vimtex#syntax#core#new_region_math('mathpar') call vimtex#syntax#core#new_region_math('multline') call vimtex#syntax#core#new_region_math('xalignat') call vimtex#syntax#core#new_region_math('xxalignat', {'starred': 0}) - call vimtex#syntax#core#new_region_math('mathpar') " Amsmath [lr][vV]ert if &encoding ==# 'utf-8' && g:vimtex_syntax_config.conceal.math_delimiters @@ -26,6 +26,10 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 syntax match texMathDelim contained conceal cchar=‖ "\\\%([bB]igg\?l\|left\)\\lVert" syntax match texMathDelim contained conceal cchar=‖ "\\\%([bB]igg\?r\|right\)\\rVert" endif + + syntax match texMathCmdEnv "\\begin{subarray}" contained contains=texCmdEnv nextgroup=texMathArrayArg skipwhite skipnl + syntax match texMathCmdEnv "\\begin{x\?alignat\*\?}" contained contains=texCmdEnv nextgroup=texMathArrayArg skipwhite skipnl + syntax match texMathCmdEnv "\\begin{xxalignat}" contained contains=texCmdEnv nextgroup=texMathArrayArg skipwhite skipnl endfunction " }}}1 diff --git a/test/tests/test-syntax/test-amsmath.tex b/test/tests/test-syntax/test-amsmath.tex index de1a076f15..0a0cec9272 100644 --- a/test/tests/test-syntax/test-amsmath.tex +++ b/test/tests/test-syntax/test-amsmath.tex @@ -8,4 +8,33 @@ f(x) &= \Bigg\lVert 0 \Bigg\rVert \\ \end{align} +\begin{equation} + \sum_{\begin{subarray}{l}i\in\Lambda\\ 0 Date: Sun, 15 Nov 2020 13:55:32 +0100 Subject: [PATCH 70/99] wip: minor adjustment --- autoload/vimtex/syntax/core.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index e7e3e33516..b48838bfb8 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -401,14 +401,14 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdMathText "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texMathTextArg call vimtex#syntax#core#new_arg('texMathTextArg') - call s:match_math_sub_super(l:cfg) - call s:match_math_symbols(l:cfg) - call s:match_math_delims(l:cfg) - " Support for array environment syntax match texMathCmdEnv "\\begin{array}" contained contains=texCmdEnv nextgroup=texMathArrayArg skipwhite skipnl call vimtex#syntax#core#new_arg('texMathArrayArg', {'contains': ''}) + call s:match_math_sub_super(l:cfg) + call s:match_math_symbols(l:cfg) + call s:match_math_delims(l:cfg) + " }}}2 " {{{2 Conceal mode support From 10dace2ed35d53b7230d870d06e2eaeb8db1ab16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 15 Nov 2020 14:18:44 +0100 Subject: [PATCH 71/99] feat: improve mathtools support --- autoload/vimtex/syntax/p/mathtools.vim | 13 ++++++ test/tests/test-syntax/test-mathtools.tex | 50 +++++++++++++++++++++++ test/tests/test-syntax/test-mathtools.vim | 9 ++++ 3 files changed, 72 insertions(+) create mode 100644 test/tests/test-syntax/test-mathtools.tex create mode 100644 test/tests/test-syntax/test-mathtools.vim diff --git a/autoload/vimtex/syntax/p/mathtools.vim b/autoload/vimtex/syntax/p/mathtools.vim index 9d9cb0c56d..8f2108e5d3 100644 --- a/autoload/vimtex/syntax/p/mathtools.vim +++ b/autoload/vimtex/syntax/p/mathtools.vim @@ -11,6 +11,19 @@ function! vimtex#syntax#p#mathtools#load() abort " {{{1 let b:vimtex_syntax.mathtools = 1 call vimtex#syntax#p#amsmath#load() + + " Support for various envionrments with option groups + syntax match texMathCmdEnv "\\begin{aligned}" contained contains=texCmdEnv nextgroup=texMathToolsOptPos1 + syntax match texMathCmdEnv "\\begin{[lr]gathered}" contained contains=texCmdEnv nextgroup=texMathToolsOptPos1 + syntax match texMathCmdEnv "\\begin{[pbBvV]\?\%(small\)\?matrix\*}" contained contains=texCmdEnv nextgroup=texMathToolsOptPos1 + syntax match texMathCmdEnv "\\begin{multlined}" contained contains=texCmdEnv nextgroup=texMathToolsOptPos2 skipwhite + call vimtex#syntax#core#new_opt('texMathToolsOptPos1', {'contains': ''}) + call vimtex#syntax#core#new_opt('texMathToolsOptPos2', {'contains': '', 'next': 'texMathToolsOptWidth'}) + call vimtex#syntax#core#new_opt('texMathToolsOptWidth', {'contains': 'texLength'}) + + highlight def link texMathToolsOptPos1 texOpt + highlight def link texMathToolsOptPos2 texOpt + highlight def link texMathToolsOptWidth texOpt endfunction " }}}1 diff --git a/test/tests/test-syntax/test-mathtools.tex b/test/tests/test-syntax/test-mathtools.tex new file mode 100644 index 0000000000..eb66f6ab39 --- /dev/null +++ b/test/tests/test-syntax/test-mathtools.tex @@ -0,0 +1,50 @@ +\documentclass{article} +\usepackage{mathtools} + +\begin{document} + +\begin{align} + f(x) &= \bigg\lvert 0 \bigg\rvert \\ + f(x) &= \Bigg\lVert 0 \Bigg\rVert \\ +\end{align} + +\[ + \begin{multlined}[b] + \framebox[4cm]{first} \\ + \framebox[4cm]{last} + \end{multlined} = B + \begin{multlined}[b][7cm] + \framebox[4cm]{first} \\ + \framebox[4cm]{last} + \end{multlined} = B +\] + +\begin{align*} + f(a) &= + \!\begin{aligned}[t] + & \frac{1}{2}+\cdots \\& \dots+\frac{1}{2} + \end{aligned} +\end{align*} + +\begin{equation} + \begin{lgathered}[c] + x=1,\quad x+1=2 \\ + y=235 + \end{lgathered} +\end{equation} + +\[ + \begin{pmatrix*}[r] + -1 & 3 \\ + 2 & -4 + \end{pmatrix*} +\] + +\[ + \begin{smallmatrix*}[r] + -1 & 3 \\ + 2 & -4 + \end{smallmatrix*} +\] + +\end{document} diff --git a/test/tests/test-syntax/test-mathtools.vim b/test/tests/test-syntax/test-mathtools.vim new file mode 100644 index 0000000000..9d7470b738 --- /dev/null +++ b/test/tests/test-syntax/test-mathtools.vim @@ -0,0 +1,9 @@ +source common.vim + +silent edit test-mathtools.tex + +if empty($INMAKE) | finish | endif + +call vimtex#test#assert(vimtex#syntax#in('texMathRegionEnv', 7, 1)) + +quit! From fec126e025bc110a4f4c90ef08af2d1d41cc6804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 15 Nov 2020 15:00:16 +0100 Subject: [PATCH 72/99] feat: better tikz and pgfplots support --- autoload/vimtex/syntax/p/pgfplots.vim | 35 ++++++++++++++++++++++++--- autoload/vimtex/syntax/p/tikz.vim | 26 ++++++++++++++------ test/tests/test-syntax/test-tikz.tex | 9 +++++++ 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/autoload/vimtex/syntax/p/pgfplots.vim b/autoload/vimtex/syntax/p/pgfplots.vim index f1e355cb2d..d335b2f062 100644 --- a/autoload/vimtex/syntax/p/pgfplots.vim +++ b/autoload/vimtex/syntax/p/pgfplots.vim @@ -14,9 +14,6 @@ function! vimtex#syntax#p#pgfplots#load() abort " {{{1 syntax match texCmdTikzset nextgroup=texTikzsetArg skipwhite "\\pgfplotsset\>" - syntax match texCmdAxis contained nextgroup=texTikzOpt skipwhite "\\addplot3\?\>" - syntax match texCmdAxis contained nextgroup=texTikzOpt skipwhite "\\nextgroupplot\>" - syntax match texTikzEnvBgn contains=texCmdEnv nextgroup=texTikzOpt skipwhite skipnl "\\begin{\%(log\)*axis}" syntax match texTikzEnvBgn contains=texCmdEnv nextgroup=texTikzOpt skipwhite skipnl "\\begin{groupplot}" call vimtex#syntax#core#new_region_env('texTikzRegion', 'axis', {'contains': '@texClusterTikz'}) @@ -24,7 +21,37 @@ function! vimtex#syntax#p#pgfplots#load() abort " {{{1 call vimtex#syntax#core#new_region_env('texTikzRegion', 'loglogaxis', {'contains': '@texClusterTikz'}) call vimtex#syntax#core#new_region_env('texTikzRegion', 'groupplot', {'contains': '@texClusterTikz'}) - highlight def link texCmdAxis texCmd + + syntax match texCmdAxis contained nextgroup=texTikzOpt skipwhite skipnl "\\nextgroupplot\>" + syntax match texCmdAxis contained nextgroup=texPgfAddplotOpt,texPgfType,texPgfFunc skipwhite skipnl "\\addplot3\?\>+\?" + + call vimtex#syntax#core#new_opt('texPgfAddplotOpt', {'contains': '@texClusterTikzset', 'next': 'texPgfType,texPgfFunc'}) + call vimtex#syntax#core#new_arg('texPgfFunc', {'contains': '', 'opts': 'transparent'}) + + + syntax match texPgfType "table" contained nextgroup=texPgfTableOpt,texPgfTableArg skipwhite skipnl + call vimtex#syntax#core#new_opt('texPgfTableOpt', {'contains': '@texClusterTikzset'}) + call vimtex#syntax#core#new_arg('texPgfTableArg', {'contains': '@NoSpell,texComment'}) + + + syntax match texPgfType "gnuplot" contained nextgroup=texPgfGnuplotArg skipwhite skipnl + call vimtex#syntax#nested#include('gnuplot') + call vimtex#syntax#core#new_arg('texPgfGnuplotArg', {'contains': '@vimtex_nested_gnuplot', 'next': 'texPgfNode'}) + + + syntax match texPgfType "coordinates" contained nextgroup=texPgfCoordinates skipwhite skipnl + call vimtex#syntax#core#new_arg('texPgfCoordinates', {'contains': ''}) + + + syntax match texPgfNode "node" contained nextgroup=texTikzNodeOpt skipwhite skipnl + + + highlight def link texCmdAxis texCmd + highlight def link texPgfNode texCmd + highlight def link texPgfType texMathDelim + highlight def link texPgfFunc texArg + highlight def link texPgfTableArg texFileArg + highlight def link texPgfCoordinates texOpt endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index 7cb4c31b44..1df08ee050 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -8,22 +8,34 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 if has_key(b:vimtex_syntax, 'tikz') | return | endif let b:vimtex_syntax.tikz = 1 - syntax cluster texClusterTikz contains=texTikzEnvBgn,texTikzSemicolon,texCmd,texGroup,texComment + syntax cluster texClusterTikz contains=texCmdTikz,texTikzEnvBgn,texTikzSemicolon,texTikzDraw,texTikzCycle,texCmd,texGroup,texComment syntax cluster texClusterTikzset contains=texTikzsetArg,texMathRegionX,texTypeSize,@texClusterOpt - syntax match texCmdTikzset "\\tikzset\>" skipwhite skipnl nextgroup=texTikzsetArg - call vimtex#syntax#core#new_arg('texTikzsetArg', {'contains': '@texClusterTikzset'}) + syntax match texCmdTikzset "\\tikzset\>" + \ nextgroup=texTikzsetArg skipwhite skipnl + call vimtex#syntax#core#new_arg('texTikzsetArg', + \ {'contains': '@texClusterTikzset'}) syntax match texTikzEnvBgn "\\begin{tikzpicture}" - \ nextgroup=texTikzOpt skipwhite skipnl contains=texCmdEnv + \ nextgroup=texTikzOpt skipwhite skipnl + \ contains=texCmdEnv call vimtex#syntax#core#new_region_env('texTikzRegion', 'tikzpicture', \ {'contains': '@texClusterTikz'}) - call vimtex#syntax#core#new_opt('texTikzOpt', {'contains': '@texClusterTikzset'}) + call vimtex#syntax#core#new_opt('texTikzOpt', + \ {'contains': '@texClusterTikzset'}) - syntax match texTikzSemicolon /;/ contained + syntax keyword texTikzCycle cycle contained + syntax match texTikzSemicolon ";" contained + syntax match texTikzDraw "--" contained + syntax match texTikzDraw "|-" contained - highlight def link texCmdTikzset texCmd + syntax match texCmdTikz "\\node\>" contained nextgroup=texTikzNodeOpt skipwhite skipnl + call vimtex#syntax#core#new_opt('texTikzNodeOpt', {'contains': '@texClusterTikzset'}) + + highlight def link texCmdTikzset texCmd highlight def link texTikzSemicolon texDelim + highlight def link texTikzDraw texDelim + highlight def link texTikzCycle texMathDelim endfunction " }}}1 diff --git a/test/tests/test-syntax/test-tikz.tex b/test/tests/test-syntax/test-tikz.tex index 87bc192357..cf79650b52 100644 --- a/test/tests/test-syntax/test-tikz.tex +++ b/test/tests/test-syntax/test-tikz.tex @@ -79,6 +79,15 @@ ] \addplot[cl3-1] {t_rpt(x, 437.0, 0.6*0.135294, 0.672)}; \addplot[cl3-3, sim] table {data/instspill_m2_eps1.2.csv}; + + \addplot+ [id=parable,domain=-5:5,] gnuplot {4*x**2 - 5} node [pin=180:{$4x^2-5$}] {}; + + \addplot+ coordinates { + (0.0, 0.10) (0.1, 0.15) (0.2, 0.50) + (0.3, 0.62) (0.4, 0.56) (0.5, 0.58) + (0.6, 0.65) (0.7, 0.60) (0.8, 0.58) + (0.9, 0.55) (1.0, 0.52) + } |- (0,0) -- cycle; \end{groupplot} \end{tikzpicture} \caption{This example will not compile!} From c6618e9e89567cd89a26e87d1d6d597fad94737f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 15 Nov 2020 18:12:58 +0100 Subject: [PATCH 73/99] wip: adjustments --- autoload/vimtex/syntax/p/pgfplots.vim | 12 +++++++----- autoload/vimtex/syntax/p/tikz.vim | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/autoload/vimtex/syntax/p/pgfplots.vim b/autoload/vimtex/syntax/p/pgfplots.vim index d335b2f062..135cde7f07 100644 --- a/autoload/vimtex/syntax/p/pgfplots.vim +++ b/autoload/vimtex/syntax/p/pgfplots.vim @@ -46,12 +46,14 @@ function! vimtex#syntax#p#pgfplots#load() abort " {{{1 syntax match texPgfNode "node" contained nextgroup=texTikzNodeOpt skipwhite skipnl - highlight def link texCmdAxis texCmd - highlight def link texPgfNode texCmd - highlight def link texPgfType texMathDelim - highlight def link texPgfFunc texArg - highlight def link texPgfTableArg texFileArg + highlight def link texCmdAxis texCmd + highlight def link texPgfNode texCmd + highlight def link texPgfType texMathDelim + highlight def link texPgfFunc texArg + highlight def link texPgfTableArg texFileArg highlight def link texPgfCoordinates texOpt + highlight def link texPgfAddplotOpt texOpt + highlight def link texPgfTableOpt texOpt endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index 1df08ee050..f3f856034b 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -36,6 +36,8 @@ function! vimtex#syntax#p#tikz#load() abort " {{{1 highlight def link texTikzSemicolon texDelim highlight def link texTikzDraw texDelim highlight def link texTikzCycle texMathDelim + highlight def link texTikzsetArg texOpt + highlight def link texTikzOpt texOpt endfunction " }}}1 From 83bd7e0296b187d257ab51fddb08d6a188494824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 15 Nov 2020 21:01:57 +0100 Subject: [PATCH 74/99] wip: minor change --- autoload/vimtex/syntax/core.vim | 2 +- autoload/vimtex/syntax/p/amsmath.vim | 6 +++--- autoload/vimtex/syntax/p/mathtools.vim | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index b48838bfb8..e965db804e 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -402,7 +402,7 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_arg('texMathTextArg') " Support for array environment - syntax match texMathCmdEnv "\\begin{array}" contained contains=texCmdEnv nextgroup=texMathArrayArg skipwhite skipnl + syntax match texMathCmdEnv "\\begin{array}" contained contains=texCmdMathEnv nextgroup=texMathArrayArg skipwhite skipnl call vimtex#syntax#core#new_arg('texMathArrayArg', {'contains': ''}) call s:match_math_sub_super(l:cfg) diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index 3cf12ef39e..a4108466f5 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -27,9 +27,9 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 syntax match texMathDelim contained conceal cchar=‖ "\\\%([bB]igg\?r\|right\)\\rVert" endif - syntax match texMathCmdEnv "\\begin{subarray}" contained contains=texCmdEnv nextgroup=texMathArrayArg skipwhite skipnl - syntax match texMathCmdEnv "\\begin{x\?alignat\*\?}" contained contains=texCmdEnv nextgroup=texMathArrayArg skipwhite skipnl - syntax match texMathCmdEnv "\\begin{xxalignat}" contained contains=texCmdEnv nextgroup=texMathArrayArg skipwhite skipnl + syntax match texMathCmdEnv "\\begin{subarray}" contained contains=texCmdMathEnv nextgroup=texMathArrayArg skipwhite skipnl + syntax match texMathCmdEnv "\\begin{x\?alignat\*\?}" contained contains=texCmdMathEnv nextgroup=texMathArrayArg skipwhite skipnl + syntax match texMathCmdEnv "\\begin{xxalignat}" contained contains=texCmdMathEnv nextgroup=texMathArrayArg skipwhite skipnl endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/mathtools.vim b/autoload/vimtex/syntax/p/mathtools.vim index 8f2108e5d3..e9a7c2061a 100644 --- a/autoload/vimtex/syntax/p/mathtools.vim +++ b/autoload/vimtex/syntax/p/mathtools.vim @@ -13,10 +13,10 @@ function! vimtex#syntax#p#mathtools#load() abort " {{{1 call vimtex#syntax#p#amsmath#load() " Support for various envionrments with option groups - syntax match texMathCmdEnv "\\begin{aligned}" contained contains=texCmdEnv nextgroup=texMathToolsOptPos1 - syntax match texMathCmdEnv "\\begin{[lr]gathered}" contained contains=texCmdEnv nextgroup=texMathToolsOptPos1 - syntax match texMathCmdEnv "\\begin{[pbBvV]\?\%(small\)\?matrix\*}" contained contains=texCmdEnv nextgroup=texMathToolsOptPos1 - syntax match texMathCmdEnv "\\begin{multlined}" contained contains=texCmdEnv nextgroup=texMathToolsOptPos2 skipwhite + syntax match texMathCmdEnv contained contains=texCmdMathEnv nextgroup=texMathToolsOptPos1 "\\begin{aligned}" + syntax match texMathCmdEnv contained contains=texCmdMathEnv nextgroup=texMathToolsOptPos1 "\\begin{[lr]gathered}" + syntax match texMathCmdEnv contained contains=texCmdMathEnv nextgroup=texMathToolsOptPos1 "\\begin{[pbBvV]\?\%(small\)\?matrix\*}" + syntax match texMathCmdEnv contained contains=texCmdMathEnv nextgroup=texMathToolsOptPos2 "\\begin{multlined}" call vimtex#syntax#core#new_opt('texMathToolsOptPos1', {'contains': ''}) call vimtex#syntax#core#new_opt('texMathToolsOptPos2', {'contains': '', 'next': 'texMathToolsOptWidth'}) call vimtex#syntax#core#new_opt('texMathToolsOptWidth', {'contains': 'texLength'}) From 4ad27739906a583eabf4f685a11d56bf115d07b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 15 Nov 2020 23:06:01 +0100 Subject: [PATCH 75/99] wip: fixed missing texCmdMathEnv matchers --- autoload/vimtex/syntax/core.vim | 3 ++- autoload/vimtex/syntax/p/amsmath.vim | 9 ++++++--- autoload/vimtex/syntax/p/mathtools.vim | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index e965db804e..8e552e3081 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -402,7 +402,8 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_arg('texMathTextArg') " Support for array environment - syntax match texMathCmdEnv "\\begin{array}" contained contains=texCmdMathEnv nextgroup=texMathArrayArg skipwhite skipnl + syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\begin{array}" nextgroup=texMathArrayArg skipwhite skipnl + syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\end{array}" call vimtex#syntax#core#new_arg('texMathArrayArg', {'contains': ''}) call s:match_math_sub_super(l:cfg) diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index a4108466f5..daaeff422e 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -27,9 +27,12 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 syntax match texMathDelim contained conceal cchar=‖ "\\\%([bB]igg\?r\|right\)\\rVert" endif - syntax match texMathCmdEnv "\\begin{subarray}" contained contains=texCmdMathEnv nextgroup=texMathArrayArg skipwhite skipnl - syntax match texMathCmdEnv "\\begin{x\?alignat\*\?}" contained contains=texCmdMathEnv nextgroup=texMathArrayArg skipwhite skipnl - syntax match texMathCmdEnv "\\begin{xxalignat}" contained contains=texCmdMathEnv nextgroup=texMathArrayArg skipwhite skipnl + syntax match texMathCmdEnv contained contains=texCmdMathEnv nextgroup=texMathArrayArg skipwhite skipnl "\\begin{subarray}" + syntax match texMathCmdEnv contained contains=texCmdMathEnv nextgroup=texMathArrayArg skipwhite skipnl "\\begin{x\?alignat\*\?}" + syntax match texMathCmdEnv contained contains=texCmdMathEnv nextgroup=texMathArrayArg skipwhite skipnl "\\begin{xxalignat}" + syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\end{subarray}" + syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\end{x\?alignat\*\?}" + syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\end{xxalignat}" endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/mathtools.vim b/autoload/vimtex/syntax/p/mathtools.vim index e9a7c2061a..980c49df07 100644 --- a/autoload/vimtex/syntax/p/mathtools.vim +++ b/autoload/vimtex/syntax/p/mathtools.vim @@ -17,6 +17,10 @@ function! vimtex#syntax#p#mathtools#load() abort " {{{1 syntax match texMathCmdEnv contained contains=texCmdMathEnv nextgroup=texMathToolsOptPos1 "\\begin{[lr]gathered}" syntax match texMathCmdEnv contained contains=texCmdMathEnv nextgroup=texMathToolsOptPos1 "\\begin{[pbBvV]\?\%(small\)\?matrix\*}" syntax match texMathCmdEnv contained contains=texCmdMathEnv nextgroup=texMathToolsOptPos2 "\\begin{multlined}" + syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\end{aligned}" + syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\end{[lr]gathered}" + syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\end{[pbBvV]\?\%(small\)\?matrix\*}" + syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\end{multlined}" call vimtex#syntax#core#new_opt('texMathToolsOptPos1', {'contains': ''}) call vimtex#syntax#core#new_opt('texMathToolsOptPos2', {'contains': '', 'next': 'texMathToolsOptWidth'}) call vimtex#syntax#core#new_opt('texMathToolsOptWidth', {'contains': 'texLength'}) From 499748550a5e17a222f5c79db2cec6a2feb9b445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 15 Nov 2020 23:07:48 +0100 Subject: [PATCH 76/99] wip: minor fix --- autoload/vimtex/syntax/core.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 8e552e3081..17e09c03e6 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -606,7 +606,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texFileArg texArg highlight def link texFileOpt texOpt highlight def link texFilesArg texFileArg - highlight def link texFilesOpt texOpt + highlight def link texFilesOpt texFileOpt highlight def link texGroupError texError highlight def link texMathArg texMathRegion highlight def link texMathCmd texCmd From 68f8e7cbd5ef8fbe848f65803c794c9c8633638c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 16 Nov 2020 00:25:38 +0100 Subject: [PATCH 77/99] wip: extract babel specific stuff --- autoload/vimtex/options.vim | 4 +++- autoload/vimtex/syntax/core.vim | 8 -------- autoload/vimtex/syntax/p/babel.vim | 20 ++++++++++++++++++++ test/tests/test-syntax/test-babel.tex | 8 ++++++++ test/tests/test-syntax/test-babel.vim | 7 +++++++ 5 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 autoload/vimtex/syntax/p/babel.vim create mode 100644 test/tests/test-syntax/test-babel.tex create mode 100644 test/tests/test-syntax/test-babel.vim diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index 5048464a33..44a8142549 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -268,7 +268,6 @@ function! vimtex#options#init() abort " {{{1 \ 'greek': g:vimtex_syntax_conceal, \ 'math_bounds': g:vimtex_syntax_conceal, \ 'math_delimiters': g:vimtex_syntax_conceal, - \ 'special_chars': g:vimtex_syntax_conceal, \ 'styles': g:vimtex_syntax_conceal, \ 'super_sub': g:vimtex_syntax_conceal, \ }, @@ -302,6 +301,9 @@ function! vimtex#options#init() abort " {{{1 \}) call s:init_option('vimtex_syntax_autoload_packages', ['amsmath']) call s:init_option('vimtex_syntax_nospell_commands', []) + call s:init_option('vimtex_syntax_packages', { + \ 'babel': {'conceal': g:vimtex_syntax_conceal_default}, + \}) call s:init_option('vimtex_texcount_custom_arg', '') diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 17e09c03e6..710e40b989 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -416,14 +416,6 @@ function! vimtex#syntax#core#init() abort " {{{1 " Add support for conceal with custom replacement (conceallevel = 2) if &encoding ==# 'utf-8' - if l:cfg.conceal.special_chars - syntax match texSpecialChar '\\glq\>' contained conceal cchar=‚ - syntax match texSpecialChar '\\grq\>' contained conceal cchar=‘ - syntax match texSpecialChar '\\glqq\>' contained conceal cchar=„ - syntax match texSpecialChar '\\grqq\>' contained conceal cchar=“ - syntax match texSpecialChar '\\hyp\>' contained conceal cchar=- - endif - " Conceal replace greek letters if l:cfg.conceal.greek call s:match_conceal_greek() diff --git a/autoload/vimtex/syntax/p/babel.vim b/autoload/vimtex/syntax/p/babel.vim new file mode 100644 index 0000000000..db35a4c839 --- /dev/null +++ b/autoload/vimtex/syntax/p/babel.vim @@ -0,0 +1,20 @@ +" vimtex - LaTeX plugin for Vim +" +" Maintainer: Karl Yngve Lervåg +" Email: karl.yngve@gmail.com +" + +function! vimtex#syntax#p#babel#load() abort " {{{1 + if has_key(b:vimtex_syntax, 'babel') | return | endif + let b:vimtex_syntax.babel = 1 + + if g:vimtex_syntax_packages.babel.conceal + syntax match texSpecialChar '\\glq\>' conceal cchar=‚ + syntax match texSpecialChar '\\grq\>' conceal cchar=‘ + syntax match texSpecialChar '\\glqq\>' conceal cchar=„ + syntax match texSpecialChar '\\grqq\>' conceal cchar=“ + syntax match texSpecialChar '\\hyp\>' conceal cchar=- + endif +endfunction + +" }}}1 diff --git a/test/tests/test-syntax/test-babel.tex b/test/tests/test-syntax/test-babel.tex new file mode 100644 index 0000000000..e6a90c1a04 --- /dev/null +++ b/test/tests/test-syntax/test-babel.tex @@ -0,0 +1,8 @@ +\documentclass{article} +\usepackage{babel} + +\begin{document} + +\glq \grq \glqq \grqq \hyp + +\end{document} diff --git a/test/tests/test-syntax/test-babel.vim b/test/tests/test-syntax/test-babel.vim new file mode 100644 index 0000000000..4a9e5aca3c --- /dev/null +++ b/test/tests/test-syntax/test-babel.vim @@ -0,0 +1,7 @@ +source common.vim + +silent edit test-babel.tex + +if empty($INMAKE) | finish | endif + +quit! From 3bdb8a73b05dcc74b7d2686b06ce86f11e32090f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 16 Nov 2020 00:27:05 +0100 Subject: [PATCH 78/99] wip: changed names of options Note: Breaking change! --- autoload/vimtex/options.vim | 24 ++++++++++----------- autoload/vimtex/syntax/core.vim | 7 +++--- autoload/vimtex/syntax/p/amsmath.vim | 2 +- autoload/vimtex/syntax/p/array.vim | 2 +- test/tests/test-syntax/test-bold-italic.vim | 2 +- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index 44a8142549..5fe25da87e 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -261,19 +261,18 @@ function! vimtex#options#init() abort " {{{1 call s:init_option('vimtex_subfile_start_local', 0) - call s:init_option('vimtex_syntax_conceal', 1) - call s:init_option('vimtex_syntax_config', { - \ 'conceal': { - \ 'accents': g:vimtex_syntax_conceal, - \ 'greek': g:vimtex_syntax_conceal, - \ 'math_bounds': g:vimtex_syntax_conceal, - \ 'math_delimiters': g:vimtex_syntax_conceal, - \ 'styles': g:vimtex_syntax_conceal, - \ 'super_sub': g:vimtex_syntax_conceal, - \ }, - \}) - call s:init_option('vimtex_syntax_enabled', 1) + call s:init_option('vimtex_syntax_autoload_packages', ['amsmath']) + call s:init_option('vimtex_syntax_conceal_default', 1) + call s:init_option('vimtex_syntax_conceal', { + \ 'accents': g:vimtex_syntax_conceal_default, + \ 'greek': g:vimtex_syntax_conceal_default, + \ 'math_bounds': g:vimtex_syntax_conceal_default, + \ 'math_delimiters': g:vimtex_syntax_conceal_default, + \ 'math_super_sub': g:vimtex_syntax_conceal_default, + \ 'math_symbols': g:vimtex_syntax_conceal_default, + \ 'styles': g:vimtex_syntax_conceal_default, + \}) call s:init_option('vimtex_syntax_nested', { \ 'aliases' : { \ 'C' : 'c', @@ -299,7 +298,6 @@ function! vimtex#options#init() abort " {{{1 \ ], \ } \}) - call s:init_option('vimtex_syntax_autoload_packages', ['amsmath']) call s:init_option('vimtex_syntax_nospell_commands', []) call s:init_option('vimtex_syntax_packages', { \ 'babel': {'conceal': g:vimtex_syntax_conceal_default}, diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 710e40b989..bcc0b7bc93 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -5,8 +5,9 @@ " function! vimtex#syntax#core#init() abort " {{{1 - let l:cfg = deepcopy(g:vimtex_syntax_config) + let l:cfg = {} let l:cfg.ext = expand('%:e') + let l:cfg.conceal = deepcopy(g:vimtex_syntax_conceal) let l:cfg.is_style_document = \ index(['sty', 'cls', 'clo', 'dtx', 'ltx'], l:cfg.ext) >= 0 @@ -667,7 +668,7 @@ endfunction " }}}1 function! s:match_math_sub_super(cfg) " {{{1 - if !a:cfg.conceal.super_sub | return | endif + if !a:cfg.conceal.math_super_sub | return | endif for [l:from, l:to] in filter(copy(s:map_super), \ {_, x -> x[0][0] ==# '\' || x[0] =~# '[0-9a-zA-W.,:;+-<>/()=]'}) @@ -797,7 +798,7 @@ let s:map_super = [ " }}}1 function! s:match_math_symbols(cfg) abort " {{{1 " Many of these symbols were contributed by Björn Winckler - if !a:cfg.conceal.math_delimiters | return | endif + if !a:cfg.conceal.math_symbols | return | endif syntax match texMathSymbol "\\|" contained conceal cchar=‖ syntax match texMathSymbol "\\aleph\>" contained conceal cchar=ℵ diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index daaeff422e..53db22e17f 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -20,7 +20,7 @@ function! vimtex#syntax#p#amsmath#load() abort " {{{1 call vimtex#syntax#core#new_region_math('xxalignat', {'starred': 0}) " Amsmath [lr][vV]ert - if &encoding ==# 'utf-8' && g:vimtex_syntax_config.conceal.math_delimiters + if &encoding ==# 'utf-8' && g:vimtex_syntax_conceal.math_delimiters syntax match texMathDelim contained conceal cchar=| "\\\%([bB]igg\?l\|left\)\\lvert" syntax match texMathDelim contained conceal cchar=| "\\\%([bB]igg\?r\|right\)\\rvert" syntax match texMathDelim contained conceal cchar=‖ "\\\%([bB]igg\?l\|left\)\\lVert" diff --git a/autoload/vimtex/syntax/p/array.vim b/autoload/vimtex/syntax/p/array.vim index 9929da3a2d..b54fe3cb10 100644 --- a/autoload/vimtex/syntax/p/array.vim +++ b/autoload/vimtex/syntax/p/array.vim @@ -19,7 +19,7 @@ function! vimtex#syntax#p#array#load() abort " {{{1 \ 'start="\([<>]{\)\@ Date: Mon, 16 Nov 2020 00:29:42 +0100 Subject: [PATCH 79/99] wip: started to add proper docs --- README.md | 7 +- doc/vimtex.txt | 320 +++++++++++++++++++++++++++++-------------------- 2 files changed, 189 insertions(+), 138 deletions(-) diff --git a/README.md b/README.md index 187440957a..ae8fa1a109 100644 --- a/README.md +++ b/README.md @@ -132,12 +132,9 @@ disabled if desired. - Improved indentation (`:h 'indentexpr'`) - Syntax highlighting - A consistent core syntax specification + - General syntax highlighting for several popular LaTeX packages + - Nested syntax highlighting for several popular LaTeX packages - Highlight matching delimiters - - Support for `biblatex`/`natbib` package - - Support for `cleveref` package - - Support for `listings` package - - Nested syntax highlighting (`minted`, `dot2tex`, `lualatex`, - `gnuplottex`, `asymptote`, `pythontex`) - Support for multi-file project packages - [import](http://ctan.uib.no/macros/latex/contrib/import/import.pdf) - [subfiles](http://ctan.uib.no/macros/latex/contrib/subfiles/subfiles.pdf) diff --git a/doc/vimtex.txt b/doc/vimtex.txt index e694f92950..2faec1aeea 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -96,40 +96,37 @@ CONTENTS *vimtex-contents* ============================================================================== INTRODUCTION *vimtex-introduction* -|vimtex| provides convenient functionality for editing LaTeX documents. The -main goal of |vimtex| is to be simple, functional, and to be easy to customize +Vimtex provides convenient functionality for editing LaTeX documents. The +main goal of Vimtex is to be simple, functional, and to be easy to customize and evolve. The documentation is understandably too long for a full read through. It is recommended that new users read or skim the entire introduction, as it should -give a clear idea of what |vimtex| is and is not. The remaining part of the +give a clear idea of what Vimtex is and is not. The remaining part of the documentation should then be considered a reference for the various parts of the plugin. ------------------------------------------------------------------------------ COMMENT ON INTERNAL TEX PLUGIN *vimtex-comment-internal* -Vim ships with LaTeX support out of the box. In particular, it provides pretty -good syntax highlighting (|ft-tex-syntax|), indentation (see the source file -$VIMRUNTIME/indent/tex.vim for the documentation), and some sensible options -(|ft-tex-plugin|). - -When |vimtex| is active, it will by default be used as the main |ftplugin|, -syntax plugin (|vimtex-syntax|) and indent plugin (|vimtex-indent|). It will -define the same set of sensible settings as the internal plugin (and much -more, of course). Various features may be disabled by the user, see the -`g:vimtex_*_enabled` style of configuration options in |vimtex-options|. +Vim ships with pretty decent LaTeX support out of the box. In particular, it +provides syntax highlighting (|ft-tex-syntax|), indentation (see the source +file $VIMRUNTIME/indent/tex.vim for the documentation), and some sensible +options (|ft-tex-plugin|). *vimtex-tex-flavor* -|ft-tex-plugin| supports both plain TeX, ConTeXt, and LaTeX files. This means -that the `.tex` extension is ambiguous. Vimtex is only activated for LaTeX -files with 'filetype' set to `tex`. In most cases, the filetype is -correcly specified automatically. When this is not possible, then it falls -back to the setting of |g:tex_flavor|. The default (when |g:tex_flavor| is not -defined) is to fallback to plain TeX, which means vimtex is not loaded! As -this may be surprising to a lot of people, Vimtex will give a warning if it is -installed and if the |g:tex_flavor| option is not defined. In most cases, you -want to set: > +When Vimtex is active, it will by default override the internal TeX plugin. In +particular, Vimtex is loaded when the 'filetype' is set to `tex`. This is +usually the case for most files with the `.tex` extension. However, the `.tex` +extension is ambiguous in that it may be used for both plain TeX, ConTeXt, and +LaTeX files. The built-in |ft-tex-plugin| provides an |ftdetect| mechanism for +detecting the filetype by looking at the top lines of a file. In most cases, +the filetype is specified as `tex`, but by default it will fall back to +`plaintex`. To prevent this behaviour and ensure that Vimtex is loaded for all +`.tex` files, one should set the |g:tex_flavor| option to `'latex'`. As this +behaviour may be surprising to a lot of people, Vimtex will give a warning if +it is installed and if the |g:tex_flavor| option is not defined. In most +cases, you want to set: > let g:tex_flavor = 'latex' @@ -198,12 +195,9 @@ FEATURE OVERVIEW *vimtex-features* - Indentation - Syntax highlighting - A consistent core syntax specification + - General syntax highlighting for several popular LaTeX packages + - Nested syntax highlighting for several popular LaTeX packages - Highlight matching delimiters - - Support for `biblatex`/`natbib` package - - Support for `cleveref` package - - Support for `listings` package - - Nested syntax highlighting for `dot2tex`, `lualatex`, `gnuplottex`, - `asymptote`, `pythontex`, `listings`, and `minted` - Support for multi-file project packages - `import` - `subfiles` @@ -211,13 +205,13 @@ FEATURE OVERVIEW *vimtex-features* ------------------------------------------------------------------------------ REQUIREMENTS *vimtex-requirements* -The following is a list of specific requirements for running |vimtex| and some +The following is a list of specific requirements for running Vimtex and some of its key features. One may also be interested in reading |vimtex-faq-neovim| and |vimtex-faq-windows|. Vim version~ *vimtex_version_check* - |vimtex| requires Vim version 8.0.1453 or neovim version 0.4.3. It will not + Vimtex requires Vim version 8.0.1453 or neovim version 0.4.3. It will not load for older versions, unless one adds > let g:vimtex_version_check = 0 @@ -227,7 +221,7 @@ Vim version~ Compiler backend~ - |vimtex| uses `latexmk`, `latexrun`, `tectonic` or `arara` to compile the LaTeX document. + Vimtex uses `latexmk`, `latexrun`, `tectonic` or `arara` to compile the LaTeX document. `latexmk`: http://users.phys.psu.edu/~collins/software/latexmk-jcc "a perl script for running LaTeX the correct number of times to resolve @@ -342,7 +336,7 @@ Tag navigation~ Manipulate surrounding commands/delimiters/environments~ *vimtex-nf-surround* - |vimtex| provides mappings that change, delete and toggle commands, + Vimtex provides mappings that change, delete and toggle commands, delimiters and environments (see the `ds`, `cs` and `ts` family of mappings listed under |vimtex-default-mappings|). These mappings are inspired by the great `surround.vim` [0] (|surround.txt|) by Tim Pope, @@ -382,7 +376,7 @@ Manipulate surrounding commands/delimiters/environments~ Enhanced matching and higlighting of delimiters~ *vimtex-nf-enhanced-matchparen* - |vimtex| highlights and allows navigation between matching pairs of + Vimtex highlights and allows navigation between matching pairs of delimiters including those in math mode, such as `\bigl(` and `\bigr)`, and the `\begin` and `\end` tags of environments. However, the implementation may be slow (see also |vimtex-faq-slow-matchparen|, and so one may use @@ -397,7 +391,7 @@ Enhanced matching and higlighting of delimiters~ - `\item`s in `itemize` and `enumerate` environments - `\toprule`, `\midrule`, `\bottomrule` in the `tabular` environment. - `\if`, `\else` and `\endif` - Note: |vimtex| does not support highlighting the middle delimiters. + Note: Vimtex does not support highlighting the middle delimiters. - Adds motions, `g%`, `[%`, and `]%` and text objects, `a%` and `i%` which move between matching delimiters and operate on delimited text. @@ -474,7 +468,7 @@ Formatting~ Filetype plugin for bib files~ *vimtex-nf-ftplugin-bib* - |vimtex| is not a filetype plugin for bibliography (`.bib`) files. However, + Vimtex is not a filetype plugin for bibliography (`.bib`) files. However, it does include a couple of minor things, such as setting the 'comments' and 'commentstring' options and a simple indentation expression, see |g:vimtex_indent_bib_enabled|. @@ -513,7 +507,7 @@ Language server / texlab~ ------------------------------------------------------------------------------ SUPPORT FOR MULTI-FILE PROJECTS *vimtex-multi-file* -|vimtex| supports most multi-file documents. The main method uses a recursive +Vimtex supports most multi-file documents. The main method uses a recursive search algorithm that should find the main LaTeX file in most cases. For special cases, there are several alternative methods for specifying the main file. These alternative methods all require some explicit declaration of the @@ -557,7 +551,7 @@ TeX root directive~ *vimtex-subfiles* *vimtex-import* Subfiles package~ - |vimtex| also supports the `import` [0] and the `subfiles` [1] packages that + Vimtex also supports the `import` [0] and the `subfiles` [1] packages that can be used to make it easier to work with multi-file projects. If one uses the `subfiles` package, the |VimtexToggleMain| command is particularly useful. Also note the option |g:vimtex_subfile_start_local|, which can be @@ -629,7 +623,7 @@ Recursive search~ ------------------------------------------------------------------------------ SUPPORT FOR TEX DIRECTIVES *vimtex-tex-directives* -|vimtex| supports two of the commonly used TeX directives [0]: the TeX root and +Vimtex supports two of the commonly used TeX directives [0]: the TeX root and the TeX program directive. The TeX root directive was already described above, see |vimtex-tex-root|. @@ -692,7 +686,7 @@ USAGE *vimtex-usage* ------------------------------------------------------------------------------ DEFAULT MAPPINGS *vimtex-default-mappings* -|vimtex| is designed to be controlled by a selection of mappings. Note, +Vimtex is designed to be controlled by a selection of mappings. Note, though, that most of the mappings are also available as commands, see |vimtex-commands|. @@ -716,7 +710,7 @@ are valid. See |map-modes| for an explanation of the various modes. The indicator refers to the prefix of the corresponding map command, e.g. `n` refers to an |nmap|, `nx` refers to both |nmap| and |xmap|, and so on. -In addition to the mappings listed below, |vimtex| provides convenient insert +In addition to the mappings listed below, Vimtex provides convenient insert mode mappings to make it easier and faster to type mathematical equations. This feature is explained in more detail later, see |vimtex-imaps|. @@ -800,12 +794,12 @@ This feature is explained in more detail later, see |vimtex-imaps|. OPTIONS *vimtex-options* *g:vimtex_enabled* - Set to 0 to disable |vimtex|. + Set to 0 to disable Vimtex. Default value: Undefined. *g:vimtex_cache_root* - Specify the cache directory for |vimtex|. + Specify the cache directory for Vimtex. Default value: `'$XDG_CACHE_HOME/vimtex'` if `$XDG_CACHE_HOME` is defined @@ -1066,7 +1060,7 @@ OPTIONS *vimtex-options* should work well for most people. *g:vimtex_complete_enabled* - Use this option to disable/enable |vimtex| completion. + Use this option to disable/enable Vimtex completion. Default value: 1 @@ -1182,7 +1176,7 @@ OPTIONS *vimtex-options* *g:vimtex_delim_list* A dictionary that defines the pairs of delimiters that are recognized by - |vimtex| for various commands and functions. The dictionary contains 5 sub + Vimtex for various commands and functions. The dictionary contains 5 sub dictionaries: `env_tex` Pairs of environment delimiters in normal TeX mode @@ -1369,7 +1363,7 @@ OPTIONS *vimtex-options* *g:vimtex_echo_verbose_input* For the set of operator mappings that change a surrounding type [0], - |vimtex| by default prints some information about what you are doing while + Vimtex by default prints some information about what you are doing while waiting for user input. For advanced/experienced users, one will not need this info and can get a slightly clearner UI by disabling this feature (set the option 0). @@ -1400,7 +1394,7 @@ OPTIONS *vimtex-options* Default value: 0 *g:vimtex_fold_manual* - With this option enabled, |vimtex| uses |fold-manual| as the main + With this option enabled, Vimtex uses |fold-manual| as the main |foldmethod|. It still uses the |foldexpr| function to compute the fold levels, but it only computes the fold levels on demand, see |VimtexRefreshFolds| and |vimtex-zx|. @@ -1605,7 +1599,7 @@ OPTIONS *vimtex-options* \} *g:vimtex_format_enabled* - If enabled, |vimtex| uses a custom |formatexpr| that should handle inline + If enabled, Vimtex uses a custom |formatexpr| that should handle inline comments and environments. That is, if it is enabled, comments at end of lines will not be joined with the |gq| command, and environments like `equation` will not be joined/changed. @@ -1744,12 +1738,12 @@ OPTIONS *vimtex-options* Default value: 1 *g:vimtex_indent_enabled* - Use this option to disable/enable |vimtex| indentation. + Use this option to disable/enable Vimtex indentation. Default value: 1 *g:vimtex_indent_bib_enabled* - Use this option to disable/enable |vimtex| indentation of bibliography files. + Use this option to disable/enable Vimtex indentation of bibliography files. Default value: 1 @@ -1853,7 +1847,7 @@ OPTIONS *vimtex-options* Note: This is an improved version of |matchparen|. It should be possible to keep |matchparen| activated, which matches delimiters listed in - 'matchpairs'. The |vimtex| specific version will also match LaTeX + 'matchpairs'. The Vimtex specific version will also match LaTeX specific delimiters, which is not possible with |matchparen|. Note: If you think this feature is slow, see |vimtex-faq-slow-matchparen|. @@ -1992,53 +1986,113 @@ OPTIONS *vimtex-options* Default value: 1. +*g:vimtex_syntax_autoload_packages* + Specify list of syntax packages to load on start. See |vimtex-syntax-packages| + for more info. + + Default value: ['amsmath'] + +*g:vimtex_syntax_conceal* + A dictionary for specifying which core conceal features to activate. This + mostly implies concealing particular elements with a replacement unicode + character. See |conceallevel| for more info on this Vim feature. The + following keys are available: + + accents~ + Replace TeX accents into the accented character, e.g. `\aa` -> å. This + will also replace a few ligatures. + + greek~ + Replace TeX greek letter commands into the equivalent unicode greek + letter. + + math_bounds~ + Conceal the TeX math bounds characters: pairs of `$` and `$$`, `\(` ... + `\)`, and `\[` ... `\]`. + + math_delimiters~ + Replace possibly modified math delimiters with a single unicode + letter. Modified means delimiters prepended with e.g. `\left` or + `\bigl`. As an example, this will perform the replacement + + `\Biggl\langle ... \Biggr\rangle` --> `〈 ... 〉` + + math_super_sub~ + Replace simple math super and sub operators, e.g. `x^2` --> `x²`. + + math_symbols~ + Replace various math symbol commands to an equivalent unicode character. + + styles~ + Conceal the LaTeX command "boundaries" for italized and bolded style + commands, i.e. `\emph`, `\textit`, and `\textbf`. This means that one + will see something like: + + `\emph{text here}` --> `text here` + + Default value: All keys set to |g:vimtex_syntax_conceal_default|. + +*g:vimtex_syntax_conceal_default* + Specify the default flag for the conceal feature. This is used e.g. in + |vimtex_syntax_conceal| and for package specific options in + |vimtex_syntax_packages|. + + Default value: 1 + *g:vimtex_syntax_nested* - A dictionary for configuring nested syntaxes. Has two keys: `aliases` and - `ignored`. + A dictionary for configuring nested syntaxes. The following keys are + available for configuration: - The `aliases` key holds a dictionary of aliases, such as mapping `C` to `c`. - This is useful e.g. because the Vim syntax files are case sensitive. + aliases~ + Holds a dictionary of aliases, such as mapping `C` to `c`. This is + useful e.g. because the Vim syntax files are case sensitive. - The `ignored` key holds a dictionary of ignore lists for each language. This - is useful to ignore some groups that may conflict in e.g. the `\begin{...}` - or `\end{...}` part of the nested syntax regions. + ignored~ + Holds a dictionary of ignore lists for each language. This is useful to + ignore some groups that may conflict in e.g. the `\begin{...}` or + `\end{...}` part of the nested syntax regions. Default value: > let g:vimtex_syntax_nested = { - \ 'aliases' : { - \ 'C' : 'c', - \ 'csharp' : 'cs', - \ }, - \ 'ignored' : { - \ 'cs' : [ - \ 'csBraces', - \ ], - \ 'python' : [ - \ 'pythonEscape', - \ 'pythonBEscape', - \ 'pythonBytesEscape', - \ ], - \ 'java' : [ - \ 'javaError', - \ ], - \ 'haskell' : [ - \ 'hsVarSym', - \ ], - \ } - \} - -*g:vimtex_syntax_autoload_packages* - Specify list of syntax packages to load on start. See |vimtex-syntax-packages| - for more info. - - Default value: ['amsmath'] + \ 'aliases' : { + \ 'C' : 'c', + \ 'csharp' : 'cs', + \ }, + \ 'ignored' : { + \ 'cs' : [ + \ 'csBraces', + \ ], + \ 'python' : [ + \ 'pythonEscape', + \ 'pythonBEscape', + \ 'pythonBytesEscape', + \ ], + \ 'java' : [ + \ 'javaError', + \ ], + \ 'haskell' : [ + \ 'hsVarSym', + \ ], + \ } + \} *g:vimtex_syntax_nospell_commands* A list of commands whose argument should be excluded from spell checking. Default value: [] +*g:vimtex_syntax_packages* + A dictionary for package specific configuration. The following keys are + currently available: + + babel~ + Dictionary. Default value: > + + { + 'conceal': g:vimtex_syntax_conceal_default + } + *g:vimtex_texcount_custom_arg* Option that makes it possible to add custom arguments to `texcount` for |VimtexCountWords| and |VimtexCountLetters|. @@ -2296,7 +2350,7 @@ OPTIONS *vimtex-options* Whether or not to sort the TODOs at the top of the ToC window. *g:vimtex_view_enabled* - Use this option to disable/enable the |vimtex| viewer interface. + Use this option to disable/enable the Vimtex viewer interface. Default value: 1 @@ -2306,7 +2360,7 @@ OPTIONS *vimtex-options* is disabled. `latexmk` will typically start the viewer directly. However, with this - option enabled, |vimtex| will start the viewer through callbacks also for + option enabled, Vimtex will start the viewer through callbacks also for the |vimtex-latexrun|, |vimtex-arara| and |vimtex-tectonic| compilers. Default value: 1 @@ -2746,8 +2800,8 @@ COMMANDS *vimtex-commands* *VimtexReload* *(vimtex-reload)* -:VimtexReload Reload |vimtex| scripts. This is primarely useful - when developing and debugging |vimtex| itself. +:VimtexReload Reload Vimtex scripts. This is primarely useful + when developing and debugging Vimtex itself. *VimtexReloadState* *(vimtex-reload-state)* @@ -2797,7 +2851,7 @@ COMMANDS *vimtex-commands* *VimtexToggleMain* *(vimtex-toggle-main)* -:VimtexToggleMain In general, |vimtex| detects the main file for the +:VimtexToggleMain In general, Vimtex detects the main file for the current LaTeX project and uses it for compilation and many other features. However, in some cases it may be useful to instead focus on the current file, @@ -2820,8 +2874,8 @@ COMMANDS *vimtex-commands* MAP DEFINITIONS *vimtex-mappings* *vimtex-zx* - When |vimtex| folding is enabled and when the manual mode is turned on - (|g:vimtex_fold_manual|), then |vimtex| remaps |zx| and |zX| in such that + When Vimtex folding is enabled and when the manual mode is turned on + (|g:vimtex_fold_manual|), then Vimtex remaps |zx| and |zX| in such that the folds are refreshed appropriately. *(vimtex-env-delete)* @@ -3005,7 +3059,7 @@ object, see |text-objects|. INSERT MODE MAPPINGS *vimtex-imaps* Some LaTeX commands are very common, and so it is both natural and convenient -to have insert mode mappings/abbreviations for them. |vimtex| therefore +to have insert mode mappings/abbreviations for them. Vimtex therefore provides a list of such mappings that are enabled by default, see |g:vimtex_imaps_list|. The mappings utilize a map leader defined by |g:vimtex_imaps_leader|. The default list of maps are all math mode mappings, @@ -3057,7 +3111,7 @@ Explanation of the keys: wrapper~ The name of a wrapper function that is used to generate the `rhs`. Two - functions are available from |vimtex|: + functions are available from Vimtex: `vimtex#imaps#wrap_trivial` Trivial wrapper: Simply returns `rhs`. @@ -3080,7 +3134,7 @@ Explanation of the keys: expands to different `rhs`s in different environments. Of course, one may use custom wrapper functions. To write a custom wrapper - function, please see the source for examples on how the |vimtex| wrappers + function, please see the source for examples on how the Vimtex wrappers are written. context~ @@ -3089,9 +3143,9 @@ Explanation of the keys: *vimtex-neosnippet* *vimtex-UltiSnips* Note: that this feature is not the same as the snippet feature of |UltiSnips| -or |neosnippet|. The imaps feature of |vimtex| previously supported `automatic` +or |neosnippet|. The imaps feature of Vimtex previously supported `automatic` snippets, but these have been removed after careful considerations and input -from |vimtex| users, please see vimtex issue #295: +from Vimtex users, please see vimtex issue #295: https://github.com/lervag/vimtex/issues/295#issuecomment-164262446 It has been decided that the best approach is to only provide basic mappings, and to let users manully create automatic snippets through the anonymous @@ -3116,7 +3170,7 @@ therefore a better approach than using the anonymous snippet function. ------------------------------------------------------------------------------ EVENTS *vimtex-events* -|vimtex| defines some events using the |User| autocmd that may be used for +Vimtex defines some events using the |User| autocmd that may be used for further customization. *VimtexEventQuit* @@ -3136,7 +3190,7 @@ further customization. *VimtexEventInitPre* *VimtexEventInitPost* - This event is triggered at the start/end of |vimtex| initialization. The + This event is triggered at the start/end of Vimtex initialization. The post event may e.g. be used to automatically start compiling a document. *VimtexEventCompileStarted* @@ -3206,7 +3260,7 @@ Examples: > ============================================================================== COMPLETION *vimtex-completion* -If |g:vimtex_complete_enabled| is 1 (default), then |vimtex| sets the +If |g:vimtex_complete_enabled| is 1 (default), then Vimtex sets the 'omnifunc' to provide omni completion, see |compl-omni|. Omni completion is then accessible with |i_CTRL-X_CTRL-O|. @@ -3353,7 +3407,7 @@ several good plugins that provide this: |coc-nvim|, |deoplete|, |neocomplete|, | |nvim-completion-manager| and |youcompleteme|. Moreover, there is |VimCompletesMe| that overrides to trigger different built-in completions, such as the omni-completion by vimtex, depending on the context. See below for -descriptions on how to setup these with |vimtex|. +descriptions on how to setup these with Vimtex. coc.nvim~ *vimtex-complete-coc.nvim* @@ -3412,7 +3466,7 @@ active development has been stopped. Users are recommended to change to https://github.com/Shougo/neocomplete.vim. The following options may be used to enable automatic completion for LaTeX -documents with |neocomplete| and |vimtex|s omni completion function: > +documents with |neocomplete| and Vimtex's omni completion function: > if !exists('g:neocomplete#sources#omni#input_patterns') let g:neocomplete#sources#omni#input_patterns = {} @@ -3563,7 +3617,7 @@ suitable to the current contex. The plugin is available here: https://github.com/ajh17/VimCompletesMe. The following options may be used to enable completion with the trigger -for LaTeX documents with |VimCompletesMe| and |vimtex|s omni completion function: > +for LaTeX documents with |VimCompletesMe| and Vimtex's omni completion function: > augroup VimCompletesMeTex autocmd! @@ -3574,7 +3628,7 @@ for LaTeX documents with |VimCompletesMe| and |vimtex|s omni completion function ============================================================================== FOLDING *vimtex-folding* -|vimtex| can fold documents according to the LaTeX structure (part, chapter, +Vimtex can fold documents according to the LaTeX structure (part, chapter, section and subsection). Folding is turned off by default, but it can be enabled if desired, either through the option |g:vimtex_fold_enabled|, or manually with > @@ -3610,7 +3664,7 @@ Associated settings: INDENTATION *vimtex-indent* *vimtex-bib-indent* -|vimtex| provides custom indentation functions both for LaTeX documents and +Vimtex provides custom indentation functions both for LaTeX documents and for bibliography files (`.bib` files). Associated settings: @@ -3624,7 +3678,7 @@ Associated settings: ============================================================================== SYNTAX HIGHLIGHTING *vimtex-syntax* -|vimtex| provides a core syntax plugin that should generally work well out of +Vimtex provides a core syntax plugin that should generally work well out of the box. It includes package specific syntax highlighting for a lot of different packages, e.g.: @@ -3662,10 +3716,10 @@ Associated settings: NAVIGATION *vimtex-navigation* Vim already has a lot of useful navigation related features, such as -|tags-and-searches| and |include-search|. |vimtex| improves the latter feature +|tags-and-searches| and |include-search|. Vimtex improves the latter feature by setting the 'include' and 'includeexpr' options, see |vimtex-includeexpr|. -|vimtex| also provides a separate table-of-content feature. This works by +Vimtex also provides a separate table-of-content feature. This works by parsing the LaTeX project and displaying a table of contents in a separate window. For more info, see |vimtex-toc|. @@ -3677,7 +3731,7 @@ to write custom sources or sources for other, similar plugins. ------------------------------------------------------------------------------ INCLUDE EXPRESSION *vimtex-includeexpr* -|vimtex| provides an advanced |includeexpr| that makes it possible to open +Vimtex provides an advanced |includeexpr| that makes it possible to open source files for e.g. packages and documentclasses with the |gf| command. The implementation relies on `kpsewhich` to find the source files. Consider the following example: > @@ -3773,14 +3827,14 @@ DENITE AND UNITE SOURCES *vimtex-denite* https://github.com/Shougo/denite.nvim https://github.com/Shougo/unite.vim |denite.nvim| is is a popular interface for many things, including outlines. -Although |vimtex| includes a simple interface for a tables of contents, it also +Although Vimtex includes a simple interface for a tables of contents, it also makes sense to provide these as a source to |denite.nvim|. The source name is simply `vimtex`. |unite.vim| is the predecessor to |denite.nvim|. As for denite, there is a source called `vimtex`. -If one prefers the |denite.nvim| or |unite.vim| source to the |vimtex| interface, +If one prefers the |denite.nvim| or |unite.vim| source to the Vimtex interface, one may override the default mapping, e.g.: > nnoremap lt :Denite vimtex @@ -3793,7 +3847,7 @@ FZF INTEGRATION *vimtex-fzf* https://github.com/junegunn/fzf |fzf.vim| integrates the general-purpose command-line fuzzy finder |fzf| into vim and neovim. Similar to the |denite.vim| and |unite.vim| source it may be used to -quickly navigate |vimtex|'s built-in ToC feature. To use it, just define a +quickly navigate Vimtex's built-in ToC feature. To use it, just define a mapping to `vimtex#fzf#run()` in your .vimrc, e.g.: > nnoremap lt :call vimtex#fzf#run() @@ -3824,7 +3878,7 @@ example, if you've defined `g:fzf_layout`, then those options can be passed to ============================================================================== COMPILER *vimtex-compiler* -|vimtex| provides an interface to the following LaTeX compilers/compiler +Vimtex provides an interface to the following LaTeX compilers/compiler backends: |vimtex-latexmk| http://users.phys.psu.edu/~collins/software/latexmk-jcc @@ -3896,7 +3950,7 @@ LATEXMK *vimtex-latexmk* > MS-WINDOWS (XP, etc). `latexmk` is a compiler backend that handles recompilation of LaTeX documents -when source files have been changed. |vimtex| uses the continuous mode by +when source files have been changed. Vimtex uses the continuous mode by default, but `latexmk` also allows single shot compilations. The compiler may be configured through the |g:vimtex_compiler_latexmk| option. @@ -3914,7 +3968,7 @@ particular things in a configuration file. A particular set of options are very convenient for a good coupling between `latexmk` and Vim: `$compiling_cmd`, `$success_cmd`, and `$failure_cmd`. These options can be used to specify commands that are run by `latexmk` before and after -compilation. This is used by |vimtex| to achieve callbacks after compilation +compilation. This is used by Vimtex to achieve callbacks after compilation has finished with something like this: > $success_cmd = "gvim --remote-expr 'vimtex#compiler#callback(1)'"; @@ -3931,8 +3985,8 @@ the viewer to indicate the compilation status: > "set_window --name \"%D FAILURE\""; Note: If you define these options similar to the above `xdotool` trick and - still want to enable the |vimtex| callbacks, then one must include - a semicolon at the end of the `cmd` strings so that |vimtex| may append + still want to enable the Vimtex callbacks, then one must include + a semicolon at the end of the `cmd` strings so that Vimtex may append safely to the options. Note: More info on `xdotool` here: https://www.semicomplete.com/projects/xdotool. @@ -3971,7 +4025,7 @@ to see the compilation output. As for |vimtex-latexrun| and |vimtex-arara|, the viewer can be started automatically with |g:vimtex_view_automatic|. `tectonic` cleans up intermediate files like `.aux` and log files by default. -However, |vimtex|'s backend invoke it with the flags `--keep-logs` and +However, Vimtex's backend invoke it with the flags `--keep-logs` and `--keep-synctex` which enables us to see the errors on the quickfix and it gives us synctex support. Therefor, by default, |(vimtex-clean)| and |VimtexClean| clean these files. @@ -4006,7 +4060,7 @@ Note: It is not possible to directly specify an output directory from vimtex. ============================================================================== SYNTAX CHECKING (LINTING) *vimtex-lint* -|vimtex| provides syntax checking (linting) for TeX and BibTeX files through +Vimtex provides syntax checking (linting) for TeX and BibTeX files through three compilers: `lacheck` [1], `chktex` [2], and `biber` [3]. 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 the following @@ -4089,7 +4143,7 @@ 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 the |compiler-select| +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 @@ -4169,7 +4223,7 @@ Note: Spell checking with `LanguageTool` is only enabled if a country code is ============================================================================== VIEW *vimtex-view* -|vimtex| provides the command |VimtexView| to open the desired viewer. The +Vimtex provides the command |VimtexView| to open the desired viewer. The command is mapped to 'lv' by default. The list of supported viewers are given in the description of |g:vimtex_view_method|. @@ -4247,7 +4301,7 @@ Note: For backward search to work on windows, one must ensure that the folder ============================================================================== LATEX DOCUMENTATION *vimtex-latexdoc* -|vimtex| provides the command |VimtexDocPackage| to open documentation for +Vimtex provides the command |VimtexDocPackage| to open documentation for packages and documentclasses. The command is mapped to `K` by default, and by default package documentation is looked up through http://texdoc.net/. This can be customized through |g:vimtex_doc_handlers|. @@ -4303,7 +4357,7 @@ since it may be easily downloaded in various formats from [8]. ============================================================================== CONTEXT MENU *vimtex-context-menu* -|vimtex| provides the command |VimtexContextMenu| to open a context menu for +Vimtex provides the command |VimtexContextMenu| to open a context menu for the item below the cursor. The menu allows various actions relevant to the current context. It is mapped by default to ``. @@ -4341,7 +4395,7 @@ Possible actions: ============================================================================== CODE STRUCTURE *vimtex-code* -The |vimtex| code is based on the |autoload| feature of vim. For each new +The Vimtex code is based on the |autoload| feature of vim. For each new latex buffer, the function *vimtex#init* initializes a state variable as well as buffer local mappings and commands, all based on the desired options (see |vimtex-options|). @@ -4394,10 +4448,10 @@ A: Set |g:vimtex_view_method| to `skim` (and read |vimtex_viewer_skim| if you https://sourceforge.net/p/skim-app/wiki/TeX_and_PDF_Synchronization *vimtex-faq-surround* -Q: |vimtex| provides `dse`, `dsc`, `cse`, and `csc`. These seem to be inspired by - |surround.vim|. Does |vimtex| also provide the corresponding `yse` and `ysc`? +Q: Vimtex provides `dse`, `dsc`, `cse`, and `csc`. These seem to be inspired by + |surround.vim|. Does Vimtex also provide the corresponding `yse` and `ysc`? A: The mentioned mappings are indeed inspired by |surround.vim|. However, - |vimtex| does not provide `yse` and `ysc`. If you use + Vimtex does not provide `yse` and `ysc`. If you use |surround.vim|, then the asked for mappings may be easily added if one adds the following lines to `~/.vim/after/ftplugin/tex.vim` or any other `ftplugin/tex.vim` in your |runtimepath|: > @@ -4424,7 +4478,7 @@ A: This might be due to the |isfname| setting, which by default contains `{,}` set isfname-={,} < *vimtex-faq-neovim* -Q: Does |vimtex| work with neovim? +Q: Does Vimtex work with neovim? A: Yes, but backward sync requires the `neovim-remote` utility. It may be installed and used by vimtex as follows: @@ -4440,7 +4494,7 @@ A: Yes, but backward sync requires the `neovim-remote` utility. It may be *vimtex-faq-tags* Q: How can I jump from a `\ref{label}` to the corresponding label? -A: This is not a feature provided by |vimtex| itself, but vim has very good +A: This is not a feature provided by Vimtex itself, but vim has very good support for tag navigation, see |tags-and-searches|. It is worth mentioning that the |ctags| support for LaTeX is somewhat lacking. This can be amended by adding some lines to your `~/.ctags` configuration file (or @@ -4459,7 +4513,7 @@ A: This is not a feature provided by |vimtex| itself, but vim has very good *vimtex-faq-tags-bibtex* Q: How can I jump from a `\cite{key}` to the corresponding bibtex entry? -A: This is not a feature provided by |vimtex| itself. Similar to +A: This is not a feature provided by Vimtex itself. Similar to |vimtex-faq-tags|, the feature is available through |tags-and-searches|. The following `~/.ctags` configuration will be useful (or `.ctags.d/default.ctags` if you use Universal ctags): > @@ -4652,11 +4706,11 @@ Note: Plugins like |supertab| [0], which often maps the |i_| key, will ============================================================================== CREDITS *vimtex-credits* -|vimtex| is developed by Karl Yngve Lervåg , and is +Vimtex is developed by Karl Yngve Lervåg , and is distributed under the MIT license. The project is available as a Git repository: https://github.com/lervag/vimtex. -|vimtex| was developed from scratch, but much of the code has been based on +Vimtex was developed from scratch, but much of the code has been based on LaTeX-Box: https://github.com/LaTeX-Box-Team/LaTeX-Box. LaTeX-suite was also an inspiration: http://vim-latex.sourceforge.net/. @@ -4906,7 +4960,7 @@ Deprecated option: *g:latex_viewer* 2014-06-13: Changed some option names~ -Some |vimtex| option names were changed in an attempt to make the names +Some Vimtex option names were changed in an attempt to make the names more consistent. These options are listed here for reference: *g:latex_errorformat_ignore_warnings* *g:latex_errorformat_show_warnings* @@ -4919,9 +4973,9 @@ The new names are, respectively: |g:vimtex_quickfix_mode| 2013-10-05: First public release~ -|vimtex| was first released on github on this date. Initial version was named +Vimtex was first released on github on this date. Initial version was named vim-latex, which conflicted with Vim LaTeX-Suite which is also known as -vim-latex. Some time later, the plugin was renamed to |vimtex|. +vim-latex. Some time later, the plugin was renamed to Vimtex. ============================================================================== vim:tw=78:ts=8:ft=help:norl: From b06b289f6fb7243a05b5483899373658c82b2c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 16 Nov 2020 11:35:55 +0100 Subject: [PATCH 80/99] feat: override ftdetect mechanism Unless the user defines g:tex_flavor! --- doc/vimtex.txt | 26 +++++-------------- plugin/vimtex.vim => ftdetect/tex.vim | 6 ++--- test/examples/book-multifile/minivimrc | 2 -- .../test-compiler-pdfmode/test-pdfps/test.vim | 1 - .../test.vim | 2 -- test/tests/test-delim/test.vim | 2 -- test/tests/test-folding/test.vim | 1 - test/tests/test-formatting/test.vim | 1 - test/tests/test-get-main/test.vim | 2 -- test/tests/test-indentation/test.vim | 1 - test/tests/test-matchparen-speed/test.vim | 2 -- test/tests/test-metadata/test-sources.vim | 2 -- test/tests/test-motions-virtual/test.vim | 1 - test/tests/test-parser-cmds/test.vim | 2 -- test/tests/test-parser-tex/test_recursive.vim | 2 -- test/tests/test-quickfix-fix-path/test.vim | 2 -- test/tests/test-quickfix/test.vim | 2 -- test/tests/test-state/test_builddir.vim | 2 -- test/tests/test-state/test_modified-quit.vim | 2 -- test/tests/test-state/test_no-hidden.vim | 2 -- test/tests/test-state/test_reload.vim | 2 -- test/tests/test-state/test_reopen.vim | 2 -- test/tests/test-state/test_toggle-main.vim | 2 -- test/tests/test-syntax/common.vim | 2 -- test/tests/test-texflavor/test-defined.vim | 19 ++++---------- test/tests/test-texflavor/test-undefined.vim | 17 +++--------- test/tests/test-textobj-targets/test.vim | 2 -- 27 files changed, 17 insertions(+), 92 deletions(-) rename plugin/vimtex.vim => ftdetect/tex.vim (52%) diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 2faec1aeea..c23aaf3187 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -115,25 +115,13 @@ file $VIMRUNTIME/indent/tex.vim for the documentation), and some sensible options (|ft-tex-plugin|). *vimtex-tex-flavor* -When Vimtex is active, it will by default override the internal TeX plugin. In -particular, Vimtex is loaded when the 'filetype' is set to `tex`. This is -usually the case for most files with the `.tex` extension. However, the `.tex` -extension is ambiguous in that it may be used for both plain TeX, ConTeXt, and -LaTeX files. The built-in |ft-tex-plugin| provides an |ftdetect| mechanism for -detecting the filetype by looking at the top lines of a file. In most cases, -the filetype is specified as `tex`, but by default it will fall back to -`plaintex`. To prevent this behaviour and ensure that Vimtex is loaded for all -`.tex` files, one should set the |g:tex_flavor| option to `'latex'`. As this -behaviour may be surprising to a lot of people, Vimtex will give a warning if -it is installed and if the |g:tex_flavor| option is not defined. In most -cases, you want to set: > - - let g:tex_flavor = 'latex' - -Some people may want to keep the default behaviour. If so, one may explicitly -set the default value: > - - let g:tex_flavor = 'plain' +When Vimtex is active, it will override the internal TeX plugin for the +filetype `tex` (|ft-tex-plugin|), both for syntax highlighting and for +filetype specific features. To prevent the unexpected behaviour where `.tex` +files by default will be recognized as the filetype `plaintex` +(|ft-plaintex-syntax|) for e.g. empty documents, Vimtex overrides the filetype +detection for `.tex`. The user may prevent this overriding by specifying the +|g:tex_flavor| option something different than `'latex'`. ----------------------------------------------------------------------------- FEATURE OVERVIEW *vimtex-features* diff --git a/plugin/vimtex.vim b/ftdetect/tex.vim similarity index 52% rename from plugin/vimtex.vim rename to ftdetect/tex.vim index 13b99c31e1..80900ada2a 100644 --- a/plugin/vimtex.vim +++ b/ftdetect/tex.vim @@ -5,10 +5,8 @@ " if !get(g:, 'vimtex_enabled', 1) + \ || get(g:, 'tex_flavor', 'latex') !=# 'latex' finish endif -if !exists('g:tex_flavor') - call vimtex#log#warning(['g:tex_flavor not specified', - \ 'Please read :help vimtex-tex-flavor!']) -endif +autocmd BufNewFile,BufRead *.tex set filetype=tex diff --git a/test/examples/book-multifile/minivimrc b/test/examples/book-multifile/minivimrc index aab5b774c9..3d93880b52 100644 --- a/test/examples/book-multifile/minivimrc +++ b/test/examples/book-multifile/minivimrc @@ -6,8 +6,6 @@ syntax enable nnoremap q :qall! -let g:tex_flavor = 'latex' - let g:vimtex_toc_config = { \ 'layer_status' : {'include' : 0}, \ 'layer_keys' : {'content' : ''}, diff --git a/test/tests/test-compiler-pdfmode/test-pdfps/test.vim b/test/tests/test-compiler-pdfmode/test-pdfps/test.vim index c6bf08cd3f..19f0bf8b22 100644 --- a/test/tests/test-compiler-pdfmode/test-pdfps/test.vim +++ b/test/tests/test-compiler-pdfmode/test-pdfps/test.vim @@ -6,7 +6,6 @@ nnoremap q :qall! set nomore -let g:tex_flavor = 'latex' let g:vimtex_view_automatic = 0 if empty($INMAKE) diff --git a/test/tests/test-completion-glossary-texinputs/test.vim b/test/tests/test-completion-glossary-texinputs/test.vim index 41f21754ad..445c413340 100644 --- a/test/tests/test-completion-glossary-texinputs/test.vim +++ b/test/tests/test-completion-glossary-texinputs/test.vim @@ -6,8 +6,6 @@ syntax enable nnoremap q :qall! -let g:tex_flavor = 'latex' - let g:vimtex_cache_persistent = 0 silent edit texwork/example.tex diff --git a/test/tests/test-delim/test.vim b/test/tests/test-delim/test.vim index 6df8493e4f..7393c15dc0 100644 --- a/test/tests/test-delim/test.vim +++ b/test/tests/test-delim/test.vim @@ -5,8 +5,6 @@ syntax on nnoremap q :qall! -let g:tex_flavor = 'latex' - silent edit test.tex normal! G diff --git a/test/tests/test-folding/test.vim b/test/tests/test-folding/test.vim index 2437283a98..7bf3010709 100644 --- a/test/tests/test-folding/test.vim +++ b/test/tests/test-folding/test.vim @@ -8,7 +8,6 @@ set foldcolumn=4 nnoremap q :qall! -let g:tex_flavor = 0 let g:vimtex_fold_enabled = 1 let g:vimtex_fold_types = {'comments' : {'enabled': 1}} diff --git a/test/tests/test-formatting/test.vim b/test/tests/test-formatting/test.vim index 90d60f7822..a153378b9a 100644 --- a/test/tests/test-formatting/test.vim +++ b/test/tests/test-formatting/test.vim @@ -10,7 +10,6 @@ set textwidth=79 set nojoinspaces set shiftwidth=2 -let g:tex_flavor = 'latex' let g:vimtex_format_enabled = 1 let s:file = empty($FILE) ? 'test-01' : $FILE diff --git a/test/tests/test-get-main/test.vim b/test/tests/test-get-main/test.vim index 92da818785..ce3ca9b432 100644 --- a/test/tests/test-get-main/test.vim +++ b/test/tests/test-get-main/test.vim @@ -4,8 +4,6 @@ filetype plugin on set nomore -let g:tex_flavor = 'latex' - " Ugly paths call vimtex#test#main('test-ugly-paths/[code college-1] title/test.tex', \ 'test-ugly-paths/[code college-1] title/test.tex') diff --git a/test/tests/test-indentation/test.vim b/test/tests/test-indentation/test.vim index 2764f43a95..5abd7c788e 100644 --- a/test/tests/test-indentation/test.vim +++ b/test/tests/test-indentation/test.vim @@ -7,7 +7,6 @@ nnoremap q :qall! set nomore set shiftwidth=2 set expandtab -let g:tex_flavor = 'latex' if !empty($FLAGS) if $FLAGS == 1 diff --git a/test/tests/test-matchparen-speed/test.vim b/test/tests/test-matchparen-speed/test.vim index f98244cd48..579a720635 100644 --- a/test/tests/test-matchparen-speed/test.vim +++ b/test/tests/test-matchparen-speed/test.vim @@ -8,8 +8,6 @@ set noswapfile nnoremap q :qall! -let g:tex_flavor = 'latex' - " let g:vimtex_matchparen_enabled = 0 " let g:vimtex_delim_stopline = 1000 " let g:vimtex_delim_timeout = 100 diff --git a/test/tests/test-metadata/test-sources.vim b/test/tests/test-metadata/test-sources.vim index cd45e47f99..c9eb79d012 100644 --- a/test/tests/test-metadata/test-sources.vim +++ b/test/tests/test-metadata/test-sources.vim @@ -2,8 +2,6 @@ set nocompatible let &rtp = '../../..,' . &rtp filetype plugin on -let g:tex_flavor = 'latex' - silent edit test-sources/main.tex call vimtex#test#assert_equal([ diff --git a/test/tests/test-motions-virtual/test.vim b/test/tests/test-motions-virtual/test.vim index 9459975583..fe1ad54d1c 100644 --- a/test/tests/test-motions-virtual/test.vim +++ b/test/tests/test-motions-virtual/test.vim @@ -8,7 +8,6 @@ set nomore nnoremap q :qall! -let g:tex_flavor = 'latex' " let g:vimtex_matchparen_enabled = 0 silent edit test.tex diff --git a/test/tests/test-parser-cmds/test.vim b/test/tests/test-parser-cmds/test.vim index 9e38132823..b26d433292 100644 --- a/test/tests/test-parser-cmds/test.vim +++ b/test/tests/test-parser-cmds/test.vim @@ -4,8 +4,6 @@ filetype plugin on nnoremap q :qall! -let g:tex_flavor = 'latex' - silent edit test.tex if empty($INMAKE) | finish | endif diff --git a/test/tests/test-parser-tex/test_recursive.vim b/test/tests/test-parser-tex/test_recursive.vim index 14a9e0cd6f..819ffcd46c 100644 --- a/test/tests/test-parser-tex/test_recursive.vim +++ b/test/tests/test-parser-tex/test_recursive.vim @@ -7,8 +7,6 @@ set hidden nnoremap q :qall! -let g:tex_flavor = 'latex' - if empty($INMAKE) | finish | endif silent! edit test_recursive.tex diff --git a/test/tests/test-quickfix-fix-path/test.vim b/test/tests/test-quickfix-fix-path/test.vim index d28329dd7d..13ac961704 100644 --- a/test/tests/test-quickfix-fix-path/test.vim +++ b/test/tests/test-quickfix-fix-path/test.vim @@ -6,8 +6,6 @@ nnoremap q :qall! set nomore -let g:tex_flavor = 'latex' - silent edit main.tex if empty($INMAKE) | finish | endif diff --git a/test/tests/test-quickfix/test.vim b/test/tests/test-quickfix/test.vim index fbd15781cc..2712e687c3 100644 --- a/test/tests/test-quickfix/test.vim +++ b/test/tests/test-quickfix/test.vim @@ -6,8 +6,6 @@ nnoremap q :qall! set nomore -let g:tex_flavor = 'latex' - let g:vimtex_view_automatic = 0 if has('nvim') let g:vimtex_compiler_progname = 'nvr' diff --git a/test/tests/test-state/test_builddir.vim b/test/tests/test-state/test_builddir.vim index 6f9526975a..2d6d1ba2aa 100644 --- a/test/tests/test-state/test_builddir.vim +++ b/test/tests/test-state/test_builddir.vim @@ -4,8 +4,6 @@ filetype plugin on nnoremap q :qall! -let g:tex_flavor = 'latex' - function! TestBuildDir(expected) abort silent edit test.tex let l:build_dir = vimtex#paths#shorten_relative( diff --git a/test/tests/test-state/test_modified-quit.vim b/test/tests/test-state/test_modified-quit.vim index 72a6e53a4f..da41421bde 100644 --- a/test/tests/test-state/test_modified-quit.vim +++ b/test/tests/test-state/test_modified-quit.vim @@ -6,8 +6,6 @@ set nomore nnoremap q :qall! -let g:tex_flavor = 'latex' - if empty($INMAKE) | finish | endif let g:test = 0 diff --git a/test/tests/test-state/test_no-hidden.vim b/test/tests/test-state/test_no-hidden.vim index 78f970ed07..c7b66bd37d 100644 --- a/test/tests/test-state/test_no-hidden.vim +++ b/test/tests/test-state/test_no-hidden.vim @@ -6,8 +6,6 @@ set nomore nnoremap q :qall! -let g:tex_flavor = 'latex' - if empty($INMAKE) | finish | endif silent edit minimal.tex diff --git a/test/tests/test-state/test_reload.vim b/test/tests/test-state/test_reload.vim index 4430b5b9ff..0f8a54641d 100644 --- a/test/tests/test-state/test_reload.vim +++ b/test/tests/test-state/test_reload.vim @@ -7,8 +7,6 @@ set hidden nnoremap q :qall! -let g:tex_flavor = 'latex' - if empty($INMAKE) | finish | endif silent edit test_reload.cls diff --git a/test/tests/test-state/test_reopen.vim b/test/tests/test-state/test_reopen.vim index 80d8bc5073..0c1ce2da61 100644 --- a/test/tests/test-state/test_reopen.vim +++ b/test/tests/test-state/test_reopen.vim @@ -6,8 +6,6 @@ set nomore nnoremap q :qall! -let g:tex_flavor = 'latex' - if empty($INMAKE) | finish | endif silent edit minimal.tex diff --git a/test/tests/test-state/test_toggle-main.vim b/test/tests/test-state/test_toggle-main.vim index 58859dcba2..cbeea1be9a 100644 --- a/test/tests/test-state/test_toggle-main.vim +++ b/test/tests/test-state/test_toggle-main.vim @@ -6,8 +6,6 @@ set nomore nnoremap q :qall! -let g:tex_flavor = 'latex' - if empty($INMAKE) | finish | endif " Open included file should create two states (main and included) diff --git a/test/tests/test-syntax/common.vim b/test/tests/test-syntax/common.vim index ea19073d3b..84c940cd60 100644 --- a/test/tests/test-syntax/common.vim +++ b/test/tests/test-syntax/common.vim @@ -5,8 +5,6 @@ syntax enable set nomore -let g:tex_flavor = 'latex' - nnoremap q :qall! " Use a more colorful colorscheme diff --git a/test/tests/test-texflavor/test-defined.vim b/test/tests/test-texflavor/test-defined.vim index 86d4a978e5..0783713302 100644 --- a/test/tests/test-texflavor/test-defined.vim +++ b/test/tests/test-texflavor/test-defined.vim @@ -1,19 +1,10 @@ +let g:tex_flavor = 'plain' + set nocompatible let &rtp = '../../..,' . &rtp filetype plugin on -set nomore - -let g:tex_flavor = 3 -let g:vimtex_log_verbose = 0 - -nnoremap q :qall! - -function! Test() abort - silent edit plaintex.tex - let l:entries = vimtex#log#get() - call vimtex#test#assert_equal(0, len(l:entries)) - quit! -endfunction +silent edit plaintex.tex +call vimtex#test#assert_equal('plaintex', &filetype) -autocmd VimEnter * call Test() +quit! diff --git a/test/tests/test-texflavor/test-undefined.vim b/test/tests/test-texflavor/test-undefined.vim index 23e1933772..e5c21e10bf 100644 --- a/test/tests/test-texflavor/test-undefined.vim +++ b/test/tests/test-texflavor/test-undefined.vim @@ -2,18 +2,7 @@ set nocompatible let &rtp = '../../..,' . &rtp filetype plugin on -set nomore +silent edit plaintex.tex +call vimtex#test#assert_equal('tex', &filetype) -let g:vimtex_log_verbose = 0 - -nnoremap q :qall! - -function! Test() abort - silent edit plaintex.tex - let l:entries = vimtex#log#get() - call vimtex#test#assert_equal(1, len(l:entries)) - call vimtex#test#assert_equal('g:tex_flavor not specified', l:entries[0].msg[0]) - quit! -endfunction - -autocmd VimEnter * call Test() +quit! diff --git a/test/tests/test-textobj-targets/test.vim b/test/tests/test-textobj-targets/test.vim index 282f367bf2..5ad4e1c038 100644 --- a/test/tests/test-textobj-targets/test.vim +++ b/test/tests/test-textobj-targets/test.vim @@ -5,8 +5,6 @@ filetype plugin on runtime plugin/targets.vim -let g:tex_flavor = 'latex' - set noswapfile set softtabstop=16 set expandtab From b7435dd52f1489c4d45f3b03de6eb6472a46a89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 16 Nov 2020 22:54:35 +0100 Subject: [PATCH 81/99] wip: more minor updates to docs --- doc/vimtex.txt | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/doc/vimtex.txt b/doc/vimtex.txt index c23aaf3187..4d43bf2484 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -1,4 +1,4 @@ -*vimtex.txt* A modern Vim and neovim filetype plugin for LaTeX files. +*vimtex.txt* A modern Vim/neovim filetype and syntax plugin for LaTeX files. *vimtex* Author: Karl Yngve Lervåg @@ -3666,9 +3666,12 @@ Associated settings: ============================================================================== SYNTAX HIGHLIGHTING *vimtex-syntax* -Vimtex provides a core syntax plugin that should generally work well out of -the box. It includes package specific syntax highlighting for a lot of -different packages, e.g.: +Vimtex provides a core syntax plugin combined with package specific addons. +The syntax plugin aims to be both consistent, structured, and efficient. The +package specific addons are generally only loaded when applicable. + +Package specific syntax highlighting is provided for a lot of different +packages, e.g.: - Support for `biblatex` and `natbib` package - Support for `cleveref` package @@ -3676,9 +3679,17 @@ different packages, e.g.: - Nested syntax highlighting for `dot2tex`, `lualatex`, `gnuplottex`, `asymptote`, `pythontex`, `listings`, and `minted` -See also |vimtex-comment-internal| on the internal syntax plugin shipped with Vim. +Associated settings: + |g:vimtex_syntax_enabled| + |g:vimtex_syntax_nested| + |g:vimtex_syntax_autoload_packages| + +------------------------------------------------------------------------------ +SYNTAX CORE SPECIFICATION *vimtex-syntax-core* + +------------------------------------------------------------------------------ +SYNTAX PACKAGE SPECIFICATION *vimtex-syntax-packages* - *vimtex-syntax-packages* The syntax improvements for a specific package is loaded if that package is detected in the current document, see |vimtex-package-detection|. This generally works well when a document is compiled, but may fail to detect @@ -3686,20 +3697,6 @@ packages for new documents or documents that are not compiled. One may therefore specify a list of packages to autoload regardless of the package detection, see |g:vimtex_syntax_autoload_packages|. -Note: The default syntax highlighting of vim maintained by Charles Campbell - does not support any package (:h tex-package). However, C. Campbell - provides syntax highlighting files on his website for some packages, see - http://www.drchip.org/astronaut/vim/index.html#LATEXPKGS - -Note: For people that are interested in improved conceal support, please check - out Keita Nakamura's plugin tex-conceal.vim: - https://github.com/KeitaNakamura/tex-conceal.vim - -Associated settings: - |g:vimtex_syntax_enabled| - |g:vimtex_syntax_nested| - |g:vimtex_syntax_autoload_packages| - ============================================================================== NAVIGATION *vimtex-navigation* From 0d6f91e0d174eea812d57fadda1dc4d75602717e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Tue, 17 Nov 2020 00:38:23 +0100 Subject: [PATCH 82/99] wip: major change to syntax addon loading --- autoload/vimtex/options.vim | 3 +- autoload/vimtex/syntax/p/amsmath.vim | 5 +- autoload/vimtex/syntax/p/array.vim | 7 +- autoload/vimtex/syntax/p/asymptote.vim | 5 +- autoload/vimtex/syntax/p/babel.vim | 17 ++--- autoload/vimtex/syntax/p/beamer.vim | 5 +- autoload/vimtex/syntax/p/biblatex.vim | 5 +- autoload/vimtex/syntax/p/booktabs.vim | 5 +- autoload/vimtex/syntax/p/breqn.vim | 5 +- autoload/vimtex/syntax/p/cases.vim | 5 +- autoload/vimtex/syntax/p/cleveref.vim | 5 +- autoload/vimtex/syntax/p/csquotes.vim | 5 +- autoload/vimtex/syntax/p/dot2texi.vim | 5 +- autoload/vimtex/syntax/p/glossaries.vim | 5 +- autoload/vimtex/syntax/p/glossaries_extra.vim | 10 +-- autoload/vimtex/syntax/p/gnuplottex.vim | 5 +- autoload/vimtex/syntax/p/hyperref.vim | 5 +- autoload/vimtex/syntax/p/ieeetrantools.vim | 5 +- autoload/vimtex/syntax/p/listings.vim | 4 +- autoload/vimtex/syntax/p/luacode.vim | 5 +- autoload/vimtex/syntax/p/markdown.vim | 5 +- autoload/vimtex/syntax/p/mathtools.vim | 9 +-- autoload/vimtex/syntax/p/minted.vim | 5 +- autoload/vimtex/syntax/p/moreverb.vim | 5 +- autoload/vimtex/syntax/p/natbib.vim | 7 +- autoload/vimtex/syntax/p/pdfpages.vim | 5 +- autoload/vimtex/syntax/p/pgfplots.vim | 7 +- autoload/vimtex/syntax/p/pythontex.vim | 5 +- autoload/vimtex/syntax/p/subfile.vim | 5 +- autoload/vimtex/syntax/p/tabularx.vim | 5 +- autoload/vimtex/syntax/p/tikz.vim | 5 +- autoload/vimtex/syntax/p/url.vim | 7 +- autoload/vimtex/syntax/p/varioref.vim | 5 +- autoload/vimtex/syntax/p/wiki.vim | 5 +- autoload/vimtex/syntax/packages.vim | 59 +++++++++++----- doc/vimtex.txt | 70 +++++++++++++++---- test/tests/test-imaps/test.vim | 2 +- test/tests/test-syntax/test-fls-reload.vim | 6 +- .../test-syntax/test-various-packages.vim | 2 +- 39 files changed, 149 insertions(+), 186 deletions(-) diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index 5fe25da87e..51d21f3a84 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -262,7 +262,6 @@ function! vimtex#options#init() abort " {{{1 call s:init_option('vimtex_subfile_start_local', 0) call s:init_option('vimtex_syntax_enabled', 1) - call s:init_option('vimtex_syntax_autoload_packages', ['amsmath']) call s:init_option('vimtex_syntax_conceal_default', 1) call s:init_option('vimtex_syntax_conceal', { \ 'accents': g:vimtex_syntax_conceal_default, @@ -300,6 +299,7 @@ function! vimtex#options#init() abort " {{{1 \}) call s:init_option('vimtex_syntax_nospell_commands', []) call s:init_option('vimtex_syntax_packages', { + \ 'amsmath': {'load': 2}, \ 'babel': {'conceal': g:vimtex_syntax_conceal_default}, \}) @@ -436,6 +436,7 @@ function! s:check_for_deprecated_options() abort " {{{1 \ 'g:vimtex_quickfix_ignored_warnings', \ 'g:vimtex_quickfix_latexlog', \ 'g:vimtex_quickfix_warnings', + \ 'g:vimtex_syntax_autoload_packages', \ 'g:vimtex_textidote_jar', \ 'g:vimtex_toc_fold', \ 'g:vimtex_toc_fold_level_start', diff --git a/autoload/vimtex/syntax/p/amsmath.vim b/autoload/vimtex/syntax/p/amsmath.vim index 53db22e17f..70d735bdee 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -6,10 +6,7 @@ scriptencoding utf-8 -function! vimtex#syntax#p#amsmath#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'amsmath') | return | endif - let b:vimtex_syntax.amsmath = 1 - +function! vimtex#syntax#p#amsmath#load(cfg) abort " {{{1 call vimtex#syntax#core#new_region_math('align') call vimtex#syntax#core#new_region_math('alignat') call vimtex#syntax#core#new_region_math('flalign') diff --git a/autoload/vimtex/syntax/p/array.vim b/autoload/vimtex/syntax/p/array.vim index b54fe3cb10..42a90dea2a 100644 --- a/autoload/vimtex/syntax/p/array.vim +++ b/autoload/vimtex/syntax/p/array.vim @@ -4,11 +4,8 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#array#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'array') | return | endif - let b:vimtex_syntax.array = 1 - - call vimtex#syntax#p#tabularx#load() +function! vimtex#syntax#p#array#load(cfg) abort " {{{1 + call vimtex#syntax#packages#load('tabularx') " Change inline math to improve column specifiers, e.g. " diff --git a/autoload/vimtex/syntax/p/asymptote.vim b/autoload/vimtex/syntax/p/asymptote.vim index d1d6a6474c..2d63adc30a 100644 --- a/autoload/vimtex/syntax/p/asymptote.vim +++ b/autoload/vimtex/syntax/p/asymptote.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#asymptote#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'asymptote') | return | endif - let b:vimtex_syntax.asymptote = 1 - +function! vimtex#syntax#p#asymptote#load(cfg) abort " {{{1 if !empty(vimtex#syntax#nested#include('asy')) let l:opts = {'contains': '@vimtex_nested_asy'} else diff --git a/autoload/vimtex/syntax/p/babel.vim b/autoload/vimtex/syntax/p/babel.vim index db35a4c839..2d27d8a129 100644 --- a/autoload/vimtex/syntax/p/babel.vim +++ b/autoload/vimtex/syntax/p/babel.vim @@ -4,17 +4,14 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#babel#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'babel') | return | endif - let b:vimtex_syntax.babel = 1 +function! vimtex#syntax#p#babel#load(cfg) abort " {{{1 + if !a:cfg.conceal | return | endif - if g:vimtex_syntax_packages.babel.conceal - syntax match texSpecialChar '\\glq\>' conceal cchar=‚ - syntax match texSpecialChar '\\grq\>' conceal cchar=‘ - syntax match texSpecialChar '\\glqq\>' conceal cchar=„ - syntax match texSpecialChar '\\grqq\>' conceal cchar=“ - syntax match texSpecialChar '\\hyp\>' conceal cchar=- - endif + syntax match texSpecialChar '\\glq\>' conceal cchar=‚ + syntax match texSpecialChar '\\grq\>' conceal cchar=‘ + syntax match texSpecialChar '\\glqq\>' conceal cchar=„ + syntax match texSpecialChar '\\grqq\>' conceal cchar=“ + syntax match texSpecialChar '\\hyp\>' conceal cchar=- endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/beamer.vim b/autoload/vimtex/syntax/p/beamer.vim index bf969598ec..0e6e18209c 100644 --- a/autoload/vimtex/syntax/p/beamer.vim +++ b/autoload/vimtex/syntax/p/beamer.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#beamer#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'beamer') | return | endif - let b:vimtex_syntax.beamer = 1 - +function! vimtex#syntax#p#beamer#load(cfg) abort " {{{1 syntax match texBeamerDelim '<\|>' contained syntax match texBeamerOpt '<[^>]*>' contained contains=texBeamerDelim diff --git a/autoload/vimtex/syntax/p/biblatex.vim b/autoload/vimtex/syntax/p/biblatex.vim index fca97e0e10..2020c4b8d8 100644 --- a/autoload/vimtex/syntax/p/biblatex.vim +++ b/autoload/vimtex/syntax/p/biblatex.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#biblatex#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'biblatex') | return | endif - let b:vimtex_syntax.biblatex = 1 - +function! vimtex#syntax#p#biblatex#load(cfg) abort " {{{1 syntax match texCmdBib nextgroup=texFilesArg "\\addbibresource\>" syntax match texCmdRef nextgroup=texRefOpt,texRefArg skipwhite skipnl "\\bibentry\>" diff --git a/autoload/vimtex/syntax/p/booktabs.vim b/autoload/vimtex/syntax/p/booktabs.vim index d6cc97dc22..ffbd9f6010 100644 --- a/autoload/vimtex/syntax/p/booktabs.vim +++ b/autoload/vimtex/syntax/p/booktabs.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#booktabs#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'booktabs') | return | endif - let b:vimtex_syntax.booktabs = 1 - +function! vimtex#syntax#p#booktabs#load(cfg) abort " {{{1 syntax match texCmdBooktabs "\\\%(top\|mid\|bottom\)rule\>" highlight def link texCmdBooktabs texMathDelim diff --git a/autoload/vimtex/syntax/p/breqn.vim b/autoload/vimtex/syntax/p/breqn.vim index 11449353e2..90f64a1399 100644 --- a/autoload/vimtex/syntax/p/breqn.vim +++ b/autoload/vimtex/syntax/p/breqn.vim @@ -6,10 +6,7 @@ scriptencoding utf-8 -function! vimtex#syntax#p#breqn#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'breqn') | return | endif - let b:vimtex_syntax.breqn = 1 - +function! vimtex#syntax#p#breqn#load(cfg) abort " {{{1 call vimtex#syntax#core#new_region_math('dmath') call vimtex#syntax#core#new_region_math('dseries') call vimtex#syntax#core#new_region_math('dgroup') diff --git a/autoload/vimtex/syntax/p/cases.vim b/autoload/vimtex/syntax/p/cases.vim index 38c63c557e..cd77dcb379 100644 --- a/autoload/vimtex/syntax/p/cases.vim +++ b/autoload/vimtex/syntax/p/cases.vim @@ -6,10 +6,7 @@ scriptencoding utf-8 -function! vimtex#syntax#p#cases#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'cases') | return | endif - let b:vimtex_syntax.cases = 1 - +function! vimtex#syntax#p#cases#load(cfg) abort " {{{1 call vimtex#syntax#core#new_region_math('\(sub\)\?numcases', {'starred': 0}) endfunction diff --git a/autoload/vimtex/syntax/p/cleveref.vim b/autoload/vimtex/syntax/p/cleveref.vim index c9e9010226..b0cb536c9b 100644 --- a/autoload/vimtex/syntax/p/cleveref.vim +++ b/autoload/vimtex/syntax/p/cleveref.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#cleveref#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'cleveref') | return | endif - let b:vimtex_syntax.cleveref = 1 - +function! vimtex#syntax#p#cleveref#load(cfg) abort " {{{1 syntax match texCmdCRef nextgroup=texCRefArg skipwhite skipnl \ "\\\%(\%(label\)\?c\%(page\)\?\|C\)ref\>" diff --git a/autoload/vimtex/syntax/p/csquotes.vim b/autoload/vimtex/syntax/p/csquotes.vim index 923471a248..b729cc2665 100644 --- a/autoload/vimtex/syntax/p/csquotes.vim +++ b/autoload/vimtex/syntax/p/csquotes.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#csquotes#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'csquotes') | return | endif - let b:vimtex_syntax.csquotes = 1 - +function! vimtex#syntax#p#csquotes#load(cfg) abort " {{{1 syntax match texCmdQuote nextgroup=texQuoteArg skipwhite skipnl "\\\%(foreign\|hyphen\)textcquote\*\?\>" syntax match texCmdQuote nextgroup=texQuoteArg skipwhite skipnl "\\\%(foreign\|hyphen\)blockcquote\>" syntax match texCmdQuote nextgroup=texQuoteArg skipwhite skipnl "\\hybridblockcquote\>" diff --git a/autoload/vimtex/syntax/p/dot2texi.vim b/autoload/vimtex/syntax/p/dot2texi.vim index 58c517744e..482e214901 100644 --- a/autoload/vimtex/syntax/p/dot2texi.vim +++ b/autoload/vimtex/syntax/p/dot2texi.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#dot2texi#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'dot2texi') | return | endif - let b:vimtex_syntax.dot2texi = 1 - +function! vimtex#syntax#p#dot2texi#load(cfg) abort " {{{1 call vimtex#syntax#nested#include('dot') call vimtex#syntax#core#new_region_env('texDotRegion', 'dot2tex', \ {'contains': '@vimtex_nested_dot'}) diff --git a/autoload/vimtex/syntax/p/glossaries.vim b/autoload/vimtex/syntax/p/glossaries.vim index 63f103bd54..a93b03fd58 100644 --- a/autoload/vimtex/syntax/p/glossaries.vim +++ b/autoload/vimtex/syntax/p/glossaries.vim @@ -6,10 +6,7 @@ scriptencoding utf-8 -function! vimtex#syntax#p#glossaries#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'glossaries') | return | endif - let b:vimtex_syntax.glossaries = 1 - +function! vimtex#syntax#p#glossaries#load(cfg) abort " {{{1 syntax match texCmd nextgroup=texGlsArg skipwhite skipnl "\\gls\>" call vimtex#syntax#core#new_arg('texGlsArg', {'contains': '@NoSpell'}) endfunction diff --git a/autoload/vimtex/syntax/p/glossaries_extra.vim b/autoload/vimtex/syntax/p/glossaries_extra.vim index 82ebdcef1f..46f0304cf3 100644 --- a/autoload/vimtex/syntax/p/glossaries_extra.vim +++ b/autoload/vimtex/syntax/p/glossaries_extra.vim @@ -4,14 +4,8 @@ " Email: karl.yngve@gmail.com " -scriptencoding utf-8 - -function! vimtex#syntax#p#glossaries_extra#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'glossaries_extra') | return | endif - let b:vimtex_syntax.glossaries_extra = 1 - - " Load amsmath - call vimtex#syntax#p#glossaries#load() +function! vimtex#syntax#p#glossaries_extra#load(cfg) abort " {{{1 + call vimtex#syntax#packages#load('glossaries') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/gnuplottex.vim b/autoload/vimtex/syntax/p/gnuplottex.vim index 25807059c1..82b7bd03a4 100644 --- a/autoload/vimtex/syntax/p/gnuplottex.vim +++ b/autoload/vimtex/syntax/p/gnuplottex.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#gnuplottex#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'gnuplottex') | return | endif - let b:vimtex_syntax.gnuplottex = 1 - +function! vimtex#syntax#p#gnuplottex#load(cfg) abort " {{{1 call vimtex#syntax#nested#include('gnuplot') call vimtex#syntax#core#new_region_env('texGnuplotRegion', 'gnuplot', \ {'contains': '@vimtex_nested_gnuplot'}) diff --git a/autoload/vimtex/syntax/p/hyperref.vim b/autoload/vimtex/syntax/p/hyperref.vim index d51d1788b5..c13ed34f09 100644 --- a/autoload/vimtex/syntax/p/hyperref.vim +++ b/autoload/vimtex/syntax/p/hyperref.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#hyperref#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'hyperref') | return | endif - let b:vimtex_syntax.hyperref = 1 - +function! vimtex#syntax#p#hyperref#load(cfg) abort " {{{1 syntax match texCmdHyperref '\\autoref\>' nextgroup=texRefOpt,texRefArg syntax match texCmdHyperref '\\hyperref\>' nextgroup=texRefOpt,texRefArg syntax match texCmdHyperref '\\href\>' nextgroup=texHrefArgLink skipwhite diff --git a/autoload/vimtex/syntax/p/ieeetrantools.vim b/autoload/vimtex/syntax/p/ieeetrantools.vim index ef989cdcf3..e146bdffd2 100644 --- a/autoload/vimtex/syntax/p/ieeetrantools.vim +++ b/autoload/vimtex/syntax/p/ieeetrantools.vim @@ -6,10 +6,7 @@ scriptencoding utf-8 -function! vimtex#syntax#p#ieeetrantools#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'ieeetrantools') | return | endif - let b:vimtex_syntax.ieeetrantools = 1 - +function! vimtex#syntax#p#ieeetrantools#load(cfg) abort " {{{1 call vimtex#syntax#core#new_arg('texMathEnvIEEEArg') call vimtex#syntax#core#new_opt('texMathEnvIEEEOpt', \ {'next': 'texMathEnvIEEEArg'}) diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index 6ae3f4e01f..953571a241 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -4,9 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#listings#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'listings') | return | endif - +function! vimtex#syntax#p#listings#load(cfg) abort " {{{1 let b:vimtex_syntax.listings = map( \ filter(getline(1, '$'), "v:val =~# 'language='"), \ {_, x -> matchstr(x, 'language=\zs\w\+')}) diff --git a/autoload/vimtex/syntax/p/luacode.vim b/autoload/vimtex/syntax/p/luacode.vim index d9591457d5..d5974f8af0 100644 --- a/autoload/vimtex/syntax/p/luacode.vim +++ b/autoload/vimtex/syntax/p/luacode.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#luacode#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'luacode') | return | endif - let b:vimtex_syntax.luacode = 1 - +function! vimtex#syntax#p#luacode#load(cfg) abort " {{{1 call vimtex#syntax#nested#include('lua') call vimtex#syntax#core#new_region_env('texLuaRegion', 'luacode\*\?', diff --git a/autoload/vimtex/syntax/p/markdown.vim b/autoload/vimtex/syntax/p/markdown.vim index f5babe9a01..714302668f 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#markdown#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'markdown') | return | endif - let b:vimtex_syntax.markdown = 1 - +function! vimtex#syntax#p#markdown#load(cfg) abort " {{{1 call vimtex#syntax#nested#include('markdown') call vimtex#syntax#core#new_region_env('texMarkdownRegion', 'markdown', \ {'contains': 'texCmd,@vimtex_nested_markdown'}) diff --git a/autoload/vimtex/syntax/p/mathtools.vim b/autoload/vimtex/syntax/p/mathtools.vim index 980c49df07..bea7a14681 100644 --- a/autoload/vimtex/syntax/p/mathtools.vim +++ b/autoload/vimtex/syntax/p/mathtools.vim @@ -4,13 +4,8 @@ " Email: karl.yngve@gmail.com " -scriptencoding utf-8 - -function! vimtex#syntax#p#mathtools#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'mathtools') | return | endif - let b:vimtex_syntax.mathtools = 1 - - call vimtex#syntax#p#amsmath#load() +function! vimtex#syntax#p#mathtools#load(cfg) abort " {{{1 + call vimtex#syntax#packages#load('amsmath') " Support for various envionrments with option groups syntax match texMathCmdEnv contained contains=texCmdMathEnv nextgroup=texMathToolsOptPos1 "\\begin{aligned}" diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index 1fba3505f6..176d53049d 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#minted#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'minted') | return | endif - let b:vimtex_syntax.minted = 1 - +function! vimtex#syntax#p#minted#load(cfg) abort " {{{1 " Parse minted macros in the current project call s:parse_minted_constructs() diff --git a/autoload/vimtex/syntax/p/moreverb.vim b/autoload/vimtex/syntax/p/moreverb.vim index f19b117dc4..129cb4f28a 100644 --- a/autoload/vimtex/syntax/p/moreverb.vim +++ b/autoload/vimtex/syntax/p/moreverb.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#moreverb#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'moreverb') | return | endif - let b:vimtex_syntax.moreverb = 1 - +function! vimtex#syntax#p#moreverb#load(cfg) abort " {{{1 call vimtex#syntax#core#new_region_env('texVerbRegion', 'verbatimtab', {'transparent': 0}) call vimtex#syntax#core#new_region_env('texVerbRegion', 'verbatimwrite', {'transparent': 0}) call vimtex#syntax#core#new_region_env('texVerbRegion', 'boxedverbatim', {'transparent': 0}) diff --git a/autoload/vimtex/syntax/p/natbib.vim b/autoload/vimtex/syntax/p/natbib.vim index 8befeb4994..1b4e20f3ee 100644 --- a/autoload/vimtex/syntax/p/natbib.vim +++ b/autoload/vimtex/syntax/p/natbib.vim @@ -4,11 +4,8 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#natbib#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'natbib') | return | endif - let b:vimtex_syntax.natbib = 1 - - call vimtex#syntax#p#biblatex#load() +function! vimtex#syntax#p#natbib#load(cfg) abort " {{{1 + call vimtex#syntax#packages#load('biblatex') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/pdfpages.vim b/autoload/vimtex/syntax/p/pdfpages.vim index f4e2c82ccb..2e5ecf2096 100644 --- a/autoload/vimtex/syntax/p/pdfpages.vim +++ b/autoload/vimtex/syntax/p/pdfpages.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#pdfpages#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'pdfpages') | return | endif - let b:vimtex_syntax.pdfpages = 1 - +function! vimtex#syntax#p#pdfpages#load(cfg) abort " {{{1 syntax match texCmdInput "\\includepdf\>" nextgroup=texFileOpt,texFileArg skipwhite skipnl endfunction diff --git a/autoload/vimtex/syntax/p/pgfplots.vim b/autoload/vimtex/syntax/p/pgfplots.vim index 135cde7f07..7ccb095702 100644 --- a/autoload/vimtex/syntax/p/pgfplots.vim +++ b/autoload/vimtex/syntax/p/pgfplots.vim @@ -4,11 +4,8 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#pgfplots#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'pgfplots') | return | endif - let b:vimtex_syntax.pgfplots = 1 - - call vimtex#syntax#p#tikz#load() +function! vimtex#syntax#p#pgfplots#load(cfg) abort " {{{1 + call vimtex#syntax#packages#load('tikz') syntax cluster texClusterTikz add=texCmdAxis diff --git a/autoload/vimtex/syntax/p/pythontex.vim b/autoload/vimtex/syntax/p/pythontex.vim index b41a4cbce2..d2146c3bc1 100644 --- a/autoload/vimtex/syntax/p/pythontex.vim +++ b/autoload/vimtex/syntax/p/pythontex.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#pythontex#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'pythontex') | return | endif - let b:vimtex_syntax.pythontex = 1 - +function! vimtex#syntax#p#pythontex#load(cfg) abort " {{{1 call vimtex#syntax#nested#include('python') syntax match texCmdPythontex /\\py[bsc]\?/ nextgroup=texPythontexArg skipwhite skipnl diff --git a/autoload/vimtex/syntax/p/subfile.vim b/autoload/vimtex/syntax/p/subfile.vim index ddf85e6373..4b28c73375 100644 --- a/autoload/vimtex/syntax/p/subfile.vim +++ b/autoload/vimtex/syntax/p/subfile.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#subfile#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'subfile') | return | endif - let b:vimtex_syntax.subfile = 1 - +function! vimtex#syntax#p#subfile#load(cfg) abort " {{{1 syntax match texCmdInput nextgroup=texFileArg skipwhite skipnl "\\subfile\>" syntax match texCmdInput nextgroup=texFileArg skipwhite skipnl "\\subfileinclude\>" endfunction diff --git a/autoload/vimtex/syntax/p/tabularx.vim b/autoload/vimtex/syntax/p/tabularx.vim index e215afc6ba..beabf03984 100644 --- a/autoload/vimtex/syntax/p/tabularx.vim +++ b/autoload/vimtex/syntax/p/tabularx.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#tabularx#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'tabularx') | return | endif - let b:vimtex_syntax.tabularx = 1 - +function! vimtex#syntax#p#tabularx#load(cfg) abort " {{{1 syntax match texTabularCol /[lcr]/ contained syntax match texTabularCol /[pmb]/ contained nextgroup=texTabularLength syntax match texTabularCol /\*/ contained nextgroup=texTabularMulti diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index f3f856034b..c58dd69483 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#tikz#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'tikz') | return | endif - let b:vimtex_syntax.tikz = 1 - +function! vimtex#syntax#p#tikz#load(cfg) abort " {{{1 syntax cluster texClusterTikz contains=texCmdTikz,texTikzEnvBgn,texTikzSemicolon,texTikzDraw,texTikzCycle,texCmd,texGroup,texComment syntax cluster texClusterTikzset contains=texTikzsetArg,texMathRegionX,texTypeSize,@texClusterOpt diff --git a/autoload/vimtex/syntax/p/url.vim b/autoload/vimtex/syntax/p/url.vim index 583ea20a69..159409a720 100644 --- a/autoload/vimtex/syntax/p/url.vim +++ b/autoload/vimtex/syntax/p/url.vim @@ -4,11 +4,8 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#url#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'url') | return | endif - let b:vimtex_syntax.url = 1 - - call vimtex#syntax#p#hyperref#load() +function! vimtex#syntax#p#url#load(cfg) abort " {{{1 + call vimtex#syntax#packages#load('hyperref') endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/varioref.vim b/autoload/vimtex/syntax/p/varioref.vim index 669ccd82f0..9e4cd919a5 100644 --- a/autoload/vimtex/syntax/p/varioref.vim +++ b/autoload/vimtex/syntax/p/varioref.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#varioref#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'varioref') | return | endif - let b:vimtex_syntax.varioref = 1 - +function! vimtex#syntax#p#varioref#load(cfg) abort " {{{1 syntax match texCmdRef '\\Vref\>' nextgroup=texRefArg skipwhite skipnl endfunction diff --git a/autoload/vimtex/syntax/p/wiki.vim b/autoload/vimtex/syntax/p/wiki.vim index 8dc3330a8d..012a5af91a 100644 --- a/autoload/vimtex/syntax/p/wiki.vim +++ b/autoload/vimtex/syntax/p/wiki.vim @@ -4,10 +4,7 @@ " Email: karl.yngve@gmail.com " -function! vimtex#syntax#p#wiki#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'wiki') | return | endif - let b:vimtex_syntax.wiki = 1 - +function! vimtex#syntax#p#wiki#load(cfg) abort " {{{1 call vimtex#syntax#nested#include('markdown') syntax region texWikiRegion diff --git a/autoload/vimtex/syntax/packages.vim b/autoload/vimtex/syntax/packages.vim index 2acc565b82..b0227d7a3a 100644 --- a/autoload/vimtex/syntax/packages.vim +++ b/autoload/vimtex/syntax/packages.vim @@ -12,26 +12,51 @@ function! vimtex#syntax#packages#init() abort " {{{1 let b:vimtex.syntax = {} endif - try - call vimtex#syntax#p#{b:vimtex.documentclass}#load() - catch /E117:/ - endtry - - for l:pkg in map(keys(b:vimtex.packages), "substitute(v:val, '-', '_', 'g')") - try - call vimtex#syntax#p#{tolower(l:pkg)}#load() - catch /E117:/ - endtry + call s:register_packages() + + for [l:pkg, l:cfg] in items(b:vimtex_syntax) + if !l:cfg.__load || l:cfg.__loaded | continue | endif + + call vimtex#syntax#p#{l:pkg}#load(l:cfg) + let l:cfg.__loaded = 1 endfor +endfunction + +" }}}1 +function! vimtex#syntax#packages#load(pkg) abort " {{{1 + let l:cfg = get(b:vimtex_syntax, a:pkg, {}) + if empty(l:cfg) || l:cfg.__loaded | return | endif + + call vimtex#syntax#p#{a:pkg}#load(l:cfg) + let l:cfg.__loaded = 1 +endfunction + +" }}}1 - for l:pkg in g:vimtex_syntax_autoload_packages - try - call vimtex#syntax#p#{l:pkg}#load() - catch /E117:/ - call vimtex#log#warning('Syntax package does not exist: ' . l:pkg, - \ 'Please see :help g:vimtex_syntax_autoload_packages') - endtry +function! s:register_packages() abort " {{{1 + let l:packages = map( + \ keys(b:vimtex.packages) + [b:vimtex.documentclass], + \ {_, x -> tolower(substitute(x, '-', '_', 'g'))}) + + for l:pkg in s:addons + " Register "state" for package in current buffer + if !has_key(b:vimtex_syntax, l:pkg) + let b:vimtex_syntax[l:pkg] = extend({ + \ 'load': 1, + \ '__load': 0, + \ '__loaded': 0, + \}, get(g:vimtex_syntax_packages, l:pkg, {})) + endif + let l:cfg = b:vimtex_syntax[l:pkg] + + let l:cfg.__load = + \ l:cfg.load > 1 + \ || (l:cfg.load == 1 && index(l:packages, l:pkg) >= 0) endfor endfunction +let s:addons = map( + \ glob(fnamemodify(expand(''), ':h') . '/p/*.vim', 0, 1), + \ "fnamemodify(v:val, ':t:r')") + " }}}1 diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 4d43bf2484..5799636e80 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -1974,12 +1974,6 @@ OPTIONS *vimtex-options* Default value: 1. -*g:vimtex_syntax_autoload_packages* - Specify list of syntax packages to load on start. See |vimtex-syntax-packages| - for more info. - - Default value: ['amsmath'] - *g:vimtex_syntax_conceal* A dictionary for specifying which core conceal features to activate. This mostly implies concealing particular elements with a replacement unicode @@ -2071,15 +2065,53 @@ OPTIONS *vimtex-options* Default value: [] *g:vimtex_syntax_packages* - A dictionary for package specific configuration. The following keys are - currently available: - + A dictionary for package specific syntax configuration. Each key represent + a single package and the values are themselves configuration dictionaries. + All packages share the following options: + + `load` Specify when to load the package syntax addon. + 0 = disable this syntax package + 1 = enable this syntax package if it is detected (DEFAULT) + 2 = always enable this syntax package + + The following is a list of the available packages and, if applicable, their + configuration keys or where they deviate from the above specified defaults. + + amsmath~ + `load` is 2 by default + array~ + asymptote~ babel~ - Dictionary. Default value: > - - { - 'conceal': g:vimtex_syntax_conceal_default - } + `conceal` whether to enable conceal + Default: |g:vimtex_syntax_conceal_default| + biblatex~ + booktabs~ + breqn~ + cases~ + cleveref~ + csquotes~ + dot2texi~ + glossaries_extra~ + glossaries~ + gnuplottex~ + hyperref~ + ieeetrantools~ + listings~ + luacode~ + markdown~ + mathtools~ + minted~ + moreverb~ + natbib~ + pdfpages~ + pgfplots~ + pythontex~ + subfile~ + tabularx~ + tikz~ + url~ + varioref~ + wiki~ *g:vimtex_texcount_custom_arg* Option that makes it possible to add custom arguments to `texcount` for @@ -3681,8 +3713,11 @@ packages, e.g.: Associated settings: |g:vimtex_syntax_enabled| + |g:vimtex_syntax_conceal| + |g:vimtex_syntax_conceal_default| |g:vimtex_syntax_nested| - |g:vimtex_syntax_autoload_packages| + |g:vimtex_syntax_nospell_commands| + |g:vimtex_syntax_packages| ------------------------------------------------------------------------------ SYNTAX CORE SPECIFICATION *vimtex-syntax-core* @@ -4718,6 +4753,11 @@ The following changelog only logs particularly important changes, such as changes that break backwards compatibility. See the git log for the detailed changelog. +2020-11-16: More flexible package syntax options~ +Deprecate *g:vimtex_syntax_autoload_packages* in favor of +|g:vimtex_syntax_packages|, which allows more fine grained control over each +package. + 2020-09-24: More consise grammar options~ Deprecate *g:vimtex_textidote_jar* in favor of |g:vimtex_grammar_textidote|. diff --git a/test/tests/test-imaps/test.vim b/test/tests/test-imaps/test.vim index 0244c90a92..b4aeca8eac 100644 --- a/test/tests/test-imaps/test.vim +++ b/test/tests/test-imaps/test.vim @@ -78,7 +78,7 @@ call vimtex#test#keys('ocool', \['\begin{enumerate}', ' \item', '\end{enumerate}']) " Test inside align environment: ;b -> \beta (#1648) -call vimtex#syntax#p#amsmath#load() +call vimtex#syntax#packages#load('amsmath') call vimtex#test#keys('o;b', \ ['\begin{align}', '\end{align}'], \ ['\begin{align}', ' \beta', '\end{align}']) diff --git a/test/tests/test-syntax/test-fls-reload.vim b/test/tests/test-syntax/test-fls-reload.vim index 784f4b99a3..1d1f2912cc 100644 --- a/test/tests/test-syntax/test-fls-reload.vim +++ b/test/tests/test-syntax/test-fls-reload.vim @@ -8,13 +8,13 @@ call delete(s:fls) silent edit test-fls-reload.tex " Class should load, but implied package is not loaded -call vimtex#test#assert(has_key(b:vimtex_syntax, 'beamer')) -call vimtex#test#assert(!has_key(b:vimtex_syntax, 'url')) +call vimtex#test#assert(b:vimtex_syntax.beamer.__loaded) +call vimtex#test#assert(!b:vimtex_syntax.url.__loaded) " Imitate compilation process -> implied package should also be loaded call writefile(['INPUT /usr/share/texmf-dist/tex/latex/url/url.sty'], s:fls) silent call vimtex#compiler#callback(1) -call vimtex#test#assert(has_key(b:vimtex_syntax, 'url')) +call vimtex#test#assert(b:vimtex_syntax.url.__loaded) call delete(s:fls) quit! diff --git a/test/tests/test-syntax/test-various-packages.vim b/test/tests/test-syntax/test-various-packages.vim index 32bd6df8a0..662c7d28cc 100644 --- a/test/tests/test-syntax/test-various-packages.vim +++ b/test/tests/test-syntax/test-various-packages.vim @@ -4,6 +4,6 @@ silent edit test-various-packages.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert_equal(12, len(keys(b:vimtex_syntax))) +call vimtex#test#assert_equal(12, len(filter(b:vimtex_syntax, 'v:val.__loaded'))) quit! From ea278f501319f2c175b7cb3ffb2145d022752f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 18 Nov 2020 00:30:44 +0100 Subject: [PATCH 83/99] wip: more docs --- autoload/vimtex/syntax/core.vim | 8 +-- doc/vimtex.txt | 91 ++++++++++++++++++++++++++++++--- 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index bcc0b7bc93..102727a99a 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -537,9 +537,9 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texError Error highlight def link texLength Number highlight def link texMathDelim Type + highlight def link texMathEnvArgName Delimiter highlight def link texMathOper Operator highlight def link texMathRegion Special - highlight def link texMathEnvArgName Delimiter highlight def link texOpt Identifier highlight def link texOptSep NormalNC highlight def link texParm Special @@ -601,11 +601,12 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texFilesArg texFileArg highlight def link texFilesOpt texFileOpt highlight def link texGroupError texError + highlight def link texLigature texSymbol highlight def link texMathArg texMathRegion - highlight def link texMathCmd texCmd highlight def link texMathArrayArg texOpt - highlight def link texMathDelimRegion texDelim + highlight def link texMathCmd texCmd highlight def link texMathDelimMod texMathDelim + highlight def link texMathDelimRegion texDelim highlight def link texMathError texError highlight def link texMathErrorDelim texError highlight def link texMathGroup texMathRegion @@ -625,7 +626,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texNewenvParm texParm highlight def link texOptEqual texSymbol highlight def link texRefOpt texOpt - highlight def link texLigature texSymbol highlight def link texTabularArg texOpt highlight def link texTabularChar texSymbol highlight def link texVerbRegion texRegion diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 5799636e80..ce05efa3da 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -3702,14 +3702,15 @@ Vimtex provides a core syntax plugin combined with package specific addons. The syntax plugin aims to be both consistent, structured, and efficient. The package specific addons are generally only loaded when applicable. -Package specific syntax highlighting is provided for a lot of different -packages, e.g.: +LaTeX syntax is in a way very simple, but it is also complicated in that it is +often very hard to know if any given command has one or more optional or real +arguments. Vimtex aims to be pragmatic and will not aim to fully parse all +LaTeX syntax to top precision, but instead aims to provide a decent trade of +between simplicity and completeness. -- Support for `biblatex` and `natbib` package -- Support for `cleveref` package -- Improved highlighting of `listings` package -- Nested syntax highlighting for `dot2tex`, `lualatex`, `gnuplottex`, - `asymptote`, `pythontex`, `listings`, and `minted` +The Vimtex syntax plugin is loosely based on Dr Chip's syntax plugin for LaTeX +which is shipped by default with Vim and neovim (|ft-tex-syntax|): +http://www.drchip.org/astronaut/vim/index.html#SYNTAX_TEX Associated settings: |g:vimtex_syntax_enabled| @@ -3722,6 +3723,82 @@ Associated settings: ------------------------------------------------------------------------------ SYNTAX CORE SPECIFICATION *vimtex-syntax-core* +As it is relatively common for some users to customize their colorschemes, it +is useful to describe some of the underlying "philosophy" of the syntax rules. + +The main philosophy of the Vimtex syntax plugin is to keep things simple, +structured, and consistent. There is a small set of primitive syntax elements +whose higlighting rules are linked to conventional highlight groups (see +|group-name|). More specialized syntax elements are then linked to +a corresponding primitive syntax element. This allows a user to change the +highlighting of primitives with the effect that corresponding elements are +automatically also updated. This gives a high degree of flexibility with +regards to customizing colorschemes for LaTeX files. + +The following is a list of the main primitive groups and which of the +conventional syntax groups are used by default for highlighting (again, see +|group-name|). + + `texCmd` -> `Statement` + Most rules are based on the "generic" LaTeX command `\cmd[...]{...}...` + where the number of optional and real arguments is generally unknown. + + `texOpt` -> `Identifier` + Optional argument groups, `[...]`. + + `texArg` -> `Include` + Real argument groups, `{...}`. + + `texComment` -> `Comment` + Needs no introduction... + + `texDelim` -> `Delimiter` + `texError` -> `Error` + `texLength` -> `Number` + `texMathRegion` -> `Special` + `texOpt` -> `Identifier` + `texParm` -> `Special` + `texRegion` -> `PreCondit` + `texSpecialChar` -> `SpecialChar` + `texSymbol` -> `SpecialChar` + +In addition, some more specific groups are also linked directly to +a conventional syntax group: + + `texCmdSpaceCodeChar` -> `Special` + `texCmdTodo` -> `Todo` + `texCmdType` -> `Type` + `texCommentTodo` -> `Todo` + `texEnvArgName` -> `PreCondit` + `texMathDelim` -> `Type` + `texMathEnvArgName` -> `Delimiter` + `texMathOper` -> `Operator` + `texOptSep` -> `NormalNC` + `texPartArgTitle` -> `String` + `texRefArg` -> `Special` + `texTitleArg` -> `Underlined` + +Finally, the following is a simplified description of how the more +specialised groups and syntax rules are structured and named. + + `texCmd{type}` + `tex{type}Opt` + `tex{type}Arg` + A lot of LaTeX macros and commands are specified specifically with a given + number of optional and real arguments. They may also specify what those + arguments are. For instance, `\include{...}` wants a file argument. This + is matched as `texCmdInput`, and it is followed by a `texFileArg` argument + group. In most cases, the highlighting of `texCmd{type}` is linked to + `texCmd` and the highlighting of `tex{type}Opt` and `tex{type}Arg` are + respectively linked to `texOpt` and `texArg`. + + `tex{type}Region` + Some commands open specific syntax regions that have different rules. Math + mode is a good example. Math mode is highlighted differently, and the + syntax regions are name `texMathRegion.*`. These regions may typically + contain their own (sub)sets of syntax groups, many that will only match + within a specific region. + ------------------------------------------------------------------------------ SYNTAX PACKAGE SPECIFICATION *vimtex-syntax-packages* From 039cd997140272131af5dfd70f4304dc81f78260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 18 Nov 2020 00:36:37 +0100 Subject: [PATCH 84/99] wip: slightly more docs --- doc/vimtex.txt | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/vimtex.txt b/doc/vimtex.txt index ce05efa3da..0581f69440 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -65,6 +65,8 @@ CONTENTS *vimtex-contents* Folding |vimtex-folding| Indentation |vimtex-indent| Syntax highlighting |vimtex-syntax| + Syntax core specification |vimtex-syntax-core| + Syntax package specification |vimtex-syntax-packages| Navigation |vimtex-navigation| Include expression (|gf| command) |vimtex-includeexpr| Table of contents |vimtex-toc| @@ -3802,12 +3804,18 @@ specialised groups and syntax rules are structured and named. ------------------------------------------------------------------------------ SYNTAX PACKAGE SPECIFICATION *vimtex-syntax-packages* -The syntax improvements for a specific package is loaded if that package is -detected in the current document, see |vimtex-package-detection|. This -generally works well when a document is compiled, but may fail to detect -packages for new documents or documents that are not compiled. One may -therefore specify a list of packages to autoload regardless of the package -detection, see |g:vimtex_syntax_autoload_packages|. +Vimtex provides several package specific syntax addons that provide richer +syntax highlighting. These are built around the same principles as explained +in |vimtex-syntax-core|. + +The syntax improvements for a specific package are by default loaded only if +that package is detected in the current document (as explained in +|vimtex-package-detection|). This generally works well when a document is +compiled, but Vimtex may fail to detect packages for new documents or +documents that are not compiled. It is therefore possible to configure that +individual syntax packages should always load. One may also disable individual +syntax packages. See |g:vimtex_syntax_packages| for a full list of which +syntax addons exist and how to configure them. ============================================================================== NAVIGATION *vimtex-navigation* From 01e500158e2195bf691b4ccd473527a0caff0c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 18 Nov 2020 23:30:05 +0100 Subject: [PATCH 85/99] feat: support \newcolumntype from array/tabularx --- autoload/vimtex/syntax/p/tabularx.vim | 51 +++++++++++++++++++----- test/tests/test-syntax/test-tabularx.tex | 3 ++ 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/autoload/vimtex/syntax/p/tabularx.vim b/autoload/vimtex/syntax/p/tabularx.vim index beabf03984..68aa1de4ab 100644 --- a/autoload/vimtex/syntax/p/tabularx.vim +++ b/autoload/vimtex/syntax/p/tabularx.vim @@ -5,29 +5,60 @@ " function! vimtex#syntax#p#tabularx#load(cfg) abort " {{{1 - syntax match texTabularCol /[lcr]/ contained - syntax match texTabularCol /[pmb]/ contained nextgroup=texTabularLength - syntax match texTabularCol /\*/ contained nextgroup=texTabularMulti - syntax match texTabularAtSep /@/ contained nextgroup=texTabularLength - syntax match texTabularVertline /||\?/ contained - syntax match texTabularPostPre /[<>]/ contained nextgroup=texTabularPostPreArg - syntax match texTabularMathdelim /\$\$\?/ contained + syntax match texTabularCol "[lcr]" contained + syntax match texTabularCol "[pmb]" contained nextgroup=texTabularLength + syntax match texTabularCol "\*" contained nextgroup=texTabularMulti + syntax match texTabularAtSep "@" contained nextgroup=texTabularLength + syntax match texTabularVertline "||\?" contained + syntax match texTabularPostPre "[<>]" contained nextgroup=texTabularPostPreArg + syntax match texTabularMathdelim "\$\$\?" contained syntax cluster texClusterTabular contains=texTabular.* - syntax match texCmdTabular '\\begin{tabular}' + syntax match texTabularCmd contained nextgroup=texTabularCmdOpt,texTabularCmdArg skipwhite skipnl "\\\a\+" + call vimtex#syntax#core#new_opt('texTabularCmdOpt', {'next': 'texTabularCmdArg'}) + call vimtex#syntax#core#new_arg('texTabularCmdArg', { + \ 'next': 'texTabularCmdArg', + \ 'opts': 'contained transparent', + \}) + + + syntax match texCmdTabular "\\begin{tabular}" \ nextgroup=texTabularOpt,texTabularArg skipwhite skipnl contains=texCmdEnv call vimtex#syntax#core#new_opt('texTabularOpt', {'next': 'texTabularArg', 'contains': 'texComment,@NoSpell'}) call vimtex#syntax#core#new_arg('texTabularArg', {'contains': '@texClusterTabular'}) call vimtex#syntax#core#new_arg('texTabularMulti', {'next': 'texTabularArg'}) call vimtex#syntax#core#new_arg('texTabularLength', {'contains': 'texLength,texCmd'}) - call vimtex#syntax#core#new_arg('texTabularPostPreArg', {'contains': 'texLength,texCmd,texTabularMathdelim'}) + call vimtex#syntax#core#new_arg('texTabularPostPreArg', {'contains': 'texLength,texTabularCmd,texTabularMathdelim'}) + + syntax match texCmdNewcolumn "\\newcolumntype\>" + \ nextgroup=texCmdNewcolumnName,texNewcolumnArgName skipwhite skipnl + syntax match texCmdNewcolumnName contained "\\\w\+" + \ nextgroup=texNewcolumnOpt,texNewcolumnArg skipwhite skipnl + call vimtex#syntax#core#new_arg('texNewcolumnArgName', { + \ 'next': 'texNewcolumnOpt,texNewcolumnArg', + \}) + + call vimtex#syntax#core#new_opt('texNewcolumnOpt', { + \ 'next': 'texNewcolumnArg', + \ 'opts': 'oneline', + \}) + call vimtex#syntax#core#new_arg('texNewcolumnArg', {'contains': '@texClusterTabular'}) + syntax match texNewcolumnParm contained "#\d\+" + \ containedin=texNewcolumnArg,texTabularPostPreArg,texTabularCmdArg + highlight def link texTabularCmd texCmd + highlight def link texTabularCmdOpt texOpt + highlight def link texCmdNewcolumn texCmd + highlight def link texCmdNewcolumnName texCmd + highlight def link texNewcolumnArgName texArg + highlight def link texNewcolumnOpt texOpt + highlight def link texNewcolumnParm texParm highlight def link texTabularCol texOpt highlight def link texTabularAtSep texMathDelim highlight def link texTabularVertline texMathDelim highlight def link texTabularPostPre texMathDelim - highlight def link texTabularMathdelim texMathRegionDelim + highlight def link texTabularMathdelim texMathDelimRegion highlight def link texTabularOpt texEnvOpt endfunction diff --git a/test/tests/test-syntax/test-tabularx.tex b/test/tests/test-syntax/test-tabularx.tex index 4d7c9f5827..984fabee47 100644 --- a/test/tests/test-syntax/test-tabularx.tex +++ b/test/tests/test-syntax/test-tabularx.tex @@ -2,6 +2,9 @@ \usepackage{tabularx} \usepackage{array} +\newcolumntype\vcenter[1]{>{$\vcenter\bgroup\hbox\bgroup}#1<{\egroup\egroup$}} +\newcolumntype{d}[1]{>{\rightdots{#1}}r<{\endrightdots}} + \begin{document} \begin{tabular}{*{3}{>{$}c<{$}}} From 9ec64cf579008b4661803ee7ce3406ad7b38704b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 18 Nov 2020 23:43:12 +0100 Subject: [PATCH 86/99] wip: minor fix --- test/tests/test-syntax/test-tabularx.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tests/test-syntax/test-tabularx.vim b/test/tests/test-syntax/test-tabularx.vim index 964cebdbb4..ec1aaa2921 100644 --- a/test/tests/test-syntax/test-tabularx.vim +++ b/test/tests/test-syntax/test-tabularx.vim @@ -4,7 +4,7 @@ silent edit test-tabularx.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texTabularCol', 7, 17)) -call vimtex#test#assert(vimtex#syntax#in('texTabularMathdelim', 7, 24)) +call vimtex#test#assert(vimtex#syntax#in('texTabularCol', 10, 17)) +call vimtex#test#assert(vimtex#syntax#in('texTabularMathdelim', 10, 24)) quit! From c45e71cc8702f0cd533c2fe3981f59ed55597886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 18 Nov 2020 23:49:40 +0100 Subject: [PATCH 87/99] wip: better \makeatletter regions --- autoload/vimtex/syntax/core.vim | 5 ++++- test/tests/test-syntax/test-core.tex | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 102727a99a..98e8786dac 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -322,7 +322,9 @@ function! vimtex#syntax#core#init() abort " {{{1 " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do " In short: allow @ in multicharacter macro name syntax region texStyRegion matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP - syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=texStyRegion + syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=texStyRegion,texStyArg nextgroup=texStyOpt,texStyArg skipwhite skipnl + call vimtex#syntax#core#new_opt('texStyOpt', {'next': 'texStyArg'}) + call vimtex#syntax#core#new_arg('texStyArg', {'next': 'texStyArg', 'opts': 'contained transparent'}) " }}}2 " {{{2 Region: Verbatim @@ -628,6 +630,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texRefOpt texOpt highlight def link texTabularArg texOpt highlight def link texTabularChar texSymbol + highlight def link texStyOpt texOpt highlight def link texVerbRegion texRegion highlight def link texVerbRegionInline texVerbRegion endfunction diff --git a/test/tests/test-syntax/test-core.tex b/test/tests/test-syntax/test-core.tex index 833c8b4967..e8b97e821e 100644 --- a/test/tests/test-syntax/test-core.tex +++ b/test/tests/test-syntax/test-core.tex @@ -5,7 +5,9 @@ \@asd{asd} \makeatletter -\@asd{asd} +\newlength{\my@beamer@itemsepi}\setlength{\my@beamer@itemsepi}{3ex} +\newlength{\my@beamer@itemsepii}\setlength{\my@beamer@itemsepii}{1.5ex} +\newlength{\my@beamer@itemsepiii}\setlength{\my@beamer@itemsepiii}{1.5ex} \makeatother % TODO fixme From d196ad7103550b08c8ea89d7ced57a00ab865c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 18 Nov 2020 23:57:32 +0100 Subject: [PATCH 88/99] wip: allow nested texOpt to fix edge cases --- autoload/vimtex/syntax/core.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 98e8786dac..e909f3e83d 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -22,6 +22,7 @@ function! vimtex#syntax#core#init() abort " {{{1 \texCmd, \texComment, \texLength, + \texOpt, \texOptEqual, \texOptSep, \@NoSpell From cb8c6fb131acf9b62e9fc2d34300492e68791bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 19 Nov 2020 00:00:05 +0100 Subject: [PATCH 89/99] feat: basic support for circuitikz --- autoload/vimtex/syntax/p/circuitikz.vim | 18 ++++++++++++++++++ test/tests/test-syntax/test-circuitikz.tex | 12 ++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 autoload/vimtex/syntax/p/circuitikz.vim create mode 100644 test/tests/test-syntax/test-circuitikz.tex diff --git a/autoload/vimtex/syntax/p/circuitikz.vim b/autoload/vimtex/syntax/p/circuitikz.vim new file mode 100644 index 0000000000..878228ba0c --- /dev/null +++ b/autoload/vimtex/syntax/p/circuitikz.vim @@ -0,0 +1,18 @@ +" vimtex - LaTeX plugin for Vim +" +" Maintainer: Karl Yngve Lervåg +" Email: karl.yngve@gmail.com +" + +function! vimtex#syntax#p#circuitikz#load(cfg) abort " {{{1 + call vimtex#syntax#packages#load('tikz') + + syntax match texTikzEnvBgn "\\begin{circuitikz}" + \ nextgroup=texTikzOpt skipwhite skipnl + \ contains=texCmdEnv + call vimtex#syntax#core#new_region_env('texTikzRegion', 'circuitikz', + \ {'contains': '@texClusterTikz'}) +endfunction + +" }}}1 + diff --git a/test/tests/test-syntax/test-circuitikz.tex b/test/tests/test-syntax/test-circuitikz.tex new file mode 100644 index 0000000000..ee6a97ed4a --- /dev/null +++ b/test/tests/test-syntax/test-circuitikz.tex @@ -0,0 +1,12 @@ +\documentclass[border=10pt]{standalone} +\usepackage[siunitx, RPvoltages]{circuitikz} +\newcommand{\myflow}[3][above]{%arguments: [options (default above)] {component name} {label to add} + \draw [-{Triangle[open]}] (#2-Ffrom) -- (#2-Fto) node[pos=0.5, #1]{#3}; +} + +\begin{document} +\begin{circuitikz} + \draw (0,0) to[short, f, name=S1] ++(3,0); + \myflow{S1}{$I$} +\end{circuitikz} +\end{document} From 318c226d134daf347f146dab4589ef9fc1b6e78e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 19 Nov 2020 00:14:07 +0100 Subject: [PATCH 90/99] wip: more docs --- doc/vimtex.txt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 0581f69440..fe33602a3e 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -3704,10 +3704,9 @@ Vimtex provides a core syntax plugin combined with package specific addons. The syntax plugin aims to be both consistent, structured, and efficient. The package specific addons are generally only loaded when applicable. -LaTeX syntax is in a way very simple, but it is also complicated in that it is -often very hard to know if any given command has one or more optional or real -arguments. Vimtex aims to be pragmatic and will not aim to fully parse all -LaTeX syntax to top precision, but instead aims to provide a decent trade of +LaTeX is a macro expansion language and it impossible to write a fully correct +syntax parser without running the `tex` compiler itself. Vimtex aims to be +pragmatic and provide a best-effort syntax highlighting - a decent trade of between simplicity and completeness. The Vimtex syntax plugin is loosely based on Dr Chip's syntax plugin for LaTeX @@ -3725,6 +3724,11 @@ Associated settings: ------------------------------------------------------------------------------ SYNTAX CORE SPECIFICATION *vimtex-syntax-core* +TODO +* make sure to explain the math regions +* explain difference between top level and regions, and how commands contained + in regions can make things complicated + As it is relatively common for some users to customize their colorschemes, it is useful to describe some of the underlying "philosophy" of the syntax rules. @@ -3797,7 +3801,7 @@ specialised groups and syntax rules are structured and named. `tex{type}Region` Some commands open specific syntax regions that have different rules. Math mode is a good example. Math mode is highlighted differently, and the - syntax regions are name `texMathRegion.*`. These regions may typically + syntax regions are name `texMathRegion*`. These regions may typically contain their own (sub)sets of syntax groups, many that will only match within a specific region. From 8ec04b20c997dbf085ccb19a5a5ecb5ab65e8283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 19 Nov 2020 00:16:15 +0100 Subject: [PATCH 91/99] wip: minor fix --- test/tests/test-syntax/test-core.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/tests/test-syntax/test-core.vim b/test/tests/test-syntax/test-core.vim index ebf796e9ff..2b4d00e1d0 100644 --- a/test/tests/test-syntax/test-core.vim +++ b/test/tests/test-syntax/test-core.vim @@ -7,11 +7,11 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texCmdError', 5, 3)) call vimtex#test#assert(vimtex#syntax#in('texCmdSty', 8, 3)) -call vimtex#test#assert(vimtex#syntax#in('texNewenvParm', 20, 36)) +call vimtex#test#assert(vimtex#syntax#in('texNewenvParm', 22, 36)) -call vimtex#test#assert(vimtex#syntax#in('texVerbRegionInline', 26, 36)) +call vimtex#test#assert(vimtex#syntax#in('texVerbRegionInline', 28, 36)) -call vimtex#test#assert(vimtex#syntax#in('texAuthorArg', 46, 20)) -call vimtex#test#assert(vimtex#syntax#in('texDelim', 46, 39)) +call vimtex#test#assert(vimtex#syntax#in('texAuthorArg', 48, 20)) +call vimtex#test#assert(vimtex#syntax#in('texDelim', 48, 39)) quit! From 486b8a8c4b438f315336fade4fc059eab4b45be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 19 Nov 2020 10:10:10 +0100 Subject: [PATCH 92/99] wip: improved expl3 support --- autoload/vimtex/syntax/core.vim | 31 ++++++++++++++++++--------- test/tests/test-syntax/test-expl3.tex | 30 ++++++++++++++++++++++++++ test/tests/test-syntax/test-expl3.vim | 9 ++++++++ 3 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 test/tests/test-syntax/test-expl3.tex create mode 100644 test/tests/test-syntax/test-expl3.vim diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index e909f3e83d..5883205d5d 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -345,21 +345,30 @@ function! vimtex#syntax#core#init() abort " {{{1 " }}}2 " {{{2 Region: Expl3 - syntax region texE3Region matchgroup=texCmdExpl3 + syntax region texE3Region matchgroup=texCmdE3 \ start='\\\%(ExplSyntaxOn\|ProvidesExpl\%(Package\|Class\|File\)\)' \ end='\\ExplSyntaxOff\|\%$' - \ transparent keepend + \ transparent \ contains=TOP,@NoSpell - syntax region texE3Group matchgroup=texDelim - \ start="{" skip="\\\\\|\\}" end="}" - \ contained - \ containedin=texE3Region,texE3Group + call vimtex#syntax#core#new_arg('texE3Group', {'opts': 'contained containedin=@texClusterE3'}) + + syntax match texE3Cmd contained containedin=@texClusterE3 "\\\w\+" nextgroup=texE3Opt,texE3Arg skipwhite skipnl + call vimtex#syntax#core#new_opt('texE3Opt', {'next': 'texE3Arg'}) + call vimtex#syntax#core#new_arg('texE3Arg', {'next': 'texE3Arg', 'opts': 'contained transparent'}) + + syntax region texE3RegionNested matchgroup=texCmdE3 + \ start='\\\ExplSyntaxOn' + \ end='\\ExplSyntaxOff' + \ contained containedin=@texClusterE3 + \ transparent \ contains=TOP,@NoSpell - syntax match texE3Var contained containedin=texE3Region,texE3Group "\\\a*\%(_\+[a-zA-Z]\+\)\+\>" - syntax match texE3Func contained containedin=texE3Region,texE3Group "\\\a*\%(_\+[a-zA-Z]\+\)\+:[a-zA-Z]*" - syntax match texE3Parm contained containedin=texE3Region,texE3Group "#\d\+" + syntax match texE3Var contained containedin=@texClusterE3 "\\\a*\%(_\+[a-zA-Z]\+\)\+\>" + syntax match texE3Func contained containedin=@texClusterE3 "\\\a*\%(_\+[a-zA-Z]\+\)\+:[a-zA-Z]*" + syntax match texE3Parm contained containedin=@texClusterE3 "#\d\+" + + syntax cluster texClusterE3 contains=texE3RegionNested,texE3Region,texE3Arg,texE3Group " }}}2 " {{{2 Region: Math @@ -565,7 +574,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdDef texCmd highlight def link texCmdEnv texCmd highlight def link texCmdError texError - highlight def link texCmdExpl3 texCmd + highlight def link texCmdE3 texCmd highlight def link texCmdFootnote texCmd highlight def link texCmdGreek texCmd highlight def link texCmdInput texCmd @@ -595,8 +604,10 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCommentURL texComment highlight def link texDefArgName texCmd highlight def link texDefParm texParm + highlight def link texE3Cmd texCmd highlight def link texE3Delim texDelim highlight def link texE3Func texCmdType + highlight def link texE3Opt texOpt highlight def link texE3Parm texParm highlight def link texE3Var texCmd highlight def link texFileArg texArg diff --git a/test/tests/test-syntax/test-expl3.tex b/test/tests/test-syntax/test-expl3.tex new file mode 100644 index 0000000000..a9fab0bffb --- /dev/null +++ b/test/tests/test-syntax/test-expl3.tex @@ -0,0 +1,30 @@ +\ExplSyntaxOn +\str_new:N \g_myfile_name_str +\str_gset:Nn \g_myfile_name_str {myfile.txt} +\str_new:N \g_myfile_old_mdfive_str +\str_new:N \l_myfile_mdfive_str +\cs_new_protected:Npn \getmdfive % get hash is not expandable, so protect +{ + \file_get_mdfive_hash:nN {\str_use:N \g_myfile_name_str} \l_myfile_mdfive_str + \str_use:N \l_myfile_mdfive_str +} +\cs_new:Npn \getoldmdfive +{ + \str_use:N \g_myfile_old_mdfive_str +} +\cs_new:Npn \IfMyfileChanged #1 #2 +{ + \str_if_eq:NNTF \g_myfile_old_mdfive_str \l_myfile_mdfive_str {#2} {#1} +} +\AtEndDocument +{ + \iow_now:cx { @auxout } + { + \token_to_str:N \ExplSyntaxOn + \iow_newline: + \str_gset:Nn \token_to_str:N \g_myfile_old_mdfive_str {\str_use:N \l_myfile_mdfive_str} + \iow_newline: + \token_to_str:N \ExplSyntaxOff + } +} +\ExplSyntaxOff diff --git a/test/tests/test-syntax/test-expl3.vim b/test/tests/test-syntax/test-expl3.vim new file mode 100644 index 0000000000..35ab95ebe3 --- /dev/null +++ b/test/tests/test-syntax/test-expl3.vim @@ -0,0 +1,9 @@ +source common.vim + +silent edit test-expl3.tex + +if empty($INMAKE) | finish | endif + +call vimtex#test#assert(!vimtex#syntax#in('texGroupError', 29, 1)) + +quit! From c5b307bebafe25491c4fec89f726abbf43c889f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 19 Nov 2020 10:16:16 +0100 Subject: [PATCH 93/99] wip: improve sty regions --- autoload/vimtex/syntax/core.vim | 14 +++++++++++--- test/tests/test-syntax/test-core.tex | 7 +++++++ test/tests/test-syntax/test-core.vim | 8 ++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 5883205d5d..d0e0ec2e75 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -318,15 +318,22 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_arg('texTabularArg', {'contains': ''}) " }}}2 - " {{{2 Region: \makeatletter ... \makeatother + " {{{2 Region: Sty (\makeatletter ... \makeatother) " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do " In short: allow @ in multicharacter macro name - syntax region texStyRegion matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP - syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=texStyRegion,texStyArg nextgroup=texStyOpt,texStyArg skipwhite skipnl + syntax region texStyRegion matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP,@NoSpell + + call vimtex#syntax#core#new_arg('texStyGroup', {'opts': 'contained containedin=@texClusterSty'}) + + syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=@texClusterSty nextgroup=texStyOpt,texStyArg skipwhite skipnl call vimtex#syntax#core#new_opt('texStyOpt', {'next': 'texStyArg'}) call vimtex#syntax#core#new_arg('texStyArg', {'next': 'texStyArg', 'opts': 'contained transparent'}) + syntax match texStyParm contained "#\d\+" containedin=@texClusterSty + + syntax cluster texClusterSty contains=texStyRegion,texStyArg,texStyGroup + " }}}2 " {{{2 Region: Verbatim @@ -643,6 +650,7 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texTabularArg texOpt highlight def link texTabularChar texSymbol highlight def link texStyOpt texOpt + highlight def link texStyParm texParm highlight def link texVerbRegion texRegion highlight def link texVerbRegionInline texVerbRegion endfunction diff --git a/test/tests/test-syntax/test-core.tex b/test/tests/test-syntax/test-core.tex index e8b97e821e..165b7b1a75 100644 --- a/test/tests/test-syntax/test-core.tex +++ b/test/tests/test-syntax/test-core.tex @@ -8,6 +8,13 @@ \newlength{\my@beamer@itemsepi}\setlength{\my@beamer@itemsepi}{3ex} \newlength{\my@beamer@itemsepii}\setlength{\my@beamer@itemsepii}{1.5ex} \newlength{\my@beamer@itemsepiii}\setlength{\my@beamer@itemsepiii}{1.5ex} +\def\extractcoord#1#2#3{ + \path let \p1=(#3) in \pgfextra{ + \pgfmathsetmacro#1{\x{1}/\pgf@xx} + \pgfmathsetmacro#2{\y{1}/\pgf@yy} + \xdef#1{#1} \xdef#2{#2} + }; +} \makeatother % TODO fixme diff --git a/test/tests/test-syntax/test-core.vim b/test/tests/test-syntax/test-core.vim index 2b4d00e1d0..55e4ca2fc2 100644 --- a/test/tests/test-syntax/test-core.vim +++ b/test/tests/test-syntax/test-core.vim @@ -7,11 +7,11 @@ if empty($INMAKE) | finish | endif call vimtex#test#assert(vimtex#syntax#in('texCmdError', 5, 3)) call vimtex#test#assert(vimtex#syntax#in('texCmdSty', 8, 3)) -call vimtex#test#assert(vimtex#syntax#in('texNewenvParm', 22, 36)) +call vimtex#test#assert(vimtex#syntax#in('texNewenvParm', 29, 36)) -call vimtex#test#assert(vimtex#syntax#in('texVerbRegionInline', 28, 36)) +call vimtex#test#assert(vimtex#syntax#in('texVerbRegionInline', 35, 36)) -call vimtex#test#assert(vimtex#syntax#in('texAuthorArg', 48, 20)) -call vimtex#test#assert(vimtex#syntax#in('texDelim', 48, 39)) +call vimtex#test#assert(vimtex#syntax#in('texAuthorArg', 55, 20)) +call vimtex#test#assert(vimtex#syntax#in('texDelim', 55, 39)) quit! From 0f43e0328fec519bae0366f99af84d6f455c80fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 19 Nov 2020 10:54:20 +0100 Subject: [PATCH 94/99] wip: no linting of @ in cmd names --- autoload/vimtex/syntax/core.vim | 107 ++++++++------------------- test/tests/test-syntax/test-core.vim | 3 - 2 files changed, 30 insertions(+), 80 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index d0e0ec2e75..9570bef0be 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -5,12 +5,6 @@ " function! vimtex#syntax#core#init() abort " {{{1 - let l:cfg = {} - let l:cfg.ext = expand('%:e') - let l:cfg.conceal = deepcopy(g:vimtex_syntax_conceal) - let l:cfg.is_style_document = - \ index(['sty', 'cls', 'clo', 'dtx', 'ltx'], l:cfg.ext) >= 0 - syntax spell toplevel syntax sync maxlines=500 @@ -29,7 +23,6 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax cluster texClusterMath contains= \texCmdEnv, - \texCmdError, \texCmdFootnote, \texCmdGreek, \texCmdMathText, @@ -63,7 +56,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " as TeX syntax. " * For more info on dtx files, see e.g. " https://ctan.uib.no/info/dtxtut/dtxtut.pdf - if l:cfg.ext ==# 'dtx' + if expand('%:e') ==# 'dtx' syntax match texComment "\^\^A.*$" syntax match texComment "^%\+" else @@ -94,11 +87,7 @@ function! vimtex#syntax#core#init() abort " {{{1 " E.g.: \$ \& \% \# \{ \} \_ \S \P syntax match texSpecialChar "\\[$&%#{}_]" - if l:cfg.is_style_document - syntax match texSpecialChar "\\[SP@]\ze[^a-zA-Z@]" - else - syntax match texSpecialChar "\\[SP@]\ze\A" - endif + syntax match texSpecialChar "\\[SP@]\ze[^a-zA-Z@]" syntax match texSpecialChar "\^\^\%(\S\|[0-9a-f]\{2}\)" syntax match texSpecialChar "\\[,;:!]" @@ -120,32 +109,24 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texLength contained "\<\d\+\([.,]\d\+\)\?\s*\(true\)\?\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>" " Match general commands first - if l:cfg.is_style_document - syntax match texCmdSty "\\[a-zA-Z@]\+" - endif - syntax match texCmd nextgroup=texOpt,texArg skipwhite skipnl "\\\a\+" + syntax match texCmd nextgroup=texOpt,texArg skipwhite skipnl "\\[a-zA-Z@]\+" call vimtex#syntax#core#new_opt('texOpt', {'next': 'texArg'}) call vimtex#syntax#core#new_arg('texArg', {'next': 'texArg', 'opts': 'contained transparent'}) - syntax match texCmdError "\\\a*@\a*" " Define separate "generic" commands inside math regions + " Note: Defined here because order matters! syntax match texMathCmd contained nextgroup=texMathArg skipwhite skipnl "\\\a\+" call vimtex#syntax#core#new_arg('texMathArg', {'contains': '@texClusterMath'}) " {{{2 Commands: core set " Accents and ligatures - if l:cfg.is_style_document - syntax match texCmdAccent "\\[bcdvuH]\ze[^a-zA-Z@]" - syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze[^a-zA-Z@]" - else - syntax match texCmdAccent "\\[bcdvuH]$" - syntax match texCmdAccent "\\[bcdvuH]\ze\A" - syntax match texCmdAccent /\\[=^.~"`']/ - syntax match texCmdAccent /\\['=t'.c^ud"vb~Hr]{\a}/ - syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)$" - syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze\A" - endif + syntax match texCmdAccent "\\[bcdvuH]$" + syntax match texCmdAccent "\\[bcdvuH]\ze[^a-zA-Z@]" + syntax match texCmdAccent /\\[=^.~"`']/ + syntax match texCmdAccent /\\['=t'.c^ud"vb~Hr]{\a}/ + syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)$" + syntax match texCmdLigature "\v\\%([ijolL]|ae|oe|ss|AA|AE|OE)\ze[^a-zA-Z@]" " Spacecodes (TeX'isms) " * See e.g. https://en.wikibooks.org/wiki/TeX/catcode @@ -232,7 +213,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdStyle "\\mdseries\>" " Bold and italic commands - call s:match_bold_italic(l:cfg) + call s:match_bold_italic() " Type sizes syntax match texCmdSize "\\tiny\>" @@ -270,13 +251,8 @@ function! vimtex#syntax#core#init() abort " {{{1 " Definitions/Commands " E.g. \def \foo #1#2 {foo #1 bar #2 baz} syntax match texCmdDef "\\def\>" nextgroup=texDefArgName skipwhite skipnl - if l:cfg.is_style_document - syntax match texDefArgName contained nextgroup=texDefParmPre,texDefArgBody skipwhite skipnl "\\[a-zA-Z@]\+" - syntax match texDefArgName contained nextgroup=texDefParmPre,texDefArgBody skipwhite skipnl "\\[^a-zA-Z@]" - else - syntax match texDefArgName contained nextgroup=texDefParmPre,texDefArgBody skipwhite skipnl "\\\a\+" - syntax match texDefArgName contained nextgroup=texDefParmPre,texDefArgBody skipwhite skipnl "\\\A" - endif + syntax match texDefArgName contained nextgroup=texDefParmPre,texDefArgBody skipwhite skipnl "\\[a-zA-Z@]\+" + syntax match texDefArgName contained nextgroup=texDefParmPre,texDefArgBody skipwhite skipnl "\\[^a-zA-Z@]" syntax match texDefParmPre contained nextgroup=texDefArgBody skipwhite skipnl "#[^{]*" syntax match texDefParm contained "#\d\+" containedin=texDefParmPre,texDefArgBody call vimtex#syntax#core#new_arg('texDefArgBody') @@ -317,23 +293,6 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdEnv "\\begin{tabular}" contains=texCmdEnv nextgroup=texTabularArg skipwhite skipnl call vimtex#syntax#core#new_arg('texTabularArg', {'contains': ''}) - " }}}2 - " {{{2 Region: Sty (\makeatletter ... \makeatother) - - " https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do - " In short: allow @ in multicharacter macro name - syntax region texStyRegion matchgroup=texCmd start='\\makeatletter' end='\\makeatother' contains=TOP,@NoSpell - - call vimtex#syntax#core#new_arg('texStyGroup', {'opts': 'contained containedin=@texClusterSty'}) - - syntax match texCmdSty "\\[a-zA-Z@]\+" contained containedin=@texClusterSty nextgroup=texStyOpt,texStyArg skipwhite skipnl - call vimtex#syntax#core#new_opt('texStyOpt', {'next': 'texStyArg'}) - call vimtex#syntax#core#new_arg('texStyArg', {'next': 'texStyArg', 'opts': 'contained transparent'}) - - syntax match texStyParm contained "#\d\+" containedin=@texClusterSty - - syntax cluster texClusterSty contains=texStyRegion,texStyArg,texStyGroup - " }}}2 " {{{2 Region: Verbatim @@ -344,9 +303,7 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdVerb "\\verb\>\*\?" nextgroup=texVerbRegionInline call vimtex#syntax#core#new_arg('texVerbRegionInline', { \ 'contains': '', - \ 'matcher': (l:cfg.is_style_document - \ ? 'start="\z([^\ta-zA-Z@]\)" end="\z1"' - \ : 'start="\z([^\ta-zA-Z]\)" end="\z1"'), + \ 'matcher': 'start="\z([^\ta-zA-Z]\)" end="\z1"' \}) " }}}2 @@ -394,7 +351,7 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_region_math('math') " Math regions: Inline Math Zones - if l:cfg.conceal.math_bounds + if g:vimtex_syntax_conceal.math_bounds syntax region texMathRegion matchgroup=texMathDelimRegion concealends contains=@texClusterMath keepend start="\\(" end="\\)" syntax region texMathRegion matchgroup=texMathDelimRegion concealends contains=@texClusterMath keepend start="\\\[" end="\\]" syntax region texMathRegionX matchgroup=texMathDelimRegion concealends contains=@texClusterMath start="\$" skip="\\\\\|\\\$" end="\$" @@ -426,9 +383,9 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\end{array}" call vimtex#syntax#core#new_arg('texMathArrayArg', {'contains': ''}) - call s:match_math_sub_super(l:cfg) - call s:match_math_symbols(l:cfg) - call s:match_math_delims(l:cfg) + call s:match_math_sub_super() + call s:match_math_symbols() + call s:match_math_delims() " }}}2 " {{{2 Conceal mode support @@ -437,19 +394,19 @@ function! vimtex#syntax#core#init() abort " {{{1 if &encoding ==# 'utf-8' " Conceal replace greek letters - if l:cfg.conceal.greek + if g:vimtex_syntax_conceal.greek call s:match_conceal_greek() endif " Conceal replace accented characters and ligatures - if l:cfg.conceal.accents && !l:cfg.is_style_document + if g:vimtex_syntax_conceal.accents call s:match_conceal_accents() endif endif " }}}2 - call s:init_highlights(l:cfg) + call s:init_highlights() let b:current_syntax = 'tex' endfunction @@ -540,7 +497,7 @@ endfunction " }}}1 -function! s:init_highlights(cfg) abort " {{{1 +function! s:init_highlights() abort " {{{1 " See :help group-name for list of conventional group names " Primitive TeX highlighting groups @@ -580,7 +537,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdClass texCmd highlight def link texCmdDef texCmd highlight def link texCmdEnv texCmd - highlight def link texCmdError texError highlight def link texCmdE3 texCmd highlight def link texCmdFootnote texCmd highlight def link texCmdGreek texCmd @@ -598,7 +554,6 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texCmdRef texCmd highlight def link texCmdSize texCmdType highlight def link texCmdSpaceCode texCmd - highlight def link texCmdSty texCmd highlight def link texCmdStyle texCmd highlight def link texCmdStyle texCmdType highlight def link texCmdStyleBold texCmd @@ -649,17 +604,15 @@ function! s:init_highlights(cfg) abort " {{{1 highlight def link texRefOpt texOpt highlight def link texTabularArg texOpt highlight def link texTabularChar texSymbol - highlight def link texStyOpt texOpt - highlight def link texStyParm texParm highlight def link texVerbRegion texRegion highlight def link texVerbRegionInline texVerbRegion endfunction " }}}1 -function! s:match_bold_italic(cfg) abort " {{{1 +function! s:match_bold_italic() abort " {{{1 let [l:conceal, l:concealends] = - \ (a:cfg.conceal.styles ? ['conceal', 'concealends'] : ['', '']) + \ (g:vimtex_syntax_conceal.styles ? ['conceal', 'concealends'] : ['', '']) syntax cluster texClusterBold contains=TOP,@NoSpell,texCmdStyleItal,texCmdStyleBold,texCmdStyleItalBold syntax cluster texClusterItal contains=TOP,@NoSpell,texCmdStyleItal,texCmdStyleBold,texCmdStyleBoldItal @@ -690,8 +643,8 @@ endfunction " }}}1 -function! s:match_math_sub_super(cfg) " {{{1 - if !a:cfg.conceal.math_super_sub | return | endif +function! s:match_math_sub_super() " {{{1 + if !g:vimtex_syntax_conceal.math_super_sub | return | endif for [l:from, l:to] in filter(copy(s:map_super), \ {_, x -> x[0][0] ==# '\' || x[0] =~# '[0-9a-zA-W.,:;+-<>/()=]'}) @@ -819,9 +772,9 @@ let s:map_super = [ \] " }}}1 -function! s:match_math_symbols(cfg) abort " {{{1 +function! s:match_math_symbols() abort " {{{1 " Many of these symbols were contributed by Björn Winckler - if !a:cfg.conceal.math_symbols | return | endif + if !g:vimtex_syntax_conceal.math_symbols | return | endif syntax match texMathSymbol "\\|" contained conceal cchar=‖ syntax match texMathSymbol "\\aleph\>" contained conceal cchar=ℵ @@ -1066,7 +1019,7 @@ function! s:match_math_symbols(cfg) abort " {{{1 endfunction " }}}1 -function! s:match_math_delims(cfg) abort " {{{1 +function! s:match_math_delims() abort " {{{1 syntax match texMathDelimMod contained "\\\(left\|right\)\>" syntax match texMathDelimMod contained "\\[bB]igg\?[lr]\?\>" syntax match texMathDelim contained "[<>()[\]|/.]\|\\[{}|]" @@ -1094,7 +1047,7 @@ function! s:match_math_delims(cfg) abort " {{{1 syntax match texMathDelim contained "\\updownarrow" syntax match texMathDelim contained "\\Updownarrow" - if !a:cfg.conceal.math_delimiters || &encoding !=# 'utf-8' + if !g:vimtex_syntax_conceal.math_delimiters || &encoding !=# 'utf-8' return endif diff --git a/test/tests/test-syntax/test-core.vim b/test/tests/test-syntax/test-core.vim index 55e4ca2fc2..c527660795 100644 --- a/test/tests/test-syntax/test-core.vim +++ b/test/tests/test-syntax/test-core.vim @@ -4,9 +4,6 @@ silent edit test-core.tex if empty($INMAKE) | finish | endif -call vimtex#test#assert(vimtex#syntax#in('texCmdError', 5, 3)) -call vimtex#test#assert(vimtex#syntax#in('texCmdSty', 8, 3)) - call vimtex#test#assert(vimtex#syntax#in('texNewenvParm', 29, 36)) call vimtex#test#assert(vimtex#syntax#in('texVerbRegionInline', 35, 36)) From 086076a46060063b16f54efe1a2b20e5705de56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 19 Nov 2020 12:35:41 +0100 Subject: [PATCH 95/99] doc: first full draft --- doc/vimtex.txt | 222 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 157 insertions(+), 65 deletions(-) diff --git a/doc/vimtex.txt b/doc/vimtex.txt index fe33602a3e..29331f486b 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -3710,8 +3710,14 @@ pragmatic and provide a best-effort syntax highlighting - a decent trade of between simplicity and completeness. The Vimtex syntax plugin is loosely based on Dr Chip's syntax plugin for LaTeX -which is shipped by default with Vim and neovim (|ft-tex-syntax|): -http://www.drchip.org/astronaut/vim/index.html#SYNTAX_TEX +which is shipped by default with Vim and neovim (|ft-tex-syntax|) [0]. There +are several major differences that users may want to be aware of: +* Vimtex syntax use different names for almost all syntax groups. +* Vimtex syntax does not support syntax based folding. +* Vimtex syntax does not lint `@` in commands, e.g. `\@cmd` (you should know + what you are doing). + +[0]: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_TEX Associated settings: |g:vimtex_syntax_enabled| @@ -3724,13 +3730,19 @@ Associated settings: ------------------------------------------------------------------------------ SYNTAX CORE SPECIFICATION *vimtex-syntax-core* -TODO -* make sure to explain the math regions -* explain difference between top level and regions, and how commands contained - in regions can make things complicated - As it is relatively common for some users to customize their colorschemes, it is useful to describe some of the underlying "philosophy" of the syntax rules. +Note that, for the following information to be useful, the reader should have +at least some basic understanding of how to customize their colorschemes and +syntax highlighting. The best resources to learn about this are: + + i) |usr_06| "Using syntax highlighting" (READ THIS FIRST) + ii) https://gist.github.com/romainl/379904f91fa40533175dfaec4c833f2f + "The right way to override any highlighting if you don't want to edit + the colorscheme file directly" + This is a good resource that describes how to properly customize + the highlighting of syntax groups on top of a basic colorscheme. + iii) |usr_44| "Your own syntax highlighted" (ADVANCED) The main philosophy of the Vimtex syntax plugin is to keep things simple, structured, and consistent. There is a small set of primitive syntax elements @@ -3738,72 +3750,152 @@ whose higlighting rules are linked to conventional highlight groups (see |group-name|). More specialized syntax elements are then linked to a corresponding primitive syntax element. This allows a user to change the highlighting of primitives with the effect that corresponding elements are -automatically also updated. This gives a high degree of flexibility with -regards to customizing colorschemes for LaTeX files. - -The following is a list of the main primitive groups and which of the -conventional syntax groups are used by default for highlighting (again, see -|group-name|). - - `texCmd` -> `Statement` - Most rules are based on the "generic" LaTeX command `\cmd[...]{...}...` - where the number of optional and real arguments is generally unknown. - - `texOpt` -> `Identifier` - Optional argument groups, `[...]`. - - `texArg` -> `Include` - Real argument groups, `{...}`. - - `texComment` -> `Comment` - Needs no introduction... - - `texDelim` -> `Delimiter` - `texError` -> `Error` - `texLength` -> `Number` - `texMathRegion` -> `Special` - `texOpt` -> `Identifier` - `texParm` -> `Special` - `texRegion` -> `PreCondit` - `texSpecialChar` -> `SpecialChar` - `texSymbol` -> `SpecialChar` - -In addition, some more specific groups are also linked directly to -a conventional syntax group: - - `texCmdSpaceCodeChar` -> `Special` - `texCmdTodo` -> `Todo` - `texCmdType` -> `Type` - `texCommentTodo` -> `Todo` - `texEnvArgName` -> `PreCondit` - `texMathDelim` -> `Type` - `texMathEnvArgName` -> `Delimiter` - `texMathOper` -> `Operator` - `texOptSep` -> `NormalNC` - `texPartArgTitle` -> `String` - `texRefArg` -> `Special` - `texTitleArg` -> `Underlined` - -Finally, the following is a simplified description of how the more -specialised groups and syntax rules are structured and named. +automatically also updated. It gives a high degree of flexibility with regards +to customizing colorschemes for LaTeX files. + +Most of LaTeX syntax is based around the macro expansion where forms are of +the type `\name` + `[optional group(s)]` + `{argument group(s)}`, where there +can often (not always) be white spaces and newlines between the elements. An +argument group can often consist of other top level elements, but not always. +Further, since LaTeX is designed to have very strong support for typing +mathematical equations, there are several ways to start math mode, e.g. +`$ ... $`, `$$ ... $$`, `\( ... \)`, `\[ ... \]`, and `\begin{equation}` +matched with `\end{equation}`. Within math mode, there's a different subset of +commands available, and it is common to want a slightly different highlighting +of the math mode regions. + +Vimtex's syntax script is implemented to support these basic structures as +well as a large set of more specific commands and elements. The more specific +rules define groups whose names are are more specific, and it is usually +possible to define custom highlighting of specific commands and argument +groups. + +Finally, it is useful to explain the naming scheme of specialized groups. The +general idea can be described as follows. `texCmd{type}` `tex{type}Opt` `tex{type}Arg` - A lot of LaTeX macros and commands are specified specifically with a given - number of optional and real arguments. They may also specify what those - arguments are. For instance, `\include{...}` wants a file argument. This - is matched as `texCmdInput`, and it is followed by a `texFileArg` argument - group. In most cases, the highlighting of `texCmd{type}` is linked to - `texCmd` and the highlighting of `tex{type}Opt` and `tex{type}Arg` are - respectively linked to `texOpt` and `texArg`. + A lot of LaTeX macros and commands are specified specifically with + a given number of optional and real arguments. They may also specify what + those arguments are. In most cases, the highlighting of `texCmd{type}` is + linked to `texCmd` and the highlighting of `tex{type}Opt` and + `tex{type}Arg` are respectively linked to `texOpt` and `texArg`. An + example of this scheme is `texCmdAuthor`, `texAuthorOpt`, and + `texAuthorArg` for `\author[...]{...}`. + Often, but not always, `texCmd{name}` is coupled with `tex{name}*` + groups. For example, `\include{...}` wants a file argument. The command is + matched as `texCmdInput`, but it is followed by a `texFileArg` argument + group. `tex{type}Region` Some commands open specific syntax regions that have different rules. Math mode is a good example. Math mode is highlighted differently, and the - syntax regions are name `texMathRegion*`. These regions may typically - contain their own (sub)sets of syntax groups, many that will only match - within a specific region. + syntax regions are name `texMathRegion*`. The `tex{type}Region`s may typically + contain their own (sub)sets of syntax groups that are only matched within + the specific region. Another example is the inclusion of nested syntax + highlighting with e.g. the `minted` or `listings` packages. + + `tex{type}{element}` + Some regions or commands include other types of elements, e.g. parameters + like in `\def\name #1` where `#1` is matched as `texDefParm`. For + completeness: `\def` is matched as `texCmdDef` and `\name` is matched as + `texDefArgName`. + +------------------------------------------------------------------------------ +SYNTAX CORE REFERENCE *vimtex-syntax-reference* + +The following is a reference of the main syntax groups and its default +highlighting, as well as one ore more examples of what it matches. Most of the +primitive groups are linked to conventional syntax groups as listed in +|group-name|. In the examples, capital letters are used to indicate which +parts are matched by the current group. For even more details, please refer to +the code itself in `autoload/vimtex/syntax/core.vim` for the core elements and +`autoload/vimtex/syntax/p/*.vim` for package specific elements. + +Table 1: A list of groups that are only primitive link targets.~ +> + GROUP DEFAULT + ---------------------------------------------------------------------------- + texCmdType Type + texError Error + texParm Special + texRegion PreCondit + texSymbol SpecialChar + +Table 2: A list of the most common normal LaTeX groups.~ +> + GROUP DEFAULT EXAMPLE + ---------------------------------------------------------------------------- + texComment Comment % COMMENT + texCommentTodo Todo % TODO + texDelim Delimiter {, }, [, and ] + texCmd Statement \CMD + texOpt Identifier \cmd[OPT] + texOptSep NormalNC [a, b] (commas) + texOptEqual texSymbol [a=b] + texArg Include \cmd[...]{ARG} + texSpecialChar SpecialChar \S, \P, \$, \;, ... + texCmdClass texCmd \DOCUMENTCLASS + texFileOpt texOpt \documentclass[CLASS OPTIONS] + texFileArg texArg \documentclass[...]{CLASS} + texCmdPackage texCmd \USEPACKAGE + texFilesOpt texOpt \usepackage[PACKAGE OPTIONS] + texFilesArg texArg \usepackage[...]{PACKAGE1, PACKAGE2} + texCmdInput texCmd \INPUT + texCmdInput texCmd \INCLUDEONLY + texFileArg texArg \input{FILE} + texFilesArg texArg \includeonly{FILE1, FILE2} + texCmdTitle texCmd \TITLE + texTitleArg Underlined \title{MAIN TITLE} + texCmdAuthor texCmd \AUTHOR + texAuthorOpt texOpt \author[OPT] + texAuthorArg NONE \author[...]{AUTHOR LIST} + texCmdPart texCmd \(SUB*)SECTION + texPartArgTitle String \(sub*)section{TITLE} + texCmdEnv texCmd \BEGIN; \END + texEnvArgName PreCondit \begin{ENVNAME} + texCmdRef texCmd \CITE; \LABEL + texRefArg Special \cite{REFERENCE}; \label{REF} + texE3Func texCmdType \STR_NEW:N + texE3Var texCmd \G_MYFILE_NAME_STR + +Table 3: A list of math mode groups.~ +> + GROUP DEFAULT EXAMPLE + ---------------------------------------------------------------------------- + texMathRegion Special \( HERE \); \[ HERE \] + texMathRegionEnv texMathRegion \begin{menv} HERE \end{menv} + texMathRegionEnvStarred texMathRegion \begin{menv*} HERE \end{menv*} + texMathRegionX texMathRegion $ HERE $ + texMathRegionXX texMathRegion $$ HERE $$ + texMathRegionEnsured texMathRegion \ensuremath{HERE} + texCmdMathEnv texCmdEnv \BEGIN; \END (for math environments) + texMathEnvArgName Delimiter \begin{EQUATION} + texCmdMath texCmd \ENSUREMATH + texMathDelim Type \LVERT + texMathDelimMod texMathDelim \LEFT\lvert \RIGHT\rvert + texMathOper Operator Basic operators: =; _; ^ + texMathError texError Unmatched region endings + +Table 4: A list of other important groups.~ +> + GROUP DEFAULT EXAMPLE + ---------------------------------------------------------------------------- + texLength Number Length units, e.g. "4 cm". Only when + contained e.g. in option groups. + texLigature texSymbol --; ---; ``; ''; ,, + texCmdAccent texCmd \"{a} + texCmdLigature texSpecialChar \ss; \ae + texCmdSpaceCodeChar Special https://en.wikibooks.org/wiki/TeX/catcode + texCmdTodo Todo \TODOSOMETHING + texCmdVerb texCmd \VERB + texVerbRegionInline texRegion \verb+VERB TEXT+ + texVerbRegion texRegion \begin{verbatim} VERB TEXT \end{verbatim} + texCmdDef texCmd \DEF + texDefArgName texArg \def\NAME + texDefParm texParm \def\name #1 + texCmdItem texCmd \item ------------------------------------------------------------------------------ SYNTAX PACKAGE SPECIFICATION *vimtex-syntax-packages* From 911376f3cc5981fd4df689bfe8a02266bd718c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 19 Nov 2020 12:35:50 +0100 Subject: [PATCH 96/99] wip: change texCmdParts to texCmdPart --- autoload/vimtex/syntax/core.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 9570bef0be..dd99e5245e 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -268,11 +268,11 @@ function! vimtex#syntax#core#init() abort " {{{1 call vimtex#syntax#core#new_arg('texRefArg', {'contains': 'texComment,@NoSpell'}) " Sections and parts - syntax match texCmdParts "\\\(front\|main\|back\)matter\>" - syntax match texCmdParts nextgroup=texPartArgTitle "\\part\>" - syntax match texCmdParts nextgroup=texPartArgTitle "\\chapter\>\*\?" - syntax match texCmdParts nextgroup=texPartArgTitle "\\\(sub\)*section\>\*\?" - syntax match texCmdParts nextgroup=texPartArgTitle "\\\(sub\)\?paragraph\>" + syntax match texCmdPart "\\\(front\|main\|back\)matter\>" + syntax match texCmdPart nextgroup=texPartArgTitle "\\part\>" + syntax match texCmdPart nextgroup=texPartArgTitle "\\chapter\>\*\?" + syntax match texCmdPart nextgroup=texPartArgTitle "\\\(sub\)*section\>\*\?" + syntax match texCmdPart nextgroup=texPartArgTitle "\\\(sub\)\?paragraph\>" call vimtex#syntax#core#new_arg('texPartArgTitle') " Item elements in lists @@ -550,7 +550,7 @@ function! s:init_highlights() abort " {{{1 highlight def link texCmdNewenv texCmd highlight def link texCmdNoSpell texCmd highlight def link texCmdPackage texCmd - highlight def link texCmdParts texCmd + highlight def link texCmdPart texCmd highlight def link texCmdRef texCmd highlight def link texCmdSize texCmdType highlight def link texCmdSpaceCode texCmd From 876431e42c0a56cbd011a6a388135a25344fee3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 19 Nov 2020 12:39:19 +0100 Subject: [PATCH 97/99] doc: minor improvements --- doc/vimtex.txt | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 29331f486b..0a1c94607b 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -67,6 +67,7 @@ CONTENTS *vimtex-contents* Syntax highlighting |vimtex-syntax| Syntax core specification |vimtex-syntax-core| Syntax package specification |vimtex-syntax-packages| + Syntax group reference |vimtex-syntax-reference| Navigation |vimtex-navigation| Include expression (|gf| command) |vimtex-includeexpr| Table of contents |vimtex-toc| @@ -3751,7 +3752,8 @@ whose higlighting rules are linked to conventional highlight groups (see a corresponding primitive syntax element. This allows a user to change the highlighting of primitives with the effect that corresponding elements are automatically also updated. It gives a high degree of flexibility with regards -to customizing colorschemes for LaTeX files. +to customizing colorschemes for LaTeX files. See |vimtex-syntax-reference| for +tables of the most important syntax groups with examples and descriptions. Most of LaTeX syntax is based around the macro expansion where forms are of the type `\name` + `[optional group(s)]` + `{argument group(s)}`, where there @@ -3803,7 +3805,23 @@ general idea can be described as follows. `texDefArgName`. ------------------------------------------------------------------------------ -SYNTAX CORE REFERENCE *vimtex-syntax-reference* +SYNTAX PACKAGE SPECIFICATION *vimtex-syntax-packages* + +Vimtex provides several package specific syntax addons that provide richer +syntax highlighting. These are built around the same principles as explained +in |vimtex-syntax-core|. + +The syntax improvements for a specific package are by default loaded only if +that package is detected in the current document (as explained in +|vimtex-package-detection|). This generally works well when a document is +compiled, but Vimtex may fail to detect packages for new documents or +documents that are not compiled. It is therefore possible to configure that +individual syntax packages should always load. One may also disable individual +syntax packages. See |g:vimtex_syntax_packages| for a full list of which +syntax addons exist and how to configure them. + +------------------------------------------------------------------------------ +SYNTAX GROUP REFERENCE *vimtex-syntax-reference* The following is a reference of the main syntax groups and its default highlighting, as well as one ore more examples of what it matches. Most of the @@ -3897,22 +3915,6 @@ Table 4: A list of other important groups.~ texDefParm texParm \def\name #1 texCmdItem texCmd \item ------------------------------------------------------------------------------- -SYNTAX PACKAGE SPECIFICATION *vimtex-syntax-packages* - -Vimtex provides several package specific syntax addons that provide richer -syntax highlighting. These are built around the same principles as explained -in |vimtex-syntax-core|. - -The syntax improvements for a specific package are by default loaded only if -that package is detected in the current document (as explained in -|vimtex-package-detection|). This generally works well when a document is -compiled, but Vimtex may fail to detect packages for new documents or -documents that are not compiled. It is therefore possible to configure that -individual syntax packages should always load. One may also disable individual -syntax packages. See |g:vimtex_syntax_packages| for a full list of which -syntax addons exist and how to configure them. - ============================================================================== NAVIGATION *vimtex-navigation* From f7b80ff64632dc053d46567a3b1c973e6cd58798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 19 Nov 2020 18:25:49 +0100 Subject: [PATCH 98/99] wip: more improvements to docs --- doc/vimtex.txt | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 0a1c94607b..b3f85c9e75 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -3751,9 +3751,11 @@ whose higlighting rules are linked to conventional highlight groups (see |group-name|). More specialized syntax elements are then linked to a corresponding primitive syntax element. This allows a user to change the highlighting of primitives with the effect that corresponding elements are -automatically also updated. It gives a high degree of flexibility with regards -to customizing colorschemes for LaTeX files. See |vimtex-syntax-reference| for -tables of the most important syntax groups with examples and descriptions. +automatically also updated. It is also possible to override specialized groups +to link them to other conventional groups or set colors directly. This gives +a high degree of flexibility with regards to customizing colorschemes for +LaTeX files. See |vimtex-syntax-reference| for tables of the most important +syntax groups with examples and descriptions. Most of LaTeX syntax is based around the macro expansion where forms are of the type `\name` + `[optional group(s)]` + `{argument group(s)}`, where there @@ -3828,8 +3830,12 @@ highlighting, as well as one ore more examples of what it matches. Most of the primitive groups are linked to conventional syntax groups as listed in |group-name|. In the examples, capital letters are used to indicate which parts are matched by the current group. For even more details, please refer to -the code itself in `autoload/vimtex/syntax/core.vim` for the core elements and -`autoload/vimtex/syntax/p/*.vim` for package specific elements. +the code itself: +* Core elements: The `s:init_highlights()` function in the file + `autoload/vimtex/syntax/core.vim` specifies the highlighting of the core + groups. +* Package specific groups and elements are defined in the package specific + scripts: `autoload/vimtex/syntax/p/*.vim`. Table 1: A list of groups that are only primitive link targets.~ > @@ -3854,16 +3860,28 @@ Table 2: A list of the most common normal LaTeX groups.~ texOptEqual texSymbol [a=b] texArg Include \cmd[...]{ARG} texSpecialChar SpecialChar \S, \P, \$, \;, ... + texCmdInput texCmd \INPUT + \INCLUDE + \INCLUDEONLY + \INCLUDEGRAPHICS + texCmdBib texCmd \BIBLIOGRAPHY + \BIBLIOGRAPHYSTYLE texCmdClass texCmd \DOCUMENTCLASS - texFileOpt texOpt \documentclass[CLASS OPTIONS] - texFileArg texArg \documentclass[...]{CLASS} texCmdPackage texCmd \USEPACKAGE - texFilesOpt texOpt \usepackage[PACKAGE OPTIONS] - texFilesArg texArg \usepackage[...]{PACKAGE1, PACKAGE2} - texCmdInput texCmd \INPUT - texCmdInput texCmd \INCLUDEONLY + \REQUIREPACKAGE + texFileOpt texOpt \includegraphics[PACKAGE OPTIONS] + \documentclass[CLASS OPTIONS] texFileArg texArg \input{FILE} - texFilesArg texArg \includeonly{FILE1, FILE2} + \include{FILE} + \includegraphics[...]{FILE} + \bibliographystyle{FILE} + \documentclass[...]{CLASS} + texFilesOpt texFileOpt \usepackage[PACKAGE OPTIONS] + \RequirePackage[PACKAGE OPTIONS] + texFilesArg texFileArg \includeonly{FILE1, FILE2} + \bibliography{FILE1, FILE2} + \usepackage[...]{PACKAGE1, PACKAGE2} + \RequirePackage[...]{PACKAGE1, PACKAGE2} texCmdTitle texCmd \TITLE texTitleArg Underlined \title{MAIN TITLE} texCmdAuthor texCmd \AUTHOR @@ -3905,7 +3923,8 @@ Table 4: A list of other important groups.~ texLigature texSymbol --; ---; ``; ''; ,, texCmdAccent texCmd \"{a} texCmdLigature texSpecialChar \ss; \ae - texCmdSpaceCodeChar Special https://en.wikibooks.org/wiki/TeX/catcode + texCmdSpaceCodeChar Special Catcodes. For more info, see: + https://en.wikibooks.org/wiki/TeX/catcode texCmdTodo Todo \TODOSOMETHING texCmdVerb texCmd \VERB texVerbRegionInline texRegion \verb+VERB TEXT+ From e42225e72d7276af6e17aba58102917729424261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 20 Nov 2020 16:16:38 +0100 Subject: [PATCH 99/99] wip: use texMathCmdStyle for math style commands --- autoload/vimtex/syntax/core.vim | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index dd99e5245e..df9726f6e7 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -190,16 +190,6 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdStyle "\\textup\>" syntax match texCmdStyle "\\emph\>" - syntax match texCmdStyle "\\mathbb\>" - syntax match texCmdStyle "\\mathbf\>" - syntax match texCmdStyle "\\mathcal\>" - syntax match texCmdStyle "\\mathfrak\>" - syntax match texCmdStyle "\\mathit\>" - syntax match texCmdStyle "\\mathnormal\>" - syntax match texCmdStyle "\\mathrm\>" - syntax match texCmdStyle "\\mathsf\>" - syntax match texCmdStyle "\\mathtt\>" - syntax match texCmdStyle "\\rmfamily\>" syntax match texCmdStyle "\\sffamily\>" syntax match texCmdStyle "\\ttfamily\>" @@ -378,6 +368,17 @@ function! vimtex#syntax#core#init() abort " {{{1 syntax match texCmdMathText "\\\(\(inter\)\?text\|mbox\)\>" nextgroup=texMathTextArg call vimtex#syntax#core#new_arg('texMathTextArg') + " Math style commands + syntax match texMathCmdStyle "\\mathbb\>" + syntax match texMathCmdStyle "\\mathbf\>" + syntax match texMathCmdStyle "\\mathcal\>" + syntax match texMathCmdStyle "\\mathfrak\>" + syntax match texMathCmdStyle "\\mathit\>" + syntax match texMathCmdStyle "\\mathnormal\>" + syntax match texMathCmdStyle "\\mathrm\>" + syntax match texMathCmdStyle "\\mathsf\>" + syntax match texMathCmdStyle "\\mathtt\>" + " Support for array environment syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\begin{array}" nextgroup=texMathArrayArg skipwhite skipnl syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\end{array}" @@ -581,6 +582,7 @@ function! s:init_highlights() abort " {{{1 highlight def link texMathArg texMathRegion highlight def link texMathArrayArg texOpt highlight def link texMathCmd texCmd + highlight def link texMathCmdStyle texMathCmd highlight def link texMathDelimMod texMathDelim highlight def link texMathDelimRegion texDelim highlight def link texMathError texError