Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/69298


Change subject: Enabling MathJaX in LaTeXML rendering mode except for Firefox
......................................................................

Enabling MathJaX in LaTeXML rendering mode except for Firefox

Due to a bad MathML support for all browsers, expect Firefox,
the LaTeXML rendering mode will use MathJaX's MML to something
that can be displayed by the browser rendering mode.
This is not the same as enabling MathJaX since it is much faster
since the MathML must only be transformed to e.g. SVG. In contrast
to that MathJaX must compile the TeX code in order to get the SVG
output at the client side which takes much longer.

Change-Id: I6ad17a04e9d4afff71ebbb3f4bc3cb6d4fd15e5d
---
M Math.hooks.php
M Math.php
A modules/ext.math.mathjax.enabler.mml.js
3 files changed, 102 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math 
refs/changes/98/69298/1

diff --git a/Math.hooks.php b/Math.hooks.php
index 3489da5..2eb6ec5 100644
--- a/Math.hooks.php
+++ b/Math.hooks.php
@@ -53,7 +53,17 @@
                $renderedMath = $renderer->render();
                if ( $wgUseMathJax && $mode == MW_MATH_MATHJAX ) {
                        $parser->getOutput()->addModules( array( 
'ext.math.mathjax.enabler' ) );
+               } elseif ( $wgUseMathJax && $mode == MW_MATH_LATEXML ) {
+                       if(isset($_SERVER['HTTP_USER_AGENT'])){
+                               $UA=$_SERVER['HTTP_USER_AGENT'];
+                       } else
+                       {$UA="undefined"; //required for maitenance script runs
+                       }
+                       if (!preg_match('/Firefox/',$UA)){ //Don't use MathJax 
with Firefox this has to be extenden to other browser that suppert MathML maybe 
a function supports MathML was the correct way to go
+                               $parser->getOutput()->addModules( array( 
'ext.math.mathjax.enabler.mml' ) );
                }
+               }
+               // Writes cache if rendering was successful
                $renderer->writeCache();
                return $wgContLang->armourMath( $renderedMath );
        }
diff --git a/Math.php b/Math.php
index 9314cb7..38935db 100644
--- a/Math.php
+++ b/Math.php
@@ -168,3 +168,7 @@
 $wgResourceModules['ext.math.mathjax.enabler'] = array(
        'scripts' => 'ext.math.mathjax.enabler.js',
 ) + $moduleTemplate;
+// Customized module for LaTeXML
+$wgResourceModules['ext.math.mathjax.enabler.mml'] = array(
+               'scripts' => 'ext.math.mathjax.enabler.mml.js',
+) + $moduleTemplate;
diff --git a/modules/ext.math.mathjax.enabler.mml.js 
b/modules/ext.math.mathjax.enabler.mml.js
new file mode 100644
index 0000000..7629b42
--- /dev/null
+++ b/modules/ext.math.mathjax.enabler.mml.js
@@ -0,0 +1,88 @@
+/**
+ * From https://en.wikipedia.org/wiki/User:Nageh/mathJax.js
+ */
+/*global mathJax:true, MathJax */
+( function ( mw, $ ) {
+  if ( typeof mathJax === 'undefined' ) {
+    mathJax = {};
+  }
+
+  mathJax.version = '0.2';
+
+  mathJax.loaded = false;
+
+  mathJax.config = $.extend( true, {
+    root: mw.config.get('wgExtensionAssetsPath') + '/Math/modules/MathJax',
+    config: ['MML_HTMLorMML-full.js'],
+    'v1.0-compatible': false,
+    displayAlign: 'left',
+    menuSettings: {
+      zoom: 'Click'
+    },
+    'HTML-CSS': {
+      imageFont: null,
+      availableFonts: ['TeX'],
+      mtextFontInherit: true
+    }
+  }, mathJax.config );
+
+  mathJax.Config = function () {
+    MathJax.Hub.Config( mathJax.config );
+    MathJax.OutputJax.fontDir = mw.config.get('wgExtensionAssetsPath') + 
'/Math/modules/MathJax/fonts';
+  };
+
+  /**
+   * Renders all Math TeX inside the given elements.
+   * @param {function} callback to be executed after text elements have 
rendered [optional]
+   */
+  $.fn.renderTex = function ( callback ) {
+    var elem = this.find( '.tex' ).parent().toArray();
+
+    if ( !$.isFunction( callback ) ) {
+      callback = $.noop;
+    }
+
+    function render () {
+      MathJax.Hub.Queue( ['Typeset', MathJax.Hub, elem, callback] );
+    }
+
+    mw.loader.using( 'ext.math.mathjax', function () {
+      if ( MathJax.isReady ) {
+        render();
+      } else {
+        MathJax.Hub.Startup.signal.MessageHook( 'End', render );
+      }
+    });
+    return this;
+  };
+
+  mathJax.Load = function () {
+    var config, script;
+    if (this.loaded) {
+      return true;
+    }
+
+    // create configuration element
+    config = 'mathJax.Config();';
+    script = document.createElement( 'script' );
+    script.setAttribute( 'type', 'text/x-mathjax-config' );
+    if ( window.opera ) {
+      script.innerHTML = config;
+    } else {
+      script.text = config;
+    }
+    document.getElementsByTagName('head')[0].appendChild( script );
+
+    // create startup element
+    mw.loader.load('ext.math.mathjax');
+
+    this.loaded = true;
+
+    return false;
+  };
+
+  $( document ).ready( function () {
+    mathJax.Load();
+  } );
+
+}( mediaWiki, jQuery ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/69298
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6ad17a04e9d4afff71ebbb3f4bc3cb6d4fd15e5d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <w...@physikerwelt.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to