This master's thesis introduces Typst, a new programmable markup language designed to modernize typesetting by offering a superior alternative to existing systems like TeX/LaTeX and XML-based workflows. The author argues that current tools are either too complex and error-prone (TeX) or too verbose and inflexible for direct authoring (XML), creating a poor user experience. Typst addresses this by integrating lightweight markup with a powerful, yet simple, programming language. Its design is built on strong computational foundations, using a type system with pure functions instead of macros, which eliminates common sources of error and enables clear diagnostics. The language features a composable, two-tiered styling system for both property-based (set rules) and transformational (show rules) customization. A key innovation is its introspection system, which allows code to query the document's structure and element locations, enabling the automatic generation of tables of contents, cross-references, and other dynamic content. The thesis details Typst's language design across computational, presentational, and structural layers and argues that it achieves a unique balance of simplicity and automatability.
Typst: A Modern Approach to Programmable Typesetting
Chapter 1: Introduction: The thesis identifies a gap in typesetting technology. Visual (Wysiwyg) editors lack automatability, while markup-based systems like TeX are powerful but arcane and difficult to use, and alternatives like Markdown are too limited for complex documents. Typst is proposed as a solution that is both user-friendly and highly programmable.
Chapter 2: Background: The document reviews the history and state of markup languages, covering procedural systems (Troff, TeX), descriptive systems (SGML, XML, HTML, LaTeX), and styling languages (CSS, XSL). It establishes the key concepts of separating content from presentation and the difference between property-based and transformational styling, providing context for Typst's design.
Chapter 3: The Typst Language: This chapter provides a user-facing overview of Typst's syntax.
Key Takeaway: Typst combines simple, Markdown-like syntax for common elements (e.g., *bold*, _italic_, = heading) with a consistent function-call syntax (#function(...)) for more complex operations. Markup is merely syntactic sugar for function calls.
Styling: Introduces set rules for applying properties (e.g., font size, color) across a document or scope, and show rules for completely redefining how an element is rendered.
Chapter 4: Computational Layer: The thesis explains Typst's programming model, which is fundamentally different from TeX's macros.
Pure Functions: Typst is built on pure functions and value semantics, which makes code predictable, prevents package conflicts, and enables performance optimizations like caching.
Content Type: A central feature is the content data type, which allows markup and layout elements to be treated as values that can be stored in variables, passed to functions, and composed together.
Joining: Code blocks and loops are designed to "join" the content they produce, making it ergonomic to generate document fragments programmatically.
Chapter 5: Presentational Layer: This section details the tools for visual layout and styling. Typst provides foundational building blocks like text, shapes, and images, along with powerful layout functions like stack and grid. Set rules are explained as the mechanism for context-aware, property-based styling.
Chapter 6: Structural Layer: This layer enables high-level automation by understanding the document's logical structure.
Transformational Styling:Show rules allow for powerful, transformational styling, where a user can define a custom recipe to completely change the appearance of structural elements like headings or lists.
Introspection: Typst features a powerful introspection system using the locate function. This allows code to query the document to find all elements of a certain type (e.g., all figures) or elements with a specific label, along with their final page numbers and positions.
Key Takeaway: Introspection automates complex tasks like generating a table of contents, a list of figures, or handling cross-references. The compiler automatically performs multiple passes to ensure all dependencies are resolved.
Chapter 8: Evaluation: The author evaluates Typst against TeX/LaTeX and XML/CSS, arguing for its superiority in simplicity and automatability.
Simplicity: Typst's consistent syntax, familiar programming model, and robust type system lead to clearer code and significantly more helpful error messages than TeX.
Automatability: Its combination of a real programming language, a composable styling system, and built-in introspection makes automation more powerful, principled, and less error-prone.
Chapter 9: Conclusion: The thesis concludes that Typst successfully presents a modern, simple, and automatable alternative for typesetting. It is designed not just as a language but as a complete ecosystem, with an accompanying web-based editor that provides instant previews, leveraging the compiler's design for incremental updates.