@@ -31,10 +31,11 @@ exports.convertToTspans = function(_context, gd, _callback) {
3131 // allow some elements to prohibit it by attaching 'data-notex' to the original
3232 var tex = ( ! _context . attr ( 'data-notex' ) ) &&
3333 gd && gd . _context . typesetMath &&
34- ( typeof MathJax !== 'undefined' ) &&
35- isMathJaxVersionSupported ( ) &&
3634 matchTex ( str ) ;
3735
36+ // Only complain about MathJax version once we know there's actually math to render
37+ if ( tex && ! isMathJaxVersionSupported ( ) ) tex = null ;
38+
3839 var parent = d3 . select ( _context . node ( ) . parentNode ) ;
3940 if ( parent . empty ( ) ) return ;
4041 var svgClass = ( _context . attr ( 'class' ) ) ? _context . attr ( 'class' ) . split ( ' ' ) [ 0 ] : 'text' ;
@@ -205,17 +206,25 @@ function cleanEscapesForTex(s) {
205206// and reused for subsequent calls.
206207var mathjaxSVGDocument = null ;
207208
208- // plotly.js is only compatible with MathJax v3 and v4.
209- const mathJaxMajorVersion = ( ) => parseInt ( ( MathJax . version || '' ) . split ( '.' ) [ 0 ] ) ;
209+ // Function which returns the major version of MathJax as an integer,
210+ // or null if MathJax is undefined or MathJax.version is falsy.
211+ const mathJaxMajorVersion = ( ) => ( typeof MathJax !== 'undefined' && MathJax . version ) ? parseInt ( MathJax . version . split ( '.' ) [ 0 ] ) : null ;
210212
211- // Only warn once per page
213+ // Only warn once per page about each of these conditions
214+ var warnedMissingMathJax = false ;
212215var warnedUnsupportedMathJax = false ;
213216
217+ // plotly.js is only compatible with MathJax v3 and v4.
214218function isMathJaxVersionSupported ( ) {
215219 const version = mathJaxMajorVersion ( ) ;
216220 if ( version === 3 || version === 4 ) return true ;
217221
218- if ( ! warnedUnsupportedMathJax ) {
222+ if ( version === null ) {
223+ if ( ! warnedMissingMathJax ) {
224+ warnedMissingMathJax = true ;
225+ Lib . warn ( 'MathJax is not loaded. Math equations will not be rendered.' ) ;
226+ }
227+ } else if ( ! warnedUnsupportedMathJax ) {
219228 warnedUnsupportedMathJax = true ;
220229 Lib . warn ( 'Unsupported MathJax version:' , MathJax . version ) ;
221230 }
0 commit comments