diff --git a/README.md b/README.md index 9b677d4b23..ae8fa1a109 100644 --- a/README.md +++ b/README.md @@ -130,13 +130,11 @@ 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 + - 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/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/delim.vim b/autoload/vimtex/delim.vim index df3df9e00b..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 ==# '$' ? 'texMathZoneX' : 'texMathZoneY'), + \ (a:match ==# '$' ? 'texMathRegionX' : 'texMathRegionXX'), \ a:lnum, a:cnum+1) \ ? 'open' : 'close' let result.is_open = result.side ==# 'open' diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index 8f4be01fff..51d21f3a84 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -261,16 +261,17 @@ 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': - \ get(g:, 'tex_superscripts', '[0-9a-zA-W.,:;+-<>/()=]'), - \ 'conceal_set_sub': - \ get(g:, 'tex_subscripts', '[0-9aehijklmnoprstuvx,+-/().]'), - \}) - call s:init_option('vimtex_syntax_enabled', 1) + 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', @@ -280,21 +281,27 @@ function! vimtex#options#init() abort " {{{1 \ 'cs' : [ \ 'csBraces', \ ], - \ 'python' : [ - \ 'pythonEscape', - \ 'pythonBEscape', - \ 'pythonBytesEscape', + \ 'haskell' : [ + \ 'hsVarSym', \ ], \ 'java' : [ \ 'javaError', \ ], - \ 'haskell' : [ - \ 'hsVarSym', + \ 'markdown' : [ + \ 'mkdNonListItemBlock', + \ ], + \ 'python' : [ + \ 'pythonEscape', + \ 'pythonBEscape', + \ 'pythonBytesEscape', \ ], \ } \}) - call s:init_option('vimtex_syntax_autoload_packages', ['amsmath']) 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}, + \}) call s:init_option('vimtex_texcount_custom_arg', '') @@ -429,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.vim b/autoload/vimtex/syntax.vim index 2a6ce158d7..d0d4e68e67 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' @@ -60,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', ['texMathRegion'] + a:000) endfunction " }}}1 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..df9726f6e7 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -5,587 +5,779 @@ " 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() - 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 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 + " {{{2 Define main syntax clusters + + syntax cluster texClusterOpt contains= + \texCmd, + \texComment, + \texLength, + \texOpt, + \texOptEqual, + \texOptSep, + \@NoSpell + + syntax cluster texClusterMath contains= + \texCmdEnv, + \texCmdFootnote, + \texCmdGreek, + \texCmdMathText, + \texCmdRef, + \texCmdSize, + \texCmdStyle, + \texCmdTodo, + \texCmdVerb, + \texComment, + \texGroupError, + \texMathCmd, + \texMathCmdEnv, + \texMathDelim, + \texMathDelimMod, + \texMathGroup, + \texMathOper, + \texMathSub, + \texMathSuper, + \texMathSymbol, + \texSpecialChar, + \texTabularChar, + \@NoSpell - 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 + " }}}2 - 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 + " {{{2 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 expand('%:e') ==# 'dtx' + syntax match texComment "\^\^A.*$" + syntax match texComment "^%\+" + else + syntax match texComment "%.*$" contains=@Spell + endif - 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 + " 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 cluster texClusterComment contains=texTodo,@Spell + " Todo and similar within comments + syntax case ignore + syntax keyword texCommentTodo combak fixme todo xxx + \ containedin=texComment contained + syntax case match " }}}2 + " {{{2 TeX symbols and special characters - " {{{2 Primitives + syntax match texLigature "--" + syntax match texLigature "---" + syntax match texLigature "\v%(``|''|,,)" + syntax match texTabularChar "&" + syntax match texTabularChar "\\\\" - " 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 + " E.g.: \$ \& \% \# \{ \} \_ \S \P + syntax match texSpecialChar "\\[$&%#{}_]" + syntax match texSpecialChar "\\[SP@]\ze[^a-zA-Z@]" + syntax match texSpecialChar "\^\^\%(\S\|[0-9a-f]\{2}\)" + syntax match texSpecialChar "\\[,;:!]" - syntax match texDelimiter "&" + " }}}2 + " {{{2 Commands: general - " TeX String Delimiters - syntax match texString "\(``\|''\|,,\)" + " Unspecified TeX groups + " Note: This is necessary to keep track of all nested braces + call vimtex#syntax#core#new_arg('texGroup', {'opts': ''}) - " Flag mismatching ending delimiters } and ] - syntax match texError "[}\]]" - syntax match texErrorMath "}" contained + " Flag mismatching ending brace delimiter + syntax match texGroupError "}" - " Tex commands - syntax match texStatement "\\\a\+" - syntax match texErrorStatement "\\\a*@\a*" + " Add generic option elements contained in common option groups + syntax match texOptEqual contained "=" + syntax match texOptSep contained ",\s*" - " 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 '---' - - if l:cfg.is_style_document - syntax match texStatement "\\[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 + " 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\)\>" - " 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 + " Match general commands first + 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'}) - " 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 + " 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'}) - " Other - syntax match texOption "\v%(^|[^\\]\zs)#\d+" + " {{{2 Commands: core set - " 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 texInputCurlies "[{}]" contained - syntax region texInputFileOpt matchgroup=Delimiter start="\[" end="\]" contains=texComment contained + " Accents and ligatures + 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 " * \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 - - " Comments - if l:cfg.ext ==# 'dtx' - " Documented TeX Format: Only leading "^^A" and "%" - syntax match texComment "\^\^A.*$" contains=@texClusterComment - syntax match texComment "^%\+" contains=@texClusterComment - else - syntax match texComment "%.*$" contains=@texClusterComment - endif + 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 - " 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 + " Todo commands + syntax match texCmdTodo '\\todo\w*' - " Todo and similar within comments - syntax case ignore - syntax keyword texTodo contained combak fixme todo xxx - syntax case match - syntax match texStatement '\\todo\w*' contains=texTodo - syntax match texTodo '\\todo\w*' + " \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'}) - " TeX Lengths - syntax match texLength "\<\d\+\([.,]\d\+\)\?\s*\(true\)\?\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>" + " \title + syntax match texCmdTitle nextgroup=texTitleArg skipwhite skipnl "\\title\>" + call vimtex#syntax#core#new_arg('texTitleArg') + + " \footnote + syntax match texCmdFootnote nextgroup=texFootnoteArg skipwhite skipnl "\\footnote\>" + call vimtex#syntax#core#new_arg('texFootnoteArg') + + " Various commands that take a file argument (or similar) + 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_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\>" + 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 "\\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() + + " 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 nextgroup=texNewcmdArgName skipwhite skipnl "\\\%(re\)\?newcommand\>" + 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_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 + " E.g. \def \foo #1#2 {foo #1 bar #2 baz} + syntax match texCmdDef "\\def\>" nextgroup=texDefArgName skipwhite skipnl + 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') + + " Reference and cite commands + 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_opt('texRefOpt', {'next': 'texRefOpt,texRefArg'}) + call vimtex#syntax#core#new_arg('texRefArg', {'contains': 'texComment,@NoSpell'}) + + " Sections and parts + 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 + syntax match texCmdItem "\\item\>" + + " 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_arg('texNoSpellArg', {'contains': 'TOP,@Spell'}) - " }}}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,@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 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\>" + " \begin \end environments + syntax match texCmdEnv "\v\\%(begin|end)>" nextgroup=texEnvArgName + call vimtex#syntax#core#new_arg('texEnvArgName', {'next': 'texEnvOpt'}) + call vimtex#syntax#core#new_opt('texEnvOpt', {'contains': 'texComment,@NoSpell'}) - " }}}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\>" + " Tabular arguments + syntax match texCmdEnv "\\begin{tabular}" contains=texCmdEnv nextgroup=texTabularArg skipwhite skipnl + call vimtex#syntax#core#new_arg('texTabularArg', {'contains': ''}) " }}}2 + " {{{2 Region: Verbatim - " Should probably add highlighting of things like this: - " \section - " \frontmatter -> \part - " \paragraph - " \chapter - " \author - " \title - " \begin{abstract}? + " Verbatim environment + call vimtex#syntax#core#new_region_env('texVerbRegion', '[vV]erbatim', {'transparent': 0}) - " {{{2 Math stuff + " Verbatim inline + syntax match texCmdVerb "\\verb\>\*\?" nextgroup=texVerbRegionInline + call vimtex#syntax#core#new_arg('texVerbRegionInline', { + \ 'contains': '', + \ 'matcher': 'start="\z([^\ta-zA-Z]\)" end="\z1"' + \}) - " Bad/Mismatched math - syntax match texBadMath "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}" - syntax match texBadMath "\\[\])]" + " }}}2 + " {{{2 Region: Expl3 - " Operators and similar - syntax match texMathOper "[_^=]" contained + syntax region texE3Region matchgroup=texCmdE3 + \ start='\\\%(ExplSyntaxOn\|ProvidesExpl\%(Package\|Class\|File\)\)' + \ end='\\ExplSyntaxOff\|\%$' + \ transparent + \ contains=TOP,@NoSpell - " Text Inside Math Zones - syntax region texMathText matchgroup=texStatement start="\\\(\(inter\)\?text\|mbox\)\s*{" end="}" contains=@texClusterMathText,@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) - - " Inline Math Zones - syntax region texMathZoneZ matchgroup=texStatement start="\\ensuremath\s*{" matchgroup=texStatement end="}" contains=@texMathZoneGroup - 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 - 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 - endif + call vimtex#syntax#core#new_arg('texE3Group', {'opts': 'contained containedin=@texClusterE3'}) - " Math delimiters: \left... and \right... - syntax match texMathDelimBad contained "\S" - if l:cfg.conceal !~# 'm' || &encoding !=# 'utf-8' - 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 - 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\>" + 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'}) - " {{{2 Special TeX characters + syntax region texE3RegionNested matchgroup=texCmdE3 + \ start='\\\ExplSyntaxOn' + \ end='\\ExplSyntaxOff' + \ contained containedin=@texClusterE3 + \ transparent + \ contains=TOP,@NoSpell - " E.g.: \$ \& \% \# \{ \} \_ \S \P + 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 match texSpecialChar "\\[$&%#{}_]" - if l:cfg.is_style_document - syntax match texSpecialChar "\\[SP@]\ze[^a-zA-Z@]" + syntax cluster texClusterE3 contains=texE3RegionNested,texE3Region,texE3Arg,texE3Group + + " }}}2 + " {{{2 Region: Math + + " Define math region group + call vimtex#syntax#core#new_arg('texMathGroup', {'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') + 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 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="\$" + syntax region texMathRegionXX matchgroup=texMathDelimRegion concealends contains=@texClusterMath keepend start="\$\$" end="\$\$" else - syntax match texSpecialChar "\\[SP@]\ze\A" + 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 - syntax match texSpecialChar "\\\\" - syntax match texOnlyMath "[_^]" - 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" - if l:cfg.is_style_document - syntax region texZone start="\\verb\*\?\z([^\ta-zA-Z@]\)" end="\z1" - endif + " Math regions: \ensuremath{...} + syntax match texCmdMath "\\ensuremath\>" nextgroup=texMathRegionEnsured + call vimtex#syntax#core#new_arg('texMathRegionEnsured', {'contains': '@texClusterMath'}) - " 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 - - " \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 + " Bad/Mismatched math + syntax match texMathError "\\[\])]" + syntax match texMathError "\\end\s*{\s*\(array\|[bBpvV]matrix\|split\|smallmatrix\)\s*}" - " }}}2 + " Operators and similar + syntax match texMathOper "[_^=]" contained - " {{{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=@texClusterNewCmd - 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 - - " 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\+" + " Text Inside Math regions + 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}" + call vimtex#syntax#core#new_arg('texMathArrayArg', {'contains': ''}) + + call s:match_math_sub_super() + call s:match_math_symbols() + call s:match_math_delims() + " }}}2 " {{{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=‘ - syntax match texSpecialChar '\\glqq\>' contained conceal cchar=„ - syntax match texSpecialChar '\\grqq\>' contained conceal cchar=“ - syntax match texSpecialChar '\\hyp\>' contained conceal cchar=- - endif - - " Many of these symbols were contributed by Björn Winckler - if l:cfg.conceal =~# 'm' - call s:match_conceal_math_symbols() - endif - " Conceal replace greek letters - if l:cfg.conceal =~# 'g' + if g:vimtex_syntax_conceal.greek call s:match_conceal_greek() endif - " Conceal replace superscripts and subscripts - if l:cfg.conceal =~# 's' - 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 g:vimtex_syntax_conceal.accents call s:match_conceal_accents() endif endif " }}}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 texStatement /\\' . l:macro . '/' - \ 'nextgroup=texVimtexNospell' - endfor - - call s:init_highlights(l:cfg) + call s:init_highlights() let b:current_syntax = 'tex' +endfunction - 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 +" }}}1 + +function! vimtex#syntax#core#new_arg(grp, ...) abort " {{{1 + let l:cfg = extend({ + \ 'contains': 'TOP,@NoSpell', + \ 'matcher': 'start="{" skip="\\\\\|\\}" end="}"', + \ 'next': '', + \ 'opts': 'contained', + \}, a:0 > 0 ? a:1 : {}) + + execute 'syntax region' a:grp + \ 'matchgroup=texDelim' + \ l:cfg.matcher + \ 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#load() abort " {{{1 - " Initialize b:vimtex_syntax - let b:vimtex_syntax = {} +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="\]"' + \ l:cfg.opts + \ (empty(l:cfg.contains) ? '' : 'contains=' . l:cfg.contains) + \ (empty(l:cfg.next) ? '' : 'nextgroup=' . l:cfg.next . ' skipwhite skipnl') +endfunction - " Initialize project cache (used e.g. for the minted package) - if !has_key(b:vimtex, 'syntax') - let b:vimtex.syntax = {} +" }}}1 + +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' + if !empty(l:cfg.contains) + 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 - " Reset included syntaxes (necessary e.g. when doing :e) - call vimtex#syntax#misc#include_reset() + execute 'syntax region' a:grp + \ 'start="\\begin{' . a:envname .'}"' + \ 'end="\\end{' . a:envname .'}"' + \ l:contains + \ l:options +endfunction - " Load syntax for documentclass and packages - call vimtex#syntax#packages#init() +" }}}1 +function! vimtex#syntax#core#new_region_math(mathzone, ...) abort " {{{1 + let l:cfg = extend({ + \ 'starred': 1, + \ 'next': '', + \}, a:0 > 0 ? a:1 : {}) + + let l:envname = a:mathzone . (l:cfg.starred ? '\*\?' : '') + + 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 -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*}/' - - 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' - - 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' + +function! s:init_highlights() abort " {{{1 + " See :help group-name for list of conventional group names + + " Primitive TeX highlighting groups + highlight def link texArg Include + 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 + highlight def link texEnvArgName PreCondit + 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 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 texSpecialChar SpecialChar + highlight def link texSymbol SpecialChar + highlight def link texTitleArg Underlined + highlight def texStyleBold gui=bold cterm=bold + highlight def texStyleBoth gui=bold,italic cterm=bold,italic + highlight def texStyleItal gui=italic cterm=italic + + " Inherited groups + 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 texCmdE3 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 texCmdPart texCmd + highlight def link texCmdRef texCmd + highlight def link texCmdSize texCmdType + highlight def link texCmdSpaceCode texCmd + highlight def link texCmdStyle texCmd + highlight def link texCmdStyle texCmdType + highlight def link texCmdStyleBold texCmd + highlight def link texCmdStyleBoldItal texCmd + 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 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 + highlight def link texFileOpt texOpt + 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 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 + highlight def link texMathErrorDelim texError + highlight def link texMathGroup texMathRegion + 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 texRefOpt texOpt + highlight def link texTabularArg texOpt + highlight def link texTabularChar texSymbol + highlight def link texVerbRegion texRegion + highlight def link texVerbRegionInline texVerbRegion endfunction " }}}1 -function! s:init_highlights(cfg) abort " {{{1 - " 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 - if a:cfg.is_style_document - highlight def link texOnlyMath texError - endif +function! s:match_bold_italic() abort " {{{1 + let [l:conceal, l: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 + syntax cluster texClusterItalBold contains=TOP,@NoSpell,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'], + \ ['texCmdStyleItalBold', 'textbf'], + \ ['texCmdStyleBold', 'textbf'], + \ ['texCmdStyleItal', 'emph'], + \ ['texCmdStyleItal', 'textit'], + \] + execute 'syntax match' l:group '"\\' . l:pattern . '\>\s*" skipwhite skipnl nextgroup=' . l:map[l:group] l:conceal + endfor - 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 texCite texRefZone - 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 texMathMatcher texMath - highlight def link texAccent texStatement - highlight def link texGreek texStatement - highlight def link texSuperscript texStatement - highlight def link texSubscript texStatement - highlight def link texSuperscripts texSuperscript - highlight def link texSubscripts texSubscript - highlight def link texMathSymbol texStatement - 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 texSpaceCode texStatement - highlight def link texStyleStatement texStatement - 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 texRefZone 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 texZone PreCondit - - " New - highlight def link texCommentURL Comment - highlight def link texCommentAcronym Comment - highlight def link texDefParmNested Identifier + 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_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=⇕ +function! s:match_math_sub_super() " {{{1 + if !g:vimtex_syntax_conceal.math_super_sub | return | endif - if &ambiwidth ==# 'double' - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\langle" contained conceal cchar=〈 - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\rangle" contained conceal cchar=〉 - else - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\langle" contained conceal cchar=< - syntax match texMathSymbol "\\[bB]igg\?[lr]\?\\rangle" contained conceal cchar=> - endif + 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 + + 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_conceal_math_symbols() abort " {{{1 +function! s:match_math_symbols() abort " {{{1 + " Many of these symbols were contributed by Björn Winckler + if !g:vimtex_syntax_conceal.math_symbols | return | endif + syntax match texMathSymbol "\\|" contained conceal cchar=‖ syntax match texMathSymbol "\\aleph\>" contained conceal cchar=ℵ syntax match texMathSymbol "\\amalg\>" contained conceal cchar=∐ @@ -757,13 +949,9 @@ function! s:match_conceal_math_symbols() abort " {{{1 syntax match texMathSymbol "\\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=≪ 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=⟪ endif @@ -833,31 +1021,103 @@ function! s:match_conceal_math_symbols() abort " {{{1 endfunction " }}}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 "[<>()[\]|/.]\|\\[{}|]" + 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 !g:vimtex_syntax_conceal.math_delimiters || &encoding !=# 'utf-8' + return + endif + + 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 texMathDelim contained conceal cchar=〈 "\\\%([bB]igg\?l\|left\)\\langle" + syntax match texMathDelim contained conceal cchar=〉 "\\\%([bB]igg\?r\|right\)\\rangle" + else + syntax match texMathDelim contained conceal cchar=< "\\\%([bB]igg\?l\|left\)\\langle" + syntax match texMathDelim 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 texAccent /' . 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 - 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 - 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 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 = [ @@ -919,179 +1179,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=Ω -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 - - for [l:from, l:to] in filter(copy(s:map_super), - \ {_, x -> x[0][0] ==# '\' || x[0] =~# a:cfg.conceal_set_super}) - 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}) - 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 + 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 -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 diff --git a/autoload/vimtex/syntax/misc.vim b/autoload/vimtex/syntax/nested.vim similarity index 60% rename from autoload/vimtex/syntax/misc.vim rename to autoload/vimtex/syntax/nested.vim index b7e632dc8d..5a403c585b 100644 --- a/autoload/vimtex/syntax/misc.vim +++ b/autoload/vimtex/syntax/nested.vim @@ -4,25 +4,7 @@ " 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 +function! vimtex#syntax#nested#include(name) abort " {{{1 let l:inc_name = 'vimtex_nested_' . a:name if !has_key(s:included, l:inc_name) @@ -33,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 66b2b4c6c4..70d735bdee 100644 --- a/autoload/vimtex/syntax/p/amsmath.vim +++ b/autoload/vimtex/syntax/p/amsmath.vim @@ -6,38 +6,30 @@ 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') + 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}) - " 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 - \ "\(\\begin\>\|\\end\>\)\ze{subequations}" - \ nextgroup=texBeginEndName - - 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) - - " Amsmath [lr][vV]ert (Holger Mitschke) - if has('conceal') && &enc ==# 'utf-8' && get(g:, 'tex_conceal', 'd') =~# 'd' - for l:texmath in [ - \ ['\\lvert', '|'] , - \ ['\\rvert', '|'] , - \ ['\\lVert', '‖'] , - \ ['\\rVert', '‖'] , - \ ] - execute "syntax match texMathDelim '\\\\[bB]igg\\=[lr]\\=" - \ . l:texmath[0] . "' contained conceal cchar=" . l:texmath[1] - endfor + " Amsmath [lr][vV]ert + 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" + syntax match texMathDelim contained conceal cchar=‖ "\\\%([bB]igg\?r\|right\)\\rVert" endif + + 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/array.vim b/autoload/vimtex/syntax/p/array.vim index 76090dd73d..42a90dea2a 100644 --- a/autoload/vimtex/syntax/p/array.vim +++ b/autoload/vimtex/syntax/p/array.vim @@ -4,31 +4,20 @@ " 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() - if !get(g:, 'tex_fast', 'M') =~# 'M' | return | endif - - let l:concealed = has('conceal') - \ && &enc ==# 'utf-8' - \ && get(g:, 'tex_conceal', 'd') =~# 'd' +function! vimtex#syntax#p#array#load(cfg) abort " {{{1 + call vimtex#syntax#packages#load('tabularx') " 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 texMathZoneX - execute 'syntax region texMathZoneX' - \ 'matchgroup=Delimiter' - \ 'start="\([<>]{\)\@"' - \ 'contains=@texMathZoneGroup' - \ (l:concealed ? 'concealends' : '') + execute 'syntax region texMathRegionX matchgroup=texDelim' + \ 'start="\([<>]{\)\@' 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 84ed5a3dc8..0e6e18209c 100644 --- a/autoload/vimtex/syntax/p/beamer.vim +++ b/autoload/vimtex/syntax/p/beamer.vim @@ -4,25 +4,20 @@ " 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 - syntax match texBeamerDelimiter '<\|>' contained - syntax match texBeamerOpt '<[^>]*>' contained contains=texBeamerDelimiter + syntax match texCmdBeamer '\\only\(<[^>]*>\)\?' contains=texBeamerOpt + syntax match texCmdItem '\\item<[^>]*>' contains=texBeamerOpt - syntax match texStatementBeamer '\\only\(<[^>]*>\)\?' contains=texBeamerOpt - syntax match texStatementBeamer '\\item<[^>]*>' contains=texBeamerOpt + syntax match texCmdInput "\\includegraphics<[^>]*>" + \ contains=texBeamerOpt + \ nextgroup=texFileOpt,texFileArg - syntax match texInputFile - \ '\\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 + highlight link texCmdBeamer texCmd + 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 f96ad55fea..2020c4b8d8 100644 --- a/autoload/vimtex/syntax/p/biblatex.vim +++ b/autoload/vimtex/syntax/p/biblatex.vim @@ -4,77 +4,35 @@ " 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 - - if get(g:, 'tex_fast', 'r') !~# 'r' | return | endif - - 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 texStatement' - \ '/\v\\' . l:pattern . '\ze\s*%(\[|\{)/' - \ 'nextgroup=texRefOption,texCite' - 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 texStatement' - \ '/\v\\' . l:pattern . '\ze\s*%(\[|\{)/' - \ 'nextgroup=texRefOptions,texCites' - endfor - - for l:pattern in [ - \ '%(foreign|hyphen)textcquote\*?', - \ '%(foreign|hyphen)blockcquote', - \ 'hybridblockcquote', - \] - execute 'syntax match texStatement' - \ '/\v\\' . l:pattern . '\ze\s*%(\[|\{)/' - \ 'nextgroup=texQuoteLang' - endfor - - syntax region texRefOptions contained matchgroup=Delimiter - \ start='\[' end=']' - \ contains=@texRefGroup,texRefZone - \ nextgroup=texRefOptions,texCites - - syntax region texCites contained matchgroup=Delimiter - \ start='{' end='}' - \ contains=@texRefGroup,texRefZone,texCites - \ nextgroup=texRefOptions,texCites - - syntax region texQuoteLang contained matchgroup=Delimiter - \ start='{' end='}' - \ transparent - \ contains=@texMatchGroup - \ nextgroup=texRefOption,texCite - - highlight def link texRefOptions texRefOption - highlight def link texCites texCite +function! vimtex#syntax#p#biblatex#load(cfg) abort " {{{1 + syntax match texCmdBib nextgroup=texFilesArg "\\addbibresource\>" + + 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 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_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/booktabs.vim b/autoload/vimtex/syntax/p/booktabs.vim new file mode 100644 index 0000000000..ffbd9f6010 --- /dev/null +++ b/autoload/vimtex/syntax/p/booktabs.vim @@ -0,0 +1,14 @@ +" vimtex - LaTeX plugin for Vim +" +" Maintainer: Karl Yngve Lervåg +" Email: karl.yngve@gmail.com +" + +function! vimtex#syntax#p#booktabs#load(cfg) abort " {{{1 + syntax match texCmdBooktabs "\\\%(top\|mid\|bottom\)rule\>" + + highlight def link texCmdBooktabs texMathDelim +endfunction + +" }}}1 + diff --git a/autoload/vimtex/syntax/p/breqn.vim b/autoload/vimtex/syntax/p/breqn.vim index f9ed9bb658..90f64a1399 100644 --- a/autoload/vimtex/syntax/p/breqn.vim +++ b/autoload/vimtex/syntax/p/breqn.vim @@ -6,14 +6,11 @@ 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 - - call vimtex#syntax#core#new_math_zone('BreqnA', 'dmath', 1) - call vimtex#syntax#core#new_math_zone('BreqnB', 'dseries', 1) - call vimtex#syntax#core#new_math_zone('BreqnC', 'dgroup', 1) - call vimtex#syntax#core#new_math_zone('BreqnD', 'darray', 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') + 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 8916d235d5..cd77dcb379 100644 --- a/autoload/vimtex/syntax/p/cases.vim +++ b/autoload/vimtex/syntax/p/cases.vim @@ -6,11 +6,8 @@ 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 - - call VimtexNewMathZone('E', '\(sub\)\?numcases', 0) +function! vimtex#syntax#p#cases#load(cfg) abort " {{{1 + call vimtex#syntax#core#new_region_math('\(sub\)\?numcases', {'starred': 0}) endfunction " }}}1 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/autoload/vimtex/syntax/p/cleveref.vim b/autoload/vimtex/syntax/p/cleveref.vim index d547b6a1fe..b0cb536c9b 100644 --- a/autoload/vimtex/syntax/p/cleveref.vim +++ b/autoload/vimtex/syntax/p/cleveref.vim @@ -4,37 +4,25 @@ " 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 - if get(g:, 'tex_fast', 'r') !~# 'r' | return | endif - - syntax match texStatement '\\\(\(label\)\?c\(page\)\?\|C\)ref\>' - \ nextgroup=texCRefZone +function! vimtex#syntax#p#cleveref#load(cfg) abort " {{{1 + syntax match texCmdCRef nextgroup=texCRefArg skipwhite skipnl + \ "\\\%(\%(label\)\?c\%(page\)\?\|C\)ref\>" " \crefrange, \cpagerefrange (these commands expect two arguments) - syntax match texStatement '\\c\(page\)\?refrange\>' - \ nextgroup=texCRefZoneRange skipwhite skipnl + syntax match texCmdCRef nextgroup=texCRefRangeArg skipwhite skipnl + \ "\\c\(page\)\?refrange\>" " \label[xxx]{asd} - syntax match texStatement '\\label\[.\{-}\]' - \ nextgroup=texCRefZone skipwhite skipnl - \ contains=texCRefLabelOpts + syntax match texCmdCRef nextgroup=texCRefOpt,texRefArg skipwhite skipnl "\\label\>" - syntax region texCRefZone contained matchgroup=Delimiter - \ start="{" end="}" - \ contains=@texRefGroup,texRefZone - syntax region texCRefZoneRange contained matchgroup=Delimiter - \ start="{" end="}" - \ contains=@texRefGroup,texRefZone - \ nextgroup=texCRefZone skipwhite skipnl - syntax region texCRefLabelOpts contained matchgroup=Delimiter - \ start='\[' end=']' - \ contains=@texRefGroup,texRefZone + 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 link texCRefZone texRefZone - highlight link texCRefZoneRange texRefZone - highlight link texCRefLabelOpts texCmdArgs + 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 8b5a30b61b..b729cc2665 100644 --- a/autoload/vimtex/syntax/p/csquotes.vim +++ b/autoload/vimtex/syntax/p/csquotes.vim @@ -4,11 +4,13 @@ " 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\>" + call vimtex#syntax#core#new_arg('texQuoteArg', {'next': 'texRefOpt,texRefArg', 'opts': 'contained transparent'}) - call vimtex#syntax#p#biblatex#load() + highlight def link texCmdQuote texCmd endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/dot2texi.vim b/autoload/vimtex/syntax/p/dot2texi.vim index 46285f41e1..482e214901 100644 --- a/autoload/vimtex/syntax/p/dot2texi.vim +++ b/autoload/vimtex/syntax/p/dot2texi.vim @@ -4,18 +4,10 @@ " 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 - - 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 - \ keepend - \ transparent - \ contains=texBeginEnd,@vimtex_nested_dot +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'}) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/glossaries.vim b/autoload/vimtex/syntax/p/glossaries.vim index 108fd9ef6c..a93b03fd58 100644 --- a/autoload/vimtex/syntax/p/glossaries.vim +++ b/autoload/vimtex/syntax/p/glossaries.vim @@ -6,15 +6,9 @@ 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 - - syntax match texStatement '\\gls\>' nextgroup=texGls - syntax region texGls matchgroup=Delimiter - \ start='{' end='}' - \ contained - \ contains=@NoSpell +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 " }}}1 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 c035bc6bbe..82b7bd03a4 100644 --- a/autoload/vimtex/syntax/p/gnuplottex.vim +++ b/autoload/vimtex/syntax/p/gnuplottex.vim @@ -4,18 +4,10 @@ " 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 - - 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 - \ keepend - \ transparent - \ contains=texBeginEnd,texBeginEndModifier,@vimtex_nested_gnuplot +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'}) endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/hyperref.vim b/autoload/vimtex/syntax/p/hyperref.vim index 6f97d64f1c..c13ed34f09 100644 --- a/autoload/vimtex/syntax/p/hyperref.vim +++ b/autoload/vimtex/syntax/p/hyperref.vim @@ -4,32 +4,26 @@ " 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 + call vimtex#syntax#core#new_arg('texHrefArgLink', { + \ 'next': 'texHrefArgText', + \ 'contains': 'texComment,@NoSpell', + \}) + call vimtex#syntax#core#new_arg('texHrefArgText') - syntax match texStatement '\\url\ze[^\ta-zA-Z]' nextgroup=texUrlVerb - syntax region texUrlVerb matchgroup=Delimiter - \ start='\z([^\ta-zA-Z]\)' end='\z1' contained + 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_arg('texUrlArg', {'contains': 'texComment,@NoSpell'}) - syntax match texStatement '\\url\ze\s*{' nextgroup=texUrl - syntax region texUrl matchgroup=Delimiter start='{' end='}' contained - syntax match texStatement '\\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 region texHyperref matchgroup=Delimiter start='\[' end='\]' contained - \ contains=@texRefGroup,texRefZone - syntax region texHyperref matchgroup=Delimiter start='{' end='}' contained - \ contains=@texRefGroup,texRefZone - - highlight link texUrl Function - highlight link texUrlVerb texUrl - highlight link texHref texUrl - highlight link texHyperref texRefZone + 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 2a0bd4d950..e146bdffd2 100644 --- a/autoload/vimtex/syntax/p/ieeetrantools.vim +++ b/autoload/vimtex/syntax/p/ieeetrantools.vim @@ -6,31 +6,18 @@ 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 - - call s:new_math_zone('IEEEeqnA', 'IEEEeqnarray') - call s:new_math_zone('IEEEeqnB', 'IEEEeqnarrayboxm') -endfunction - -" }}}1 - -function! s:new_math_zone(sfx, mathzone) abort " {{{1 - if get(g:, 'tex_fast', 'M') !~# 'M' | return | endif - - let foldcmd = get(g:, 'tex_fold_enabled') ? ' fold' : '' - - 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*}''' +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'}) + 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 diff --git a/autoload/vimtex/syntax/p/listings.vim b/autoload/vimtex/syntax/p/listings.vim index e608aa5223..953571a241 100644 --- a/autoload/vimtex/syntax/p/listings.vim +++ b/autoload/vimtex/syntax/p/listings.vim @@ -4,68 +4,64 @@ " Email: karl.yngve@gmail.com " -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() +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\+')}) + + " Match inline listings + syntax match texCmdVerb "\\lstinline\>" nextgroup=texVerbRegionInline + + " Match input file commands + syntax match texCmd "\\lstinputlisting\>" + \ nextgroup=texFileOpt,texFileArg skipwhite skipnl - " First some general support - syntax match texInputFile - \ "\\lstinputlisting\s*\(\[.\{-}\]\)\={.\{-}}" - \ contains=texStatement,texInputCurlies,texInputFileOpt - syntax match texZone "\\lstinline\s*\(\[.\{-}\]\)\={.\{-}}" + " Match \lstset + syntax match texCmdLstset "\\lstset\>" + \ nextgroup=texLstsetArg,texLstsetGroup skipwhite skipnl + call vimtex#syntax#core#new_arg('texLstsetGroup', { + \ 'contains': 'texComment,texLength,texOptSep,texOptEqual' + \}) - " Set all listings environments to listings - syntax cluster texFoldGroup add=texZoneListings - syntax region texZoneListings - \ start="\\begin{lstlisting}\(\_s*\[\_[^\]]\{-}\]\)\?"rs=s - \ end="\\end{lstlisting}\|%stopzone\>"re=e - \ keepend - \ contains=texBeginEnd + " Match unspecified lstlisting environment + syntax match texLstEnvBgn "\\begin{lstlisting}" + \ nextgroup=texLstOpt skipwhite skipnl contains=texCmdEnv + call vimtex#syntax#core#new_opt('texLstOpt') + call vimtex#syntax#core#new_region_env('texLstRegion', 'lstlisting', { + \ 'contains': 'texLstEnvBgn', + \ 'transparent': 0, + \}) - " 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#misc#include(l:nested) + let l:cluster = vimtex#syntax#nested#include(l:nested) if empty(l:cluster) | continue | endif - let l:group_main = 'texZoneListings' . 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:grp = 'texLstRegion' . toupper(l:nested[0]) . l:nested[1:] - execute 'syntax region' l:group_main - \ 'start="\c\\begin{lstlisting}\s*' - \ . '\[\_[^\]]\{-}language=' . l:nested . '\%(\s*,\_[^\]]\{-}\)\?\]"rs=s' - \ 'end="\\end{lstlisting}"re=e' - \ 'keepend' + execute 'syntax match texLstsetArg' + \ '"\c{\_[^}]*language=' . l:nested . '\%(\s*,\|}\)"' + \ 'nextgroup=' . l:grp 'skipwhite skipnl' \ 'transparent' - \ 'contains=texBeginEnd,@' . l:cluster + \ 'contains=texLstsetGroup' - execute 'syntax match' l:group_lstset - \ '"\c\\lstset{.*language=' . l:nested . '\%(\s*,\|}\)"' - \ 'transparent' - \ 'contains=texStatement,texMatcher' - \ 'skipwhite skipempty' - \ 'nextgroup=' . l:group_contained + call vimtex#syntax#core#new_region_env(l:grp, 'lstlisting', { + \ 'contains': 'texLstEnvBgn,@' . l:cluster, + \ 'opts': 'contained', + \}) - execute 'syntax region' l:group_contained - \ 'start="\\begin{lstlisting}"rs=s' - \ 'end="\\end{lstlisting}"re=e' - \ 'keepend' - \ 'transparent' - \ 'containedin=' . l:group_lstset - \ 'contains=texStatement,texBeginEnd,@' . l:cluster + execute 'syntax region' l:grp + \ 'start="\c\\begin{lstlisting}\s*' + \ . '\[\_[^\]]\{-}language=' . l:nested . '\%(\s*,\_[^\]]\{-}\)\?\]"' + \ 'end="\\end{lstlisting}"' + \ 'keepend transparent' + \ 'contains=texCmdEnv,texLstEnvBgn,@' . l:cluster endfor - highlight link texZoneListings texZone -endfunction - -" }}}1 - -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/luacode.vim b/autoload/vimtex/syntax/p/luacode.vim index 0a3d96b7cc..d5974f8af0 100644 --- a/autoload/vimtex/syntax/p/luacode.vim +++ b/autoload/vimtex/syntax/p/luacode.vim @@ -4,24 +4,19 @@ " 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#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 - \ keepend - \ transparent - \ contains=texBeginEnd,@vimtex_nested_lua - syntax match texStatement '\\\(directlua\|luadirect\)' nextgroup=texZoneLuaArg - syntax region texZoneLuaArg matchgroup=Delimiter - \ start='{' - \ end='}' - \ contained - \ contains=@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', { + \ 'contains': '@vimtex_nested_lua', + \ 'opts': 'contained 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 f558dc6b9b..714302668f 100644 --- a/autoload/vimtex/syntax/p/markdown.vim +++ b/autoload/vimtex/syntax/p/markdown.vim @@ -4,36 +4,12 @@ " 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'}) - 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 - syntax match texBeginEnd - \ '\(\\begin\>\|\\end\>\)\ze{markdown}' - \ nextgroup=texBeginEndName - - syntax region texZoneMarkdown - \ start='\\begin{markdown}'rs=s - \ end='\\end{markdown}'re=e - \ keepend - \ transparent - \ contains=@texFoldGroup,@texDocGroup,@vimtex_nested_markdown - - " Input files - syntax match texInputFile /\\markdownInput\>/ - \ contains=texStatement - \ nextgroup=texInputFileArg - syntax region texInputFileArg - \ matchgroup=texInputCurlies - \ start="{" end="}" - \ contained - \ contains=texComment - - highlight default link texInputFileArg texInputFile + syntax match texCmdInput "\\markdownInput\>" nextgroup=texFileArg skipwhite skipnl endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/mathtools.vim b/autoload/vimtex/syntax/p/mathtools.vim index 90d524ba35..bea7a14681 100644 --- a/autoload/vimtex/syntax/p/mathtools.vim +++ b/autoload/vimtex/syntax/p/mathtools.vim @@ -4,14 +4,25 @@ " Email: karl.yngve@gmail.com " -scriptencoding utf-8 +function! vimtex#syntax#p#mathtools#load(cfg) abort " {{{1 + call vimtex#syntax#packages#load('amsmath') -function! vimtex#syntax#p#mathtools#load() abort " {{{1 - if has_key(b:vimtex_syntax, 'mathtools') | return | endif - let b:vimtex_syntax.mathtools = 1 + " Support for various envionrments with option groups + 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}" + 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'}) - " Load amsmath - call vimtex#syntax#p#amsmath#load() + highlight def link texMathToolsOptPos1 texOpt + highlight def link texMathToolsOptPos2 texOpt + highlight def link texMathToolsOptWidth texOpt endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/minted.vim b/autoload/vimtex/syntax/p/minted.vim index 954c64b996..176d53049d 100644 --- a/autoload/vimtex/syntax/p/minted.vim +++ b/autoload/vimtex/syntax/p/minted.vim @@ -4,148 +4,130 @@ " 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() - " Match minted language names - syntax region texMintedName matchgroup=Delimiter start="{" end="}" contained - syntax region texMintedNameOpt matchgroup=Delimiter start="\[" end="\]" contained - - " Match boundaries of minted environments - syntax match texMintedBounds '\\end{minted}' - \ contained - \ contains=texBeginEnd - syntax match texMintedBounds '\\begin{minted}' - \ contained - \ contains=texBeginEnd - \ nextgroup=texMintedBoundsOpts,texMintedName - syntax region texMintedBoundsOpts matchgroup=Delimiter - \ start="\[" end="\]" - \ contained - \ nextgroup=texMintedName - - " Match starred custom minted environments with options - syntax match texMintedStarred "\\begin{\w\+\*}" - \ contained - \ contains=texBeginEnd - \ nextgroup=texMintedStarredOpts - syntax region texMintedStarredOpts matchgroup=Delimiter - \ start='{' - \ end='}' - \ contained - \ containedin=texMintedStarred - " Match \newminted type macros - 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 - \ keepend - \ contains=texMintedBounds.* - - " Match "unknown" commands - syntax match texArgMinted "{\w\+}" - \ contained - \ contains=texMintedName - \ nextgroup=texZoneMintedCmd - syntax region texZoneMintedCmd matchgroup=Delimiter - \ start='\z([|+/]\)' - \ end='\z1' - \ contained - syntax region texZoneMintedCmd matchgroup=Delimiter - \ start='{' - \ end='}' - \ contained + syntax match texCmdNewmint '\\newmint\%(ed\|inline\)\?\>' + \ skipwhite skipnl nextgroup=texNewmintOpt,texNewmintArgX + 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 + 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 + 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#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_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 = '' - let l:contains_env = '' - let l:contains_macro = '' - execute 'highlight link' l:group_main 'texZoneMinted' - execute 'highlight link' l:group_arg_zone 'texZoneMinted' + let l:cluster = vimtex#syntax#nested#include(l:nested) + + let l:name = toupper(l:nested[0]) . l:nested[1:] + 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 - \ 'start="\\begin{minted}\%(\_s*\[\_[^\]]\{-}\]\)\?\_s*{' . l:nested . '}"rs=s' - \ 'end="\\end{minted}"re=e' - \ 'keepend' - \ l:transparent - \ 'contains=texMintedBounds.*' . l:contains_env + " Match normal minted environments + execute 'syntax region' l:grp_env + \ 'start="\\begin{minted}\%(\_s*\[\_[^\]]\{-}\]\)\?\_s*{' . l:nested . '}"' + \ 'end="\\end{minted}"' + \ 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 - \ 'start="\\begin{\z(' . l:env . '\*\?\)}"rs=s' - \ 'end="\\end{\z1}"re=e' - \ 'keepend' - \ l:transparent - \ 'contains=texMintedStarred,texBeginEnd' . l:contains_env + execute 'syntax region' l:grp_env + \ 'start="\\begin{\z(' . l:env . '\*\?\)}"' + \ 'end="\\end{\z1}"' + \ l:options + \ l:contains endfor - " Match minted macros - " - \mint[]{lang}|...| - " - \mint[]{lang}{...} - " - \mintinline[]{lang}|...| - " - \mintinline[]{lang}{...} - execute 'syntax match' l:group_arg '''{' . l:nested . '}''' - \ 'contained' - \ 'contains=texMintedName' - \ 'nextgroup=' . l:group_arg_zone - execute 'syntax region' l:group_arg_zone - \ 'matchgroup=Delimiter' - \ 'start=''\z([|+/]\)''' - \ 'end=''\z1''' + " 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' - \ l:contains_macro - execute 'syntax region' l:group_arg_zone - \ 'matchgroup=Delimiter' - \ 'start=''{''' - \ 'end=''}''' - \ 'contained' - \ l:contains_macro - - " Match minted custom macros + \ 'contains=texMintedArg' + \ '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 texStatement ''\\%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 texStatement '\\mint\(inline\)\?' nextgroup=texArgOptMinted,texArgMinted.* - syntax region texArgOptMinted matchgroup=Delimiter - \ start='\[' - \ end='\]' - \ contained - \ nextgroup=texArgMinted.* - - highlight link texZoneMinted texZone - highlight link texZoneMintedCmd texZone - highlight link texMintedName texInputFileOpt - highlight link texMintedNameOpt texMintedName + " 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/autoload/vimtex/syntax/p/moreverb.vim b/autoload/vimtex/syntax/p/moreverb.vim index 8074ba4d47..129cb4f28a 100644 --- a/autoload/vimtex/syntax/p/moreverb.vim +++ b/autoload/vimtex/syntax/p/moreverb.vim @@ -4,19 +4,10 @@ " 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 - - 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 - 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\>" - endif +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}) endfunction " }}}1 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 2eddac2b5a..2e5ecf2096 100644 --- a/autoload/vimtex/syntax/p/pdfpages.vim +++ b/autoload/vimtex/syntax/p/pdfpages.vim @@ -4,26 +4,8 @@ " 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 - - syntax match texInputFile /\\includepdf\>/ - \ contains=texStatement - \ 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 +function! vimtex#syntax#p#pdfpages#load(cfg) abort " {{{1 + 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 0b076097ee..7ccb095702 100644 --- a/autoload/vimtex/syntax/p/pgfplots.vim +++ b/autoload/vimtex/syntax/p/pgfplots.vim @@ -4,31 +4,53 @@ " 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 - - " Load Tikz first - call vimtex#syntax#p#tikz#load() - - " Add texAxisStatement to Tikz cluster - syntax cluster texTikz add=texAxisStatement - - " Match pgfplotsset and axis environments - syntax match texTikzSet /\\pgfplotsset\>/ - \ contains=texStatement skipwhite nextgroup=texTikzOptsCurly - syntax match texTikzEnv /\v\\begin\{%(log)*axis}/ - \ contains=texBeginEnd nextgroup=texTikzOpts skipwhite - syntax match texTikzEnv /\v\\begin\{groupplot}/ - \ contains=texBeginEnd nextgroup=texTikzOpts skipwhite - - " Match some custom pgfplots macros - syntax match texAxisStatement /\\addplot3\>/ - \ contained skipwhite nextgroup=texTikzOpts - syntax match texAxisStatement /\\nextgroupplot\>/ - \ contained skipwhite nextgroup=texTikzOpts - - highlight def link texAxisStatement texStatement +function! vimtex#syntax#p#pgfplots#load(cfg) abort " {{{1 + call vimtex#syntax#packages#load('tikz') + + syntax cluster texClusterTikz add=texCmdAxis + + syntax match texCmdTikzset nextgroup=texTikzsetArg skipwhite "\\pgfplotsset\>" + + 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'}) + 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'}) + + + 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 + highlight def link texPgfAddplotOpt texOpt + highlight def link texPgfTableOpt texOpt endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/pythontex.vim b/autoload/vimtex/syntax/p/pythontex.vim index a2ca94f7f2..d2146c3bc1 100644 --- a/autoload/vimtex/syntax/p/pythontex.vim +++ b/autoload/vimtex/syntax/p/pythontex.vim @@ -4,33 +4,21 @@ " 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') - call vimtex#syntax#misc#include('python') - - syntax match texStatement /\\py[bsc]\?/ contained nextgroup=texPythontexArg - syntax region texPythontexArg matchgroup=Delimiter - \ start='{' end='}' - \ contained contains=@vimtex_nested_python - syntax region texPythontexArg matchgroup=Delimiter + syntax match texCmdPythontex /\\py[bsc]\?/ nextgroup=texPythontexArg skipwhite skipnl + 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 + \ contained contains=@vimtex_nested_python keepend + + 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'}) - call vimtex#syntax#misc#add_to_section_clusters('texZonePythontex') - syntax region texZonePythontex - \ start='\\begin{pyblock}'rs=s - \ end='\\end{pyblock}'re=e - \ keepend - \ transparent - \ contains=texBeginEnd,@vimtex_nested_python - syntax region texZonePythontex - \ start='\\begin{pycode}'rs=s - \ end='\\end{pycode}'re=e - \ keepend - \ transparent - \ contains=texBeginEnd,@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 188c6058e9..4b28c73375 100644 --- a/autoload/vimtex/syntax/p/subfile.vim +++ b/autoload/vimtex/syntax/p/subfile.vim @@ -4,12 +4,9 @@ " 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 - - syntax match texInputFile /\\subfile\s*\%(\[.\{-}\]\)\=\s*{.\{-}}/ - \ contains=texStatement,texInputCurlies,texInputFileOpt +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 " }}}1 diff --git a/autoload/vimtex/syntax/p/tabularx.vim b/autoload/vimtex/syntax/p/tabularx.vim index b82ffca846..68aa1de4ab 100644 --- a/autoload/vimtex/syntax/p/tabularx.vim +++ b/autoload/vimtex/syntax/p/tabularx.vim @@ -4,69 +4,62 @@ " 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 + 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.* - call vimtex#syntax#misc#add_to_section_clusters('texTabular') + 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 texTabular '\\begin{tabular}\_[^{]\{-}\ze{' - \ contains=texBeginEnd - \ nextgroup=texTabularArg - syntax region texTabularArg matchgroup=Delimiter - \ start='{' end='}' - \ contained - syntax match texTabularCol /[lcr]/ - \ containedin=texTabularArg - \ contained - syntax match texTabularCol /[pmb]/ - \ containedin=texTabularArg - \ nextgroup=texTabularLength - \ contained - syntax match texTabularCol /\*/ - \ containedin=texTabularArg - \ nextgroup=texTabularMulti - \ contained - syntax region texTabularMulti matchgroup=Delimiter - \ start='{' end='}' - \ containedin=texTabularArg - \ nextgroup=texTabularArg - \ contained + 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'}) - syntax match texTabularAtSep /@/ - \ containedin=texTabularArg - \ nextgroup=texTabularLength - \ contained - syntax match texTabularVertline /||\?/ - \ containedin=texTabularArg - \ contained - syntax match texTabularPostPre /[<>]/ - \ containedin=texTabularArg - \ nextgroup=texTabularPostPreArg - \ contained + 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,texTabularCmd,texTabularMathdelim'}) - syntax region texTabularPostPreArg matchgroup=Delimiter - \ start='{' end='}' - \ containedin=texTabularArg - \ contains=texLength,texStatement,texMathDelimSingle - \ contained + 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', + \}) - syntax region texTabularLength matchgroup=Delimiter - \ start='{' end='}' - \ containedin=texTabularArg - \ contains=texLength,texStatement - \ contained + 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 - 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 + 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 texMathDelimRegion + highlight def link texTabularOpt texEnvOpt endfunction " }}}1 diff --git a/autoload/vimtex/syntax/p/tikz.vim b/autoload/vimtex/syntax/p/tikz.vim index cc12907f02..c58dd69483 100644 --- a/autoload/vimtex/syntax/p/tikz.vim +++ b/autoload/vimtex/syntax/p/tikz.vim @@ -4,40 +4,37 @@ " 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 - - 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 - - " Define tikz option groups - syntax match texTikzSet /\\tikzset\>/ - \ contains=texStatement skipwhite nextgroup=texTikzOptsCurly - syntax region texTikzOpts matchgroup=Delimiter - \ start='\[' end='\]' contained contains=@texTikzOS - syntax region texTikzOptsCurly matchgroup=Delimiter - \ start='{' end='}' contained contains=@texTikzOS - - syntax region texTikzpicture - \ start='\\begin{tikzpicture}'rs=s - \ end='\\end{tikzpicture}'re=e - \ keepend - \ transparent - \ contains=@texTikz - syntax match texTikzEnv /\v\\begin\{tikzpicture\}/ - \ contains=texBeginEnd nextgroup=texTikzOpts skipwhite - - syntax match texTikzEqual /=/ contained - syntax match texTikzSemicolon /;/ contained - - highlight def link texTikzEqual Operator - highlight def link texTikzSemicolon Delimiter +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 + + 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 + call vimtex#syntax#core#new_region_env('texTikzRegion', 'tikzpicture', + \ {'contains': '@texClusterTikz'}) + call vimtex#syntax#core#new_opt('texTikzOpt', + \ {'contains': '@texClusterTikzset'}) + + syntax keyword texTikzCycle cycle contained + syntax match texTikzSemicolon ";" contained + syntax match texTikzDraw "--" contained + syntax match texTikzDraw "|-" contained + + 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 + highlight def link texTikzsetArg texOpt + highlight def link texTikzOpt texOpt endfunction " }}}1 - 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 ea14e062d1..9e4cd919a5 100644 --- a/autoload/vimtex/syntax/p/varioref.vim +++ b/autoload/vimtex/syntax/p/varioref.vim @@ -4,18 +4,8 @@ " 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 - if get(g:, 'tex_fast', 'r') !~# 'r' | return | endif - - syntax match texStatement '\\Vref\>' nextgroup=texVarioRefZone - - syntax region texVarioRefZone contained matchgroup=Delimiter - \ start="{" end="}" - \ contains=@texRefGroup,texRefZone - - highlight link texVarioRefZone texRefZone +function! vimtex#syntax#p#varioref#load(cfg) abort " {{{1 + 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 1c6abdc2c7..012a5af91a 100644 --- a/autoload/vimtex/syntax/p/wiki.vim +++ b/autoload/vimtex/syntax/p/wiki.vim @@ -4,19 +4,15 @@ " 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') - call vimtex#syntax#misc#add_to_section_clusters('texZoneWiki') - call vimtex#syntax#misc#include('markdown') - - syntax region texZoneWiki + syntax region texWikiRegion \ start='\\wikimarkup\>' - \ end='\\nowikimarkup\>'re=e + \ end='\\nowikimarkup\>' \ keepend \ transparent - \ contains=@vimtex_nested_markdown,@texFoldGroup,@texDocGroup + \ contains=texCmd,@vimtex_nested_markdown endfunction " }}}1 diff --git a/autoload/vimtex/syntax/packages.vim b/autoload/vimtex/syntax/packages.vim index 4cdf9db736..b0227d7a3a 100644 --- a/autoload/vimtex/syntax/packages.vim +++ b/autoload/vimtex/syntax/packages.vim @@ -5,28 +5,58 @@ " function! vimtex#syntax#packages#init() abort " {{{1 - if !exists('b:vimtex_syntax') | return | 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 + 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 + + 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 - 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 + call vimtex#syntax#p#{a:pkg}#load(l:cfg) + let l:cfg.__loaded = 1 +endfunction + +" }}}1 + +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 9d6f910fd5..b3f85c9e75 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 @@ -65,6 +65,9 @@ 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| + Syntax group reference |vimtex-syntax-reference| Navigation |vimtex-navigation| Include expression (|gf| command) |vimtex-includeexpr| Table of contents |vimtex-toc| @@ -96,47 +99,32 @@ 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 some LaTeX support out of the box. In particular, it provides -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|. +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: > - - 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* @@ -196,13 +184,11 @@ 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 + - 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` @@ -210,13 +196,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 @@ -226,7 +212,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 @@ -293,7 +279,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 +311,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 @@ -346,7 +327,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, @@ -386,7 +367,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 @@ -401,7 +382,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. @@ -478,7 +459,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|. @@ -517,7 +498,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 @@ -561,7 +542,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 @@ -633,7 +614,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|. @@ -696,7 +677,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|. @@ -720,7 +701,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|. @@ -804,12 +785,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 @@ -1070,7 +1051,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 @@ -1186,7 +1167,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 @@ -1373,7 +1354,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). @@ -1404,7 +1385,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|. @@ -1609,7 +1590,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. @@ -1748,12 +1729,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 @@ -1857,7 +1838,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,57 +1973,149 @@ 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. +*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 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~ + `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 |VimtexCountWords| and |VimtexCountLetters|. @@ -2300,7 +2373,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 @@ -2310,7 +2383,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 @@ -2750,8 +2823,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)* @@ -2801,7 +2874,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, @@ -2824,8 +2897,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)* @@ -3009,7 +3082,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, @@ -3061,7 +3134,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`. @@ -3084,7 +3157,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~ @@ -3093,9 +3166,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 @@ -3120,7 +3193,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* @@ -3140,7 +3213,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* @@ -3210,7 +3283,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|. @@ -3357,7 +3430,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* @@ -3416,7 +3489,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 = {} @@ -3567,7 +3640,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! @@ -3578,7 +3651,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 > @@ -3614,7 +3687,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: @@ -3628,52 +3701,247 @@ 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: - -- 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` - - *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|. - -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 - 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 +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 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 +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| + |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* + +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 +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 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 +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. 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*`. 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 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 +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: +* 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.~ +> + 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, \$, \;, ... + texCmdInput texCmd \INPUT + \INCLUDE + \INCLUDEONLY + \INCLUDEGRAPHICS + texCmdBib texCmd \BIBLIOGRAPHY + \BIBLIOGRAPHYSTYLE + texCmdClass texCmd \DOCUMENTCLASS + texCmdPackage texCmd \USEPACKAGE + \REQUIREPACKAGE + texFileOpt texOpt \includegraphics[PACKAGE OPTIONS] + \documentclass[CLASS OPTIONS] + texFileArg texArg \input{FILE} + \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 + 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 Catcodes. For more info, see: + 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 ============================================================================== 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|. @@ -3685,7 +3953,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: > @@ -3781,14 +4049,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 @@ -3801,7 +4069,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() @@ -3832,7 +4100,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 @@ -3904,7 +4172,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. @@ -3922,7 +4190,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)'"; @@ -3939,8 +4207,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. @@ -3979,7 +4247,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. @@ -4014,7 +4282,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 @@ -4097,7 +4365,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 @@ -4177,7 +4445,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|. @@ -4255,7 +4523,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|. @@ -4311,7 +4579,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 ``. @@ -4349,7 +4617,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|). @@ -4402,10 +4670,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|: > @@ -4432,7 +4700,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: @@ -4448,7 +4716,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 @@ -4467,7 +4735,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): > @@ -4660,11 +4928,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/. @@ -4687,6 +4955,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|. @@ -4914,7 +5187,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* @@ -4927,9 +5200,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: 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/syntax/tex.vim b/syntax/tex.vim index a6abd4076a..270978f517 100644 --- a/syntax/tex.vim +++ b/syntax/tex.vim @@ -3,5 +3,39 @@ " 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 +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! +call vimtex#options#init() + + +" 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#nested#reset() + + +" 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 -call vimtex#syntax#init() +unlet s:is_loading 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/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 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-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-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 19311404b5..84c940cd60 100644 --- a/test/tests/test-syntax/common.vim +++ b/test/tests/test-syntax/common.vim @@ -1,13 +1,10 @@ set nocompatible let &rtp = '../../..,' . &rtp -let &rtp .= ',../../../after' filetype plugin on syntax enable set nomore -let g:tex_flavor = 'latex' - nnoremap q :qall! " Use a more colorful colorscheme 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-amsmath.tex b/test/tests/test-syntax/test-amsmath.tex new file mode 100644 index 0000000000..0a0cec9272 --- /dev/null +++ b/test/tests/test-syntax/test-amsmath.tex @@ -0,0 +1,40 @@ +\documentclass{article} +\usepackage{amsmath} + +\begin{document} + +\begin{align} + f(x) &= \bigg\lvert 0 \bigg\rvert \\ + f(x) &= \Bigg\lVert 0 \Bigg\rVert \\ +\end{align} + +\begin{equation} + \sum_{\begin{subarray}{l}i\in\Lambda\\ 0 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-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} diff --git a/test/tests/test-syntax/test-core.tex b/test/tests/test-syntax/test-core.tex index 8e6479a7c0..165b7b1a75 100644 --- a/test/tests/test-syntax/test-core.tex +++ b/test/tests/test-syntax/test-core.tex @@ -5,12 +5,86 @@ \@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} +\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 +% +% 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.\footnote{here {asd} with \cmd also}. + +\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} + +\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} + +\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-core.vim b/test/tests/test-syntax/test-core.vim new file mode 100644 index 0000000000..c527660795 --- /dev/null +++ b/test/tests/test-syntax/test-core.vim @@ -0,0 +1,14 @@ +source common.vim + +silent edit test-core.tex + +if empty($INMAKE) | finish | endif + +call vimtex#test#assert(vimtex#syntax#in('texNewenvParm', 29, 36)) + +call vimtex#test#assert(vimtex#syntax#in('texVerbRegionInline', 35, 36)) + +call vimtex#test#assert(vimtex#syntax#in('texAuthorArg', 55, 20)) +call vimtex#test#assert(vimtex#syntax#in('texDelim', 55, 39)) + +quit! 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! 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-hyperref.vim b/test/tests/test-syntax/test-hyperref.vim index fd891de33f..2fec85e991 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('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 1a335f2755..0e8ad3839f 100644 --- a/test/tests/test-syntax/test-ieeetrantools.vim +++ b/test/tests/test-syntax/test-ieeetrantools.vim @@ -4,14 +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)) - -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)) +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-large.tex b/test/tests/test-syntax/test-large.tex deleted file mode 100644 index 5a9b646909..0000000000 --- a/test/tests/test-syntax/test-large.tex +++ /dev/null @@ -1,363 +0,0 @@ -\documentclass{beamer} -\usepackage{subfile} -\usepackage{includegraphics} -\usepackage{pdfpages} -\usepackage{hyperref} -\usepackage{testx} " Package does not exist - test try catch block -\usepackage{biblatex} -\usepackage{csquotes} -\usepackage{cleveref} -\usepackage{tabularx} -\usepackage{array} -\usepackage{varioref} -\usepackage{amsmath} -\usepackage{cases} -\usepackage{dot2texi} -\usepackage{luacode} -\usepackage{gnuplottex} -\usepackage[inline]{asymptote} -\usepackage{pythontex} -\usepackage{listings} -\usepackage{tikz} -\usepackage{pgfplots} - -\begin{document} - -\section{General} -\todostuff \todocommand \todo{content} - -This text is \emph{emphasized}, \textit{italized}, \textbf{bolded}. - -\def\A{A} -\def\B{\V{B}} - -\newenvironment{example}[1][]{Start #1}{Stop} -\renewenvironment{example}[1][]{Start #1}{Stop} -\newenvironment{nestedexample}[1][]{% - \renewenvironment{nested}[1][0]{% - Outerarg #1}{% - Innerarg ##1 - }% - \begin{nested}{title}}{% - \end{nested}% -} - -\newcommand{\testA}[1]{Test #1} -\renewcommand{\testA}[1]{Test #1} -\newcommand{\mycommand}[1]{% - \renewcommand{\myothercommand}[1]{% - \dosomethingwithouterarg{#1}% - \dosomethingwithinnerarg{##1}% - }% -} - -\section{Documentclass: beamer} -\begin{frame}[asd] - \includegraphics[height=0.5062\linewidth]{test.png} - \includegraphics<2>[height=0.5062\linewidth]{test.png} - - \only{asd} - \only<2>{asd} - - \item asdasd - \item<1-3> asdasd -\end{frame} - -\section{Package: minor stuff} -% subfile -\subfile{test-syntax.tex} - -% pdfpages -\includepdf{test.pdf} - -\section{Package: biblatex and csquotes} -\cite{} -\citet*{} -\citep{bibtexkey1} -\citep[e.g.][]{bibtexkey2} -\citealt{} -\citealt*{} -\citealp{} -\citealp*{} -\citenum{} -\citetext{} -\citeauthor{} -\citeauthor*{} -\citeyear{} -\citeyearpar{} -\bibentry{} - -\section{Package: cleveref} -\label[asd]{sec:cleveref} - -\crefname{equation}{Eq}{Eqs} -\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. - -\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 { - a -- b; - b -- c; - b -- d; - d -- a; - } -\end{dot2tex} - -\section{Package: luacode} -\directlua{ - if pdf.getminorversion() \string~= 7 then - print "pfd version 1.7" - end -} - -\begin{luacode} - if pdf.getminorversion() \string~= 7 then - print "pfd version 1.7" - end -\end{luacode} - -\section{Package: gnuplottex} -\begin{gnuplot}[terminal=..., terminaloptions=...] - 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} - -\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} - -\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 deleted file mode 100644 index b3162b40c6..0000000000 --- a/test/tests/test-syntax/test-large.vim +++ /dev/null @@ -1,18 +0,0 @@ -source common.vim - -let &rtp = '.,' . &rtp -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) - -" 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-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..cdcf71709e --- /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('texE3Region', 7, 2)) +call vimtex#test#assert(vimtex#syntax#in('texE3Func', 7, 2)) +call vimtex#test#assert(vimtex#syntax#in('texE3Var', 7, 15)) + +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-markdown.vim b/test/tests/test-syntax/test-markdown.vim index c79725a874..03a88bff27 100644 --- a/test/tests/test-syntax/test-markdown.vim +++ b/test/tests/test-syntax/test-markdown.vim @@ -4,9 +4,9 @@ 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('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('texInputFileArg', 16, 16)) +call vimtex#test#assert(vimtex#syntax#in('texFileArg', 16, 16)) quit! 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! 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! diff --git a/test/tests/test-syntax/test-minted.vim b/test/tests/test-syntax/test-minted.vim index eaa4b72cdf..4a9442e241 100644 --- a/test/tests/test-syntax/test-minted.vim +++ b/test/tests/test-syntax/test-minted.vim @@ -8,12 +8,12 @@ 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('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! 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..5e1b6621d1 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('texArg', 7, 14)) +call vimtex#test#assert(vimtex#syntax#in('texNoSpellArg', 8, 14)) quit! 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-tabularx.tex b/test/tests/test-syntax/test-tabularx.tex new file mode 100644 index 0000000000..984fabee47 --- /dev/null +++ b/test/tests/test-syntax/test-tabularx.tex @@ -0,0 +1,29 @@ +\documentclass{article} +\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<{$}}} + \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..ec1aaa2921 --- /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', 10, 17)) +call vimtex#test#assert(vimtex#syntax#in('texTabularMathdelim', 10, 24)) + +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..cf79650b52 --- /dev/null +++ b/test/tests/test-syntax/test-tikz.tex @@ -0,0 +1,97 @@ +\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}; + + \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!} + \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..e0e6b0953f --- /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('texTikzRegion', 66, 61)) +call vimtex#test#assert(vimtex#syntax#in('texCmdAxis', 71, 9)) + +quit! diff --git a/test/tests/test-syntax/test-various-packages.tex b/test/tests/test-syntax/test-various-packages.tex new file mode 100644 index 0000000000..24eb94bd2f --- /dev/null +++ b/test/tests/test-syntax/test-various-packages.tex @@ -0,0 +1,119 @@ +\documentclass{beamer} +\usepackage{subfile} +\usepackage{includegraphics} +\usepackage{pdfpages} +\usepackage{hyperref} +\usepackage{testx} " Package does not exist - test try catch block +\usepackage{biblatex} +\usepackage{csquotes} +\usepackage{cleveref} +\usepackage{varioref} +\usepackage{dot2texi} +\usepackage{luacode} +\usepackage{gnuplottex} + +\begin{document} + +\section{General} +\todostuff \todocommand \todo{content} + +This text is \emph{emphasized}, \textit{italized}, \textbf{bolded}. + +\def\A{A} +\def\B{\V{B}} + +\newenvironment{example}[1][]{Start #1}{Stop} +\renewenvironment{example}[1][]{Start #1}{Stop} +\newenvironment{nestedexample}[1][]{% + \renewenvironment{nested}[1][0]{% + Outerarg #1}{% + Innerarg ##1 + }% + \begin{nested}{title}}{% + \end{nested}% +} + +\newcommand{\testA}[1]{Test #1} +\renewcommand{\testA}[1]{Test #1} +\newcommand{\mycommand}[1]{% + \renewcommand{\myothercommand}[1]{% + \dosomethingwithouterarg{#1}% + \dosomethingwithinnerarg{##1}% + }% +} + +\section{Documentclass: beamer} +\begin{frame}[asd] + \includegraphics[height=0.5062\linewidth]{test.png} + \includegraphics<2>[height=0.5062\linewidth]{test.png} + + \only{asd} + \only<2>{asd} + + \item asdasd + \item<1-3> asdasd +\end{frame} + +\section{Package: minor stuff} +% subfile +\subfile{test-syntax.tex} + +% pdfpages +\includepdf{test.pdf} + +\section{Package: biblatex and csquotes} +\cite{} +\citet*{} +\citep{bibtexkey1} +\citep[e.g.][]{bibtexkey2} +\citealt{} +\citealt*{} +\citealp{} +\citealp*{} +\citenum{} +\citetext{} +\citeauthor{asd} +\citeauthor*{} +\citeyear{} +\citeyearpar{} +\bibentry{} + +\section{Package: cleveref} +\label[asd]{sec:cleveref} + +\crefname{equation}{Eq}{Eqs} +\cref{eq:test} +\crefrange{eq:test}{eq:test2} + +\section{Package: varioref} +\Vref{sec_one} does what you need. Still \vref{sec_one} works. + +\section{Package: dot2texi} +\begin{dot2tex} + graph graphname { + a -- b; + b -- c; + b -- d; + d -- a; + } +\end{dot2tex} + +\section{Package: luacode} +\directlua{ + if pdf.getminorversion() \string~= 7 then + print "pfd version 1.7" + end +} + +\begin{luacode} + if pdf.getminorversion() \string~= 7 then + print "pfd version 1.7" + end +\end{luacode} + +\section{Package: gnuplottex} +\begin{gnuplot}[terminal=..., terminaloptions=...] + plot file using 1:2 with lines +\end{gnuplot} + +\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..662c7d28cc --- /dev/null +++ b/test/tests/test-syntax/test-various-packages.vim @@ -0,0 +1,9 @@ +source common.vim + +silent edit test-various-packages.tex + +if empty($INMAKE) | finish | endif + +call vimtex#test#assert_equal(12, len(filter(b:vimtex_syntax, 'v:val.__loaded'))) + +quit! diff --git a/test/tests/test-syntax/test-wiki.vim b/test/tests/test-syntax/test-wiki.vim index 6339071341..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('texZoneWiki', 6, 1)) +call vimtex#test#assert(vimtex#syntax#in('texWikiRegion', 6, 1)) " call vimtex#test#assert(vimtex#syntax#in('markdownHeader', 7, 1)) quit! 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