sile-typesetter / sile

The SILE Typesetter — Simon’s Improved Layout Engine
https://sile-typesetter.org
MIT License
1.63k stars 96 forks source link

Some MathML that fails #1293

Open Omikhleia opened 2 years ago

Omikhleia commented 2 years ago

SILE 0.12

Math input:

<sile>
<mathml>
<mtable><mtr><mtd><mi>A</mi></mtd></mtr><mtr><mtd><mi>B</mi></mtd></mtr></mtable>
<mi>C</mi>
<mtable><mtr><mtd><mi>D</mi></mtd></mtr><mtr><mtd><mi>E</mi></mtd></mtr></mtable>
</mathml>
</sile>

Expected:

A D
 C
B E

Observed

Error detected:
    /usr/share/sile/core/length.lua:96: attempt to index local 'self' (a nil value)
stack traceback:
    /usr/share/sile/core/length.lua:96: in function '__add'
    packages/math/base-elements.lua:486: in function 'shape'
    packages/math/base-elements.lua:309: in function 'shapeTree'
    /usr/share/sile/packages/math/typesetter.lua:117: in function 'handleMath'
...

At line 486, self.children[i - 1].relY is nil for i == 2 (and indeed not initialized above in the case i == 1 ? However setting it there to 0 avoids the crash, but all items are then stacked vertically...

(MathML is hard, maybe I am doing it wrong ? the above MathML snippet was generated with the demo at https://demo.wiris.com/mathtype/en/developers.php and and also shows up correctly in https://www.mathmlcentral.com/Tools/FromMathML.jsp)

ctrlcctrlv commented 2 years ago

Hey, I think you're doing it wrong, but am not sure, I have not a lot of experience with MathML. In my understanding, MathML is supposed to be used to “describe the layout structure of mathematical notation whereas content markup provides the underlying mathematical meaning and is not supposed to be rendered by the MathML parser”. “The intent of Content Markup is to provide an explicit encoding of the underlying mathematical meaning of an expression, rather than any particular rendering for the expression.

That's not to say you're causing this bug, but I think that an <mi/> between <mtable/>'s is undefined behavior?? So you're supposed to have multiple <math>'s? That would explain why no child other than the first is considered. Maybe I'm reading it wrong, sorry if I am. :-)

OlivierNicole commented 2 years ago

This code should, in fact, be accepted, so this is a bug. Currently, when a mathml tag has several children, SILE should typeset them stacked vertically (although the MathML spec says that it should be horizontal like in an mrow, so we'll need to change that). And the above code shouldn't be a problem. I'll look into it.

Edit: replaced wrong word.