Upgrade MathJax support from v2/v3 to v3/v4#7898
Conversation
…cript to reference mathjax v3/v4 instead of v2/v3
…roach, and migrate to v3/v4
…t of render, make sure raw input text is hidden at end of MathJax render, start render chain with Promise.resolve()
656d638 to
9c0b33c
Compare
9c0b33c to
83bb307
Compare
|
|
||
| // Now that the MathJax render has finished, re-hide the source text. | ||
| // We hid it earlier, too, but since this callback runs async, | ||
| // another function may have made it visible again |
There was a problem hiding this comment.
add a TODO to investigate this further
| // Strip $…$ delimiters and clean up escape charaters, | ||
| // then pass the result to MathDocument.convert() to get an SVG element back | ||
| const texMath = cleanEscapesForTex(_texString).replace(/^\$+|\$+$/g, ''); | ||
| return MathJax._.mathjax.mathjax.handleRetriesFor(function() { |
There was a problem hiding this comment.
Why is this call to handleRetriesFor required?
There was a problem hiding this comment.
Found a page in the docs which explains it: https://docs.mathjax.org/en/v4.0/web/retry.html
From what I understand, it sounds like MathJax dynamically loads some features/extensions only as needed, and the internal synchronous functions are designed to error out if a required feature is not available, with a wrapper function catching the failure, loading the required feature, then retrying the function. The wrapper function returns a Promise which resolves when the wrapped function eventually completes successfully.
handleRetriesFor() is that wrapper function.
.convert() is a synchronous function, so wrapping it inside handleRetriesFor() has the additional impact of turning the call to .convert() into an asynchronous function.
| MathJax.config.startup.output = 'svg'; | ||
| var tmpDiv; | ||
|
|
||
| const initiateMathJax = function() { |
There was a problem hiding this comment.
Should this be an async function?
| @@ -0,0 +1 @@ | |||
| - Add support for MathJax v4, and **drop support for v2** [[#7898](https://github.com/plotly/plotly.js/pull/7898)] | |||
There was a problem hiding this comment.
| - Add support for MathJax v4, and **drop support for v2** [[#7898](https://github.com/plotly/plotly.js/pull/7898)] | |
| - **Breaking:** Add support for MathJax v4, and **drop support for v2** [[#7898](https://github.com/plotly/plotly.js/pull/7898)] |
There was a problem hiding this comment.
Do you now why the legend got smaller?
There was a problem hiding this comment.
Is the MathJax specifier supposed to be showing up in the pie chart? Is this the fallback behavior?
Co-authored-by: Cameron DeCoster <cameron.decoster@gmail.com>
Update plotly.js to be compatible with MathJax v4, and drop support for MathJax v2.
Due to some logic improvements, this should also make MathJax rendering faster.
svg_text_utils.jsto use MathJax v3/v4 syntax to render math symbolsMathJax.startup.defaultReady()on every individual render. This was very slow and also not recommended usage of the MathJax APIMathDocument.convert(tex)rather thanMathJax.typeset(tex)MathJax._.namespace. While not officially documented, the pattern is used in several places (one, two, three) in the MathJax documentation for advanced configurationSteps for testing
npm start) which uses MathJax 4mathjaxin the name (and the other baselines changed here) looks OK and matches the new baselines on this branchmathjaxmock itself contains several strings of TeX which don't render due to syntax errors; this is not new, and it's deliberate, to test the fallback behaviorhttp://localhost:3000/devtools/test_dashboard/index-mathjax3.html) and verify again that everything looks fine