Skip to content

Commit b02ba17

Browse files
committed
Add support for a new global window.PlotlyConfig configuration object
Add a MathJaxConfig option that, when set to 'local', causes plotly.js to bypass all global MathJax configuration. Regardless of the value of MathJaxConfig, all MathJax rendering commands are surrounded by logic to properly configure the MathJax properties that plotly.js needs. When MathJaxConfig is not 'local', plotly.js will continue to setup the global MathJax config as it always has. This is the default behavior for backward compatibility. When plotly.js is used in a situation where it is not the only component using MathJax, then MathJaxConfig should be set to 'local' to keep from overwriting the user's desired global configuration.
1 parent 41f7747 commit b02ba17

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/fonts/mathjax_config.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@
1616
if(typeof MathJax !== 'undefined') {
1717
exports.MathJax = true;
1818

19-
MathJax.Hub.Config({
20-
skipStartupTypeset: true,
21-
tex2jax: {
22-
inlineMath: [['$', '$'], ['\\(', '\\)']]
23-
},
24-
});
19+
var globalConfig = (window.PlotlyConfig || {}).MathJaxConfig !== 'local';
20+
21+
if(globalConfig) {
22+
MathJax.Hub.Config({
23+
messageStyle: 'none',
24+
skipStartupTypeset: true,
25+
displayAlign: 'left',
26+
tex2jax: {
27+
inlineMath: [['$', '$'], ['\\(', '\\)']]
28+
}
29+
});
30+
MathJax.Hub.Configured();
31+
}
2532

26-
MathJax.Hub.Configured();
2733
} else {
2834
exports.MathJax = false;
2935
}

src/lib/svg_text_utils.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,15 @@ function texToSVG(_texString, _config, _callback) {
175175

176176
originalProcessSectionDelay = MathJax.Hub.processSectionDelay;
177177
if(MathJax.Hub.processSectionDelay !== undefined) {
178-
// MathJax 3.5+
178+
// MathJax 2.5+
179179
MathJax.Hub.processSectionDelay = 0;
180180
}
181181

182182
return MathJax.Hub.Config({
183183
messageStyle: 'none',
184+
tex2jax: {
185+
inlineMath: [['$', '$'], ['\\(', '\\)']]
186+
},
184187
displayAlign: 'left',
185188
});
186189
},
@@ -202,7 +205,6 @@ function texToSVG(_texString, _config, _callback) {
202205
return MathJax.Hub.Typeset(tmpDiv.node());
203206
},
204207
function() {
205-
206208
var glyphDefs = d3.select('body').select('#MathJax_SVG_glyphs');
207209

208210
if(tmpDiv.select('.MathJax_SVG').empty() || !tmpDiv.select('svg').node()) {
@@ -221,7 +223,7 @@ function texToSVG(_texString, _config, _callback) {
221223
}
222224
},
223225
function() {
224-
if (originalProcessSectionDelay !== undefined) {
226+
if(originalProcessSectionDelay !== undefined) {
225227
MathJax.Hub.processSectionDelay = originalProcessSectionDelay;
226228
}
227229
return MathJax.Hub.Config(originalConfig);

0 commit comments

Comments
 (0)