@@ -71,7 +71,11 @@ exports.convertToTspans = function(_context, gd, _callback) {
7171 parent . selectAll ( 'svg.' + svgClass ) . remove ( ) ;
7272 parent . selectAll ( 'g.' + svgClass + '-group' ) . remove ( ) ;
7373
74- var newSvg = _svgEl && _svgEl . select ( 'svg' ) ;
74+ var newSvg = _svgEl && _svgEl . select (
75+ v3Chtml ( ) ?
76+ 'mjx-math' :
77+ 'svg'
78+ ) ;
7579 if ( ! newSvg || ! newSvg . node ( ) ) {
7680 showText ( ) ;
7781 resolve ( ) ;
@@ -165,6 +169,15 @@ exports.convertToTspans = function(_context, gd, _callback) {
165169
166170// MathJax
167171
172+ function v3Chtml ( ) {
173+ return (
174+ MathJax &&
175+ MathJax . config &&
176+ MathJax . config . startup &&
177+ MathJax . config . startup . output === 'chtml'
178+ ) ;
179+ }
180+
168181var LT_MATCH = / ( < | & l t ; | & # 6 0 ; ) / g;
169182var GT_MATCH = / ( > | & g t ; | & # 6 2 ; ) / g;
170183
@@ -236,16 +249,21 @@ function texToSVG(_texString, _config, _callback) {
236249 MathJaxVersion < 3 ? '.MathJax_SVG' : '.MathJax'
237250 ) ;
238251
239- var node = ! sel . empty ( ) && tmpDiv . select ( 'svg' ) . node ( ) ;
252+ var node = ! sel . empty ( ) && (
253+ v3Chtml ( ) ?
254+ tmpDiv . select ( 'mjx-math' ) . node ( ) : // TODO: handle non-svg element in texToSVG callback!
255+ tmpDiv . select ( 'svg' ) . node ( )
256+ ) ;
257+
240258 if ( ! node ) {
241259 Lib . log ( 'There was an error in the tex syntax.' , _texString ) ;
242260 _callback ( ) ;
243261 } else {
244- var svgBBox = node . getBoundingClientRect ( ) ;
262+ var nodeBBox = node . getBoundingClientRect ( ) ;
245263 var glyphDefs = d3 . select ( 'body' ) . select (
246264 MathJaxVersion < 3 ? '#MathJax_SVG_glyphs' : 'defs'
247265 ) ;
248- _callback ( sel , glyphDefs , svgBBox ) ;
266+ _callback ( sel , glyphDefs , nodeBBox ) ;
249267 }
250268
251269 tmpDiv . remove ( ) ;
0 commit comments