Typst: resolve CSS generic font families to an installed font - #788
Merged
gordonwoodhull merged 1 commit intoOct 3, 2026
Merged
Conversation
Typst has no generic font families, but typst_css.lua passed `serif`, `sans-serif`, `monospace` and friends straight through, so every compile warned `unknown font family`. `system-ui` and the `ui-*` keywords were not recognized at all. Replace each generic keyword, at its position in the list, with the first available font from an ordered candidate list built from Chromium's per-OS defaults, fontconfig's 60-latin.conf, Modern Font Stacks and Bootstrap's stacks, ending in Typst's bundled fonts so serif, monospace and math always resolve. The keyword is never emitted. If nothing resolves, the keyword is dropped, and an otherwise empty list falls back to Typst's default text font, since Typst rejects an empty font list. No fonts are bundled. Tracked as bd-hkf3r8i1.
Contributor
✅ 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. |
gordonwoodhull
deleted the
feature/bd-hkf3r8i1-typst-generic-font-stacks
branch
October 3, 2026 17:31
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.
Typst has no generic font families, but we passed
serif,sans-serif,monospaceand friends straight through. Any brand or style that used one producedunknown font family: sans-serifwarnings on every compile, and Typst then fell back to whatever it liked.system-uiand theui-*keywords weren't recognized at all, so they were treated as font names.Each generic keyword is now replaced, at its position in the font list, by the first installed font from an ordered candidate list. The lists are built from Chromium's per-OS defaults, fontconfig's
60-latin.conf, Modern Font Stacks and Bootstrap's stacks, with Typst's bundled fonts last soserif,monospaceandmathalways resolve. The keyword itself is never emitted, sofont-family: Roboto, sans-serifbecomesRobotowhen it's installed and otherwise the first installed sans-serif candidate. The candidate lists are intypst_css.luawith their sources cited. No font is bundled.When nothing in a generic's list is installed (realistically
sans-serifon a bare Linux box), the keyword is dropped. If that leaves the list empty, we use Typst's default text font, because Typst rejects an emptyfont: ().generic(...)is dropped, as it has no Typst equivalent.Because the winning font differs per machine, the tests don't assert one. The resolver is a pure function, unit-tested against synthetic font sets. The smoke-all fixtures assert only that no keyword reaches the
.typ. The portedfont-filtering-genericsfixture previously asserted the keyword was preserved, which is the behavior this changes.This is also being backported to quarto-cli: