Move remapping of <mo> contents to output jax, so that the original MathML is left unchanged

This commit is contained in:
Davide P. Cervone 2012-01-14 16:33:43 -05:00
parent f2170f4c4a
commit 65892262ac
13 changed files with 41 additions and 30 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -145,8 +145,6 @@
if (child.nodeName === "#text") {
if (mml.isToken && !mml.mmlSelfClosing) {
var text = this.trimSpace(child.nodeValue);
if (mml.isa(MML.mo) && text.length === 1 && this.Remap[text.charAt(0)])
{text = this.Remap[text.charAt(0)]}
text = text.replace(/&([a-z][a-z0-9]*);/ig,this.replaceEntity);
mml.Append(MML.chars(text));
} else if (child.nodeValue.match(/\S/)) {
@ -187,16 +185,6 @@
MathJax.Hub.RestartAfter(MathJax.Ajax.Require(MATHML.entityDir+"/"+file+".js"));
}
return match;
},
//
// Characters to remap to better unicode values when they are
// single-character <mo> elements
//
Remap: {
'\u0027': '\u2032', // '
'\u002A': '\u2217', // *
'\u002D': '\u2212' // -
}
}, {
loaded: [] // the entity files that are loaded

View File

@ -1788,8 +1788,9 @@
});
MML.chars.Augment({
toHTML: function (span,variant) {
toHTML: function (span,variant,remap,chars) {
var text = this.data.join("").replace(/[\u2061-\u2064]/g,""); // remove invisibles
if (remap) {text = remap(text,chars)}
if (!variant) {
var scale = Math.floor(100/HTMLCSS.scale+.5) + "%";
HTMLCSS.addElement(span,"span",{style:{"font-size":scale}},[text]);
@ -1858,7 +1859,7 @@
if (values.largeop)
{variant = HTMLCSS.FONTDATA.VARIANT[values.displaystyle ? "-largeOp" : "-smallOp"]}
for (var i = 0, m = this.data.length; i < m; i++)
{if (this.data[i]) {this.data[i].toHTML(span,variant)}}
{if (this.data[i]) {this.data[i].toHTML(span,variant,this.HTMLremap,this.HTMLremapChars)}}
if (!span.bbox) {span.bbox = {w:0, h:0, d:0, rw:0, lw:0}}
if (text.length !== 1) {delete span.bbox.skew}
if (HTMLCSS.AccentBug && span.bbox.w === 0 && text.length === 1 && span.firstChild) {
@ -1889,6 +1890,16 @@
this.HTMLhandleColor(span);
return span;
},
HTMLremapChars: {
'-':"\u2212",
'*':"\u2217",
'"':"\u2033"
},
HTMLremap: function (text,map) {
text = text.replace(/'/g,"\u2032");
if (text.length === 1) {text = map[text]||text}
return text;
},
HTMLcanStretch: function (direction) {
if (!this.Get("stretchy")) {return false}
var c = this.data.join("");

View File

@ -1203,8 +1203,10 @@
});
MML.chars.Augment({
toSVG: function (variant,scale) {
return this.SVGhandleVariant(variant,scale,this.data.join("").replace(/[\u2061-\u2064]/g,"")); // remove invisibles
toSVG: function (variant,scale,remap,chars) {
var text = this.data.join("").replace(/[\u2061-\u2064]/g,""); // remove invisibles
if (remap) {text = remap(text,chars)}
return this.SVGhandleVariant(variant,scale,text);
}
});
MML.entity.Augment({
@ -1224,7 +1226,7 @@
{variant = SVG.FONTDATA.VARIANT[values.displaystyle ? "-largeOp" : "-smallOp"]}
for (var i = 0, m = this.data.length; i < m; i++) {
if (this.data[i]) {
var text = this.data[i].toSVG(variant,scale), x = svg.w;
var text = this.data[i].toSVG(variant,scale,this.SVGremap,this.SVGremapChars), x = svg.w;
if (x === 0 && -text.l > 10*text.w) {x += -text.l} // initial combining character doesn't combine
svg.Add(text,x,0,true);
if (text.skew) {svg.skew = text.skew}
@ -1240,6 +1242,16 @@
this.SVGsaveData(svg);
return svg;
},
SVGremapChars: {
'-':"\u2212",
'*':"\u2217",
'"':"\u2033"
},
SVGremap: function (text,map) {
text = text.replace(/'/g,"\u2032");
if (text.length === 1) {text = map[text]||text}
return text;
},
SVGcanStretch: function (direction) {
if (!this.Get("stretchy")) {return false}
var c = this.data.join("");