NSoiffer / MathCAT

MathCAT: Math Capable Assistive Technology for generating speech, braille, and navigation.
MIT License
63 stars 35 forks source link

Parse error: Mover should have 2 children #302

Closed Almost-Senseless-Coder closed 1 month ago

Almost-Senseless-Coder commented 1 month ago

I'm unsure what to do with this error message. Maybe you can help me figure it out.

Original LaTeX

y:= \widetilde{\sin } x:= \text {rd}(\sin x) = (\sin x) (1 + \tau _y).

Which, when rendered, looks like this:

$$ y:= \widetilde{\sin } x:= \text {rd}(\sin x) = (\sin x) (1 + \tau _y). $$

KaTeX output

Note: Only the output from <math until </math> (both inclusive) gets passed to MathCAT.

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>y</mi><mo>:</mo><mo>=</mo><mover accent="true"><mi>sin</mi><mo>⁡</mo><mo stretchy="true">~</mo></mover><mi>x</mi><mo>:</mo><mo>=</mo><mtext>rd</mtext><mo stretchy="false">(</mo><mi>sin</mi><mo>⁡</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mo stretchy="false">(</mo><mi>sin</mi><mo>⁡</mo><mi>x</mi><mo stretchy="false">)</mo><mo stretchy="false">(</mo><mn>1</mn><mo>+</mo><msub><mi>τ</mi><mi>y</mi></msub><mo stretchy="false">)</mo><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex"> y:= \widetilde{\sin } x:= \text {rd}(\sin x) = (\sin x) (1 + \tau _y). </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</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.9279em;"></span><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.9279em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mop">sin</span></span><span class="svg-align" style="top:-3.6679em;"><span class="pstrut" style="height:3em;"></span><span style="height:0.26em;"><svg xmlns="http://www.w3.org/2000/svg" width='100%' height='0.26em' viewBox='0 0 600 260' preserveAspectRatio='none'><path d='M200 55.538c-77 0-168 73.953-177 73.953-3 0-7
-2.175-9-5.437L2 97c-1-2-2-4-2-6 0-4 2-7 5-9l20-12C116 12 171 0 207 0c86 0
 114 68 191 68 78 0 168-68 177-68 4 0 7 2 9 5l12 19c1 2.175 2 4.35 2 6.525 0
 4.35-2 7.613-5 9.788l-19 13.05c-92 63.077-116.937 75.308-183 76.128
-68.267.847-113-73.952-191-73.952z'/></svg></span></span></span></span></span></span><span class="mord mathnormal">x</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:1em;vertical-align:-0.25em;"></span><span class="mord text"><span class="mord">rd</span></span><span class="mopen">(</span><span class="mop">sin</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">x</span><span class="mclose">)</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:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mop">sin</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">x</span><span class="mclose">)</span><span class="mopen">(</span><span class="mord">1</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:1.0361em;vertical-align:-0.2861em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.1132em;">τ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.1132em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.03588em;">y</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mclose">)</span><span class="mord">.</span></span></span></span></span>

MathCAT error:

mover should have 2 children: <mover accent='true'> <mi>sin</mi> <mo>&#x2061;</mo> <mo stretchy='true'>~</mo> </mover>

Context

I'm extracting LaTeX from the alt attributes of (probably) MathJAX-generated images, converting them to MathML using KaTeX and then trying to run MathCAT. For the most part it goes well, but this error leaves me stumped.

Almost-Senseless-Coder commented 1 month ago

Actually, I figured it out. The <mo>&#x2061;</mo> gets added by MathML to ensure spacing, but in a mover that's illegal according to the spec. The solution is to simply strip the offending mo.