Skip to content

typst book: TOC entries, links, and heading numbers unreadable when brand primary is a bright color #14510

Open

Description

@cderv

Description

In a Typst book project with a _brand.yml that sets a bright primary color (and a separate foreground for body text), the bundled orange-book extension applies brand.primary as the text fill for:

  • TOC entries (chapter and section names, plus chapter/section numbers)
  • All links
  • Heading numbers for level 2+ headings (e.g. 1.1)
  • Citations

These elements become unreadable when primary is a bright color, even though foreground is set to a readable text color and is correctly applied to body text and chapter heading titles.

Body text and chapter heading titles (level 1) are correct — they pick up brand.foreground via the #set text(fill: brand-color.foreground) rule and the #show heading: set text(fill: foreground) rule emitted by typst-brand-yaml.lua. The unreadable elements bypass that wiring and read main-color directly.

Reproduction

_quarto.yml:

project:
  type: book

brand: _brand.yml

book:
  title: "Reproduction"
  chapters:
    - index.qmd
    - chapter1.qmd

format:
  typst: default

_brand.yml — bright yellow primary, dark foreground on cream background:

color:
  palette:
    sw-yellow: "#FFE81F"
    sw-black: "#0B0B0F"
    sw-cream: "#F5F0E1"
  primary: sw-yellow
  foreground: sw-black
  background: sw-cream

index.qmd:

# Preface {.unnumbered}

This contains a [link to Quarto](https://quarto.org).

chapter1.qmd:

# First chapter

A paragraph with a [link](https://quarto.org).

## A sub-section

Body text.

Render with quarto render. The cover renders correctly (pale yellow band with dark title), but on subsequent pages every TOC entry and every link renders in yellow on the cream page background, and the 1.1 heading number renders in yellow.

Three layers involved

To make the discussion concrete, three layers of code participate:

  1. The Lua filter typst-brand-yaml.lua reads _brand.yml and emits the Typst header that declares #let brand-color = (...), #set text(fill: brand-color.foreground), and the #show link rule.

  2. Quarto's orange-book wrapper (typst-show.typ under src/resources/extension-subtrees/orange-book/_extensions/orange-book/) is Quarto-controlled Typst code that consumes brand-color and calls into the upstream package. This is the natural place for any Quarto-specific brand wiring.

  3. The upstream Typst package @preview/orange-book:0.7.1 is vendored at src/resources/extension-subtrees/orange-book/_extensions/orange-book/typst/packages/preview/orange-book/0.7.1/. The bundled copy can be modified, but doing so diverges from the published package on typst.app/universe; any later update of the vendored copy would have to re-apply local patches (or have them upstreamed).

Where main-color is read in the upstream package

Layer 2 — Quarto's wrapper — wires a single main-color parameter from brand.primary:

main-color: brand-color.at("primary", default: blue),

Inside layer 3 — the bundled book() function — main-color is used for both decorative roles (cover tint, heading box strokes, theorem strokes, exercise box borders, lighten() backgrounds) and text-fill roles. There is no separate parameter for text fill:

#let book(title: "", subtitle: "", date: "", author: (), paper-size: "a4", width: none, height: none, margin: (x: 3cm, bottom: 2.5cm, top: 3cm), logo: none, cover: none, cover-background: auto, image-index:none, body, main-color: blue, copyright: [], lang: "en", list-of-figure-title: none, list-of-table-title: none, supplement-chapter: "Chapter", supplement-part: "Part", font-size: 10pt, part-style: 0, part-font-size: auto, lowercase-references: false, padded-heading-number: true, outline-font-size: auto, outline-small-depth: 2, outline-small-width: 9.5cm, heading-style: 0, first-line-indent: true, outline-depth: 3) = {

Text-fill uses of main-color in the upstream package:

The upstream book() already has a cover-background: auto parameter that decouples the cover tint from main-color, but typst-show.typ does not set it and no equivalent parameter exists for text fills.

Why this is hard to work around

Users cannot redefine brand-color before the orange-book template reads it. The Quarto-generated header places user include-in-header content before the brand-color let declaration emitted by typst-brand-yaml.lua, so a user document has no entry point to override main-color.

The only known workaround is to ship a local override extension that replaces the bundled typst-show.typ (using the local extension override added in #14332) and passes a different main-color. That requires the user to know about the bundled extension's existence.

Where the fix can live

Two options, in order of how much they touch layer 3 (the vendored upstream package):

Option 1 — Layer 2 only (Quarto wrapper). Change typst-show.typ to pass main-color: brand-color.at("foreground", default: black) and explicitly pass cover-background: brand-color.at("primary", default: blue).lighten(70%) to preserve the cover tint. Pure layer-2 change, no divergence from upstream. Trade-off: every other use of main-color (heading box strokes, theorem strokes, exercise borders, line() stroke under heading-style 2) becomes the foreground color — the brand accent is lost for those decorative elements.

Option 2 — Layer 2 plus layer 3. Add a text-color parameter to book() (defaulting to main-color for backward compatibility) and route the text-fill uses (TOC entries, heading numbers, link text, citation text) through it. Pass text-color: brand-color.at("foreground", default: black) from typst-show.typ. Result: text becomes readable, decorative uses keep the brand accent.

Option 2 means modifying book() in lib.typ (and the corresponding signatures in my-outline.typ). That change has to land somewhere — and there are two non-exclusive ways to ship it:

  • Patch the vendored copy of the package at src/resources/extension-subtrees/orange-book/_extensions/orange-book/typst/packages/preview/orange-book/0.7.1/. Fix ships in the next Quarto release; the local copy diverges from upstream until the vendored version is bumped to one that incorporates the change.
  • Contribute the parameter upstream at https://github.com/flavio20002/typst-orange-template and wait for a published version that includes it. No local divergence, but the fix waits on upstream's release cadence (last push 2026-01-30, so the repo is active but not on a fast cadence).

The two are compatible: patch the vendored copy now to unblock users, contribute upstream in parallel, drop the local patch when the vendored version is bumped.

Option 1 is purely a Quarto-side change and may be acceptable as an interim mitigation, but Option 2 produces the cleanest visual outcome.

Related

Activity

  1. added
    themes
    on May 13, 2026
  2. gordonwoodhull commented on May 13, 2026

    @gordonwoodhull
    Member

    I think we should contribute a fix upstream (option 3). If the maintainer doesn't want it, we can also fork the Typst package and import it @local.

    There are a few other changes in this category, like a11y and integration with Marginalia. Let's plan on making changes to the template in the Quarto 1.10 timeframe, one way or the other.

    As discussed, although this would technically work, it is not the proper way to use typst-gather:

    • Patch the vendored copy of the package at src/resources/extension-subtrees/orange-book/_extensions/orange-book/typst/packages/preview/orange-book/0.7.1/. Fix ships in the next Quarto release; the local copy diverges from upstream until the vendored version is bumped to one that incorporates the change.

    Instead, fork the typst template and import it as @local instead of @preview (using a distinct version number for good measure). Declare it in typst-gather.yml so that it's picked up from your local copy.

    Otherwise you are implying that orange-book@0.7.1 on Typst Preview has content which is different from what is published.

  3. added
    enhancement
    on May 13, 2026
  4. cderv commented on May 13, 2026

    @cderv
    MemberAuthor

    Instead, fork the typst template and import it as @Local instead of @Preview (using a distinct version number for good measure). Declare it in typst-gather.yml so that it's picked up from your local copy.

    Otherwise you are implying that orange-book@0.7.1 on Typst Preview has content which is different from what is published

    Ok I understand what you mean. I need to experiment it to really get to the bottom of it. But this is clearer. Thank you !

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    booksenhancementthemestypst

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions