From dbe594872f9b3ad73cdde80a2dabe1ffd18a7d18 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Fri, 3 Apr 2015 15:50:48 -0400 Subject: [PATCH] Avoid infinite loop when \mathchoice is used in munderover. Resolves issue #1151. --- unpacked/extensions/TeX/mathchoice.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/unpacked/extensions/TeX/mathchoice.js b/unpacked/extensions/TeX/mathchoice.js index eae6dc031..54b8bbd6c 100644 --- a/unpacked/extensions/TeX/mathchoice.js +++ b/unpacked/extensions/TeX/mathchoice.js @@ -45,10 +45,17 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { MML.TeXmathchoice = MML.mbase.Subclass({ type: "TeXmathchoice", notParent: true, - choice: function (nocache) { + choice: function () { + if (this.selection != null) return this.selection; + if (this.choosing) return 2; // prevent infinite loops: see issue #1151 + this.choosing = true; var selection = 0, values = this.getValues("displaystyle","scriptlevel"); if (values.scriptlevel > 0) {selection = Math.min(3,values.scriptlevel+1)} else {selection = (values.displaystyle ? 0 : 1)} + // only cache the result if we are actually in place in a tag. + var node = this.inherit; while (node && node.type !== "math") node = node.inherit; + if (node) this.selection = selection; + this.choosing = false; return selection; }, selected: function () {return this.data[this.choice()]},