Skip to content

Commit

Permalink
Call final MathJax.Hub.setRenderer directly (not with Queue)
Browse files Browse the repository at this point in the history
This should remove a potential race condition
  • Loading branch information
jonmmease committed Sep 12, 2018
1 parent 951523d commit 1dd4fd3
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/lib/svg_text_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ function texToSVG(_texString, _config, _callback) {
['setRenderer', MathJax.Hub, 'SVG'],
['Typeset', MathJax.Hub, tmpDiv.node()],
function() {
// Restore original renderer if not SVG
if(originalRenderer !== 'SVG') {
MathJax.Hub.Queue(['setRenderer', MathJax.Hub, originalRenderer]);
}

var glyphDefs = d3.select('body').select('#MathJax_SVG_glyphs');

if(tmpDiv.select('.MathJax_SVG').empty() || !tmpDiv.select('svg').node()) {
Expand All @@ -195,6 +190,8 @@ function texToSVG(_texString, _config, _callback) {
}

tmpDiv.remove();

return MathJax.Hub.setRenderer(originalRenderer);

This comment has been minimized.

Copy link
@alexcjohnson

alexcjohnson Sep 12, 2018

Collaborator

This could still benefit from if(originalRenderer !== 'SVG'), right?

Actually, it occurs to me then: perhaps the first two queue items could also be merged:

function() {
    originalRenderer = MathJax.Hub.config.menuSettings.renderer;
    if(originalRenderer !== 'SVG') {
        return MathJax.Hub.setRenderer('SVG');
    }
}

That way when we're living in a pure-SVG environment, the only overhead is (synchronously) querying the renderer, and the potentially-async setRenderer calls are all bypassed.

This comment has been minimized.

Copy link
@jonmmease

jonmmease Sep 12, 2018

Author Contributor

Oh, I see. I was missing the significance of the return value of Queue commands. This works and was updated in 9569648

});
}

Expand Down

0 comments on commit 1dd4fd3

Please sign in to comment.