Hi everyone!
Following up on the TypLens-V1 release, I’m happy to share TypLens V2-Pro (v2.0) — a ground-up rebuild of TypLens that is now live to try at typstpad.com!
TypLens V2-Pro turns screenshots of printed mathematical formulas — from short inline expressions to wide equations, matrices, piecewise cases(...), and multi-line & = derivations — directly into clean, idiomatic Typst.
What’s new in V2-Pro
1. Clean, idiomatic Typst output
In V1/V1.1, outputs often carried verbose conversion artifacts (lr(\( ... \)), upright(i f), extra spaces inside _ ( ... ), and mat(delim: #none, ... zws ;) workarounds for multi-line formulas).
V2-Pro is trained on 974,001 compiler-verified native Typst pairs (verified with Typst 0.15) with a new 4,096-token math-aware byte-level BPE vocabulary. It writes clean & = ... \ alignments, native cases(...), and native mat(...), cutting output token counts by roughly 35%–50% compared to V1.1:
2. Aspect-preserving SigLIP 2 NaFlex encoder + automatic dark mode
V1/V1.1 squashed every crop into a fixed 384×384 square, which hurt wide equations and tall multi-line proofs.
V2-Pro replaces it with a 12-layer google/siglip2-base-patch16-naflex vision encoder folded analytically into a single grayscale luminance channel (max_err = 5.07e-7). Each crop is packed into a dynamic grid of 16×16 patches (up to 1,024 patches, up to 2,048 px per side) preserving its original aspect ratio, and dark-background screenshots (GitHub, VS Code, dark slides) are inverted automatically:
3. Upgraded architecture & compact browser weights
- Architecture (
121.5Mparams): 12-layer grayscale SigLIP 2 NaFlex encoder +Linear(768 → 512) + RMSNorm(512)bridge + 8-layer custom Transformer decoder (d=512, RoPE, GQA8Q/4KV, SwiGLU, RMSNorm,2,048positions). - Three ONNX variants (all WebGPU-safe 2-graph KV-cache exports):
- Compact INT4 (
84.9 MB): Live on TypstPad (runs in multi-threaded WASM in ~1.9 s forcases(...)and ~3.2 s for a 3-line PDE on desktop; also WebGPU-ready in the standalone browser demo). - Balanced INT8 (
130.7 MB): Dynamic per-channelQInt8for WASM / CPU runtimes. - Full FP32 (
486.8 MB): Unquantized reference (max_logit_diff = 4.29e-6vs PyTorch).
- Compact INT4 (
Benchmarks
- Zero-leakage frozen test (
450formulas, document-isolated): 99.33% Typst compile rate, 0.9699 mean visual CDM F1, 82.22% visual exact match (100% compile / 0.9840 CDM F1 even on513+-token formulas). - 12 unseen OOD screenshots (Word Cambria Math, dark mode, warm JPEG PDFs, 1,329 px wide equation, 3-line PDE, 4-line SGD proof): V2-Pro INT4 (
0.8367) vs V1.1 INT8 (0.6258) — +21.1 CDM F1 points, tracking FP32 (0.8427) closely at ~17% of the size.
More live examples (from TypLens V2-Pro INT4 on typstpad.com)
Piecewise cases(...) (34 tokens · 1.86 s):
f(x) = cases(x^2 + 1 & quad "if " x >= 0, -sin(x) & quad "if " x < 0)
3×3 Matrix Eigendecomposition (76 tokens · CDM F1 1.000):
A = Q Lambda Q^(-1) = mat(u_11, u_12, u_13; u_21, u_22, u_23; u_31, u_32, u_33) mat(lambda_1, 0, 0; 0, lambda_2, 0; 0, 0, lambda_3) Q^top
3-Line Navier-Stokes PDE (89 tokens · 3.22 s · CDM F1 1.000):
rho(frac(partial bold(u), partial t) + (bold(u) dot.op nabla) bold(u)) & = - nabla p + mu Delta bold(u) + rho bold(g) \
nabla dot.op bold(u) & = 0, quad "in" Omega times(0, T) \
bold(u) & = bold(0), quad "on" partial Omega times(0, T)
Harder 4-line SGD proof (196 tokens · CDM F1 0.965 — still needs a quick manual touch-up on two norm(...) delimiters):
EE [norm(x_(k + 1) - x^*)_2^2] & = EE [norm(x_k - x^* - alpha_k g_k)_2^2] \
& = norm(x_k - x^*)_2^2 - 2 alpha_k chevron.l nabla f vec(x)_k), x_k - x^* chevron.r + alpha_k^2 EE [norm(g_k)_2^2] \
& <= (1 - 2 mu alpha_k) bar(x)_k - x^*)_2^2 + alpha_k^2 (sigma^2 + L^2 bar(x)_k - x^*)_2^2) \
& <= exp(-mu sum_(j = 0)^k alpha_j) bar(x)_0 - x^*)_2^2 + frac(sigma^2, mu) sum_(j = 0)^k alpha_j^2
Current limitations
This is still an experimental release aimed at single printed formula crops:
- Handwritten formulas and full-page multi-column layout OCR are out of scope.
- Unseen non-Computer-Modern fonts (such as Word Cambria Math italic
x) or very low-resolution crops can still cause subtle symbol/boldness mistakes. - Please always review the generated draft against your image (TypstPad displays an editable draft with live syntax/safety checks before inserting it into the editor).
Try it: https://typstpad.com (click Image to Typst in the editor)
GitHub (inference code & offline browser ZIP): GitHub - dbccccccc/TypLens: The AI model transforming formula image into Typst code. · GitHub
Hugging Face (PyTorch + INT4 / INT8 / FP32 ONNX weights): dbcccc/TypLens · Hugging Face
License: MIT (project code & decoder) + Apache 2.0 (upstream Google SigLIP 2 vision encoder)
I’d love to hear how V2-Pro handles your formulas! Examples where recognition still makes mistakes are especially helpful.
Thanks for giving it a try!



