Hey everyone, I’m glad to announce that elembic v1.0.0 is out now on the package manager!
Elembic is a framework for custom elements and types in Typst. It implements this long-awaited feature in pure Typst, so you can use it for your packages and templates right now!
If you’ve used lilaq
before, you’ve already been using it, but now it’s your turn
Check the elembic docs here: Introduction - The Elembic Handbook
It lets you create:
-
Custom elements: Reusable and customizable document components, with support for typechecked fields, show and set rules (without
state
by default, so it is reasonably performant!), reference and outline support, as well as features not yet in Typst such as revokable rules and child element selectors. -
Custom types: Data structures with support for typechecked fields but also custom type casting. They can be used in element fields, but also for your own needs through
e.types.cast(value, type)
.
It is well-suited for:
-
Packages: elembic’s elements allows creating reusable components which can be freely customized by your package’s end users. With typechecking and other features, elembic’s got you covered in terms of flexibility.
-
Templates: elembic’s elements can be used for fine-grained configuration of parts of your template. See e.g. the “Simple Thesis” example.
Note that it has a few limitations - check docs for info!
Here’s a quick example (outputs a purple box):
#import "@preview/elembic:1.0.0" as e: field, types
#let fbox = e.element.declare(
"fbox",
prefix: "@preview/my-package,v1",
doc: "My filled box",
display: it => block(fill: it.fill, inset: 5pt, it.body),
fields: (
field("body", content, doc: "Goes inside the box", required: true),
field("fill", types.option(types.paint), doc: "Fills the box"),
)
)
#show: e.set_(fbox, fill: purple)
#fbox[elembic 1.0]
As a fun fact, elembic’s name comes from “element” + “alembic”, to indicate how elembic aims to experiment with and gather feedback for this feature before it eventually becomes built-in.