From 93065ef0557910fdd30fabf7fa712ed7498f5110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Wed, 29 May 2013 15:45:58 +0200 Subject: [PATCH 1/3] Native MathML: add workarounds for mi, mo (lspace/rspace), mmultiscripts and mspace (width) elements in WebKit. Fix issue #482. --- unpacked/jax/output/NativeMML/jax.js | 147 ++++++++++++++++++++++++++- 1 file changed, 146 insertions(+), 1 deletion(-) diff --git a/unpacked/jax/output/NativeMML/jax.js b/unpacked/jax/output/NativeMML/jax.js index 5e866301e..5935e5020 100644 --- a/unpacked/jax/output/NativeMML/jax.js +++ b/unpacked/jax/output/NativeMML/jax.js @@ -444,7 +444,14 @@ negativemediummathspace: "-.2222em", negativethickmathspace: "-.2778em", negativeverythickmathspace: "-.3333em", - negativeveryverythickmathspace: "-.3889em" + negativeveryverythickmathspace: "-.3889em", + veryverythinmathspace: ".0556em", + verythinmathspace: ".1111em", + thinmathspace: ".1667em", + mediummathspace: ".2222em", + thickmathspace: ".2778em", + verythickmathspace: ".3333em", + veryverythickmathspace: ".3889em" } }); @@ -1089,6 +1096,138 @@ } }); + MML.mi.Augment({ + toNativeMML: function (parent) { + this.SUPER(arguments).toNativeMML.call(this,parent); + if (nMML.miItalicBug) { + if (this.Get("mathvariant") == "normal") { + // + // When not explicitly specified, mathvariant is set to "italic" + // with single char mi and to "normal" with multiple char mi. + // Some browsers always set the default to "italic", so modify the + // style when it is supposed to be "normal". + // + var mi = parent.lastChild; + var span = HTML.Element("span"); + span.style.cssText = (mi.getAttribute("style")||""); + span.style.fontStyle = "normal"; + mi.setAttribute("style",span.style.cssText); + } + } + } + }); + + MML.mo.Augment({ + toNativeMML: function (parent) { + this.SUPER(arguments).toNativeMML.call(this,parent); + if (nMML.webkitMoSpacingBug) { + // + // WebKit does not support lspace/rspace values around operators + // (neither explicit nor given by the operator dictionary) and uses + // constant values instead. So let's modify the CSS properties here. + // + + // + // Retrieve the values of lspace/rspace and convert named spaces. + // Other values (except unitless) will be parsed by the CSS engine. + // + var values = this.getValues("lspace", "rspace"); + var lspace = values.lspace, rspace = values.rspace; + if (nMML.NAMEDSPACE[lspace]) {lspace = nMML.NAMEDSPACE[lspace]} + if (nMML.NAMEDSPACE[rspace]) {rspace = nMML.NAMEDSPACE[rspace]} + + // + // Now update -webkit-margin-start and -webkit-margin-end. + // + var mo = parent.lastChild; + var span = HTML.Element("span"); + span.style.cssText = (mo.getAttribute("style")||""); + span.style.setProperty("-webkit-margin-start", lspace); + span.style.setProperty("-webkit-margin-end", rspace); + mo.setAttribute("style",span.style.cssText); + } + } + }); + + MML.mmultiscripts.Augment({ + toNativeMML: function (parent) { + // + // Some browsers do not implement the mmultiscripts element. + // Try to emulate the support using basic script elements. + // + if (!nMML.mmultiscriptsBug || this.data.length == 0 ) { + this.SUPER(arguments).toNativeMML.call(this,parent); + return; + } + + // + // The children of the mmultiscripts will be wrapped in an mrow so that + // attributes and properties set on the original mmultiscripts will + // be reflected on this mrow element. + // + var tag = this.NativeMMLelement("mrow"); + this.NativeMMLattributes(tag); + + // + // Create the base + // + if (this.data[0]) {this.data[0].toNativeMML(tag)} + else {tag.appendChild(this.NativeMMLelement("mrow"))} + base = tag.removeChild(tag.lastChild); + + // + // Process the postscript pairs + // + var m = this.data.length, i; + for (i = 1; i < m; i+=2) { + if (this.data[i].type == "mprescripts") break; + + var msubsup = this.NativeMMLelement("msubsup"); + msubsup.appendChild(base); + + // + // append the subscript + // + if (this.data[i]) {this.data[i].toNativeMML(msubsup)} + else {msubsup.appendChild(this.NativeMMLelement("mrow"))} + + // + // append the supscript + // + if (i+1 < m && this.data[i+1]) {this.data[i+1].toNativeMML(msubsup)} + else {msubsup.appendChild(this.NativeMMLelement("mrow"))} + + base = msubsup; + } + + tag.appendChild(base); + + // + // Process the prescript pairs + // + for (i++; i < m; i+=2) { + var msubsup = this.NativeMMLelement("msubsup"); + msubsup.appendChild(this.NativeMMLelement("mrow")); + + // + // append the presubscript + // + if (this.data[i]) {this.data[i].toNativeMML(msubsup)} + else {msubsup.appendChild(this.NativeMMLelement("mrow"))} + + // + // append the presupscript + // + if (i+1 < m && this.data[i+1]) {this.data[i+1].toNativeMML(msubsup)} + else {msubsup.appendChild(this.NativeMMLelement("mrow"))} + + tag.insertBefore(msubsup, base); + } + + parent.appendChild(tag); + } + }); + HUB.Register.StartupHook("TeX mathchoice Ready",function () { MML.TeXmathchoice.Augment({ // @@ -1121,6 +1260,8 @@ nMML.stretchyMoBug = true; nMML.tableLabelBug = true; nMML.mfencedBug = true; + nMML.miBug = true; + nMML.mmultiscriptsBug = true; }, Firefox: function (browser) { nMML.ffTableWidthBug = !browser.versionAtLeast("13.0"); // not implemented @@ -1145,6 +1286,10 @@ nMML.tableSpacingBug = true; nMML.tableLabelBug = true; nMML.mfencedBug = true; + nMML.miItalicBug = true; + nMML.webkitMoSpacingBug = true; + nMML.spaceWidthBug = true; + nMML.mmultiscriptsBug = true; } }); From d0e795705b4148903afbb59ea17481c1c0123fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Thu, 30 May 2013 11:26:50 +0200 Subject: [PATCH 2/3] WebKit NativeMML: only apply lspace/rspace in non-embellised mrow and set them to 0 otherwise. --- unpacked/jax/output/NativeMML/jax.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/unpacked/jax/output/NativeMML/jax.js b/unpacked/jax/output/NativeMML/jax.js index 5935e5020..f6fa1e5cb 100644 --- a/unpacked/jax/output/NativeMML/jax.js +++ b/unpacked/jax/output/NativeMML/jax.js @@ -1127,14 +1127,17 @@ // constant values instead. So let's modify the CSS properties here. // - // - // Retrieve the values of lspace/rspace and convert named spaces. - // Other values (except unitless) will be parsed by the CSS engine. - // - var values = this.getValues("lspace", "rspace"); - var lspace = values.lspace, rspace = values.rspace; - if (nMML.NAMEDSPACE[lspace]) {lspace = nMML.NAMEDSPACE[lspace]} - if (nMML.NAMEDSPACE[rspace]) {rspace = nMML.NAMEDSPACE[rspace]} + var lspace = 0, rspace = 0, p = this.parent; + if (p && p.type === "mrow" && (p.inferred || !p.isEmbellished())) { + // + // Retrieve the values of lspace/rspace and convert named spaces. + // Other values (except unitless) will be parsed by the CSS engine. + // + var values = this.getValues("lspace", "rspace"); + lspace = values.lspace, rspace = values.rspace; + if (nMML.NAMEDSPACE[lspace]) {lspace = nMML.NAMEDSPACE[lspace]} + if (nMML.NAMEDSPACE[rspace]) {rspace = nMML.NAMEDSPACE[rspace]} + } // // Now update -webkit-margin-start and -webkit-margin-end. From 4ec11da1f19713193138ed550f4a60a233473ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Fri, 2 Aug 2013 09:58:58 +0200 Subject: [PATCH 3/3] Address review comments. --- unpacked/jax/output/NativeMML/jax.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/unpacked/jax/output/NativeMML/jax.js b/unpacked/jax/output/NativeMML/jax.js index f6fa1e5cb..c7504b894 100644 --- a/unpacked/jax/output/NativeMML/jax.js +++ b/unpacked/jax/output/NativeMML/jax.js @@ -1100,18 +1100,15 @@ toNativeMML: function (parent) { this.SUPER(arguments).toNativeMML.call(this,parent); if (nMML.miItalicBug) { - if (this.Get("mathvariant") == "normal") { + if (this.Get("mathvariant") === MML.VARIANT.NORMAL) { // // When not explicitly specified, mathvariant is set to "italic" // with single char mi and to "normal" with multiple char mi. - // Some browsers always set the default to "italic", so modify the - // style when it is supposed to be "normal". + // Some browsers always set the default to "italic", so let's + // attach an explicit mathvariant="normal" attribute. // var mi = parent.lastChild; - var span = HTML.Element("span"); - span.style.cssText = (mi.getAttribute("style")||""); - span.style.fontStyle = "normal"; - mi.setAttribute("style",span.style.cssText); + mi.setAttribute("mathvariant",MML.VARIANT.NORMAL); } } } @@ -1158,7 +1155,7 @@ // Some browsers do not implement the mmultiscripts element. // Try to emulate the support using basic script elements. // - if (!nMML.mmultiscriptsBug || this.data.length == 0 ) { + if (!nMML.mmultiscriptsBug || this.data.length === 0 ) { this.SUPER(arguments).toNativeMML.call(this,parent); return; } @@ -1183,7 +1180,7 @@ // var m = this.data.length, i; for (i = 1; i < m; i+=2) { - if (this.data[i].type == "mprescripts") break; + if (this.data[i].type === "mprescripts") break; var msubsup = this.NativeMMLelement("msubsup"); msubsup.appendChild(base);