commit a259bcba88656e7824023210d3f992c4fe540df4
parent 4400d42d5777552023fd28d6abb540f5d58ff42d
Author: Frédéric Wang <fred.wang@free.fr>
Date: Mon, 21 Oct 2013 04:49:55 -0700
Merge pull request #634 from fred-wang/bidi
Implement bidi on MathML token elements and fix incorrect rendering of RTL error messages
Diffstat:
9 files changed, 49 insertions(+), 18 deletions(-)
diff --git a/unpacked/jax/element/mml/jax.js b/unpacked/jax/element/mml/jax.js
@@ -223,7 +223,19 @@ MathJax.ElementJax.mml.Augment({
"fontfamily", "fontsize", "fontweight", "fontstyle",
"color", "background",
"id", "class", "href", "style"
- ]
+ ],
+ Error: function (message,def) {
+ var mml = this.merror(message),
+ dir = MathJax.Localization.fontDirection(),
+ font = MathJax.Localization.fontFamily();
+ if (def) {mml = mml.With(def)}
+ if (dir || font) {
+ mml = this.mstyle(mml);
+ if (dir) {mml.dir = dir}
+ if (font) {mml.style.fontFamily = "font-family: "+font}
+ }
+ return mml;
+ }
});
(function (MML) {
@@ -232,7 +244,8 @@ MathJax.ElementJax.mml.Augment({
type: "base", isToken: false,
defaults: {
mathbackground: MML.INHERIT,
- mathcolor: MML.INHERIT
+ mathcolor: MML.INHERIT,
+ dir: MML.INHERIT,
},
noInherit: {},
noInheritAttribute: {
@@ -428,7 +441,8 @@ MathJax.ElementJax.mml.Augment({
mathvariant: MML.AUTO,
mathsize: MML.INHERIT,
mathbackground: MML.INHERIT,
- mathcolor: MML.INHERIT
+ mathcolor: MML.INHERIT,
+ dir: MML.INHERIT
},
autoDefault: function (name) {
if (name === "mathvariant") {
@@ -458,7 +472,8 @@ MathJax.ElementJax.mml.Augment({
mathvariant: MML.INHERIT,
mathsize: MML.INHERIT,
mathbackground: MML.INHERIT,
- mathcolor: MML.INHERIT
+ mathcolor: MML.INHERIT,
+ dir: MML.INHERIT
}
});
@@ -469,6 +484,7 @@ MathJax.ElementJax.mml.Augment({
mathsize: MML.INHERIT,
mathbackground: MML.INHERIT,
mathcolor: MML.INHERIT,
+ dir: MML.INHERIT,
form: MML.AUTO,
fence: MML.AUTO,
separator: MML.AUTO,
@@ -630,7 +646,8 @@ MathJax.ElementJax.mml.Augment({
mathvariant: MML.INHERIT,
mathsize: MML.INHERIT,
mathbackground: MML.INHERIT,
- mathcolor: MML.INHERIT
+ mathcolor: MML.INHERIT,
+ dir: MML.INHERIT
}
});
@@ -665,6 +682,7 @@ MathJax.ElementJax.mml.Augment({
mathsize: MML.INHERIT,
mathbackground: MML.INHERIT,
mathcolor: MML.INHERIT,
+ dir: MML.INHERIT,
lquote: '"',
rquote: '"'
}
@@ -810,6 +828,7 @@ MathJax.ElementJax.mml.Augment({
scriptminsize: "8pt",
mathbackground: MML.INHERIT,
mathcolor: MML.INHERIT,
+ dir: MML.INHERIT,
infixlinebreakstyle: MML.LINEBREAKSTYLE.BEFORE,
decimalseparator: "."
},
@@ -1226,6 +1245,7 @@ MathJax.ElementJax.mml.Augment({
mathsize: MML.SIZE.NORMAL,
mathcolor: "", // should be "black", but allow it to inherit from surrounding text
mathbackground: MML.COLOR.TRANSPARENT,
+ dir: "ltr",
scriptlevel: 0,
displaystyle: MML.AUTO,
display: "inline",
diff --git a/unpacked/jax/input/AsciiMath/jax.js b/unpacked/jax/input/AsciiMath/jax.js
@@ -1292,7 +1292,7 @@ junk = null;
formatError: function (err,math,script) {
var message = err.message.replace(/\n.*/,"");
MathJax.Hub.signal.Post(["AsciiMath Jax - parse error",message,math,script]);
- return MML.merror(message);
+ return MML.Error(message);
},
Error: function (message) {
throw MathJax.Hub.Insert(Error(message),{asciimathError: true});
diff --git a/unpacked/jax/input/MathML/jax.js b/unpacked/jax/input/MathML/jax.js
@@ -77,7 +77,7 @@
mml = this.TeXAtom(match[2]);
} else if (!(MML[type] && MML[type].isa && MML[type].isa(MML.mbase))) {
MathJax.Hub.signal.Post(["MathML Jax - unknown node type",type]);
- return MML.merror(_("UnknownNodeType","Unknown node type: %1",type));
+ return MML.Error(_("UnknownNodeType","Unknown node type: %1",type));
} else {
mml = MML[type]();
}
@@ -267,7 +267,7 @@
formatError: function (err,math,script) {
var message = err.message.replace(/\n.*/,"");
MathJax.Hub.signal.Post(["MathML Jax - parse error",message,math,script]);
- return MML.merror(message);
+ return MML.Error(message);
},
Error: function (message) {
//
diff --git a/unpacked/jax/input/TeX/jax.js b/unpacked/jax/input/TeX/jax.js
@@ -2099,7 +2099,7 @@
formatError: function (err,math,display,script) {
var message = err.message.replace(/\n.*/,"");
HUB.signal.Post(["TeX Jax - parse error",message,math,display,script]);
- return MML.merror(message);
+ return MML.Error(message);
},
//
diff --git a/unpacked/jax/output/HTML-CSS/autoload/mglyph.js b/unpacked/jax/output/HTML-CSS/autoload/mglyph.js
@@ -45,7 +45,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
} else {
if (values.alt === "")
{values.alt = LOCALE._(["MathML","BadMglyphFont"],"Bad font: %1",font.family)}
- err = MML.merror(values.alt).With({mathsize:"75%"});
+ err = MML.Error(values.alt,{mathsize:"75%"});
this.Append(err); err.toHTML(span); this.data.pop();
span.bbox = err.HTMLspanElement().bbox;
}
@@ -62,9 +62,9 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
MathJax.Hub.RestartAfter(img.onload);
}
if (this.img.status !== "OK") {
- err = MML.merror(
- LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src)
- ).With({mathsize:"75%"});
+ err = MML.Error(
+ LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src),
+ {mathsize:"75%"});
this.Append(err); err.toHTML(span); this.data.pop();
span.bbox = err.HTMLspanElement().bbox;
} else {
diff --git a/unpacked/jax/output/HTML-CSS/autoload/ms.js b/unpacked/jax/output/HTML-CSS/autoload/ms.js
@@ -41,6 +41,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
this.HTMLhandleVariant(span,this.HTMLgetVariant(),values.lquote+text+values.rquote);
this.HTMLhandleSpace(span);
this.HTMLhandleColor(span);
+ this.HTMLhandleDir(span);
return span;
},
HTMLquoteRegExp: function (string) {
diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js
@@ -1723,6 +1723,12 @@
return span;
},
+ HTMLhandleDir: function (span) {
+ var dir = this.Get("dir",true); // only get value if not the default
+ if (dir) {span.dir = dir}
+ return span;
+ },
+
HTMLhandleColor: function (span) {
var values = this.getValues("mathcolor","color");
if (this.mathbackground) {values.mathbackground = this.mathbackground}
@@ -1973,6 +1979,7 @@
}
this.HTMLhandleSpace(span);
this.HTMLhandleColor(span);
+ this.HTMLhandleDir(span);
return span;
}
});
@@ -1987,6 +1994,7 @@
if (this.data.join("").length !== 1) {delete span.bbox.skew}
this.HTMLhandleSpace(span);
this.HTMLhandleColor(span);
+ this.HTMLhandleDir(span);
return span;
}
});
@@ -2061,6 +2069,7 @@
//
this.HTMLhandleSpace(span);
this.HTMLhandleColor(span);
+ this.HTMLhandleDir(span);
return span;
},
CoreParent: function () {
@@ -2157,6 +2166,7 @@
if (this.data.join("").length !== 1) {delete span.bbox.skew}
this.HTMLhandleSpace(span);
this.HTMLhandleColor(span);
+ this.HTMLhandleDir(span);
return span;
}
});
diff --git a/unpacked/jax/output/SVG/autoload/mglyph.js b/unpacked/jax/output/SVG/autoload/mglyph.js
@@ -74,9 +74,9 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
MathJax.Hub.RestartAfter(img.onload);
}
if (this.img.status !== "OK") {
- err = MML.merror(
- LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src)
- ).With({mathsize:"75%"});
+ err = MML.Error(
+ LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src),
+ {mathsize:"75%"});
this.Append(err); svg = err.toSVG(); this.data.pop();
} else {
var mu = this.SVGgetMu(svg);
diff --git a/unpacked/jax/output/SVG/jax.js b/unpacked/jax/output/SVG/jax.js
@@ -1465,7 +1465,7 @@
if (this.Parent().type === "merror") {
// *** FIXME: Make color, style, scale configurable
svg = this.SVG(); this.SVGhandleSpace(svg);
- text = BBOX.G(); text.Add(BBOX.TEXT(.9*scale,this.data.join(""),{fill:"#C00"}));
+ text = BBOX.G(); text.Add(BBOX.TEXT(.9*scale,this.data.join(""),{fill:"#C00",direction:this.Get("dir")}));
svg.Add(BBOX.RECT(text.h+100,text.d+100,text.w+200,{fill:"#FF8",stroke:"#C00","stroke-width":50}),0,0);
svg.Add(text,150,0); svg.H += 150; svg.D += 50;
svg.Clean();
@@ -1473,7 +1473,7 @@
return svg;
} else if (SVG.config.mtextFontInherit) {
svg = this.SVG(); this.SVGhandleSpace(svg);
- var variant = this.SVGgetVariant(), def = {};
+ var variant = this.SVGgetVariant(), def = {direction:this.Get("dir")};
if (variant.bold) {def["font-weight"] = "bold"}
if (variant.italic) {def["font-style"] = "italic"}
svg.Add(BBOX.TEXT(scale,this.data.join(""),def)); svg.Clean();