This workflow is great until I need to actually generate an industry-standard screenplay PDF. I got tired of manually copying and pasting my text back into the clunky software just to export it, so I decided to write a script to automate the process. That's when I hit a wall.
I tried using React-pdf and other high-level libraries, but they failed me on two fronts: true multilingual text shaping, and complex contextual pagination. Specifically, the strict screenplay requirement to automatically inject (MORE) at the bottom of a page and (CONT'D) at the top of the next page when a character's dialogue is split across a page break.
You can't really do that elegantly when the layout engine is a black box. So, I bypassed them and built my own typesetting engine from scratch.
VMPrint is a deterministic, zero-browser layout VM written in pure TypeScript. It abandons the DOM entirely. It loads OpenType fonts, runs grapheme-accurate text segmentation (Intl.Segmenter), calculates interval-arithmetic spatial boundaries for text wrapping, and outputs a flat array of absolute coordinates.
Some stats:
Zero dependencies on Node.js APIs or the DOM (runs in Cloudflare Workers, Lambda, browser).
88 KiB core packed.
Performance: On a Snapdragon Elite ARM chip, the engine's "God Fixture" (8 pages of mixed CJK, Arabic RTL, drop caps, and multi-page spanning tables) completes layout and rendering in ~28ms.
The repo also includes draft2final, the CLI tool I built to convert Markdown into publication-grade PDFs (including the screenplay flavor) using this engine.
This is my first open-source launch. The manuscript is still waiting, but the engine shipped instead. I’d love to hear your thoughts, answer any questions about the math or the architecture, and see if anyone else finds this useful!
--- A note on AI usage: To be fully transparent about how this was built, I engineered the core concept (an all-flat, morphable box-based system inspired by game engines, applied to page layouts), the interval-arithmetic math, the grapheme segmentation, and the layout logic entirely by hand. I did use AI as a coding assistant at the functional level, but the overall software architecture, component structures, and APIs were meticulously designed by me.
For a little background: I’ve been a professional systems engineer since 1992. I’ve worked as a senior system architect for several Fortune 500 companies and currently serve as Chief Scientist at a major telecom infrastructure provider. I also created one of the world's first real-time video encoding technologies for low-power mobile phones (in the pre-smartphone era). I'm no stranger to deep tech, and a deterministic layout VM is exactly the kind of strict, math-heavy system that simply cannot be effectively constructed with a few lines of AI prompts.
flexagoon•2h ago
cosmiciron•1h ago
The core differences come down to the runtime environment and the integration paradigm:
1. Edge-Native vs. WASM: Typst is written in Rust. To run it in a serverless environment, you have to ship and instantiate a WebAssembly binary. In strict Edge environments (like Cloudflare Workers or Vercel Edge) where bundle sizes and cold starts are heavily penalized, WASM can be a bottleneck. VMPrint is an 88 KiB pure-JS engine. It drops natively into any V8/Edge runtime with zero WASM bridge, allowing you to synchronously generate and stream deterministic PDFs directly from the edge in milliseconds.
2. Programmatic AST vs. Custom Markup: Typst is a markup compiler—you write in its .typ language. VMPrint is a lower-level layout VM. It doesn't parse markup; it consumes a flat JSON instruction stream (an AST) and spits out absolute X/Y coordinates. It's designed for developers who want to build their own custom document generators programmatically, rather than writing a document by hand.
3. Mid-Flight Pagination Control: My specific pain point was screenplays. I needed strict contextual rules, like automatically injecting (MORE) at the bottom of a page and (CONT'D) at the top of the next if a dialogue block splits across a page break. Achieving that kind of hyper-specific programmatic intervention is tough in a closed compiler. With VMPrint's two-stage pipeline, you have absolute access to the layout tree in native JS to manipulate it before it ever hits the renderer.
In short: if you want a beautiful, incredibly fast LaTeX replacement to write documents, use Typst. If you are a JS developer who needs to build a custom document pipeline and wants a lightweight, native layout VM to run the heavy math at the edge, that's VMPrint.