Repository navigation
upgrade inline math previews to mathjax 4 - #18210
Merged
Merged
Conversation
Bundle MathJax 4.1.3 (with the mathjax-newcm font's CHTML resources) alongside the existing MathJax 2.7.9 bundle, serve it from the new /mathjax4/ session URI, and port the GWT inline LaTeX / math preview subsystem (source editor line widgets and popup, visual editor preview) from the removed MathJax.Hub v2 API to the v4 typesetPromise API. Rendered R Markdown documents are unchanged: rmarkdown's local mode still consumes the 2.7 bundle via RMARKDOWN_MATHJAX_PATH. Addresses #8715.
Contributor
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
The script cds into RSTUDIO_TOOLS_ROOT before the MathJax 4 section, so the lazily computed relative dirname no longer pointed at the script's own directory. Resolve the script directory up front, and remove the empty zip a failed buildtools download leaves behind.
While typing, incomplete expressions (e.g. a trailing subscript) briefly rendered a TeX error before the previous render was restored. Typeset into a hidden scratch sibling instead, and only swap the output into the visible element when it typesets cleanly; on failure the previous render never leaves the DOM. When there is no previous render to preserve, the error output is still shown.
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
3 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #8715.
This is phase 1 of the MathJax upgrade discussed in #8715: the IDE's inline LaTeX / math previews (source editor line widgets and popup, and the visual editor's live math preview via
PanmirrorUIMath) now render with MathJax 4.1.3, while rendered R Markdown documents are untouched -- rmarkdown'smathjax = "local"mode still uses the bundled MathJax 2.7.9 viaRMARKDOWN_MATHJAX_PATH(rmarkdown hardcodes the v2MathJax.js?config=entry point, so swapping that bundle requires coordinated rmarkdown changes; that's phase 2).What's included
install-mathjaxnow also installs amathjax-4bundle. It first triesmathjax-4.1.3.zipfrom rstudio-buildtools, and falls back to assembling the bundle from npm registry tarballs (dependencies/tools/build-mathjax4, which prunes themathjax@4package and adds the@mathjax/mathjax-newcm-fontCHTML resources underfonts/mathjax-newcm-font).dependencies/tools/upload-mathjax4.shbuilds and uploads the zip.external-mathjax4-pathsession option (defaultresources/mathjax-4), installed by CMake next tomathjax-27, and served at the/mathjax4/URI (registered before/mathjax, since URI handlers match by prefix in registration order). The server-side/mathjaxproxy forwards/mathjax4/by prefix, so no server changes are needed.MathJaxLoadernow sets a v4-style config (inline$/display$$TeX delimiters,ui/safe, menu/speech/enrichment disabled,output.fontPathpointed at the locally served font so woff2 fonts and dynamic glyph-range data never hit the CDN) and loadsmathjax4/tex-mml-chtml.js.MathJaxTypesetis ported fromMathJax.Hub.Queue/Typeset/getAllJaxtoMathJax.typesetPromise, keeping the restore-previous-render-on-error behavior via adata-mathjax-last-textattribute. The v2-era hidden-retry hack is gone.Notable findings
constructoris identity-equal to the host window'sObject; a config literal created inside the GWT frame fails that check and the whole config is dropped (symptom:$$math worked,$...$didn't, fonts fell back to jsdelivr). The loader now re-creates the config in the host realm via$wnd.JSON.parse(JSON.stringify(config)).mjx-merrornodes; undefined macros render as red text via the bundlednoundefinedpackage. Error detection accounts for both.Action needed before Windows CI can build this
dependencies/windows/install-dependencies.cmdexpectsmathjax-4.1.3.zipon the rstudio-buildtools S3 bucket; someone with AWS credentials needs to rundependencies/tools/upload-mathjax4.shonce. macOS/Linux builds work without it via the npm-registry fallback.Developers will need to re-run
install-mathjax(orinstall-dependencies) after pulling, since CMake now validates themathjax-4directory.Testing
e2e/rstudio/tests/panes/editor/math_preview.test.ts: MathJax 4 loads from the local bundle with the RStudio config applied, display math renders as a line-widget preview, and inline math renders a popup preview. All pass against the dev desktop build.ant javac/ant draft, backend build, and e2e typecheck all clean.