latex-lsp / tree-sitter-latex

LaTeX grammar for tree-sitter
MIT License
87 stars 21 forks source link

Add sagetex environments as 'special' similarly to pycode #89

Closed lnay closed 1 year ago

lnay commented 1 year ago

Why

SageMath installations ship with a latex package sagetex which defines a few commands (\sage, \sageplot...) and environments (sagesilent, sageblock) in which users embed Sage code (similar to Python).

Since there is precedence in this project to treat certain environments minted, listing, pycode specially to enable language injection in nvim-treesitter, I took the opportunity to do the same for sagesilent and sageblock especially as I believe they can be treated exactly like pycode.

I personally have interest in enabling Python highlighting in these environments, and this also has enough general interest for it to be raised as an issue, and completed for the vimtex plugin: https://github.com/lervag/vimtex/issues/2027 .

Review brief

For review purposes, the following are separated into different commits:

Note for corresponding changes to nvim-treesitter:

Python highlighting for these extra environments seems to work fine with the following change to queries/latex/injections.scm (alongside the changes in this pull request):

(pycode_environment
  code: (source_code) @python
)

+ (sagesilent_environment
+  code: (source_code) @python
+ )

+ (sageblock_environment
+  code: (source_code) @python
+ )