Skip to content

Self-host MathJax via @prosemark/latex vite plugin (url-import) - #150

Merged
jsimonrichard merged 22 commits into
mainfrom
cursor/latex-static-mathjax-import-5663
Jun 6, 2026
Merged

Self-host MathJax via @prosemark/latex vite plugin (url-import)#150
jsimonrichard merged 22 commits into
mainfrom
cursor/latex-static-mathjax-import-5663

Conversation

@jsimonrichard

@jsimonrichard jsimonrichard commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

Self-host MathJax in the LaTeX VS Code extension via url-import instead of bundling tex-svg.js into webview.js, and resolve the MathJax package URL from the extension host using webview.asWebviewUri.

Changes

  • @prosemark/latex/vite-plugin-mathjax — Vite plugin to copy configurable paths from the mathjax npm package (default: tex-svg.js + sre/) into the build output under mathjax/.
  • @prosemark/vscode-extension-integratorSubExtensionCallback receives context as a single object (including webview).
  • vscode-prosemark-latex-integration — Extension host passes mathJaxPackageUrl from webview.asWebviewUri; webview uses url-import.
  • @prosemark/latex — Removed mathJaxPackageUrlFromWebviewScript.
  • Docs — Document MathJax a11y/speech worker behavior for static-import (disable a11y or copy sre/).

Dist layout

dist/webview/webview.js          (~48 KB)
dist/webview/mathjax/tex-svg.js
dist/webview/mathjax/sre/...
Open in Web Open in Cursor 

Replace deferred dynamic imports with a build-time side-effect import of
mathjax/tex-svg.js (peer dependency of @prosemark/latex) so Vite fully
bundles MathJax into webview.js before the webview loads.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
@changeset-bot

changeset-bot Bot commented Jun 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8e545e6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@prosemark/vscode-extension-integrator Patch
@prosemark/latex Patch
vscode-prosemark-latex-integration Patch
vscode-prosemark Patch
vscode-prosemark-cspell-integration Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 6, 2026

Copy link
Copy Markdown
@prosemark/core

npm i https://pkg.pr.new/@prosemark/core@150

@prosemark/latex

npm i https://pkg.pr.new/@prosemark/latex@150

@prosemark/paste-rich-text

npm i https://pkg.pr.new/@prosemark/paste-rich-text@150

@prosemark/render-html

npm i https://pkg.pr.new/@prosemark/render-html@150

@prosemark/spellcheck-frontend

npm i https://pkg.pr.new/@prosemark/spellcheck-frontend@150

@prosemark/vscode-extension-integrator

npm i https://pkg.pr.new/@prosemark/vscode-extension-integrator@150

commit: cfd93b0

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 6, 2026

Copy link
Copy Markdown

Deploying prosemark with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8e545e6
Status:⚡️  Build in progress...

View logs

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
@jsimonrichard
jsimonrichard marked this pull request as ready for review June 6, 2026 20:31
cursoragent and others added 3 commits June 6, 2026 20:37
The tex-svg combined component loads sre/speech-worker.js at runtime, but
Vite only emits webview.js. Turn off speech/enrichment for editor preview.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
The tex-svg bundle loads sre/speech-worker.js at runtime as a web worker.
Vite inlines the main IIFE but cannot bundle workers loaded via importScripts,
so copy mathjax/sre/ next to webview.js after each build.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Export copyMathJaxAssets from @prosemark/latex/vite-plugin-mathjax with a
configurable copy list (default tex-svg.js + sre). The LaTeX VS Code webview
loads MathJax via url-import from dist/webview/mathjax/ instead of bundling
tex-svg into webview.js (~48 KB vs ~1.8 MB).

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
@cursor cursor Bot changed the title Use top-level static MathJax import in LaTeX VS Code webview Self-host MathJax via @prosemark/latex vite plugin (url-import) Jun 6, 2026
cursoragent and others added 17 commits June 6, 2026 20:58
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
mathJaxPackageUrlFromWebviewScript used the last script tag, which was
cspell-integration's webview.js when both companions are installed.
Add scriptSrcIncludes and use latex-integration in the LaTeX webview.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Extend SubExtensionCallback with the webview instance so sub-extensions
can resolve local resource URLs with webview.asWebviewUri instead of
reverse-engineering script tags in the webview.

The LaTeX integration now passes mathJaxPackageUrl into setup from the
extension host, removing the scriptSrcIncludes workaround.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
VS Code integrations should pass mathJaxPackageUrl from the extension
host via webview.asWebviewUri; script-tag discovery is no longer needed.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Sub-extension factories now receive { document, callProcAndForget,
callProcWithReturnValue, webview } so each integration can destructure
only what it needs without breaking when new fields are added.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Explain that tex-svg loads sre/speech-worker.js separately, and that
static-import setups must either disable a11y or copy and serve sre/.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Use a type guard for the webview vscode API instead of an unsafe cast,
tighten the MathJax loader test helper, and include vite.config.mts in
eslint file patterns.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
MathJax 4 removed skipStartupTypeset; use startup.typeset: false to skip
automatic page typesetting. Update @prosemark/latex preconfiguration, docs,
and tests accordingly.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
vite.config.mts is git-tracked source, but sibling VS Code extensions do not
list their vite configs in eslint.config.ts and lint passes without it.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
The VS Code extension keeps speech support via url-import and copied sre/.
Frame disabling a11y as a static-import tradeoff, not a preview default.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Describe the 0.0.2 bug as math failing when MathJax was bundled into
the extension; drop the speech-worker cause (introduced in this PR).

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Self-host MathJax in the extension to resolve rendering issues.
@jsimonrichard
jsimonrichard merged commit da39c71 into main Jun 6, 2026
1 of 2 checks passed
@lishaduck
lishaduck deleted the cursor/latex-static-mathjax-import-5663 branch June 7, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants