JMM’s notes on

MathML

Example

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mn> 2 </mn>
  <mo> + </mo>
  <mfrac>
    <mn> 1 </mn>
    <mn> 3 </mn>
  </mfrac>
</math>
2 + 1 3

Aligning equations

Align equations by using “<mtable/>” like so:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
 <mtable style="math-style: normal;">
  <mtr>
   <mtd><mi>x</mi></mtd>
   <mtd><mo>=</mo></mtd>
   <mtd><mfrac><mn>2</mn><mn>3</mn></mfrac></mtd>
  </mtr>
  <mtr>
   <mtd><mi>y</mi></mtd>
   <mtd><mo>=</mo></mtd>
   <mtd><mn>3</mn></mtd>
  </mtr>
  <mtr>
   <mtd><mi>z</mi><mo>+</mo><mi>x</mi></mtd>
   <mtd><mo>=</mo></mtd>
   <mtd><mn>5</mn></mtd>
  </mtr>
 </mtable>
</math>

Make sure to set the CSS math-style: normal; (thanks to this stackoverflow answer). This gives you:

x = 23 y = 3 z+x = 5

LaTeX to MathML

You can use LaTeXML (as mentioned by this stackoverflow answer.

nix-shell -p perl538Packages.LaTeXML
latexmlmath '2+\frac{1}{3}'

You can also use Pandoc (see my Pandoc notes).

echo '$2 + \\frac{1}{3}$' | pandoc -f html+tex_math_dollars --mathml

TeXZilla converts LaTeX in the browser.

contenteditable

You can’t seem to directly set contenteditable on a <math> tag (since it’s an HTML thing), but you can wrap it in something like a <div> like:

acc = 1 K k = 1 K exp ( lppd ^ k n test , k ) \text{acc} = \frac{1}{K}\sum_{k=1}^{K} \exp\left(\frac{\hat{lppd}_k}{n_{test,k}}\right)

mrow parentheses

A 2 = ( 1 2 3 4 5 6 7 8 9 )

Misc