Skip to content

Commit 9493f95

Browse files
committed
Fix the issue with MathJax rendering when certain fonts are used.
See issue #2955 for details. This is just the code suggested by @dpvc in that issue.
1 parent 7b6ae48 commit 9493f95

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

htdocs/js/MathJaxConfig/mathjax-config.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,32 @@ if (!window.MathJax) {
101101
AM.symbols.splice(i, 0, { input: trigger, ...newTriggers[trigger].symbols });
102102
}
103103

104-
return MathJax.startup.defaultReady();
104+
MathJax.startup.defaultReady();
105+
MathJax.startup.document.constructor.ProcessBits.allocate('findScripts');
105106
}
106107
},
107108
options: {
108109
renderActions: {
109110
findScript: [
110111
10,
111112
(doc) => {
112-
for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
113-
const math = new doc.options.MathItem(
114-
node.textContent,
115-
doc.inputJax[0],
116-
!!node.type.match(/; *mode=display/)
117-
);
118-
const text = document.createTextNode('');
119-
node.parentNode.replaceChild(text, node);
120-
math.start = { node: text, delim: '', n: 0 };
121-
math.end = { node: text, delim: '', n: 0 };
122-
doc.math.push(math);
113+
if (doc.processed.isSet('findScripts')) return;
114+
const containers = doc.adaptor.getElements(doc.options.elements || [doc.document.body], doc);
115+
for (const container of containers) {
116+
for (const node of container.querySelectorAll('script[type^="math/tex"]')) {
117+
const math = new doc.options.MathItem(
118+
node.textContent,
119+
doc.inputJax[0],
120+
!!node.type.match(/; *mode=display/)
121+
);
122+
const text = document.createTextNode('');
123+
node.parentNode.replaceChild(text, node);
124+
math.start = { node: text, delim: '', n: 0 };
125+
math.end = { node: text, delim: '', n: 0 };
126+
doc.math.push(math);
127+
}
123128
}
129+
doc.processed.set('findScripts');
124130
},
125131
''
126132
]

0 commit comments

Comments
 (0)