2011-12-06 01:17:35 +00:00
|
|
|
/**
|
|
|
|
* From https://en.wikipedia.org/wiki/User:Nageh/mathJax/config/TeX-AMS-texvc_HTML.js
|
|
|
|
*/
|
2014-08-29 19:03:41 +00:00
|
|
|
/* global MathJax:true, $:true */
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2012-03-05 22:24:54 +00:00
|
|
|
MathJax.Extension.wiki2jax = {
|
2014-08-29 19:03:41 +00:00
|
|
|
version: '1.0',
|
2012-03-05 22:24:54 +00:00
|
|
|
|
|
|
|
config: {
|
2014-04-08 15:25:55 +00:00
|
|
|
element: null // The ID of the element to be processed
|
2012-03-05 22:24:54 +00:00
|
|
|
// (defaults to full document)
|
|
|
|
},
|
|
|
|
|
|
|
|
PreProcess: function (element) {
|
|
|
|
if (!this.configured) {
|
2014-08-29 19:03:41 +00:00
|
|
|
this.config = MathJax.Hub.CombineConfig('wiki2jax', this.config);
|
|
|
|
if (this.config.Augment) {MathJax.Hub.Insert(this,this.config.Augment);}
|
2012-03-12 20:41:43 +00:00
|
|
|
|
2012-03-05 22:24:54 +00:00
|
|
|
this.previewClass = MathJax.Hub.config.preRemoveClass;
|
2012-09-07 14:58:18 +00:00
|
|
|
this.setupPrefilter();
|
2012-03-05 22:24:54 +00:00
|
|
|
this.configured = true;
|
|
|
|
}
|
|
|
|
var that = this;
|
2014-03-17 06:14:02 +00:00
|
|
|
$('.mwe-math-fallback-png-display, .mwe-math-fallback-png-inline, .mwe-math-fallback-source-display,'+
|
|
|
|
'.mwe-math-fallback-source-inline, strong.texerror', element || document).each(function(i, span) {
|
2012-03-05 22:24:54 +00:00
|
|
|
that.ConvertMath(span);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-09-07 14:58:18 +00:00
|
|
|
setupPrefilter: function() { // used to fix a number of common wiki math hacks
|
2014-08-29 19:03:41 +00:00
|
|
|
MathJax.Hub.Register.StartupHook('TeX Jax Ready', function() {
|
2012-09-07 14:58:18 +00:00
|
|
|
MathJax.InputJax.TeX.prefilterHooks.Add( function(data) {
|
2014-08-29 19:03:41 +00:00
|
|
|
data.math = data.math.replace(/^\s*\\scriptstyle(\W)/,'\\textstyle$1').replace(/^\s*\\scriptscriptstyle(\W)/,'\\scriptstyle$1');
|
|
|
|
if (data.script.type.match(/(;|\s|\n)mode\s*=\s*display-nobreak(;|\s|\n|$)/) !== null) {
|
|
|
|
data.math = '\\displaystyle ' + data.math;
|
|
|
|
}
|
2012-09-07 14:58:18 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-03-05 22:24:54 +00:00
|
|
|
ConvertMath: function (node) {
|
|
|
|
var parent = node.parentNode,
|
2014-08-29 19:03:41 +00:00
|
|
|
mode = '', //Bug 61051 (heuristic unwanted by the community)
|
2012-03-05 22:24:54 +00:00
|
|
|
tex;
|
2014-08-29 19:03:41 +00:00
|
|
|
if (node.nodeName === 'IMG') {
|
2012-03-05 22:24:54 +00:00
|
|
|
tex = node.alt;
|
|
|
|
} else {
|
2014-08-29 19:03:41 +00:00
|
|
|
if (node.nodeName === 'STRONG') {
|
|
|
|
tex = $(node).text().replace(/^[^:]*: (.*)$/,'$1');
|
2013-09-09 10:07:18 +00:00
|
|
|
} else {
|
2014-08-29 19:03:41 +00:00
|
|
|
tex = $(node).text().replace(/^\$/,'').replace(/\$$/,'');
|
2013-09-09 10:07:18 +00:00
|
|
|
}
|
2014-08-29 19:03:41 +00:00
|
|
|
tex = tex.replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&').replace(/ /g,' ');
|
2012-03-05 22:24:54 +00:00
|
|
|
}
|
2014-08-29 19:03:41 +00:00
|
|
|
if ( $( node ).hasClass( 'mwe-math-fallback-png-display') || $( node ).hasClass( 'mwe-math-fallback-source-display') ){
|
|
|
|
mode = '; mode=display';
|
2014-03-17 06:14:02 +00:00
|
|
|
}
|
2012-09-07 12:56:35 +00:00
|
|
|
// We don't allow comments (%) in texvc and escape all literal % by default.
|
2014-08-29 19:03:41 +00:00
|
|
|
tex = tex.replace(/([^\\])%/g, '$1\\%' );
|
2012-09-07 12:56:35 +00:00
|
|
|
|
2014-08-29 19:03:41 +00:00
|
|
|
tex = tex.replace(/\\iiint([^!]*)!\\!\\!\\!\\!.*\\subset\\!\\supset/g,'\\iiint$1mkern-2.5em\\subset\\!\\supset').replace(/\\iint([^!]*)!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!(.*)\\subset\\!\\supset/g,'\\iint$1mkern-1.65em$2\\subset\\!\\!\\supset').replace(/\\int\\!\\!\\!(\\!)+\\int\\!\\!\\!(\\!)+\\int([^!]*)!\\!\\!\\!\\!.*\\bigcirc(\\,)*/g,'\\iiint$3mkern-2.5em\\subset\\!\\supset').replace(/\\int\\!\\!\\!(\\!)+\\int([^!]*)!\\!\\!\\!\\!\\!\\!\\!\\!(.*)\\bigcirc(\\,)*/g,'\\iint$2mkern-1.65em$3\\subset\\!\\!\\supset');
|
2012-09-07 14:58:18 +00:00
|
|
|
|
2014-08-29 19:03:41 +00:00
|
|
|
if (mode === '' && parent.firstChild === node) {mode = '; mode=display-nobreak';}
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2014-08-29 19:03:41 +00:00
|
|
|
var script = document.createElement('script');
|
|
|
|
script.type = 'math/tex' + mode;
|
2012-03-12 20:41:43 +00:00
|
|
|
MathJax.HTML.setScript(script, tex);
|
2012-03-05 22:24:54 +00:00
|
|
|
|
2014-08-29 19:03:41 +00:00
|
|
|
if (node.nextSibling) {parent.insertBefore(script,node.nextSibling);}
|
|
|
|
else {parent.appendChild(script);}
|
2012-03-05 22:24:54 +00:00
|
|
|
|
2014-08-29 19:03:41 +00:00
|
|
|
var preview = MathJax.HTML.Element('span', {
|
2013-09-09 10:07:18 +00:00
|
|
|
className: MathJax.Hub.config.preRemoveClass
|
|
|
|
});
|
|
|
|
preview.appendChild(parent.removeChild(node));
|
|
|
|
parent.insertBefore(preview, script);
|
2014-04-08 15:25:55 +00:00
|
|
|
}
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2012-03-05 22:24:54 +00:00
|
|
|
};
|
2011-12-06 01:17:35 +00:00
|
|
|
|
2014-08-29 19:03:41 +00:00
|
|
|
MathJax.Hub.Register.PreProcessor(['PreProcess',MathJax.Extension.wiki2jax]);
|
|
|
|
MathJax.Ajax.loadComplete(MathJax.Ajax.config.path.MediaWiki + '/wiki2jax.js');
|