Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions autoload/vimtex/syntax/p/amsmath.vim
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,45 @@ function! vimtex#syntax#p#amsmath#load(cfg) abort " {{{1
syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\end{x\?alignat\*\?}"
syntax match texMathCmdEnv contained contains=texCmdMathEnv "\\end{xxalignat}"

" numberwithin
syntax match texCmdNumberWithin "\\numberwithin\>"
\ nextgroup=texNumberWithinArg1 skipwhite skipnl
call vimtex#syntax#core#new_arg('texNumberWithinArg1', {
\ 'next': 'texNumberWithinArg2',
\ 'contains': 'TOP,@Spell'
\})
call vimtex#syntax#core#new_arg('texNumberWithinArg2', {
\ 'contains': 'TOP,@Spell'
\})

" subjclass
syntax match texCmdSubjClass "\\subjclass\>"
\ nextgroup=texSubjClassOpt,texSubjClassArg skipwhite skipnl
call vimtex#syntax#core#new_opt('texSubjClassOpt', {
\ 'next': 'texSubjClassArg',
\ 'contains': 'TOP,@Spell'
\})
call vimtex#syntax#core#new_arg('texSubjClassArg', {
\ 'contains': 'TOP,@Spell'
\})

" DeclareMathOperator
syntax match texCmdDeclmathoper nextgroup=texDeclmathoperArgName skipwhite skipnl "\\DeclareMathOperator\>\*\?"
call vimtex#syntax#core#new_arg('texDeclmathoperArgName', {
\ 'next': 'texDeclmathoperArgBody',
\ 'contains': ''
\})
call vimtex#syntax#core#new_arg('texDeclmathoperArgBody')
call vimtex#syntax#core#new_arg('texDeclmathoperArgBody', {'contains': 'TOP,@Spell'})

" operatorname
syntax match texCmdOpname nextgroup=texOpnameArg skipwhite skipnl "\\operatorname\>"
call vimtex#syntax#core#new_arg('texOpnameArg', {
\ 'contains': 'TOP,@Spell'
\})

" \tag{label} or \tag*{label}
syntax match texMathCmd "\\tag\>\*\?" contained nextgroup=texMathTagArg
call vimtex#syntax#core#new_arg('texMathTagArg')
call vimtex#syntax#core#new_arg('texMathTagArg', {'contains': 'TOP,@Spell'})

" Conceal the command and delims of "\operatorname{ ... }"
if g:vimtex_syntax_conceal.math_delimiters
Expand All @@ -52,8 +80,17 @@ function! vimtex#syntax#p#amsmath#load(cfg) abort " {{{1
endif

highlight def link texCmdDeclmathoper texCmdNew
highlight def link texCmdNumberWithin texCmd
highlight def link texCmdOpName texCmd
highlight def link texCmdSubjClass texCmd
highlight def link texDeclmathoperArgName texArgNew
highlight def link texDeclmathoperArgBody texMathZone
highlight def link texMathConcealedArg texMathTextArg
highlight def link texNumberWithinArg1 texArg
highlight def link texNumberWithinArg2 texArg
highlight def link texOpnameArg texMathZone
highlight def link texSubjClassArg texArg
highlight def link texSubjClassOpt texOpt
endfunction

" }}}1
8 changes: 8 additions & 0 deletions autoload/vimtex/syntax/p/amsthm.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ function! vimtex#syntax#p#amsthm#load(cfg) abort " {{{1
\ 'contains': 'TOP,@NoSpell'
\})

syntax match texCmdThmStyle "\\theoremstyle\>"
\ nextgroup=texThmStyleArg skipwhite skipnl
call vimtex#syntax#core#new_arg('texThmStyleArg', {
\ 'contains': 'TOP,@Spell'
\})

highlight def link texCmdThmStyle texCmd
highlight def link texProofEnvOpt texEnvOpt
highlight def link texThmStyleArg texArg
endfunction

" }}}1
9 changes: 8 additions & 1 deletion test/test-syntax/test-amsmath.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
\documentclass{article}
\documentclass{amsart}
\usepackage{amsmath}

\DeclareMathOperator{\GL}{GL}
\newcommand{\SL}{\operatorname{SL}}

\numberwithin{equation}{section}

\subjclass[2010]{Primary: 11F67}

\begin{document}

\begin{align}
Expand Down
18 changes: 17 additions & 1 deletion test/test-syntax/test-amsmath.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@ source common.vim

silent edit test-amsmath.tex

set spell

if empty($INMAKE) | finish | endif

call assert_true(vimtex#syntax#in('texCmdDeclmathoper', 4, 1))
call assert_true(vimtex#syntax#in('texDeclmathoperArgName', 4, 22))
call assert_true(vimtex#syntax#in('texDeclmathoperArgBody', 4, 27))

call assert_true(vimtex#syntax#in('texCmdOpname', 5, 18))
call assert_true(vimtex#syntax#in('texOpnameArg', 5, 32))

call assert_true(vimtex#syntax#in('texCmdNumberWithin', 7, 1))
call assert_true(vimtex#syntax#in('texNumberWithinArg1', 7, 15))
call assert_true(vimtex#syntax#in('texNumberWithinArg2', 7, 25))

call assert_true(vimtex#syntax#in('texCmdSubjClass', 9, 1))
call assert_true(vimtex#syntax#in('texSubjClassOpt', 9, 12))
call assert_true(vimtex#syntax#in('texSubjClassArg', 9, 18))

quit!
call vimtex#test#finished()
5 changes: 5 additions & 0 deletions test/test-syntax/test-amsthm.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
\documentclass{article}
\usepackage{amsthm}

\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\newtheorem{prp}[thm]{Proposition}
\newtheorem{lemma}{Lemma}
Expand All @@ -19,4 +20,8 @@
A lemma here.
\end{lemma}

\begin{proof}[Proof of theorem abc]
Proof goes here.
\end{proof}

\end{document}
21 changes: 13 additions & 8 deletions test/test-syntax/test-amsthm.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ set spell

if empty($INMAKE) | finish | endif

call assert_true(vimtex#syntax#in('texNewthmOptNumberby', 4, 32))
call assert_true(vimtex#syntax#in('texNewthmOptCounter', 5, 19))
call assert_true(vimtex#syntax#in('texCmdThmStyle', 4, 1))
call assert_true(vimtex#syntax#in('texThmStyleArg', 4, 15))
call assert_true(vimtex#syntax#in('texNewthmOptNumberby', 5, 32))
call assert_true(vimtex#syntax#in('texNewthmOptCounter', 6, 19))

call assert_true(vimtex#syntax#in('texTheoremEnvBgn', 10, 1))
call assert_true(vimtex#syntax#in('texTheoremEnvBgn', 14, 1))
call assert_true(vimtex#syntax#in('texTheoremEnvBgn', 18, 1))
call assert_true(vimtex#syntax#in('texProofEnvBgn', 23, 1))
call assert_true(vimtex#syntax#in('texProofEnvOpt', 23, 15))

call assert_true(vimtex#syntax#in('texTheoremEnvOpt', 10, 36))
call assert_true(vimtex#syntax#in('texCmdRefConcealed', 10, 42))
call assert_true(vimtex#syntax#in('texRefConcealedArg', 10, 47))
call assert_true(vimtex#syntax#in('texTheoremEnvBgn', 11, 1))
call assert_true(vimtex#syntax#in('texTheoremEnvBgn', 15, 1))
call assert_true(vimtex#syntax#in('texTheoremEnvBgn', 19, 1))

call assert_true(vimtex#syntax#in('texTheoremEnvOpt', 11, 36))
call assert_true(vimtex#syntax#in('texCmdRefConcealed', 11, 42))
call assert_true(vimtex#syntax#in('texRefConcealedArg', 11, 47))

call vimtex#test#finished()