Arabic MathML

by Manuel Souto Pico

HTML

<script src="https://cdn.mathjax.org/mathjax/2.5-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<!-- Type LaTeX math wrapped in double dollar signs here.
Press run. Then copy and paste from textbox into MS Word --> 

<p>Display:</p>
$$Area = \frac{1}{2}  b × h$$

$$‪المساحة ‎= \frac{1}{2} b × h‬$$

<p>MathML (Math XML) Paste this into word:</p>
<div id="result"></div>

CSS

.copytext {
    width: 100%;
    height: 200px;
    margin-bottom: 12px;
}

JavaScript

function toMathML(jax,callback) {
  var mml;
  try {
    mml = jax.root.toMathML("");
  } catch(e) {
    if (!e.restart) {
        throw e;
    }
    return MathJax.Callback.After([toMathML,jax,callback],err.restart);
  }
  MathJax.Callback(callback)(mml);
}
  
  MathJax.Hub.Queue(
    function () {
      var jax = MathJax.Hub.getAllJax();
      for (var i = 0; i < jax.length; i++) {
        toMathML(jax[i], function(mml) {
          $("#result").append($('<code>' + jax[i].originalText + '</code>'))
          .append($('<textarea>', {class: 'copytext', spellcheck: 'false'}).val(mml));
        });
      }
    }
  );