From b08fbbbe38a0fbedb884fae642b6002929bf1ac9 Mon Sep 17 00:00:00 2001 From: nageh Date: Fri, 7 Sep 2012 16:58:18 +0200 Subject: [PATCH] (bug 35188) Do not poison the tex formula with markup We move the block/inline styling (aka display vs textstyle) markup into a filter used just before rendering. This way the 'used' formula will not suddenly contain styling information that wasn't part of the original formula. Change-Id: Ie0c308c31d38581e556dc73109879c7a3d365121 --- modules/MathJax/extensions/wiki2jax.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/MathJax/extensions/wiki2jax.js b/modules/MathJax/extensions/wiki2jax.js index 606ac75..baf6536 100644 --- a/modules/MathJax/extensions/wiki2jax.js +++ b/modules/MathJax/extensions/wiki2jax.js @@ -20,6 +20,7 @@ MathJax.Extension.wiki2jax = { if (this.config.Augment) {MathJax.Hub.Insert(this,this.config.Augment)} this.previewClass = MathJax.Hub.config.preRemoveClass; + this.setupPrefilter(); this.configured = true; } var that = this; @@ -28,6 +29,16 @@ MathJax.Extension.wiki2jax = { }); }, + setupPrefilter: function() { // used to fix a number of common wiki math hacks + MathJax.Hub.Register.StartupHook("TeX Jax Ready", function() { + MathJax.InputJax.TeX.prefilterHooks.Add( function(data) { + 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; + }); + }); + }, + ConvertMath: function (node) { var parent = node.parentNode, mode = parent.tagName === "DD" && parent.childNodes.length === 1 ? "; mode=display" : "", @@ -40,10 +51,8 @@ MathJax.Extension.wiki2jax = { } 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"); - if (mode === "") { - tex = tex.replace(/ *\\scriptstyle(\W)/g,"\\textstyle$1").replace(/ *\\scriptscriptstyle(\W)/g,"\\scriptstyle$1"); - if (parent.firstChild === node) tex = "\\displaystyle "+tex; - } + + if (mode === "" && parent.firstChild === node) mode = "; mode=display-nobreak"; var script = document.createElement("script"); script.type = "math/tex" + mode;