Skip to content

Commit a259bcb

Browse files
committed
Merge pull request #634 from fred-wang/bidi
Implement bidi on MathML token elements and fix incorrect rendering of RTL error messages
2 parents 4400d42 + 28afef1 commit a259bcb

File tree

9 files changed

+49
-18
lines changed

9 files changed

+49
-18
lines changed

unpacked/jax/element/mml/jax.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,19 @@ MathJax.ElementJax.mml.Augment({
223223
"fontfamily", "fontsize", "fontweight", "fontstyle",
224224
"color", "background",
225225
"id", "class", "href", "style"
226-
]
226+
],
227+
Error: function (message,def) {
228+
var mml = this.merror(message),
229+
dir = MathJax.Localization.fontDirection(),
230+
font = MathJax.Localization.fontFamily();
231+
if (def) {mml = mml.With(def)}
232+
if (dir || font) {
233+
mml = this.mstyle(mml);
234+
if (dir) {mml.dir = dir}
235+
if (font) {mml.style.fontFamily = "font-family: "+font}
236+
}
237+
return mml;
238+
}
227239
});
228240

229241
(function (MML) {
@@ -232,7 +244,8 @@ MathJax.ElementJax.mml.Augment({
232244
type: "base", isToken: false,
233245
defaults: {
234246
mathbackground: MML.INHERIT,
235-
mathcolor: MML.INHERIT
247+
mathcolor: MML.INHERIT,
248+
dir: MML.INHERIT,
236249
},
237250
noInherit: {},
238251
noInheritAttribute: {
@@ -428,7 +441,8 @@ MathJax.ElementJax.mml.Augment({
428441
mathvariant: MML.AUTO,
429442
mathsize: MML.INHERIT,
430443
mathbackground: MML.INHERIT,
431-
mathcolor: MML.INHERIT
444+
mathcolor: MML.INHERIT,
445+
dir: MML.INHERIT
432446
},
433447
autoDefault: function (name) {
434448
if (name === "mathvariant") {
@@ -458,7 +472,8 @@ MathJax.ElementJax.mml.Augment({
458472
mathvariant: MML.INHERIT,
459473
mathsize: MML.INHERIT,
460474
mathbackground: MML.INHERIT,
461-
mathcolor: MML.INHERIT
475+
mathcolor: MML.INHERIT,
476+
dir: MML.INHERIT
462477
}
463478
});
464479

@@ -469,6 +484,7 @@ MathJax.ElementJax.mml.Augment({
469484
mathsize: MML.INHERIT,
470485
mathbackground: MML.INHERIT,
471486
mathcolor: MML.INHERIT,
487+
dir: MML.INHERIT,
472488
form: MML.AUTO,
473489
fence: MML.AUTO,
474490
separator: MML.AUTO,
@@ -630,7 +646,8 @@ MathJax.ElementJax.mml.Augment({
630646
mathvariant: MML.INHERIT,
631647
mathsize: MML.INHERIT,
632648
mathbackground: MML.INHERIT,
633-
mathcolor: MML.INHERIT
649+
mathcolor: MML.INHERIT,
650+
dir: MML.INHERIT
634651
}
635652
});
636653

@@ -665,6 +682,7 @@ MathJax.ElementJax.mml.Augment({
665682
mathsize: MML.INHERIT,
666683
mathbackground: MML.INHERIT,
667684
mathcolor: MML.INHERIT,
685+
dir: MML.INHERIT,
668686
lquote: '"',
669687
rquote: '"'
670688
}
@@ -810,6 +828,7 @@ MathJax.ElementJax.mml.Augment({
810828
scriptminsize: "8pt",
811829
mathbackground: MML.INHERIT,
812830
mathcolor: MML.INHERIT,
831+
dir: MML.INHERIT,
813832
infixlinebreakstyle: MML.LINEBREAKSTYLE.BEFORE,
814833
decimalseparator: "."
815834
},
@@ -1226,6 +1245,7 @@ MathJax.ElementJax.mml.Augment({
12261245
mathsize: MML.SIZE.NORMAL,
12271246
mathcolor: "", // should be "black", but allow it to inherit from surrounding text
12281247
mathbackground: MML.COLOR.TRANSPARENT,
1248+
dir: "ltr",
12291249
scriptlevel: 0,
12301250
displaystyle: MML.AUTO,
12311251
display: "inline",

unpacked/jax/input/AsciiMath/jax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ junk = null;
12921292
formatError: function (err,math,script) {
12931293
var message = err.message.replace(/\n.*/,"");
12941294
MathJax.Hub.signal.Post(["AsciiMath Jax - parse error",message,math,script]);
1295-
return MML.merror(message);
1295+
return MML.Error(message);
12961296
},
12971297
Error: function (message) {
12981298
throw MathJax.Hub.Insert(Error(message),{asciimathError: true});

unpacked/jax/input/MathML/jax.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
mml = this.TeXAtom(match[2]);
7878
} else if (!(MML[type] && MML[type].isa && MML[type].isa(MML.mbase))) {
7979
MathJax.Hub.signal.Post(["MathML Jax - unknown node type",type]);
80-
return MML.merror(_("UnknownNodeType","Unknown node type: %1",type));
80+
return MML.Error(_("UnknownNodeType","Unknown node type: %1",type));
8181
} else {
8282
mml = MML[type]();
8383
}
@@ -267,7 +267,7 @@
267267
formatError: function (err,math,script) {
268268
var message = err.message.replace(/\n.*/,"");
269269
MathJax.Hub.signal.Post(["MathML Jax - parse error",message,math,script]);
270-
return MML.merror(message);
270+
return MML.Error(message);
271271
},
272272
Error: function (message) {
273273
//

unpacked/jax/input/TeX/jax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,7 @@
20992099
formatError: function (err,math,display,script) {
21002100
var message = err.message.replace(/\n.*/,"");
21012101
HUB.signal.Post(["TeX Jax - parse error",message,math,display,script]);
2102-
return MML.merror(message);
2102+
return MML.Error(message);
21032103
},
21042104

21052105
//

unpacked/jax/output/HTML-CSS/autoload/mglyph.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
4545
} else {
4646
if (values.alt === "")
4747
{values.alt = LOCALE._(["MathML","BadMglyphFont"],"Bad font: %1",font.family)}
48-
err = MML.merror(values.alt).With({mathsize:"75%"});
48+
err = MML.Error(values.alt,{mathsize:"75%"});
4949
this.Append(err); err.toHTML(span); this.data.pop();
5050
span.bbox = err.HTMLspanElement().bbox;
5151
}
@@ -62,9 +62,9 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
6262
MathJax.Hub.RestartAfter(img.onload);
6363
}
6464
if (this.img.status !== "OK") {
65-
err = MML.merror(
66-
LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src)
67-
).With({mathsize:"75%"});
65+
err = MML.Error(
66+
LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src),
67+
{mathsize:"75%"});
6868
this.Append(err); err.toHTML(span); this.data.pop();
6969
span.bbox = err.HTMLspanElement().bbox;
7070
} else {

unpacked/jax/output/HTML-CSS/autoload/ms.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
4141
this.HTMLhandleVariant(span,this.HTMLgetVariant(),values.lquote+text+values.rquote);
4242
this.HTMLhandleSpace(span);
4343
this.HTMLhandleColor(span);
44+
this.HTMLhandleDir(span);
4445
return span;
4546
},
4647
HTMLquoteRegExp: function (string) {

unpacked/jax/output/HTML-CSS/jax.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,12 @@
17231723
return span;
17241724
},
17251725

1726+
HTMLhandleDir: function (span) {
1727+
var dir = this.Get("dir",true); // only get value if not the default
1728+
if (dir) {span.dir = dir}
1729+
return span;
1730+
},
1731+
17261732
HTMLhandleColor: function (span) {
17271733
var values = this.getValues("mathcolor","color");
17281734
if (this.mathbackground) {values.mathbackground = this.mathbackground}
@@ -1973,6 +1979,7 @@
19731979
}
19741980
this.HTMLhandleSpace(span);
19751981
this.HTMLhandleColor(span);
1982+
this.HTMLhandleDir(span);
19761983
return span;
19771984
}
19781985
});
@@ -1987,6 +1994,7 @@
19871994
if (this.data.join("").length !== 1) {delete span.bbox.skew}
19881995
this.HTMLhandleSpace(span);
19891996
this.HTMLhandleColor(span);
1997+
this.HTMLhandleDir(span);
19901998
return span;
19911999
}
19922000
});
@@ -2061,6 +2069,7 @@
20612069
//
20622070
this.HTMLhandleSpace(span);
20632071
this.HTMLhandleColor(span);
2072+
this.HTMLhandleDir(span);
20642073
return span;
20652074
},
20662075
CoreParent: function () {
@@ -2157,6 +2166,7 @@
21572166
if (this.data.join("").length !== 1) {delete span.bbox.skew}
21582167
this.HTMLhandleSpace(span);
21592168
this.HTMLhandleColor(span);
2169+
this.HTMLhandleDir(span);
21602170
return span;
21612171
}
21622172
});

unpacked/jax/output/SVG/autoload/mglyph.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
7474
MathJax.Hub.RestartAfter(img.onload);
7575
}
7676
if (this.img.status !== "OK") {
77-
err = MML.merror(
78-
LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src)
79-
).With({mathsize:"75%"});
77+
err = MML.Error(
78+
LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src),
79+
{mathsize:"75%"});
8080
this.Append(err); svg = err.toSVG(); this.data.pop();
8181
} else {
8282
var mu = this.SVGgetMu(svg);

unpacked/jax/output/SVG/jax.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,15 +1465,15 @@
14651465
if (this.Parent().type === "merror") {
14661466
// *** FIXME: Make color, style, scale configurable
14671467
svg = this.SVG(); this.SVGhandleSpace(svg);
1468-
text = BBOX.G(); text.Add(BBOX.TEXT(.9*scale,this.data.join(""),{fill:"#C00"}));
1468+
text = BBOX.G(); text.Add(BBOX.TEXT(.9*scale,this.data.join(""),{fill:"#C00",direction:this.Get("dir")}));
14691469
svg.Add(BBOX.RECT(text.h+100,text.d+100,text.w+200,{fill:"#FF8",stroke:"#C00","stroke-width":50}),0,0);
14701470
svg.Add(text,150,0); svg.H += 150; svg.D += 50;
14711471
svg.Clean();
14721472
this.SVGsaveData(svg);
14731473
return svg;
14741474
} else if (SVG.config.mtextFontInherit) {
14751475
svg = this.SVG(); this.SVGhandleSpace(svg);
1476-
var variant = this.SVGgetVariant(), def = {};
1476+
var variant = this.SVGgetVariant(), def = {direction:this.Get("dir")};
14771477
if (variant.bold) {def["font-weight"] = "bold"}
14781478
if (variant.italic) {def["font-style"] = "italic"}
14791479
svg.Add(BBOX.TEXT(scale,this.data.join(""),def)); svg.Clean();

0 commit comments

Comments
 (0)