-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Description
The Quarto VS Code extension's TextMate grammar currently only recognizes $...$ (inline) and $$...$$ (display) as math scopes in .qmd files. LaTeX math environments like \begin{equation}, \begin{align}, and \[...\] receive no math highlighting, even though they are valid and commonly used in Quarto documents — especially in math-heavy academic papers.
Current behaviour
In a .qmd file:
$x^2$→ highlighted as math ✅$$x^2$$→ highlighted as math ✅\begin{equation} x^2 \end{equation}→ no highlighting ❌\begin{align} x^2 \end{align}→ no highlighting ❌\[ x^2 \]→ no highlighting ❌
Proposed solution
Add begin/end rules to quarto.tmLanguage.yaml for LaTeX math environments, scoped as markup.math.block.quarto with meta.embedded.math.quarto content — identical to how $$ blocks are handled. The change is small (~20 lines of YAML):
math_environment:
name: markup.math.block.quarto
contentName: meta.embedded.math.quarto
begin: '(\\begin\{(equation|align|alignat|gather|multline|flalign|split|aligned|gathered|multlined)\*?\})'
beginCaptures:
'1':
name: keyword.control.import.math.begin.quarto
end: '(\\end\{\2\*?\})'
endCaptures:
'1':
name: keyword.control.import.math.end.quarto
patterns:
- {include: 'text.html.markdown.math#math'}
math_display_delim:
name: markup.math.block.quarto
contentName: meta.embedded.math.quarto
begin: '(\\\[)'
beginCaptures:
'1':
name: keyword.control.import.math.begin.quarto
end: '(\\\])'
endCaptures:
'1':
name: keyword.control.import.math.end.quarto
patterns:
- {include: 'text.html.markdown.math#math'}These rules would be added to the repository section of the grammar and included in the block patterns before math_block.
Use case
I write computational statistics papers in Quarto using \begin{equation}, \begin{align}, and custom theorem environments. The lack of math highlighting for these standard LaTeX environments makes the editing experience significantly worse compared to pure .tex files, especially for equation-heavy documents. This is likely a common pain point for anyone using Quarto for academic writing.
Happy to submit a PR if that would be helpful.