fix(typst-book): pass brand font paths to typst compile#14517
Merged
Conversation
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.
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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.
In a Typst book project rendered with brand fonts (e.g. via
_brand.ymlsource: google), the brand font cache directory is added toformat.metadata["font-paths"]byresolveExtrasbut never reachestypst compile. Headings fall back to Libertinus Serif and the render emits anunknown font familywarning. Standaloneformat: typstdocuments with the same_brand.ymlwork fine.Root cause
renderSingleFileBookcallswithBookTitleMetadatabetween recipe construction andrenderPandoc, and that helper deep-clones the format. After the clone,recipe.formatand theformatparameter captured bytypstPdfOutputRecipe'scompleteclosure point at different metadata objects.resolveExtrasmutates the post-clonerecipe.format.metadata["font-paths"]when it adds the brand font directory. The recipe'scompletereads from the pre-clone capture, so the mutation is invisible at compile time. The standalone document path never reacheswithBookTitleMetadata, so the reference is preserved.Fix
Accept the
PandocOptionsthatrecipe.completealready receives and read format state frompandocOptions.format(set torecipe.formatat render time) instead of the captured parameter. This coversfont-paths,pdf-standard, andkeep-typlookups insidecomplete.The synchronous variant-resolution block earlier in the recipe still reads from the captured
format, which is safe because it runs beforerenderPandoc. A comment was added there to flag the constraint for future changes.Test plan
tests/docs/smoke-all/typst/font-paths/brand-font-paths-book/reproducing the book + brand-font setup. BundledAmaranth-Regular.ttfis referenced as the heading font viafont-pathsso the test stays offline (nosource: googledownload).Fixes #14511