Skip to content

Commit 6cba8e3

Browse files
committed
Perform MathJax.Hub.Config before each rendering call, and restore config afterward
1 parent 8d610e7 commit 6cba8e3

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

Diff for: src/fonts/mathjax_config.js

-11
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@
1515
*/
1616
if(typeof MathJax !== 'undefined') {
1717
exports.MathJax = true;
18-
19-
MathJax.Hub.Config({
20-
messageStyle: 'none',
21-
displayAlign: 'left',
22-
tex2jax: {
23-
inlineMath: [['$', '$'], ['\\(', '\\)']]
24-
},
25-
SVG: {font: 'STIX-Web'},
26-
});
27-
28-
MathJax.Hub.Configured();
2918
} else {
3019
exports.MathJax = false;
3120
}

Diff for: src/lib/svg_text_utils.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,21 @@ function cleanEscapesForTex(s) {
165165
function texToSVG(_texString, _config, _callback) {
166166

167167
var originalRenderer,
168+
originalConfig,
168169
tmpDiv;
169-
MathJax.Hub.Queue(function() {
170+
MathJax.Hub.Queue(
171+
function() {
172+
originalConfig = Lib.extendDeepAll({}, MathJax.Hub.config);
173+
return MathJax.Hub.Config({
174+
messageStyle: 'none',
175+
displayAlign: 'left',
176+
tex2jax: {
177+
inlineMath: [['$', '$'], ['\\(', '\\)']]
178+
},
179+
SVG: {font: 'STIX-Web'},
180+
});
181+
},
182+
function() {
170183
// Get original renderer
171184
originalRenderer = MathJax.Hub.config.menuSettings.renderer;
172185
if(originalRenderer !== 'SVG') {
@@ -180,6 +193,7 @@ function texToSVG(_texString, _config, _callback) {
180193
.style({visibility: 'hidden', position: 'absolute'})
181194
.style({'font-size': _config.fontSize + 'px'})
182195
.text(cleanEscapesForTex(_texString));
196+
183197
return MathJax.Hub.Typeset(tmpDiv.node());
184198
},
185199
function() {
@@ -200,6 +214,9 @@ function texToSVG(_texString, _config, _callback) {
200214
if(originalRenderer !== 'SVG') {
201215
return MathJax.Hub.setRenderer(originalRenderer);
202216
}
217+
},
218+
function() {
219+
return MathJax.Hub.Config(originalConfig);
203220
});
204221
}
205222

0 commit comments

Comments
 (0)