Skip to content

Commit dbe5948

Browse files
committed
Avoid infinite loop when \mathchoice is used in munderover. Resolves issue #1151.
1 parent 48b594a commit dbe5948

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

unpacked/extensions/TeX/mathchoice.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,17 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
4545

4646
MML.TeXmathchoice = MML.mbase.Subclass({
4747
type: "TeXmathchoice", notParent: true,
48-
choice: function (nocache) {
48+
choice: function () {
49+
if (this.selection != null) return this.selection;
50+
if (this.choosing) return 2; // prevent infinite loops: see issue #1151
51+
this.choosing = true;
4952
var selection = 0, values = this.getValues("displaystyle","scriptlevel");
5053
if (values.scriptlevel > 0) {selection = Math.min(3,values.scriptlevel+1)}
5154
else {selection = (values.displaystyle ? 0 : 1)}
55+
// only cache the result if we are actually in place in a <math> tag.
56+
var node = this.inherit; while (node && node.type !== "math") node = node.inherit;
57+
if (node) this.selection = selection;
58+
this.choosing = false;
5259
return selection;
5360
},
5461
selected: function () {return this.data[this.choice()]},

0 commit comments

Comments
 (0)