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?
There was a problem hiding this comment.
I believe since initiateMathJax() always returns a Promise, there's no programmatic reason to make it an async function (all that would achieve is making the function return a Promise, but it's doing that anyway).
I guess it wouldn't cause any problems to add async to the function definition, but I don't think we've done that anywhere else in the codebase.
There was a problem hiding this comment.
Do you now why the legend got smaller?
There was a problem hiding this comment.
I don't know, but I did add a new mock mathjax-font-size to ensure that the rendered MathJax is picking up the font size of the original text.
Since that seems to be working, I think this change might just be a styling difference between MathJax v2 and v4.
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?
There was a problem hiding this comment.
@camdecoster I think I said something different in our call, but the actual reason why the raw MathJax string is showing up here because the library doesn't yet render MathJax for pie labels. So the entire rendering step is skipped and the string is shown as-is. (The exact same string is rendered 'correctly' in the legend to the right.)
The raw MathJax string shown here is present since the mathjax baseline image was first added to the repo. The fact that the string wasn't shown in the mathjax3__ version of the mock is the outlier. I'm pretty neutral on which behavior is more correct.
Co-authored-by: Cameron DeCoster <cameron.decoster@gmail.com>
Co-authored-by: Cameron DeCoster <cameron.decoster@gmail.com>
…d larger than 16)
dc176ac to
5b03600
Compare
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