Skip to content

Incorrect highlighting/parsing mid-paragraph display math #775

@CoryMcCartan

Description

@CoryMcCartan

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions