8000 load and config mathjax v3 if not defined but requested · lzhice/plotly.js@612272e · GitHub
[go: up one dir, main page]

Skip to content

Commit 612272e

Browse files
committed
load and config mathjax v3 if not defined but requested
1 parent 4bb1714 commit 612272e

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/lib/svg_text_utils.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,33 @@ var LINE_SPACING = require('../constants/alignment').LINE_SPACING;
1313

1414
var FIND_TEX = /([^$]*)([$]+[^$]*[$]+)([^$]*)/;
1515

16+
var inlineMath = [['$', '$'], ['\\(', '\\)']];
17+
1618
exports.convertToTspans = function(_context, gd, _callback) {
19+
if(!window.MathJax) {
20+
// configure & load MathJax v3 if not defined
21+
window.MathJax = {
22+
tex: {
23+
inlineMath: inlineMath
24+
}
25+
};
26+
27+
var script = document.createElement('script');
28+
script.async = true;
29+
document.head.appendChild(script);
30+
31+
// open and send a synchronous request
32+
var xhrObj = new XMLHttpRequest();
33+
xhrObj.open('GET', 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js', false);
34+
xhrObj.send('');
35+
36+
// add the returned content to a newly created script tag
37+
var script = document.createElement('script');
38+
script.type = "text/javascript";
39+
script.text = xhrObj.responseText;
40+
document.getElementsByTagName('head')[0].appendChild(script);
41+
}
42+
1743
var str = _context.text();
1844

1945
// Until we get tex integrated more fully (so it can be used along with non-tex)
@@ -173,8 +199,6 @@ function cleanEscapesForTex(s) {
173199
.replace(GT_MATCH, '\\gt ');
174200
}
175201

176-
var inlineMath = [['$', '$'], ['\\(', '\\)']];
177-
178202
function texToSVG(_texString, _config, _callback) {
179203
var MathJaxVersion = parseInt(
180204
(MathJax.version || '').split('.')[0]

0 commit comments

Comments
 (0)
0