Skip to content

Quarto visual mode / source mode switching breaks equation block formatting and syntax highlighting #1047

Description

@Vara326

Bug description

👋hello! This issue was originally posted at posit-dev/positron#14763 (comment), and is reposted here at the request of @juliasilge .

When switching between visual mode and source mode in a Quarto .qmd document, the editor reformats multi-line equation blocks

$$
equation
$$

into single-line form

$$equation$$

, which causes two related bugs:

Bug 1 — Cross-reference label malformation

After a visual→source mode switch, a properly formatted numbered equation like:

$$
y_i = \alpha + \sum_{j=1}^{p} \beta_j x_{ij} + \varepsilon_i
$$ {#eq-liner-model}

is reformatted into:

$$\text{equation}$$
 {#eq-a-error-format}

The label {#eq-a-error-format} is placed on a new line with a leading space, making it unrecognizable to the Quarto cross-reference engine. Rendering the document produces:

Unable to resolve crossref @eq-a-error-format

Bug 2 — Lost syntax highlighting (gray background)

A correctly formatted single-line numbered equation:

$$(\hat{\alpha}, \hat{\boldsymbol{\beta}}) = \arg\min \left\{ \sum_{i=1}^{N} \left(y_i - \alpha - \sum_{j=1}^{p} \beta_j x_{ij}\right)^2 \right\} \quad \text{subject to} \quad \sum_{j=1}^{p} |\beta_j| \leq t$$ {#eq-lasso}

renders correctly and cross-references work, but the equation block itself is not wrapped in the usual gray background box. Moreover, any R code blocks that follow this equation also lose their gray background.

Expected behavior:

Switching between visual and source mode should preserve the original multi-line equation block structure.

The {#eq-label} syntax should remain on the same line as the closing $$.

All code blocks should consistently display the gray background regardless of preceding equation formatting.

I have checked posit-dev/positron#8684 (comment). It seems to be related to the issue I am experiencing, but it looks like it has not been properly fixed yet.

My Quarto version is 1.9.38 and my Positron version is 2026.07.0.

Attachments:

Image Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions