Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw MathML bug #784

Open
zor-el opened this issue Nov 19, 2023 · 1 comment
Open

Raw MathML bug #784

zor-el opened this issue Nov 19, 2023 · 1 comment

Comments

@zor-el
Copy link

zor-el commented Nov 19, 2023

I've run into this issue while trying to migrate from Kramdown.

This is the KaTeX output for $E = m c^2$:

<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>E</mi><mo>=</mo><mi>m</mi><mo></mo><msup><mi>c</mi><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">E = m \cdot c^2</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.05764em;">E</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.4445em;"></span><span class="mord mathnormal">m</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin"></span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.8141em;"></span><span class="mord"><span class="mord mathnormal">c</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span></span></span>

Normally the above snippet would be inserted in the preprocess method of a custom renderer. But even when I paste it into the markdown text directly, it is rendered as

Screenshot 2023-11-19 at 13 43 03

instead of

Screenshot 2023-11-19 at 13 43 44

Redcarpet seems to mistakenly insert one tag as raw text:

Screenshot 2023-11-19 at 13 54 26

The bug seems somehow related to the closing </math> tag. It does not manifest when I insert a space or line break before it. What is weird (to me) is that the tag in question is further down to the closing tag, and not even adjacent to it.

The bug seems somehow related to the caret expression ^2. Inserting a space in any place after it (that doesn't break HTML syntax) - like immediately after ^2 or in between any tag, but before the tag that is treated as raw text (<span class="katex-html" aria-hidden="true">) restores correct rendering.

My workaround is to gsub the Katex output and insert the space programmatically, but it'd be nicer if the issue was properly fixed.

Any takes / ideas / better workarounds?

Thanks a bunch!

@zor-el zor-el changed the title MathML closing tag bug (</math>) Raw MathML bug Nov 19, 2023
@zor-el
Copy link
Author

zor-el commented Nov 19, 2023

Further investigation shows that the addition of a space anywhere after ^2 restores the correct rendering. Updating the description...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant