|
5 | 5 | " Last Change: Apr 22, 2022
|
6 | 6 | " 2024 Feb 19 by Vim Project: announce adoption
|
7 | 7 | " 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 |
8 | 10 | " Version: 121
|
9 | 11 | " Former URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_TEX
|
10 | 12 | "
|
@@ -167,7 +169,7 @@ syn cluster texCmdGroup contains=texCmdBody,texComment,texDefParm,texDelimiter
|
167 | 169 | if !s:tex_no_error
|
168 | 170 | syn cluster texCmdGroup add=texMathError
|
169 | 171 | endif
|
170 |
| -syn cluster texEnvGroup contains=texMatcher,texMathDelim,texSpecialChar,texStatement |
| 172 | +syn cluster texEnvGroup contains=texDefParm,texMatcher,texMathDelim,texSpecialChar,texStatement |
171 | 173 | 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
|
172 | 174 | 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
|
173 | 175 | 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 "&"
|
287 | 289 | syn match texDelimiter "\\\\"
|
288 | 290 |
|
289 | 291 | " Tex/Latex Options: {{{1
|
290 |
| -syn match texOption "[^\\]\zs#\d\+\|^#\d\+" |
| 292 | +syn match texOption "[^\\]\zs#[1-9]\|^#[1-9]" |
291 | 293 |
|
292 | 294 | " texAccent (tnx to Karim Belabas) avoids annoying highlighting for accents: {{{1
|
293 | 295 | if b:tex_stylish
|
@@ -669,16 +671,46 @@ if s:tex_fast =~# 'r'
|
669 | 671 | endif
|
670 | 672 | syn match texRefZone '\\cite\%([tp]\*\=\)\=\>' nextgroup=texRefOption,texCite
|
671 | 673 |
|
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 |
674 | 689 | if s:tex_fast =~# 'V'
|
675 | 690 | 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 |
677 | 693 | syn region texCmdBody contained matchgroup=texDelimiter start="{"rs=s+1 skip="\\\\\|\\[{}]" matchgroup=texDelimiter end="}" contains=@texCmdGroup
|
678 | 694 | 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 |
680 | 710 | 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 |
682 | 714 | syn region texEnvBgn contained matchgroup=texDelimiter start="{"rs=s+1 end="}" nextgroup=texEnvEnd skipwhite skipnl contains=@texEnvGroup
|
683 | 715 | syn region texEnvEnd contained matchgroup=texDelimiter start="{"rs=s+1 end="}" skipwhite skipnl contains=@texEnvGroup
|
684 | 716 | endif
|
|
693 | 725 | syn match texDefName contained "\\\A" nextgroup=texDefParms,texCmdBody skipwhite skipnl
|
694 | 726 | endif
|
695 | 727 | syn match texDefParms contained "#[^{]*" contains=texDefParm nextgroup=texCmdBody skipwhite skipnl
|
696 |
| -syn match texDefParm contained "#\d\+" |
| 728 | +syn match texDefParm contained "#[1-9]" |
697 | 729 |
|
698 | 730 | " TeX Lengths: {{{1
|
699 | 731 | 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")
|
1325 | 1357 | hi def link texDef Statement
|
1326 | 1358 | hi def link texDefParm Special
|
1327 | 1359 | hi def link texDelimiter Delimiter
|
| 1360 | + hi def link texEnvArgs Number |
1328 | 1361 | hi def link texInput Special
|
1329 | 1362 | hi def link texInputFile Special
|
1330 | 1363 | hi def link texLength Number
|
|
0 commit comments