Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 699ac11

Browse files
committed
Refactor: support mathjax 2 and 3
1 parent 44206be commit 699ac11

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

runestone/common/js/runestonebase.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ export default class RunestoneBase {
352352
return `${this.constructor.name}: ${this.divid}`
353353
}
354354

355+
queueMathJax(component) {
356+
if (MathJax.version.substring(0, 1) === "2") {
357+
MathJax.Hub.Queue(["Typeset", MathJax.Hub, component]);
358+
} else {
359+
MathJax.typesetPromise([component])
360+
}
361+
}
362+
355363
}
356364

357365
window.RunestoneBase = RunestoneBase;

runestone/fitb/js/fitb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export default class FITB extends RunestoneBase {
338338
}
339339
this.feedBackDiv.innerHTML = feedback_html;
340340
if (typeof MathJax !== "undefined") {
341-
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
341+
this.queueMathJax(document.body)
342342
}
343343
}
344344

runestone/parsons/js/parsons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ export default class Parsons extends RunestoneBase {
591591
this.initializeTabIndex();
592592
if (this.options.language == "natural" || this.options.language == "math") {
593593
if (typeof MathJax !== "undefined") {
594-
MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.outerDiv]);
594+
this.queueMathJax(this.outerDiv)
595595
}
596596
}
597597
}

runestone/shortanswer/js/shortanswer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default class ShortAnswer extends RunestoneBase {
127127
// before MathJax is loaded. In that case we will need to implement something
128128
// like `the solution described here <https://stackoverflow.com/questions/3014018/how-to-detect-when-mathjax-is-fully-loaded>`_
129129
if (typeof MathJax !== "undefined") {
130-
MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.containerDiv]);
130+
this.queueMathJax(this.containerDiv)
131131
}
132132
}
133133

@@ -136,7 +136,7 @@ export default class ShortAnswer extends RunestoneBase {
136136
value = value.replace(/\$\$(.*?)\$\$/g, "\\[ $1 \\]");
137137
value = value.replace(/\$(.*?)\$/g, "\\( $1 \\)");
138138
$(this.renderedAnswer).text(value);
139-
MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.renderedAnswer]);
139+
this.queueMathJax(this.renderedAnswer)
140140
}
141141
}
142142

@@ -286,7 +286,7 @@ $(document).bind("runestone:login-complete", function () {
286286
useRunestoneServices: eBookConfig.useRunestoneServices,
287287
});
288288
} catch (err) {
289-
console.log(`Error rendering ClickableArea Problem ${this.id}
289+
console.log(`Error rendering ShortAnswer Problem ${this.id}
290290
Details: ${err}`);
291291
}
292292
}

0 commit comments

Comments
 (0)