Improve template styling via overridable Typst functions #92
Merged
istathar merged 11 commits intotechnique-lang:mainfrom Mar 14, 2026
Merged
Improve template styling via overridable Typst functions #92istathar merged 11 commits intotechnique-lang:mainfrom
istathar merged 11 commits intotechnique-lang:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Redesign the rendering pipeline so that Rust walks the domain model and emits calls to thin, individually overridable Typst functions. This replaces the previous code which produced a single large Typst literal and then required the user's template code to process that data structure into markup.
This involved making a change to where the tree-walk of that structure happened. While we were able to do so in Typst (#91) the result was that iterating on the default template was difficult and providing for user overrides of style elements necessitated the user to clone the default template containing machinery that really should have been internal.
Instead we further strengthen the idea of domain to include both the domain model created by the Adapter and the Renderer able to walk such a domain model on the Rust side. Rather than emitting a data dictionary literal, or finished Typst markup, we instead emit a stream of function calls:
#render-description("Hello")#render-structure(":")and so on, with the function names matching the entities the domain's object model.The functions are initially defined in a built-in template that is copied to .domain.typ in the directory containing the document to be rendered. If a custom user-defined template is provided via
--templatethen an#include *directive for it is added to the top of the generated document, allowing that template to selectively override any of the individual render functions without having to reimplement the entire rendering pipeline.