3

I'm trying to create an HTML with a math formula, from the following markdown:

// myFile.md

This is a formula: $f(x) = y$

Then, I run the following command:

$ pandoc --mathml myFile.md -o -

The generated output, looks like follows:

<p>
  This is a formula:
  <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML">
    <semantics>
      <mrow>
        <mi> f</mi>
        <mrow>
          <mo stretchy="true" form="prefix"> (</mo> <mi> x</mi>
          <mo stretchy="true" form="postfix"> )</mo>
        </mrow>
        <mo> =</mo>
        <mi> y</mi>
      </mrow>
      <annotation encoding="application/x-tex"> f(x) = y </annotation>
    </semantics>
  </math>
</p>

And it's rendered this way:

enter image description here

Am I doing anything wrong? Is there a way to solve this problem?

Expected output

After some tries, what I would expect is what I get with one of the following hacks:

  • If I manually remove the <mrow> and </mrow> tags following "f".
  • If I manually set stretchy attribute to false.

But these are just hacks. I need Pandoc to produce the proper output:

expected output

Thanks.

sgmonda
  • 2,615
  • 1
  • 19
  • 29
  • Maybe consider using MathJax instead of MathML? My experience has been that MathML is often kind of clunky in comparison. – Robert Dodier May 30 '23 at 17:41
  • @RobertDodier The reason I prefer MathML is compatibility, as I’m using this for an ePub and it works better with MathML in relation to color themes support (formulas as images, are always black text so it is not ok for white text over dark background) – sgmonda May 30 '23 at 17:45
  • I created an html file with your code. Then I tried to display it with Firefox, Vivaldi, Edge. In all cases I didn't see the misalignment. Which navigator/software are you using ? – Damien Jun 23 '23 at 15:52
  • @Damien oh my god! I'm using Safari and it is a problem with Safari! ‍♂️ Why the hell I didn't try with other browsers? XD Thank you very much – sgmonda Jun 26 '23 at 12:48

1 Answers1

1

It is a problem with Safari. In other browsers, my first generated HTML looks good. Thank you very much to @Damien for his help :-)

This highlights the problems of using MathML for ePubs, as we don't have control over the reader being used. For instance, from iBooks I've experienced the same weird rendering than in Safari.

Finally, I've decided to use GladTeX to convert math to inline images so I ensure a better compatibility.

sgmonda
  • 2,615
  • 1
  • 19
  • 29