# Typst vs K2F

The **K2F format** relies on a dual-state model: an editable semantic JSON tree (State A) and a compiled, **pixel stable lock** (`document.K2F.lock` / State C) inside a ZIP archive. Rather than compiling executable code on demand, K2F enforces strict separation between content meaning and visual themes.

K2F is not a lossless superset of Typst. K2F v0.1 does not import or parse `.typ` source files, nor does it support embedded code execution, arbitrary programmatic vector drawing in State A, or native academic bibliography management.

## At a glance

| Topic | Typst | K2F |
| :--- | :--- | :--- |
| What the file *is* | Plain-text markup and programming language (`.typ` file) | Semantic JSON tree (State A) + compiled render lock (State C) in a ZIP archive |
| Rendering architecture | On-demand compilation from `.typ` source via Rust compiler engine | Dual-state model: viewers paint pre-compiled `document.K2F.lock` directly without reflowing |
| Node addressing for AI | Text content matching, CST/AST parsing, or optional author labels (`<intro>`) | Mandatory, hierarchical dotted IDs (`parent.child.role`) on every semantic node in State A |
| Multi-format supply chain | Primary output PDF, SVG, PNG (experimental HTML; Word via third-party tools) | Native lock-drawn exports to Microsoft Word (`.docx`), PowerPoint (`.pptx`), PDF AcroForm, Adobe InDesign (`.idml`) |
| Integrity & signatures | External PDF signing; no native package signature or viewer banner contract in format | Cryptographic hashes (`content_hash`, `appearance_hash`), Ed25519 signatures, mandatory viewer integrity banner (`SIGNED`, `UNSIGNED`, `SIGNED_BUT_BROKEN`, `BROKEN_INTEGRITY`, `UNLOCKED`) |
| Scientific & math layout | First-class native LaTeX-grade math typesetting, bibliography engine (CSL / Hayagriva) | Closed-enum semantic `math` modifier; no built-in academic bibliography engine |
| Programmable vector art | Native vector drawing primitives and community libraries (CeTZ) | Forbidden in State A JSON; vector assets stored as external SVG/images in `/assets/` |

## Typst vs K2F: What Typst is good at

Typst excels when human authors or software workflows require code-driven document generation with high mathematical and visual expressiveness:

- **Scientific and academic typesetting:** Native LaTeX-grade math layout engine with clean syntax, paired with built-in bibliography and citation handling (CSL and Hayagriva).
- **Arbitrary vector graphics:** Rich programmatic drawing primitives and ecosystem libraries (such as CeTZ) enable complex diagrams, plots, and figures directly inside source code.
- **Turing-complete scripting:** Built-in programming capabilities—functions, loops, control flow, and variables—allow dynamic template generation and runtime layout math.
- **Blazing compilation speed:** Fast Rust compiler using the `comemo` memoization framework delivers instant incremental compilation and hot-reloading preview feedback.
- **Human-friendly markup syntax:** Significantly cleaner and more readable than LaTeX or XML when written directly by developers in standard text editors or web IDEs.
- **Package ecosystem:** Centralized repository (Typst Universe) offering community-contributed templates and utility packages.

## What K2F adds

K2F is designed for workflows where automated systems and AI agents require strict schema safety, multi-format exports, and verifiable rendering:

- **Declarative semantic tree & stable dotted IDs:** Every node in State A (`content/root.json`) carries a mandatory, hierarchical dotted ID (e.g., `financials.q3_results.table_revenue`). AI agents target and patch specific nodes directly without parsing code syntax or executing script interpreters.
- **Strict intent-presentation separation:** Content nodes express intent through structural roles, variants, and closed-enum semantic byte-range modifiers (`emphasis`, `link`, `math`, etc.). Visual styling (colors, typography, spacing) lives strictly in `styles/theme.json`. Changing themes re-skins the document across all nodes without risking code errors.
- **Pre-compiled pixel-stable lock (`document.K2F.lock`):** The compiled render lock contains exact vector paths, glyph placements, and draw orders. Official web embedders (`<k2f-viewer>`), desktop readers, and export engines paint this lock directly without re-running layout math.
- **Cryptographic provenance & integrity banners:** Package state is hashed (`content_hash`, `appearance_hash`) and optionally signed with Ed25519 (`signatures/v1.json`). Official readers report five canonical integrity states (`SIGNED`, `UNSIGNED`, `SIGNED_BUT_BROKEN`, `BROKEN_INTEGRITY`, `UNLOCKED`) while tracking engine identity mismatches (`ENGINE_MISMATCH`).
- **Multi-format enterprise export pipeline:** Single-source `.K2F` compiles once to generate lock-drawn exports for Microsoft Word (`.docx`), PowerPoint (`.pptx`), fillable AcroForm PDF (`form_field` nodes), and Adobe InDesign (`.idml`). Automated workflows use verification utilities (`pack_verify`) to check package schema compliance before delivery.

## When to pick which

- **Pick Typst when:**
  - Writing academic papers, math-heavy journal articles, or scientific publications requiring native citation management and formula layout.
  - Creating complex programmatic diagrams or vector plots directly inside document markup via CeTZ.
  - Human authors want a fast, text-based code markup syntax with real-time Rust live previews.

- **Pick K2F when:**
  - AI agents generate or edit documents programmatically using stable node IDs with strict JSON schema validation and verification scripts (`pack_verify`).
  - Publishing paged business collateral that must export cleanly to Microsoft Word, PowerPoint, fillable AcroForm PDF, and Adobe InDesign from a single source.
  - Organizations require pre-compiled render locks, theme-based re-skinning without content edits, and cryptographic tamper-evidence banners.

- **Exporting from K2F:**
  - Export PDF, Word, PowerPoint, or IDML from `.K2F` when counterparties require standard office or design deliverables. Export files are unidirectional drawings of the lock, not editable sources of truth (`PDF_IS_NOT_A_SOURCE`, `DOCX_IS_NOT_A_SOURCE`, `PPTX_IS_NOT_A_SOURCE`, `IDML_IS_NOT_A_SOURCE`).

## Bottom line

For additional details on K2F architecture, explore the technical [documentation](/docs), review pre-built templates in the [Gallery](/gallery), read [why K2F exists](/why), or view the full matrix on [Compare](/compare).

This comparison is based on publicly available information at the time of writing. Capabilities, pricing, and policies may change; verify details with the relevant provider.
