@@ -119,24 +119,24 @@ export const hash = async(stringToHash) => {
119
119
* @returns {void }
120
120
*/
121
121
export const renderMathjax = ( ) => {
122
- // Render formulas with mathjax 2.7.9 .
122
+ // Render formulas with mathjax v3 .
123
123
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 : {
127
127
inlineMath : [ [ '$' , '$' ] , [ '\\(' , '\\)' ] ] ,
128
128
displayMath : [ [ '$$' , '$$' ] , [ '\\[' , '\\]' ] ] ,
129
129
} ,
130
- } ) ;
130
+ options : {
131
+ skipHtmlTags : [ 'script' , 'noscript' , 'style' , 'textarea' , 'pre' , 'code' ] ,
132
+ ignoreHtmlClass : 'tex2jax_ignore' ,
133
+ processHtmlClass : 'tex2jax_process'
134
+ }
135
+ } ;
131
136
const content = document . querySelector ( '.block_ai_chat-output' ) ;
132
137
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 ] ) ;
140
140
}
141
141
}
142
142
} ;
0 commit comments