tree-sitter-typst icon indicating copy to clipboard operation
tree-sitter-typst copied to clipboard

Distinguish block & inline equations

Open Triton171 opened this issue 2 years ago • 2 comments

Currently, the grammar parses both inline and block equations as an equation node. It would be nice to parse them as inline_equation and block_equation nodes respectively, for example to highlight them differently like Helix does for LaTex. I've tried implementing this but it seems a bit tricky. We'd probably need something like a trimmed_math node that matches math without any surrounding whitespace. If this is something that you'd consider merging, I'll try to implement it. I'm also happy about any suggestions on how to best approach this.

Triton171 avatar Jun 04 '23 12:06 Triton171

@Triton171 if you have the knowledge on how to implement it, I would say go for it.

slashformotion avatar Jun 05 '23 08:06 slashformotion

I tried integrating it into the grammar itself first, but my current implementation doesn't quite work correctly. For now I don't want to spend more time on it, as it's rather low-priority.

However, I figured that you could simply implement such a thing within the highlights.scm:

((equation) @equation.block
  (#match? @equation.block "[ \t\r\n]+.+[ \t\r\n]+"))
(equation) @equation.inline

I haven't tested it much and there are problems with it, but it should work well enough for now.

frozolotl avatar Aug 19 '23 22:08 frozolotl