Skip to content

Conversation

@breezykermo
Copy link
Contributor

@breezykermo breezykermo commented Jan 13, 2026

Rheo introduces a third supported target to Typst, EPUB. The target function in Typst allows the user to conditionally render based on the output, and we want that ability in Rheo for EPUB.

An important consideration is that one of Rheo's design goals is not to introduce new syntax, as we want a user to be able to take a file out of Typst and, in principle, compile it with the Typst toolchain instead. (We also certainly want all valid Typst files to be valid Rheo files.) EPUB compilation is, however, a feature that only exists in Rheo.

This PR implements EPUB target detection using Typst's inputs mechanism. Rheo sets sys.inputs.rheo-target to "epub", "html", or "pdf" during compilation via LibraryBuilder::with_inputs(). For user convenience, rheo also injects a target() polyfill during EPUB compilation:

#let target() = if "rheo-target" in sys.inputs { sys.inputs.rheo-target } else { std.target() }

This allows users to write natural Typst code like if target() == "epub" without any special imports or syntax in code that will be compiled by rheo.

For library developers: The target() polyfill is syntactic sugar that shadows the local function name. Packages that call std.target() (which is common practice to access the "real" target) will bypass the polyfill and see "html" (the underlying compilation target for EPUB). Library authors who want to support rheo's EPUB detection should check sys.inputs.rheo-target directly:

#let get-format() = if "rheo-target" in sys.inputs { sys.inputs.rheo-target } else { target() }

This pattern gracefully degrades in vanilla Typst, where sys.inputs exists but won't contain the rheo-target key.

@breezykermo breezykermo marked this pull request as ready for review January 13, 2026 15:03
@breezykermo breezykermo changed the title Return "epub" from target() Adds mechanism to conditionally check EPUB Jan 16, 2026
@breezykermo breezykermo merged commit f41fc21 into dev Jan 16, 2026
1 check passed
@breezykermo breezykermo deleted the feat/target-epub branch January 16, 2026 21:10
breezykermo added a commit that referenced this pull request Jan 25, 2026
* Adds mechanism to conditionally check EPUB (#68)

* Updates git submodules to latest

* Updates git submodules to latest

* Returns "epub" in target() during EPUB compilation

* Updates git submodules to latest

* Extracts XHTML content from EPUB archives for testing

* Saves EPUB XHTML content to reference files during test updates

* Verifies EPUB XHTML content against reference files during tests

* Tests target() function behavior in imported modules

* Adds XHTML reference files for all EPUB tests

* Updates EPUB module reference output to desired behavior

* Injects target() override into all Typst files during EPUB compilation

* Tests target() override in Typst Universe packages

* Uses sys.inputs for EPUB target detection instead of target() override

* Documents sys.inputs.rheo-target pattern for EPUB detection

* Injects target() polyfill using sys.inputs for EPUB compilation

* Documents sys.inputs.rheo-target for library developers

* Updates git submodules to latest

* Fixes lints

* Updates git submodules to latest

* Renders <br/> tags as self-closing in EPUB (#70)

* Renders <br/> tags in EPUB

* Fixes lints

* Corrects doc links in README (#76)

* Defaults to reasonable font (#77)

* Defaults to reasonable font

This is necessary for MacOS.

* Use Times New Roman as a default font

* Release 0.1.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants