Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete syntax support for SageTeX #2929

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
13 changes: 9 additions & 4 deletions autoload/vimtex/syntax.vim
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ function! vimtex#syntax#in_comment(...) abort " {{{1
return call('vimtex#syntax#in', ['texComment'] + a:000)
endfunction

" }}}1
function! vimtex#syntax#in_sage(...) abort " {{{1
lervag marked this conversation as resolved.
Show resolved Hide resolved
return call('vimtex#syntax#in', ['texSagetexArg'] + a:000) || call('vimtex#syntax#in', ['texSagetexZone'] + a:000)
shivangp76 marked this conversation as resolved.
Show resolved Hide resolved
endfunction

" }}}1
function! vimtex#syntax#in_mathzone(...) abort " {{{1
" The following checks if we are inside a texMathZone environment. The
" arguments to \label{...}, the texRefArg group, and \text{...} like
" commands, the texMathTextArg group, are actively ignored as these should
" not be considered to be math environments.
" arguments to \label{...}, the texRefArg group, the texSagetexArg group,
" and \text{...} like commands, the texMathTextArg group, are actively
" ignored as these should not be considered to be math environments.
let l:groups = reverse(call('vimtex#syntax#stack', a:000))
let l:group = matchstr(l:groups, '\v^tex%(Math%(Zone|Text|Tag)|RefArg)')
let l:group = matchstr(l:groups, '\v^tex%(Math%(Zone|Text|Tag)|RefArg|SagetexArg)')
lervag marked this conversation as resolved.
Show resolved Hide resolved
return l:group =~# '^texMathZone'
endfunction

Expand Down
15 changes: 13 additions & 2 deletions autoload/vimtex/syntax/p/sagetex.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -32,6 +30,19 @@ function! vimtex#syntax#p#sagetex#load(cfg) abort " {{{1
\})
endfor

for l:env in [
shivangp76 marked this conversation as resolved.
Show resolved Hide resolved
\ 'sage',
\ 'sagestr'
\]
execute 'syntax match texCmdSagetex /\\' . l:env .
\ '\>/ nextgroup=texSagetexArg skipwhite skipnl'
call vimtex#syntax#core#new_cmd({
lervag marked this conversation as resolved.
Show resolved Hide resolved
\ 'name': l:env,
\ 'mathmode': 1,
shivangp76 marked this conversation as resolved.
Show resolved Hide resolved
\ 'nextgroup': 'texSagetexArg'
\})
endfor

highlight def link texCmdSagetex texCmd
endfunction

Expand Down