arnog / mathlive

A web component for easy math input
https://cortexjs.io/mathlive
MIT License
1.59k stars 280 forks source link

Bug: convertLatexToMathMl not transforming properly extensible accents #2134

Open FrancoRossi-Globant opened 1 year ago

FrancoRossi-Globant commented 1 year ago

Description

I need to convert Latex formulas to MathML with the convertLatexToMathMl(string). Currently there are a few Extensible Accents formulas that are not being correctly converted.

In this codepen i've added a couple of Extensible Accents conversion adding its return value to the doc. In mathfield I'm showing how we need to be render with the exact formula.

Steps to Reproduce

Provide steps that are specific and repeatable

  1. add function with a call to convertLatexToMathMl.
  2. on convertLatexToMathMl add a string param of ('\\overgroup{ab}') ej: convertLatexToMathMl('\\overgroup{ab}');
  3. log/print result of called function.

Actual Behavior

The return of convertLatexToMathMl function isn't returning expected math tags of Extensible Accents.

Expected Behavior

convertLatexToMathMl function to return expected math tags of Extensible Accents.

Environment

Operating System Windows

Browser _Chrome, Firefox ... didn't test in others.

arnog commented 1 year ago

Thanks for providing the CodePen, that's useful.

However, I'm not sure what the "expected math tags" are. Could you elaborate on what you are expecting?

FrancoRossi-Globant commented 1 year ago

Yes sorry, that wasn't very tech. I was referring to the conversion from latex to mathml, "math tags" would be mathml. Taking for example "\overbrace{ab}" the conversion to mathml would be something like...

<math display="block">
  <mover accent="true">
    <mrow>
      <mi>A</mi>
      <mi>B</mi>
    </mrow>
    <mo>&#x23DE</mo>
  </mover>
</math>

instead im getting:

<mover >⏞</mover>
arnog commented 1 year ago

OK, got it. You don't know where I could find a mapping of the LaTeX commands to the matching MathML Unicode operators by any chance?

NSoiffer commented 1 year ago

Take a look at https://github.com/joom/latex-unicoder.vim/blob/master/autoload/unicoder.vim

arnog commented 1 year ago

Thanks, @NSoiffer. That's a start, it seems to give the following:

But there are several missing, include \overgroup, \overline, \overlinesegment, \overrightarrow, \overleftarrow, \overarc, \wideparen and `\widetilde.

And some are only provided with combining characters: \overline, \overleftrightarrow which seems like it's an error.

NSoiffer commented 1 year ago

I can't vouch for the accuracy of the list. Sorry.

For MathML, the over arrows would simply be mover with the appropriate arrow as the second arg. Same for a line (U+005F).

I don't know if there is a stretchy/wider tilde or arc.

arnog commented 1 year ago

The MathML operator dictionary does list some accents: see https://www.w3.org/TR/2009/WD-MathML3-20090924/appendixc.html, "stretchy accent" operators.

NSoiffer commented 1 year ago

In case it isn't clear, you can click on a column and it will sort by that column. So clicking on "properties" is a way to get all the stretch operators together. Of course, whether a character actually will stretch depends upon the font being used.

FrancoRossi-Globant commented 1 year ago

Any update on this? Or any other help I could bring?

arnog commented 1 year ago

It could help if you could provide the specific mappings you are looking for.

FrancoRossi-Globant commented 11 months ago

Hi Arno, a long time without coming here. What are you referring to the mapping??? An example here is that modifing somelines of code in the lib I get something more useful from the \overleftrightarrow. Modified lines atom-to-math-ml.ts:

864: overscript = atom.above || atom.svgAbove; 
866: if ((overscript) && (atom.svgBelow || underscript))

And I start getting this: <mover ><mrow><mi>A</mi><mo>&#8290;</mo><mi>b</mi></mrow>←</mover> And what I want to get is this: <mover><mrow><mi>A</mi><mi>b</mi></mrow><mo stretchy="true" style="math-style: normal; math-depth: 0;">←</mo></mover> see: https://temml.org/