quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.77k stars 308 forks source link

Named equations are incompatible with referencing equations #7769

Open yuxi-liu-wired opened 9 months ago

yuxi-liu-wired commented 9 months ago

Bug description

I can't get it to create a named equation while also referencing it.

Steps to reproduce

Here are several possible attempts. All of them produce the wrong result:

This one has an extraneous (1) number.

Black-Scholes (@eq-black-scholes) is a mathematical model that seeks to explain the behavior of financial derivatives, most commonly options:

$$
\begin{equation*}
\frac{\partial \mathrm C}{ \partial \mathrm t } + \frac{1}{2}\sigma^{2} \mathrm S^{2} \frac{\partial^{2} \mathrm C}{\partial \mathrm C^2}   + \mathrm r \mathrm S \frac{\partial \mathrm C}{\partial \mathrm S}\ = \mathrm r \mathrm C \tag{Black--Scholes Equation}
\end{equation*}
$${#eq-black-scholes}

image

This is exactly the same as above.

$$
\begin{equation}
\frac{\partial \mathrm C}{ \partial \mathrm t } + \frac{1}{2}\sigma^{2} \mathrm S^{2} \frac{\partial^{2} \mathrm C}{\partial \mathrm C^2}   + \mathrm r \mathrm S \frac{\partial \mathrm C}{\partial \mathrm S}\ = \mathrm r \mathrm C \tag{Black--Scholes Equation}
\end{equation}
$${#eq-black-scholes}

This fails to compile:

$$
\frac{\partial \mathrm C}{ \partial \mathrm t } + \frac{1}{2}\sigma^{2} \mathrm S^{2} \frac{\partial^{2} \mathrm C}{\partial \mathrm C^2}   + \mathrm r \mathrm S \frac{\partial \mathrm C}{\partial \mathrm S}\ = \mathrm r \mathrm C \tag{Black--Scholes Equation}
$${#eq-black-scholes}

image

This breaks the reference:

\begin{equation}
\frac{\partial \mathrm C}{ \partial \mathrm t } + \frac{1}{2}\sigma^{2} \mathrm S^{2} \frac{\partial^{2} \mathrm C}{\partial \mathrm C^2}   + \mathrm r \mathrm S \frac{\partial \mathrm C}{\partial \mathrm S}\ = \mathrm r \mathrm C \tag{Black--Scholes Equation}
\end{equation}
{#eq-black-scholes}

image

Expected behavior

No response

Actual behavior

No response

Your environment

Windows 11

Quarto check output

>quarto check

[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.3.450
      Path: C:\Users\user\AppData\Local\Programs\Quarto\bin
      CodePage: 1252

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

[>] Checking Python 3 installation....OK
      Version: 3.11.5 (Conda)
      Path: C:/Users/user/miniconda3/python.exe
      Jupyter: 5.3.2
      Kernels: python3

(/) Checking Jupyter engine render....0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
[>] Checking Jupyter engine render....OK

[>] Checking R installation...........OK
      Version: 4.3.1
      Path: C:/PROGRA~1/R/R-43~1.1
      LibPaths:
        - C:/Users/user/AppData/Local/R/win-library/4.3
        - C:/Program Files/R/R-4.3.1/library
      knitr: 1.44
      rmarkdown: 2.25

[>] Checking Knitr engine render......OK
mcanouil commented 9 months ago

Thanks for the report!

Could you share a small self-contained "working" (reproducible) example to work with, i.e., a complete Quarto document or a Git repository? Thanks. Including the format in which it is not working. Note that unless a complicated and long equation is required, a small one is preferable. Also, the numbering here is done by MathJax (when HTML format) and using$$ syntax.

You can share a Quarto document using the following syntax, i.e., using more backticks than you have in your document (usually four ````).

````qmd
---
title: "Quarto Playground"
format: html
---

Cross-reference to @eq-demo.

$$
\begin{equation*}
X + Y \tag{A name}
\end{equation*}
$$ {#eq-demo}


Related threads:
- #4132
mcanouil commented 9 months ago

Playing with MathJax/LaTeX is a bit tricky and you'll have to read the corresponding documentations.

HTML PDF
image image
---
title: "Quarto Playground"
format:
  html: default
  pdf: default
---

::: {.content-visible when-format="pdf"}
## PDF

Cross-reference to \ref{eq-demo}.

\begin{equation}
X + Y \tag{A name} \label{eq-demo}
\end{equation}
:::

::: {.content-visible when-format="html"}
## HTML

Cross-reference to \ref{eq-demo}.

\begin{equation}
X + Y \tag{A name} \label{eq-demo}
\end{equation}
:::
cderv commented 9 months ago

@mcanouil your example is not using the Cross ref syntax (https://quarto.org/docs/authoring/cross-references.html#equations)

I believe our cross reference system work on Numbers and not name. Not sure we can change that for equation, and indeed not using Quarto cross ref for that is required.

Is that the conclusion for you ?

mcanouil commented 9 months ago

Yes.

Some additional work on equation cross-ref might lift this limitation in 1.5.

cderv commented 9 months ago

Ok you labelled support so maybe we should label this as feature request instead right ?

mcanouil commented 9 months ago

Let's make a future enhancement.