Skip to content

feat(typst): add @prosemark/typst with typst.ts math rendering#125

Draft
jsimonrichard wants to merge 27 commits into
mainfrom
cursor/prosemark-typst-extension-34dd
Draft

feat(typst): add @prosemark/typst with typst.ts math rendering#125
jsimonrichard wants to merge 27 commits into
mainfrom
cursor/prosemark-typst-extension-34dd

Conversation

@jsimonrichard

@jsimonrichard jsimonrichard commented Apr 12, 2026

Copy link
Copy Markdown
Owner

Summary

Adds @prosemark/typst for rendering $…$ / $$…$$ math with typst.ts, parallel to @prosemark/latex.

Recent polish in this branch:

  • Inline SVG layout (no block stacking), currentColor theming
  • jsDelivr default WASM URLs (Cloudflare Pages size limit)
  • Docs /demo/typst page
  • Inline math baseline alignment — typst SVG has no baseline metadata; widgets now compute a per-formula vertical-align em offset from glyph transforms (with bbox fallback for fractions)

Test plan

  • Open /demo/typst and confirm inline math ($x + y$, $x_i$, $frac(1,2)$) aligns with surrounding text baseline
  • Block math still centers correctly
  • Light/dark mode math color inherits editor foreground
Open in Web Open in Cursor 

Mirror @prosemark/latex: fold widgets for Math nodes, delimiter/formula
theme, LRU SVG cache, and typstMath* re-exports. Wire docs TypeDoc and
dependency on @myriaddreamin/typst.ts with pinned WASM URLs on jsDelivr.

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

changeset-bot Bot commented Apr 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d08b13e

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

This PR includes changesets to release 2 packages
Name Type
@prosemark/typst Minor
@prosemark/latex 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

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 12, 2026

Copy link
Copy Markdown

Deploying prosemark with  Cloudflare Pages  Cloudflare Pages

Latest commit: d08b13e
Status: ✅  Deploy successful!
Preview URL: https://5d14a73b.prosemark.pages.dev
Branch Preview URL: https://cursor-prosemark-typst-exten.prosemark.pages.dev

View logs

@pkg-pr-new

pkg-pr-new Bot commented Apr 12, 2026

Copy link
Copy Markdown
@prosemark/core

npm i https://pkg.pr.new/jsimonrichard/ProseMark/@prosemark/core@125

@prosemark/latex

npm i https://pkg.pr.new/jsimonrichard/ProseMark/@prosemark/latex@125

@prosemark/paste-rich-text

npm i https://pkg.pr.new/jsimonrichard/ProseMark/@prosemark/paste-rich-text@125

@prosemark/render-html

npm i https://pkg.pr.new/jsimonrichard/ProseMark/@prosemark/render-html@125

@prosemark/spellcheck-frontend

npm i https://pkg.pr.new/jsimonrichard/ProseMark/@prosemark/spellcheck-frontend@125

@prosemark/typst

npm i https://pkg.pr.new/jsimonrichard/ProseMark/@prosemark/typst@125

@prosemark/vscode-extension-integrator

npm i https://pkg.pr.new/jsimonrichard/ProseMark/@prosemark/vscode-extension-integrator@125

commit: 48c86ad

cursoragent and others added 26 commits April 12, 2026 00:53
Swap LaTeX/MathJax for typst.ts; import compiler/renderer wasm via ?url so
assets ship with the demo build. Update initDoc with Typst math examples.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Copy typst-ts-web-compiler and typst-ts-renderer wasm into dist/wasm after
tsdown; resolve default URLs via new URL(..., import.meta.url). Demo uses
defaults and drops direct wasm package deps. Ignore scripts/ in typst eslint.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Drop copy-wasm script; import compiler/renderer wasm from dependencies with
Vite-style ?url so app bundlers emit assets. Add typstWasmUrls module and
ambient declarations for TS.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
typst.ts embeds foreignObject/.tsel layers with position:fixed CSS that
fragment inline formulas in CodeMirror. Omit css/js from render options and
remove overlays before inserting SVG; tune inline widget sizing.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
typst.ts can emit multiple SVG nodes that stack vertically when treated
as block-level. Force display: inline on all widget SVGs; block math
centering relies on the container text-align: center.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Theme CSS alone may not apply or may lose to typst embedded styles.
Apply display:inline as inline styles on every SVG (including nested and
sibling fragments) and mount multiple top-level SVG nodes when typst
returns them.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
@prosemark/typst already uses cm-typst-math; cm-latex-math appears when
latexMarkdownEditorExtensions is loaded instead. Export typstMathWidgetClass
and use typst in debug-vsc-extn-in-web.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Add ProseMarkTypstDemo with typst extensions and typstInitDoc. Extract
shared demo styles. Main /demo stays on @prosemark/latex (MathJax).

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Configure matching tsconfig paths and Vite resolve alias; use in MDX
imports instead of deep relative paths.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Options compilerWasmUrl/rendererWasmUrl already existed; defaults used
?url imports that Vite copied into static output (over Cloudflare Pages
25MB limit). Default to pinned jsDelivr URLs; export jsdelivrTypstWasmUrls.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Astro scopes component CSS by default; moving styles into a separate
component broke #app / :root selectors for the demo editor markup.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
typst.ts emits fill="#000" on math glyphs. Replace black fills with
currentColor and inherit color on the widget so math matches editor text
in light and dark themes.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Strip unrelated sample content from typstInitDoc. Add /demo/typst link
under the LaTeX math section in the standard demo document.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Remove typst y-inset that added extra slack below math. After mounting
SVG widgets, detect the typst math baseline from glyph translate
transforms (fallback to ink bbox for fractions) and apply a negative
vertical-align em offset so the math baseline meets surrounding text.

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>
typst.ts often emits 8pt-tall viewBoxes while subscripts and fractions
extend farther. After mount, grow each inline SVG viewBox to getBBox()
(with padding) and scale height em proportionally so CodeMirror reserves
enough line space and glyphs are not clipped.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
typst width/height attributes are in pt but map 1:1 to CSS px, so display
formulas looked tiny next to inline math scaled to ~1.05em. Size block math
from viewBox height (same em formula as inline) and stop forcing display:inline
on display SVGs.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Starlight sets .sl-markdown-content svg { display: block; height: auto },
which broke inline MathJax on the docs demo after shared styles went global.
Override mjx-container/svg display in @prosemark/latex.

Typst SVG height used 1.05em per 8pt viewBox (~too large). Scale by typst's
12pt-per-em ratio instead (viewHeight / 12).

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Fraction bars and other rules use SVG stroke, not fill, so post-hoc
currentColor rewrites missed them. Read the editor foreground color,
pass it via #show math.equation: set text(fill: rgb("#…")), and
re-render widgets when the theme changes.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Resolve editor foreground at widget render time instead of using the
default rgb("#000000") field value on first paint. Add #show math fill
rule alongside math.equation, and restore SVG fill/stroke currentColor
fallback for any remaining black ink.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Add data-typst-widget-version on math widgets so deploy/cache issues
are easier to spot. The attribute was present in source but stale
ProseMarkTypstDemo bundles (old hashed JS) would not set it.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Remove invalid #show math: ink rule that caused compile failures, parse
typst.ts diagnostic dumps into readable tooltip messages, and use a
higher-specificity error selector so red monospace source text is visible.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Apply error color via inline styles and dedicated error theme rules,
guard async callbacks when widgets are recreated during ink sync, and
add docs demo CSS so Starlight themes do not override error red text.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
Replace raw formula fallback with a role=alert message element and
themed error styling matching main's populateLatexMathErrorDom pattern.

Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
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