Skip to content

Commit 59edd7c

Browse files
clasone-kwsm
andauthored
vim-patch:a35040f: runtime(tex): improve syntax highlighting (neovim#32370)
this change includes the following changes: - a macro option must be #1neovim#9 - add \providecommand - add starred versions of \newcommand, \newenvironment, and their variants - add number of arguments to \(re)newenvironment vim/vim@a35040f Co-authored-by: Eisuke Kawashima <[email protected]>
1 parent 818a298 commit 59edd7c

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

runtime/syntax/tex.vim

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
" Last Change: Apr 22, 2022
66
" 2024 Feb 19 by Vim Project: announce adoption
77
" 2025 Jan 18 by Vim Project: add texEmphStyle to texMatchGroup, #16228
8+
" 2025 Feb 08 by Vim Project: improve macro option, \providecommand,
9+
" \newcommand and \newenvironment #16543
810
" Version: 121
911
" Former URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_TEX
1012
"
@@ -167,7 +169,7 @@ syn cluster texCmdGroup contains=texCmdBody,texComment,texDefParm,texDelimiter
167169
if !s:tex_no_error
168170
syn cluster texCmdGroup add=texMathError
169171
endif
170-
syn cluster texEnvGroup contains=texMatcher,texMathDelim,texSpecialChar,texStatement
172+
syn cluster texEnvGroup contains=texDefParm,texMatcher,texMathDelim,texSpecialChar,texStatement
171173
syn cluster texFoldGroup 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,texSectionZone,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texTitle,texAbstract,texBoldStyle,texItalStyle,texEmphStyle,texNoSpell
172174
syn cluster texBoldGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texInputFile,texLength,texLigature,texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ,texNewCmd,texNewEnv,texOnlyMath,texOption,texParen,texRefZone,texSection,texBeginEnd,texSectionZone,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texTitle,texAbstract,texBoldStyle,texBoldItalStyle,texNoSpell
173175
syn cluster texItalGroup contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texInputFile,texLength,texLigature,texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ,texNewCmd,texNewEnv,texOnlyMath,texOption,texParen,texRefZone,texSection,texBeginEnd,texSectionZone,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texTitle,texAbstract,texItalStyle,texEmphStyle,texItalBoldStyle,texNoSpell
@@ -287,7 +289,7 @@ syn match texDelimiter "&"
287289
syn match texDelimiter "\\\\"
288290

289291
" Tex/Latex Options: {{{1
290-
syn match texOption "[^\\]\zs#\d\+\|^#\d\+"
292+
syn match texOption "[^\\]\zs#[1-9]\|^#[1-9]"
291293

292294
" texAccent (tnx to Karim Belabas) avoids annoying highlighting for accents: {{{1
293295
if b:tex_stylish
@@ -669,16 +671,46 @@ if s:tex_fast =~# 'r'
669671
endif
670672
syn match texRefZone '\\cite\%([tp]\*\=\)\=\>' nextgroup=texRefOption,texCite
671673

672-
" Handle (re)newcommand, (re)newenvironment : {{{1
673-
syn match texNewCmd "\\\%(re\)\=newcommand\>" nextgroup=texCmdName skipwhite skipnl
674+
" Handle (re)newcommand, providecommand, (re)newenvironment : {{{1
675+
" EXAMPLE:
676+
"
677+
" The followings are valid (ignoring error due to redefinition):
678+
"
679+
" \newcommand{\foo}{body}
680+
" \newcommand{\foo}[1]{#1}
681+
" \newcommand{\foo}[1][def]{#1}
682+
"
683+
" The followings are ill-formed:
684+
"
685+
" \newcommand{\foo}{#1} ! Illegal parameter number in definition of \foo.
686+
" \newcommand{\foo}[x]{…} ! Missing number, treated as zero.
687+
" \newcommand{\foo}[10]{…} ! You already have nine parameters.
688+
syn match texNewCmd "\\\%(\%(re\)\=new\|provide\)command\>\*\?" nextgroup=texCmdName skipwhite skipnl
674689
if s:tex_fast =~# 'V'
675690
syn region texCmdName contained matchgroup=texDelimiter start="{"rs=s+1 end="}" nextgroup=texCmdArgs,texCmdBody skipwhite skipnl
676-
syn region texCmdArgs contained matchgroup=texDelimiter start="\["rs=s+1 end="]" nextgroup=texCmdBody skipwhite skipnl
691+
syn region texCmdArgs contained matchgroup=texDelimiter start="\["rs=s+1 end="]" nextgroup=texCmdDefaultPar,texCmdBody skipwhite skipnl
692+
syn region texCmdDefaultPar contained matchgroup=texDelimiter start="\["rs=s+1 end="]" nextgroup=texCmdBody skipwhite skipnl
677693
syn region texCmdBody contained matchgroup=texDelimiter start="{"rs=s+1 skip="\\\\\|\\[{}]" matchgroup=texDelimiter end="}" contains=@texCmdGroup
678694
endif
679-
syn match texNewEnv "\\\%(re\)\=newenvironment\>" nextgroup=texEnvName skipwhite skipnl
695+
" EXAMPLE:
696+
"
697+
" The followings are valid (ignoring error due to redefinition):
698+
"
699+
" \newenvironment{baz}{beg}{end}
700+
" \newenvironment{baz}[1]{beg #1}{end}
701+
" \newenvironment{baz}[1][default]{beg #1}{end}
702+
"
703+
" The followings are invalid:
704+
"
705+
" \newenvironment{baz}{#1}{…} ! Illegal parameter number in definition of \baz.
706+
" \newenvironment{baz}[x]{…}{…} ! Missing number, treated as zero.
707+
" \newenvironment{baz}[10]{…}{…} ! You already have nine parameters.
708+
" \newenvironment{baz}[1]{…}{#1} ! Illegal parameter number in definition of \endbaz.
709+
syn match texNewEnv "\\\%(re\)\=newenvironment\>\*\?" nextgroup=texEnvName skipwhite skipnl
680710
if s:tex_fast =~# 'V'
681-
syn region texEnvName contained matchgroup=texDelimiter start="{"rs=s+1 end="}" nextgroup=texEnvBgn skipwhite skipnl
711+
syn region texEnvName contained matchgroup=texDelimiter start="{"rs=s+1 end="}" nextgroup=texEnvArgs,texEnvBgn skipwhite skipnl
712+
syn region texEnvArgs contained matchgroup=texDelimiter start="\["rs=s+1 end="]" nextgroup=texEnvDefaultPar,texEnvBgn skipwhite skipnl
713+
syn region texEnvDefaultPar contained matchgroup=texDelimiter start="\["rs=s+1 end="]" nextgroup=texEnvBgn skipwhite skipnl
682714
syn region texEnvBgn contained matchgroup=texDelimiter start="{"rs=s+1 end="}" nextgroup=texEnvEnd skipwhite skipnl contains=@texEnvGroup
683715
syn region texEnvEnd contained matchgroup=texDelimiter start="{"rs=s+1 end="}" skipwhite skipnl contains=@texEnvGroup
684716
endif
@@ -693,7 +725,7 @@ else
693725
syn match texDefName contained "\\\A" nextgroup=texDefParms,texCmdBody skipwhite skipnl
694726
endif
695727
syn match texDefParms contained "#[^{]*" contains=texDefParm nextgroup=texCmdBody skipwhite skipnl
696-
syn match texDefParm contained "#\d\+"
728+
syn match texDefParm contained "#[1-9]"
697729

698730
" TeX Lengths: {{{1
699731
syn match texLength "\<\d\+\([.,]\d\+\)\=\s*\(true\)\=\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>"
@@ -1325,6 +1357,7 @@ if !exists("skip_tex_syntax_inits")
13251357
hi def link texDef Statement
13261358
hi def link texDefParm Special
13271359
hi def link texDelimiter Delimiter
1360+
hi def link texEnvArgs Number
13281361
hi def link texInput Special
13291362
hi def link texInputFile Special
13301363
hi def link texLength Number

0 commit comments

Comments
 (0)