diff --git a/autoload/vimtex/syntax/p/sagetex.vim b/autoload/vimtex/syntax/p/sagetex.vim index d7364ecdc4..9d01f77195 100644 --- a/autoload/vimtex/syntax/p/sagetex.vim +++ b/autoload/vimtex/syntax/p/sagetex.vim @@ -7,8 +7,6 @@ function! vimtex#syntax#p#sagetex#load(cfg) abort " {{{1 call vimtex#syntax#nested#include('python') - syntax match texCmdSagetex /\\sagestr\>/ - \ nextgroup=texSagetexArg skipwhite skipnl syntax match texCmdSagetex /\\sageplot\>/ \ nextgroup=texSagetexOpt,texSagetexArg skipwhite skipnl @@ -16,9 +14,10 @@ function! vimtex#syntax#p#sagetex#load(cfg) abort " {{{1 \ 'contains': '@vimtex_nested_python', \ 'opts': 'contained keepend' \}) + call vimtex#syntax#add_to_mathzone_ignore('texSagetexArg') call vimtex#syntax#core#new_opt('texSagetexOpt', {'next': 'texSagetexArg'}) - for l:env in [ + for l:env_name in [ \ 'sageblock', \ 'sagesilent', \ 'sageverbatim', @@ -26,12 +25,23 @@ function! vimtex#syntax#p#sagetex#load(cfg) abort " {{{1 \ 'sagecommandline' \] call vimtex#syntax#core#new_env({ - \ 'name': l:env, + \ 'name': l:env_name, \ 'region': 'texSagetexZone', \ 'contains': '@vimtex_nested_python' \}) endfor + " The following commands are supported inside and outside of math zones + for l:cmd_name in ['sage', 'sagestr'] + for l:in_mathmode in [v:true, v:false] + call vimtex#syntax#core#new_cmd({ + \ 'name': l:cmd_name, + \ 'mathmode': l:in_mathmode, + \ 'nextgroup': 'texSagetexArg' + \}) + endfor + endfor + highlight def link texCmdSagetex texCmd endfunction