Skip to content

Feature request: Add syntax highlighting for \begin{equation}, \begin{align}, and \[...\] in .qmd files #934

@PatrickW-7878

Description

@PatrickW-7878

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions