Skip to content

fix(typst-book): pass brand font paths to typst compile#14517

Merged
cderv merged 2 commits into
mainfrom
fix/typst-book-brand-fonts-14511
May 15, 2026
Merged

fix(typst-book): pass brand font paths to typst compile#14517
cderv merged 2 commits into
mainfrom
fix/typst-book-brand-fonts-14511

Conversation

@cderv
Copy link
Copy Markdown
Member

@cderv cderv commented May 15, 2026

In a Typst book project rendered with brand fonts (e.g. via _brand.yml source: google), the brand font cache directory is added to format.metadata["font-paths"] by resolveExtras but never reaches typst compile. Headings fall back to Libertinus Serif and the render emits an unknown font family warning. Standalone format: typst documents with the same _brand.yml work fine.

Root cause

renderSingleFileBook calls withBookTitleMetadata between recipe construction and renderPandoc, and that helper deep-clones the format. After the clone, recipe.format and the format parameter captured by typstPdfOutputRecipe's complete closure point at different metadata objects.

resolveExtras mutates the post-clone recipe.format.metadata["font-paths"] when it adds the brand font directory. The recipe's complete reads from the pre-clone capture, so the mutation is invisible at compile time. The standalone document path never reaches withBookTitleMetadata, so the reference is preserved.

Fix

Accept the PandocOptions that recipe.complete already receives and read format state from pandocOptions.format (set to recipe.format at render time) instead of the captured parameter. This covers font-paths, pdf-standard, and keep-typ lookups inside complete.

The synchronous variant-resolution block earlier in the recipe still reads from the captured format, which is safe because it runs before renderPandoc. A comment was added there to flag the constraint for future changes.

Test plan

  • Added tests/docs/smoke-all/typst/font-paths/brand-font-paths-book/ reproducing the book + brand-font setup. Bundled Amaranth-Regular.ttf is referenced as the heading font via font-paths so the test stays offline (no source: google download).
  • Standalone Typst rendering with brand fonts unaffected (no behavior change on that path).

Fixes #14511

cderv added 2 commits May 15, 2026 15:48
In a Typst book project rendered with brand fonts, the brand font cache
directory is added to `format.metadata["font-paths"]` by `resolveExtras`
but never reaches `typst compile`, so headings fall back to Libertinus
Serif and the render emits an `unknown font family` warning.

Cause: `renderSingleFileBook` calls `withBookTitleMetadata`, which
deep-clones the format between recipe construction and `renderPandoc`.
The recipe's `complete` callback closed over the pre-clone `format`, so
mutations applied by `resolveExtras` on the post-clone
`recipe.format.metadata` were never observed at compile time. Standalone
typst documents skip `withBookTitleMetadata`, so they were unaffected.

Fix: accept the `PandocOptions` argument that `recipe.complete` receives
and read format state from `pandocOptions.format` (which is set to
`recipe.format` at render time) instead of the captured parameter.
Adds a guidance comment near the variant resolution block in
`typstPdfOutputRecipe` clarifying that it intentionally reads from the
captured `format` parameter (safe because it runs synchronously before
`renderPandoc`), and that any future format-state read AFTER
`renderPandoc` must use `pandocOptions.format` / `recipe.format` — the
trap behind #14511.
@posit-snyk-bot
Copy link
Copy Markdown
Collaborator

posit-snyk-bot commented May 15, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@cderv cderv merged commit 8607f5e into main May 15, 2026
51 checks passed
@cderv cderv deleted the fix/typst-book-brand-fonts-14511 branch May 15, 2026 19:36
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.

typst book: brand fonts downloaded but not passed to typst compile (unknown font family warning)

2 participants