Skip to content

Commit 7be4e73

Browse files
committed
set and reset inline mathjax config
1 parent 04d8005 commit 7be4e73

File tree

4 files changed

+41
-37
lines changed

4 files changed

+41
-37
lines changed

devtools/test_dashboard/index-mathjax3.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@
2020
</div>
2121
<div id="snapshot"></div>
2222

23-
<script>
24-
window.MathJax = window.MathJax || {
25-
tex: {
26-
inlineMath: [['$', '$'], ['\\(', '\\)']]
27-
}
28-
};
29-
</script>
3023
<script src="../../node_modules/mathjax-v3/es5/tex-mml-svg.js"></script>
3124
<script charset="utf-8" id="source" type="module">import "../../build/plotly.js"</script>
3225
<script charset="utf-8" src="../../build/test_dashboard-bundle.js"></script>

devtools/test_dashboard/index-mathjax3chtml.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
<script>
2525
window.MathJax = window.MathJax || {
26+
loader: {load: ['output/svg']},
2627
startup: {
2728
ready() {
2829
//
@@ -56,10 +57,6 @@
5657
};
5758
MathJax.svgStylesheet = () => svgOutput.styleSheet(svgDocument);
5859
}
59-
},
60-
loader: {load: ["output/svg"]},
61-
tex: {
62-
inlineMath: [["\\(", "\\)"], ["$", "$"]],
6360
}
6461
};
6562
</script>

src/lib/svg_text_utils.js

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ function cleanEscapesForTex(s) {
173173
.replace(GT_MATCH, '\\gt ');
174174
}
175175

176+
var inlineMath = [['$', '$'], ['\\(', '\\)']];
177+
176178
function texToSVG(_texString, _config, _callback) {
177179
var MathJaxVersion = parseInt(
178180
(MathJax.version || '').split('.')[0]
@@ -184,25 +186,33 @@ function texToSVG(_texString, _config, _callback) {
184186

185187
var originalRenderer,
186188
originalConfig,
189+
originalConfigTex,
187190
originalProcessSectionDelay,
188191
tmpDiv;
189192

190-
var v2SetConfig = function() {
191-
originalConfig = Lib.extendDeepAll({}, MathJax.Hub.config);
193+
var setConfig = function() {
194+
if(MathJaxVersion < 3) {
195+
originalConfig = Lib.extendDeepAll({}, MathJax.Hub.config);
192196

193-
originalProcessSectionDelay = MathJax.Hub.processSectionDelay;
194-
if(MathJax.Hub.processSectionDelay !== undefined) {
195-
// MathJax 2.5+ but not 3+
196-
MathJax.Hub.processSectionDelay = 0;
197-
}
197+
originalProcessSectionDelay = MathJax.Hub.processSectionDelay;
198+
if(MathJax.Hub.processSectionDelay !== undefined) {
199+
// MathJax 2.5+ but not 3+
200+
MathJax.Hub.processSectionDelay = 0;
201+
}
198202

199-
return MathJax.Hub.Config({
200-
messageStyle: 'none',
201-
tex2jax: {
202-
inlineMath: [['$', '$'], ['\\(', '\\)']]
203-
},
204-
displayAlign: 'left',
205-
});
203+
return MathJax.Hub.Config({
204+
messageStyle: 'none',
205+
tex2jax: {
206+
inlineMath: inlineMath
207+
},
208+
displayAlign: 'left',
209+
});
210+
} else {
211+
if(MathJax.config.tex) {
212+
originalConfigTex = Lib.extendDeepAll({}, MathJax.config.tex);
213+
MathJax.config.tex.inlineMath = inlineMath;
214+
}
215+
}
206216
};
207217

208218
var setRenderer = function() {
@@ -268,30 +278,40 @@ function texToSVG(_texString, _config, _callback) {
268278
}
269279
};
270280

271-
var v2ResetConfig = function() {
272-
if(originalProcessSectionDelay !== undefined) {
273-
MathJax.Hub.processSectionDelay = originalProcessSectionDelay;
281+
var resetConfig = function() {
282+
if(MathJaxVersion < 3) {
283+
if(originalProcessSectionDelay !== undefined) {
284+
MathJax.Hub.processSectionDelay = originalProcessSectionDelay;
285+
}
286+
return MathJax.Hub.Config(originalConfig);
287+
} else {
288+
if(originalConfigTex) {
289+
MathJax.config.tex.inlineMath = originalConfigTex.inlineMath;
290+
} else {
291+
MathJax.config.tex = undefined;
292+
}
274293
}
275-
return MathJax.Hub.Config(originalConfig);
276294
};
277295

278296
if(MathJaxVersion < 3) {
279297
MathJax.Hub.Queue(
280-
v2SetConfig,
298+
setConfig,
281299
setRenderer,
282300
initiateMathJax,
283301
finalizeMathJax,
284302
resetRenderer,
285-
v2ResetConfig
303+
resetConfig
286304
);
287305
} else {
306+
setConfig();
288307
setRenderer();
289308
MathJax.startup.defaultReady();
290309
MathJax.startup.promise.then(function() {
291310
initiateMathJax();
292311
finalizeMathJax();
293312
});
294313
resetRenderer();
314+
resetConfig();
295315
}
296316
}
297317

test/jasmine/bundle_tests/mathjax_v3_test.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ describe('Test MathJax v3:', function() {
2323
mathJaxScriptTag.onerror = function() {
2424
fail('MathJax v3 failed to load');
2525
};
26-
27-
window.MathJax = {
28-
tex: {
29-
inlineMath: [['$', '$'], ['\\(', '\\)']]
30-
}
31-
};
3226
mathJaxScriptTag.src = '/base/node_modules/mathjax-v3/es5/tex-mml-svg.js';
3327
document.body.appendChild(mathJaxScriptTag);
3428
});

0 commit comments

Comments
 (0)