Skip to content

Commit 386dd87

Browse files
committed
refactor mathjax tmp node draw and selection
1 parent 13fbb8d commit 386dd87

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/lib/svg_text_utils.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,11 @@ function texToSVG(_texString, _config, _callback) {
217217
var randomID = 'math-output-' + Lib.randstr({}, 64);
218218
tmpDiv = d3.select('body').append('div')
219219
.attr({id: randomID})
220-
.style({visibility: 'hidden', position: 'absolute'})
221-
.style({'font-size': _config.fontSize + 'px'})
220+
.style({
221+
visibility: 'hidden',
222+
position: 'absolute',
223+
'font-size': _config.fontSize + 'px'
224+
})
222225
.text(cleanEscapesForTex(_texString));
223226

224227
var tmpNode = tmpDiv.node();
@@ -233,11 +236,12 @@ function texToSVG(_texString, _config, _callback) {
233236
MathJaxVersion < 3 ? '.MathJax_SVG' : '.MathJax'
234237
);
235238

236-
if(sel.empty() || !tmpDiv.select('svg').node()) {
239+
var node = !sel.empty() && tmpDiv.select('svg').node();
240+
if(!node) {
237241
Lib.log('There was an error in the tex syntax.', _texString);
238242
_callback();
239243
} else {
240-
var svgBBox = tmpDiv.select('svg').node().getBoundingClientRect();
244+
var svgBBox = node.getBoundingClientRect();
241245
var glyphDefs = d3.select('body').select(
242246
MathJaxVersion < 3 ? '#MathJax_SVG_glyphs' : 'defs'
243247
);

0 commit comments

Comments
 (0)