Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5c62c8e

Browse filesBrowse files
authored
Merge pull request #2994 from jonmmease/mathjax_mode
Support rendering tex even when global MathJax rendering mode is not SVG
2 parents c2f868c + 57e32ba commit 5c62c8e
Copy full SHA for 5c62c8e

File tree

Expand file treeCollapse file tree

3 files changed

+78
-17
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+78
-17
lines changed

‎src/fonts/mathjax_config.js

Copy file name to clipboardExpand all lines: src/fonts/mathjax_config.js
+13-9Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@
1616
if(typeof MathJax !== 'undefined') {
1717
exports.MathJax = true;
1818

19-
MathJax.Hub.Config({
20-
messageStyle: 'none',
21-
skipStartupTypeset: true,
22-
displayAlign: 'left',
23-
tex2jax: {
24-
inlineMath: [['$', '$'], ['\\(', '\\)']]
25-
}
26-
});
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+
}
2732

28-
MathJax.Hub.Configured();
2933
} else {
3034
exports.MathJax = false;
3135
}

‎src/lib/svg_text_utils.js

Copy file name to clipboardExpand all lines: src/lib/svg_text_utils.js
+52-8Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,48 @@ function cleanEscapesForTex(s) {
163163
}
164164

165165
function texToSVG(_texString, _config, _callback) {
166-
var randomID = 'math-output-' + Lib.randstr({}, 64);
167-
var tmpDiv = d3.select('body').append('div')
168-
.attr({id: randomID})
169-
.style({visibility: 'hidden', position: 'absolute'})
170-
.style({'font-size': _config.fontSize + 'px'})
171-
.text(cleanEscapesForTex(_texString));
172-
173-
MathJax.Hub.Queue(['Typeset', MathJax.Hub, tmpDiv.node()], function() {
166+
167+
var originalRenderer,
168+
originalConfig,
169+
originalProcessSectionDelay,
170+
tmpDiv;
171+
172+
MathJax.Hub.Queue(
173+
function() {
174+
originalConfig = Lib.extendDeepAll({}, MathJax.Hub.config);
175+
176+
originalProcessSectionDelay = MathJax.Hub.processSectionDelay;
177+
if(MathJax.Hub.processSectionDelay !== undefined) {
178+
// MathJax 2.5+
179+
MathJax.Hub.processSectionDelay = 0;
180+
}
181+
182+
return MathJax.Hub.Config({
183+
messageStyle: 'none',
184+
tex2jax: {
185+
inlineMath: [['$', '$'], ['\\(', '\\)']]
186+
},
187+
displayAlign: 'left',
188+
});
189+
},
190+
function() {
191+
// Get original renderer
192+
originalRenderer = MathJax.Hub.config.menuSettings.renderer;
193+
if(originalRenderer !== 'SVG') {
194+
return MathJax.Hub.setRenderer('SVG');
195+
}
196+
},
197+
function() {
198+
var randomID = 'math-output-' + Lib.randstr({}, 64);
199+
tmpDiv = d3.select('body').append('div')
200+
.attr({id: randomID})
201+
.style({visibility: 'hidden', position: 'absolute'})
202+
.style({'font-size': _config.fontSize + 'px'})
203+
.text(cleanEscapesForTex(_texString));
204+
205+
return MathJax.Hub.Typeset(tmpDiv.node());
206+
},
207+
function() {
174208
var glyphDefs = d3.select('body').select('#MathJax_SVG_glyphs');
175209

176210
if(tmpDiv.select('.MathJax_SVG').empty() || !tmpDiv.select('svg').node()) {
@@ -183,6 +217,16 @@ function texToSVG(_texString, _config, _callback) {
183217
}
184218

185219
tmpDiv.remove();
220+
221+
if(originalRenderer !== 'SVG') {
222+
return MathJax.Hub.setRenderer(originalRenderer);
223+
}
224+
},
225+
function() {
226+
if(originalProcessSectionDelay !== undefined) {
227+
MathJax.Hub.processSectionDelay = originalProcessSectionDelay;
228+
}
229+
return MathJax.Hub.Config(originalConfig);
186230
});
187231
}
188232

‎tasks/stats.js

Copy file name to clipboardExpand all lines: tasks/stats.js
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ function getInfoContent() {
6565
'',
6666
'You can grab the relevant MathJax files in `./dist/extras/mathjax/`.',
6767
'',
68+
'By default, plotly.js will modify the global MathJax configuration on load.',
69+
'This can lead to undesirable behavior if plotly.js is loaded alongside',
70+
'other libraries that also rely on MathJax. To disable this global configuration',
71+
'process, set the `MathJaxConfig` property to `\'local\'` in the `window.PlotlyConfig`',
72+
'object. This property must be set before the plotly.js script tag, for example:',
73+
'',
74+
'```html',
75+
'<script>',
76+
' window.PlotlyConfig = {MathJaxConfig: \'local\'}',
77+
'</script>',
78+
'<script src="plotly.min.js"></script>',
79+
'```',
80+
'',
6881
'### To include localization',
6982
'',
7083
'Plotly.js defaults to US English (en-US) and includes British English (en) in the standard bundle.',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.