Skip to content

inconsistent behavior when rendering display math ($$...$$) in ipynb notebook when they are embedded ($ get escaped) #8505

@kompre

Description

@kompre

Bug description

I noticed that the math object surrounded by double $$ get rendered differently if they belong to an embedded notebook (ipynb) rather than being directly rendered as documents.

The difference is triggered by whitespace around the $ or $$:

  • if there is no space between the fence and it's content, then it will always render correctly both as native document and as embedded document (e.g. $x=4$, $$x = 5$$)

  • if there is some space or a new line between the double $$ it's content, it get rendered differently:

    • get rendered correctly as "native" document
    • get rendered incorrectly as an embed

(note: inline math with space, e.g. `$ x=4 $ will always get rendered incorrectly, therefore they are consistent at least)

Steps to reproduce

I have setup 3 files:

  1. embedding_ipynb.qmd (main to be rendere)
  2. notebook_to_embed.ipynb (ipynb to embed)
  3. converted_notebook.qmd (qmd versione of the ipynb to check the difference)

main file to render

---
title: "embedding_ipynb"
format: html
keep-tex: true
---

## embedding_ipynb

{{< embed notebook_to_embed.ipynb >}}

{{< include converted_notebook.qmd >}}

notebook to embed

(I'm not sure how to properly reproduce a ipynb for bug purpose, but it's only markdown cells)

---
format: html
---
## notebook_to_embed.ipynb

inline equation $x=4$ and $ x=4.1 $

equation with ```$$..$$```:

$$x = 5$$

$$ x = 5.1 $$

equation in the style

| `$$`
| `...`
| `$$`

$$
x=6
$$

equation with `\begin{equation}...\end{equation}`:

\begin{equation}
x=7
\end{equation}

converted notebook in qmd for check

---
format: html
jupyter: python3
---

## converted_notebook.qmd

inline equation $x=4$ and $ x=4.1 $

equation with ```$$..$$```:

$$x = 5$$

$$ x = 5.1 $$


equation in the style:

| `$$`
| `...`
| `$$`

$$
x=6
$$

equation with `\begin{equation}...\end{equation}`:

\begin{equation}
x=7
\end{equation}

Expected behavior

I expect the math object to be rendered the same either if document is rendered as is, or if document is an embed of another document. The behavior should be consistent.

Actual behavior

the $ symbol from the embedded notebook get escaped if there is any space or new line between it and it's content, and thus do not render as math object, only when the ipynb is an embed. If the ipynb get rendered as its own document, it will render correctly.

image

Your environment

  • vscode 1.85.2
  • win 10 pro v. 10.0.19045
  • quarto v. 1.4.549
  • quarto vscode extension v1.110.1

Quarto check output

Quarto 1.4.549
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.4.549
      Path: C:\Users\s.follador\AppData\Local\Programs\Quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      TinyTeX: v2023.12
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Using: TinyTex
      Path: C:\Users\s.follador\AppData\Roaming\TinyTeX\bin\windows\
      Version: 2023

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....OK
      Version: 3.12.1
      Path: C:/Users/s.follador/AppData/Local/Programs/Python/Python312/python.exe
      Jupyter: 5.7.1
      Kernels: python3

[>] Checking Jupyter engine render....OK

[>] Checking R installation...........(None)

      Unable to locate an installed version of R.
      Install R from https://cloud.r-project.org/

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingembedmathany issue related to math support in specific formats

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions