mdit-py-plugins icon indicating copy to clipboard operation
mdit-py-plugins copied to clipboard

converted formula lost its delimiters

Open redstoneleo opened this issue 2 years ago • 1 comments

Describe the bug

context I used markdown_it to convert Markdown to html, but the converted formula lost its delimiters, which caused my mathjax cannot render the formula,

Code for conversion :

from markdown_it import MarkdownIt
from mdit_py_plugins.front_matter import front_matter_plugin
from mdit_py_plugins.footnote import footnote_plugin
from mdit_py_plugins.anchors import anchors_plugin
from mdit_py_plugins.texmath import  texmath_plugin
from mdit_py_plugins.dollarmath import  dollarmath_plugin
from mdit_py_plugins.amsmath import amsmath_plugin
from markdown_it.common import  utils

import html
md = (
    # MarkdownIt('gfm-like' ,{
    MarkdownIt('commonmark' ,{
        'breaks':True,
        'html':True
        })


    # .use(texmath_plugin, delimiters="dollars")
    .use(dollarmath_plugin)
    # .use(amsmath_plugin)
	.use(front_matter_plugin)
    .use(footnote_plugin)
    .use(anchors_plugin, permalink=True, max_level=4)
    
    .enable('table')
)
s4=r'''a rational number like $\begin{matrix}
L & \  = \{ x \mid x \in \mathbb{Q},x \leq 0\} \cup \left\{ x \mid x \in \mathbb{Q},x > 0,x^{2} < 2 \right\} \\
U & \  = \mathbb{Q} - L = \left\{ x \mid x \in \mathbb{Q},x > 0,x^{2} > 2 \right\} \\
\end{matrix}$ .
  2.  A fact between two Dedekind cuts(the density of $Q$ in $R$): For any pair of real numbers $\alpha$ and $\beta$, where $\alpha > \beta$, there can always be found a real, and even in particular a rational, number $r$ which lies between them, i.e. $\alpha > r > \beta$ (and, consequently, an infinite set of such rational numbers).
'''
html_text = md.render(s4)
print(html_text)

The demo with the result at https://jsbin.com/ronasug/edit?html,output

expectation delimiters around formula.

bug converted formula lost its delimiters, the bug is also confirmed at https://groups.google.com/g/mathjax-users/c/aL3aqfp8DzU/m/KZoomKKvBwAJ

... but it looks like it might be an old one, as it seems to be producing jsMath-style delimiters (...) rather than MathJax-style ones. JsMath was MathJax's predecessor, active from 2004 to 2008, and while MathJax v2 includes an extension that would parse jsMath delimiters, that is not available in version 3. There is an example showing how to look for MathJax v2

Reproduce the bug

see the above section

List your environment

No response

redstoneleo avatar Jan 14 '23 16:01 redstoneleo

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:

welcome[bot] avatar Jan 14 '23 16:01 welcome[bot]