Skip to content

editor: Add Typst command completion in math regions - #604

Merged
adibhanna merged 4 commits into
ZenNotes:v2.29.0from
flokchvtr:typst-completions
Aug 16, 2026
Merged

editor: Add Typst command completion in math regions#604
adibhanna merged 4 commits into
ZenNotes:v2.29.0from
flokchvtr:typst-completions

Conversation

@flokchvtr

Copy link
Copy Markdown
Contributor

Following up on #594 and the feedback from the 2.28.2 merge, this PR brings the same math auto-completion experience to Typst syntax.

Because Typst writes math differently than LaTeX (parentheses instead of backslashes and braces), I built a dedicated completion source for it. The two sources are mutually exclusive: they check mathRendererOf, so you'll only get suggestions relevant to the active math renderer.

Completion fires after two letters to avoid popping up on single-letter math variables (though manual trigger still works for a single letter). For math-region detection, I reused isInMathContext this time.

The completion table covers: snippets (frac, sum, integral, lim, mat, cases...), accents, text styles (bold, upright, cal, bb), Greek letters, comparisons, sets, and the usual operators. It also includes arrows with their ASCII shorthands (e.g., arrow.r / ->).
Note: plus.circle and times.circle are deprecated, so the table uses the canonical plus.o and times.o instead.

Following the LaTeX review, previews simply use exact Unicode characters (like α, ∑, ℝ) instead of a full render whenever possible to keep things lightweight. Snippets with arguments still use the existing shared, cached render queue.

Tests cover:

  • The token matcher (handling the two-letter minimum and dotted names like arrow.l.r.double).
  • The typesetter gate (ensuring LaTeX and Typst don't step on each other's toes).
  • Ensuring popups stay out of standard prose and code blocks.
  • Verifying that every snippet preview is well-formed and doesn't leak syntax into the compiler.

The sibling of the LaTeX source for notes whose typesetter is Typst:
bare-word commands (sum, alpha, frac) complete from two letters on
inside the same math regions, gated on mathRendererOf so each source
stays out of the other typesetter's notes. Argument-taking functions
insert as snippets with Typst syntax (frac(a, b), sum_(i=1)^(n),
mat(1, 2; 3, 4)); the icon slot shows the exact Unicode glyph
(α, ∑, ∫, ℝ) — no typesetting needed for previews yet.

Starter table (~90 words): greek, core constructs, accents, set/logic
symbols, named functions.
Templated options now typeset their preview through the shared Typst
render queue: the Unicode glyph paints immediately, the compiled SVG
swaps in when ready, and the svg cache makes every later popup
instant. The preview source is the snippet template with its fields
unwrapped (frac(${a}, ${b}) previews as frac(a, b)), so preview and
insertion cannot drift apart. Glyph-only entries (greek, symbols)
keep their exact Unicode form — no compile needed.
… (slice 3)

Extends the table with the remaining everyday families: arrows with their
ASCII shorthands noted in the detail (arrow.r / ->), comparisons (lt.eq,
gt.eq, eq.not), sets (inter, nothing, subset.eq, in.not), circled
operators under their canonical post-0.13 names (plus.o, times.o — the
.circle spellings are deprecated in the bundled compiler), the dif
differential, and text styles (bold, upright, cal, bb) as snippets with
compiled previews. Every name compile-checked against typst 0.15.
@flokchvtr
flokchvtr requested a review from adibhanna as a code owner August 15, 2026 19:08
@adibhanna
adibhanna changed the base branch from main to v2.29.0 August 16, 2026 01:14

@adibhanna adibhanna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against v2.29.0. The completion source is renderer-gated, math-context-scoped, and covered by focused tests. Verified the integrated tree with app-core typechecking, all 1,648 app-core tests, direct compilation of all 25 snippet previews and 120 completion labels using the bundled Typst compiler, and the fresh four-platform CI matrix. No blocking findings.

@adibhanna
adibhanna merged commit 051be00 into ZenNotes:v2.29.0 Aug 16, 2026
4 checks passed
@adibhanna

Copy link
Copy Markdown
Contributor

Reviewed against v2.29.0 and merged in 051be0015d0baae1d2a10c56dbc314146e214f2a.

Verification completed:

  • @zennotes/app-core TypeScript check passed
  • 1,648 app-core tests passed (1 skipped)
  • All 25 snippet previews and 120 completion labels compiled with the bundled Typst compiler
  • Fresh CI passed on macOS, Windows, Ubuntu x64, and Ubuntu ARM

No blocking findings.

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