From 3d36b7a4bab0af2a53c96cad1fd09a9d0765c7f4 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Tue, 14 Jun 2016 20:00:10 -0400 Subject: [PATCH] Make minus in produce U+2212 rather than U+002D. Resolves issue #989. --- unpacked/jax/output/CommonHTML/jax.js | 3 ++- unpacked/jax/output/HTML-CSS/jax.js | 10 ++++++++-- unpacked/jax/output/NativeMML/jax.js | 22 ++++++++++++++++++++-- unpacked/jax/output/SVG/jax.js | 25 +++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/unpacked/jax/output/CommonHTML/jax.js b/unpacked/jax/output/CommonHTML/jax.js index 0b48f9ae2..9e6a3f9b4 100644 --- a/unpacked/jax/output/CommonHTML/jax.js +++ b/unpacked/jax/output/CommonHTML/jax.js @@ -1785,8 +1785,9 @@ /********************************************************/ MML.mn.Augment({ + CHTMLremapMinus: function (text) {return text.replace(/^-/,"\u2212")}, toCommonHTML: function (node) { - node = this.CHTMLdefaultNode(node); + node = this.CHTMLdefaultNode(node,{childOptions:{remap:this.CHTMLremapMinus}}); var bbox = this.CHTML, text = this.data.join(""); if (bbox.skew != null && text.length !== 1) delete bbox.skew; if (bbox.r > bbox.w && text.length === 1 && !this.CHTMLvariant.noIC) { diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index 8dad7d6aa..87fdc796a 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -2239,11 +2239,17 @@ }); MML.mn.Augment({ + HTMLremapMinus: function (text) {return text.replace(/^-/,"\u2212")}, toHTML: function (span) { span = this.HTMLhandleSize(this.HTMLcreateSpan(span)); span.bbox = null; var variant = this.HTMLgetVariant(); - for (var i = 0, m = this.data.length; i < m; i++) - {if (this.data[i]) {this.data[i].toHTML(span,variant)}} + var remap = this.HTMLremapMinus; + for (var i = 0, m = this.data.length; i < m; i++) { + if (this.data[i]) { + this.data[i].toHTML(span,variant,remap); + remap = null; + } + } if (!span.bbox) {span.bbox = this.HTMLzeroBBox()} if (this.data.join("").length !== 1) {delete span.bbox.skew} this.HTMLhandleSpace(span); diff --git a/unpacked/jax/output/NativeMML/jax.js b/unpacked/jax/output/NativeMML/jax.js index c7c436587..6936f2e98 100644 --- a/unpacked/jax/output/NativeMML/jax.js +++ b/unpacked/jax/output/NativeMML/jax.js @@ -890,6 +890,22 @@ } } }); + + MML.mn.Augment({ + NativeMMLremapMinus: function (text) {return text.replace(/^-/,"\u2212")}, + toNativeMML: function (parent) { + var tag = this.NativeMMLelement(this.type); + this.NativeMMLattributes(tag); + var remap = this.NativeMMLremapMinus; + for (var i = 0, m = this.data.length; i < m; i++) { + if (this.data[i]) { + this.data[i].toNativeMML(tag,remap); + remap = null; + } + } + parent.appendChild(tag); + } + }); var fontDir = AJAX.fileURL(MathJax.OutputJax.fontDir+"/HTML-CSS/TeX/otf"); @@ -1179,8 +1195,10 @@ // // Add a text node // - toNativeMML: function (parent) { - parent.appendChild(document.createTextNode(this.toString())); + toNativeMML: function (parent,remap) { + var text = this.toString(); + if (remap) text = remap(text); + parent.appendChild(document.createTextNode(text)); } }); diff --git a/unpacked/jax/output/SVG/jax.js b/unpacked/jax/output/SVG/jax.js index d6b7f4274..e956d687b 100644 --- a/unpacked/jax/output/SVG/jax.js +++ b/unpacked/jax/output/SVG/jax.js @@ -1566,6 +1566,31 @@ return svg; } }); + + MML.mn.Augment({ + SVGremapMinus: function (text) {return text.replace(/^-/,"\u2212")}, + toSVG: function () { + this.SVGgetStyles(); + var variant = this.SVGgetVariant(); + var svg = this.SVG(); this.SVGgetScale(svg); + this.SVGhandleSpace(svg); + var remap = this.SVGremapMinus; + for (var i = 0, m = this.data.length; i < m; i++) { + if (this.data[i]) { + var child = svg.Add(this.data[i].toSVG(variant,svg.scale,remap),svg.w,0,true); + if (child.skew) {svg.skew = child.skew} + remap = null; + } + } + svg.Clean(); var text = this.data.join(""); + if (svg.skew && text.length !== 1) {delete svg.skew} + if (svg.r > svg.w && text.length === 1 && !variant.noIC) + {svg.ic = svg.r - svg.w; svg.w = svg.r} + this.SVGhandleColor(svg); + this.SVGsaveData(svg); + return svg; + }, + }), MML.mtext.Augment({ toSVG: function () {