executablebooks / MyST-Parser

An extended commonmark compliant parser, with bridges to docutils/sphinx
https://myst-parser.readthedocs.io
MIT License
708 stars 189 forks source link

$$ equation reference is not identified unless preceded by a blank line #897

Open tillahoffmann opened 3 months ago

tillahoffmann commented 3 months ago

What version of myst-parser are you using?

2.0.0

What version dependencies are you using?

pydata-sphinx-theme==0.15.2
sphinx-book-theme==1.1.2
sphinxcontrib-applehelp==1.0.8
sphinxcontrib-devhelp==1.0.6
sphinxcontrib-htmlhelp==2.0.5
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.7
sphinxcontrib-serializinghtml==1.1.10
docutils==0.20.1

What operating system are you using?

Mac

Describe the Bug

Equation labels in dollar math are not identified unless the equation is preceded by a blank line. For example, the following two versions work as expected.

First.

$$
a = b + c
$$ (my-eqn)

{eq}`my-eqn`
First.

$$
a = b + c
$$ (my-eqn)
{eq}`my-eqn`

But this version fails with a missing reference.

First.
$$
a = b + c
$$ (my-eqn)

{eq}`my-eqn`

My conf.py contains

myst_enable_extensions = [
    "dollarmath",
]
myst_dmath_double_inline = True
myst_dmath_allow_labels = True

Expected Behavior

Equation labels are identified even if no blank line precedes the equation.

To Reproduce

See above.

welcome[bot] commented 3 months ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

72757373656c6c commented 3 months ago

This is an interesting Issue. The use of spaces, number of spaces, and blank lines is one aspect of MyST-Parser that I'm trying to understand better and be consistent.

From reading the MyST-Parser documentation on Paragraphs , it says,


Paragraphs are block of text separated by a blank line.

From the above, I would say there's a requirement for a blank line between the paragraph block (First.) and the $$ extension. When there is is no blank line, the MyST-Parser reads everything until a blank as a paragraph block, thus my-eqn is not defined, resulting in the missing reference.

i2000s commented 1 month ago

Well, an equation is not a paragraph. We commonly say ", where A is something, and B is something". So, if I put a blank line after the equation, will the incident of "where A is something, and B is something" look strange? Meanwhile, if I missed a blank line after an equation segment, the next time I use a pair of dollar signs to include an inline equation will not be compiled properly.

I suggest we implement a parser to allow equation environment put inside of a pair of double-dollar to put closely in a paragram with other text content.