quarto-dev / quarto-dev/quarto

Incorrect highlighting/parsing mid-paragraph display math

Open
#775 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug visual-editor vscode
Dominant language
TypeScript
Stars
645
Forks
62
Avg merge
17h 42m
Merged PRs (30d)
13

Description

Bug description

Mid-paragraph display math often parses incorrectly, causing problems for outline and equation preview.
Visual editor's preferred syntax makes the problem worse.

Steps to reproduce

Most of the time I use display math, it's mid-paragraph, and I'd like to continue the prose after the display without starting a new paragraph. In source mode, I would usually write like this:

We study the following partially linear structural model for an outcome $Y$, binary 
treatment $Z$, vector of covariates $X$, unobserved confounder $U$, and two 
additional variables $W_Y$ and $W_Z$.
$$
\begin{aligned}
Y &= \beta_u U + \beta_{w_y} W_Y + \beta_{w_z} W_Z + \tau Z + f_y(X) + \eps_y \\
Z &= \gamma_u U + \gamma_{w_y} W_Y + \gamma_{w_z} W_Z + f_z(X) + \eps_z \\
W_Y &= \alpha_u U + \alpha_{w_z} W_Z + f_{w_y}(X) + \eps_{w_y} \\
W_Z &=\varphi_u U + f_{w_z}(X) + \eps_{w_z}
\end{aligned}
$$ {#eq-struct} 
Above, $\eps_y, \eps_z, \eps_{w_z}, \eps_{w_y}$, and $\eps_u$ are independent noise 
terms, and $f_y$, $f_z$, $f_{w_y}$, and $f_{w_z}$ are generic functions of the covariates $X$.
Actual behavior

This renders properly. However, in Positron it is highlighted as follows, where the sentence following the math is highlighted as an equation (using sentence wrapping):

image

Visual mode wants to reformat the equation like this:

We study the following partially linear structural model for an outcome $Y$, binary 
treatment $Z$, vector of covariates $X$, unobserved confounder $U$, and two 
additional variables $W_Y$ and $W_Z$. $$
\begin{aligned}
Y &= \beta_u U + \beta_{w_y} W_Y + \beta_{w_z} W_Z + \tau Z + f_y(X) + \eps_y \\
Z &= \gamma_u U + \gamma_{w_y} W_Y + \gamma_{w_z} W_Z + f_z(X) + \eps_z \\
W_Y &= \alpha_u U + \alpha_{w_z} W_Z + f_{w_y}(X) + \eps_{w_y} \\
W_Z &=\varphi_u U + f_{w_z}(X) + \eps_{w_z}
\end{aligned}
$$ {#eq-struct} Above, $\eps_y, \eps_z, \eps_{w_z}, \eps_{w_y}$, and $\eps_u$ are independent noise 
terms, and $f_y$, $f_z$, $f_{w_y}$, and $f_{w_z}$ are generic functions of the covariates $X$.

While this also renders properly, I find this much less readable, and it also breaks the document parsing. Positron now recognizes the text after the equation as the equation. This also causes all downstream headings to not be recognized in the Outline.

image

I basically can't use Visual mode for this reason. For very short display equations, its preferred inline format (text $$1 + 1 = 2$$ more text) is readable, but also not highlighted/recognized by Positron. But for multiline equations, it reformats the source in a way that breaks the highlighting/parsing, and in my opinion is less readable.

Expected behavior
  • Only the equation be recognized as such, with outline and preview that work correctly.
  • Change visual mode to standardize syntax in a way that works with the parsing/highlighting?

Apologies if there is some proper syntax for mid-paragraph display equations I am missing. Most of the Quarto documentation uses visual mode, and I can't find a multiline equation example.

Your environment
  • IDE: Positron 2025.07.0 build 204
  • Quarto extension v 1.123.0
  • MacOS 15.5

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue's Quarto example in Positron with the listed Quarto extension version, comparing source mode and visual mode. Investigate how the displayed equation and following prose are highlighted and parsed; done means only the equation is recognized as math and subsequent headings remain available in the outline and preview.

Written by the indexing model from the issue text.

Assessment

Tech stack
markdown, typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.