Update MathJax to version 4 for format preview. - #1599
Conversation
Adjust async behavior to await for MathJax. Update Content-Security-Policy to allow MathJax to dynamically load a worker and fonts.
|
Can we simplify the CSP by bundling mathjax with the code rather than pulling from the CDN? See commit b003380 in branch https://github.com/cpeel/dproofreaders/commits/mathjax4/ for how we could do that pretty easily. We do this for other JS code like d3. Then the file is in |
|
I thought that might be an option, I'll take a closer look. |
|
Just checking - I think I should commit the corresponding update to |
Simplify Content-Security-Policy to remove jsdelivr. Fix mathjax error when first enabling Preview Math.
cpeel
left a comment
There was a problem hiding this comment.
Code looks good to me but I would appreciate @chrismiceli's eyes on it as he's our resident JS guru.
| initView().then(function () { | ||
| writePreviewText(); | ||
| hideConfig(); | ||
| writePreviewText().then(function () { |
There was a problem hiding this comment.
Very minor, but if we are using async await above, we could here too I imagine.
There was a problem hiding this comment.
Yes, I think so, but I didn't change it since it was already using .then(). It should be equivalent either way.
Use npm to install mathjax locally, and serve it locally, no longer using the jsdelivr CDN.
Adjust async behavior to await for MathJax.
Update Content-Security-Policy to allow MathJax to dynamically load a worker and fonts.
Fix old bug that showed a mathjax error (this exists in production).
The motivation for this is to use the same version of mathjax in both Format Preview and also the separate m2svg tool. This helps to avoid inconsistencies between the two tools, which are often used together for the same project.
To reproduce the old bug with the mathjax error:
I tested with math markup from PR #1527, which also has the expected output in preview mode.
To verify new consistency with m2svg 3.4.0, use this markup:
Math with text inside: \(a + b = c + d + \text{\&c.}\)Expected output is
a + b = c + d + &c.where a b c d are italic, &c is not italic. (The production version, with mathjax 3, shows it asa + b = c + d + \&c.)I also tried various sequences of enabling/disabling Preview Math in the format preview configuration.
Sandbox at: https://www.pgdp.org/~mrducky/c.branch/mathjax4