Skip to content

Commit 813fe8b

Browse files
committed
MBS-9974: update mathjax for moodle 5
1 parent 4d239e6 commit 813fe8b

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

amd/build/helper.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/helper.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/helper.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,24 @@ export const hash = async(stringToHash) => {
119119
* @returns {void}
120120
*/
121121
export const renderMathjax = () => {
122-
// Render formulas with mathjax 2.7.9.
122+
// Render formulas with mathjax v3.
123123
if (typeof window.MathJax !== "undefined") {
124-
// Change delimiters so they work with chatgpt.
125-
window.MathJax.Hub.Config({
126-
tex2jax: {
124+
// Default delimiters now work with mathjax v3, we set it to make sure.
125+
window.MathJax.config = {
126+
tex: {
127127
inlineMath: [['$', '$'], ['\\(', '\\)']],
128128
displayMath: [['$$', '$$'], ['\\[', '\\]']],
129129
},
130-
});
130+
options: {
131+
skipHtmlTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
132+
ignoreHtmlClass: 'tex2jax_ignore',
133+
processHtmlClass: 'tex2jax_process'
134+
}
135+
};
131136
const content = document.querySelector('.block_ai_chat-output');
132137
if (content) {
133-
// Maybe somebody knows why it works if you use mathjax .Queue and typeset().
134-
// I just know that it does.
135-
// Claude says: This works because you're essentially giving MathJax two chances to render - the first call
136-
// queues it up, and the second call (Moodle's built-in function) ensures it completes. While it might seem
137-
// redundant, if it's working reliably, there's nothing wrong with this approach.
138-
window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub, content]);
139-
typeset(content);
138+
// Rendering content.
139+
window.MathJax.typesetPromise([content]);
140140
}
141141
}
142142
};

0 commit comments

Comments
 (0)