Skip to content

Commit 716bac1

Browse files
committed
ensure that plot still renders in the case where an unsupported MathJax version is present
1 parent dbded83 commit 716bac1

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

src/lib/svg_text_utils.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ exports.convertToTspans = function(_context, gd, _callback) {
3232
var tex = (!_context.attr('data-notex')) &&
3333
gd && gd._context.typesetMath &&
3434
(typeof MathJax !== 'undefined') &&
35+
isMathJaxVersionSupported() &&
3536
matchTex(str);
3637

3738
var parent = d3.select(_context.node().parentNode);
@@ -204,18 +205,25 @@ function cleanEscapesForTex(s) {
204205
// and reused for subsequent calls.
205206
var mathjaxSVGDocument = null;
206207

207-
function texToSVG(_texString, _config, _callback) {
208-
const MathJaxVersion = parseInt(
209-
(MathJax.version || '').split('.')[0]
210-
);
208+
// plotly.js is only compatible with MathJax v3 and v4.
209+
const mathJaxMajorVersion = () => parseInt((MathJax.version || '').split('.')[0]);
211210

212-
if(
213-
MathJaxVersion !== 3 &&
214-
MathJaxVersion !== 4
215-
) {
211+
// Only warn once per page
212+
var warnedUnsupportedMathJax = false;
213+
214+
function isMathJaxVersionSupported() {
215+
const version = mathJaxMajorVersion();
216+
if(version === 3 || version === 4) return true;
217+
218+
if(!warnedUnsupportedMathJax) {
219+
warnedUnsupportedMathJax = true;
216220
Lib.warn('Unsupported MathJax version:', MathJax.version);
217-
return;
218221
}
222+
return false;
223+
}
224+
225+
function texToSVG(_texString, _config, _callback) {
226+
const MathJaxVersion = mathJaxMajorVersion();
219227

220228
var tmpDiv;
221229

0 commit comments

Comments
 (0)