Merge pull request #1526 from dpvc/issue989

Make minus in <mn> produce U+2212 rather than U+002D.  #989
This commit is contained in:
Davide P. Cervone 2016-07-23 15:45:43 -04:00 committed by GitHub
commit 119f050dd3
5 changed files with 67 additions and 6 deletions

View File

@ -190,7 +190,18 @@ MathJax.Extension["MathML/content-mathml"] = (function(HUB) {
*/
appendToken: function(parentNode,name,textContent) {
var element = CToP.createElement(name);
element.appendChild(document.createTextNode(textContent));
if (name === 'mn' && textContent.substr(0,1) === "-") {
//
// use <mrow><mo>&#x2212;</mo><mn>n</mn></mrow> instead of <mn>-n</mn>
//
element.appendChild(document.createTextNode(textContent.substr(1)));
var mrow = CToP.createElement('mrow');
CToP.appendToken(mrow,'mo','\u2212');
mrow.appendChild(element);
element = mrow;
} else {
element.appendChild(document.createTextNode(textContent));
}
parentNode.appendChild(element);
return element;
},

View File

@ -1794,8 +1794,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) {

View File

@ -2244,11 +2244,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);

View File

@ -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));
}
});

View File

@ -1569,6 +1569,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 () {