MathJax.Hub.Register.StartupHook('HTML-CSS Jax Require', function () {
  MathJax.Hub.Config({
    'HTML-CSS': {
      styles: {
        '.MathJax .mfliph': {
          'display': 'inline-block !important',
          '-moz-transform': 'scaleX(-1)',
          '-webkit-transform': 'scaleX(-1)',
          '-o-transform': 'scaleX(-1)',
          'transform': 'scaleX(-1)',
          '-ms-filter': 'fliph',
          'filter': 'fliph'
        },
        '.MathJax .mar': {
          'font-style': 'normal !important'
        },
        '.MathJax .mar > span': {
          'font-style': 'normal !important'
        }
      }
    }
  });
});


MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready', function () {
  MathJax.Hub.Register.StartupHook('Arabic TeX Ready', function () {
    var MML = MathJax.ElementJax.mml;

    var makeElementFlippable = function (name) {
      var originalToHTML = MML[name].prototype.toHTML;

      MML[name].Augment({
        toHTML: function () {
          var element = originalToHTML.apply(this, arguments);

          if (this.arabicFlipH) {
            var flipElement = document.createElement('span');

            var className = ' mfliph';  // Keep the leading space

            if ('ar' === this.arabicFontLang) {
              className += ' mar';  // Keep the leading space
            }

            flipElement.className = className;

            if (element.firstChild) {
              while (element.firstChild) {
                flipElement.appendChild(element.firstChild);
              }
            }

            element.appendChild(flipElement);
          }

          return element;
        }
      });
    };

    [
      'mfrac',
      'mi',
      'mn',
      'mo',
      'mrow',
      'ms',
      'msqrt',
      'msubsup',
      'mroot',
      'mtext'
    ].forEach(makeElementFlippable);

    MathJax.Hub.Register.StartupHook('HTML-CSS mtable Ready', function () {
      makeElementFlippable('mtable');

      MathJax.Hub.Startup.signal.Post('Arabic mtable Ready');
    });


    MathJax.Hub.Startup.signal.Post('Arabic Ready');
  });
});

@@ -1142,20 +1142,28 @@
         
-var 
+flipElement.
 classNam
@@ -1171,17 +1171,16 @@
  = '
- 
 mfliph';
   //
@@ -1179,35 +1179,8 @@
 ph';
-  // Keep the leading space
 %0A%0A  
@@ -1239,16 +1239,28 @@
         
+flipElement.
 classNam
@@ -1271,17 +1271,16 @@
  ' mar';
- 
  // Keep
@@ -1317,56 +1317,8 @@
  %7D%0A%0A
-            flipElement.className = className;%0A%0A
     

Simplify the logic a big