Skip to content

fix: neutralise inline code in title scaffolds for Typst output#13

Open
mcanouil wants to merge 5 commits intomainfrom
fix/title-scaffold-inline-code
Open

fix: neutralise inline code in title scaffolds for Typst output#13
mcanouil wants to merge 5 commits intomainfrom
fix/title-scaffold-inline-code

Conversation

@mcanouil
Copy link
Owner

Quarto wraps theorem/example titles in __quarto_custom_scaffold Divs with inline-only content. Both the code-window box wrapping and Pandoc's Skylighting convert inline Code elements to Typst function calls (#box(...), #NormalTok(...)) that get stringified as literal text when Quarto renders the title parameter as title: "...".

The global Code filter is replaced with a selective document walk. Title scaffolds (scaffold Divs containing only Plain/Para blocks) get inline code converted to plain Typst backtick code (\text``), preserving correct rendering inside string parameters. All other contexts continue to receive the full background box styling.

Works with both syntax-highlighting: idiomatic and syntax-highlighting: github.

Quarto wraps theorem/example titles in __quarto_custom_scaffold Divs
with inline-only content. Both the code-window box wrapping and Pandoc's
Skylighting generate Typst function calls (#box(...), #NormalTok(...))
that get stringified as literal text when Quarto renders the title
parameter as a string.

Replace the global Code filter with a selective document walk that
converts Code to plain Typst backtick code inside title scaffolds and
applies the full box styling everywhere else.
@mcanouil mcanouil added the Type: Bug 🐛 Issues related to bugs, errors, or mistakes label Mar 24, 2026
@mcanouil mcanouil self-assigned this Mar 24, 2026
Quarto renders custom type titles as title: "..." (string mode) which
stringifies any Typst markup. Inline code in titles produces Skylighting
tokens with inner quotes that break the Typst string syntax.

Two-part fix:
- Pre-quarto: convert Code in title scaffolds to plain Typst backtick
  code, avoiding Skylighting tokens that contain unescaped quotes.
- Post-quarto: inject a Typst override of simple-theorem-render that
  evaluates string titles with eval(mode: "markup"), giving title: [...]
  semantics even though Quarto emits title: "...".
The previous approach redefined simple-theorem-render, but make-frame
captures the render function by value at definition time, so the
override had no effect.

Instead, scan the Typst preamble for make-frame definitions, extract
the generated function names (e.g., example, theorem), and inject
wrapper functions that evaluate string title parameters with
eval(mode: "markup") before delegating to the original function.
header-includes is placed before template definitions in the Typst
preamble, so the theorem functions are not yet defined. RawBlocks
inserted into doc.blocks appear after the template preamble, where
make-frame has already created the theorem functions.

Also scan the source file for cross-reference div IDs (e.g., #exm-,
#thm-) to determine which theorem functions to wrap, since this
information is not available in the AST at filter time.
Each hotfix can now have its own quarto-version threshold for
auto-disable, since upstream fixes are unlikely to land in the same
Quarto release. The hotfix value can be a boolean or a map with
enabled and quarto-version keys:

  hotfix:
    code-annotations:
      quarto-version: "1.10.0"
    skylighting:
      quarto-version: "1.11.0"
    typst-title:
      quarto-version: "1.10.0"

The global quarto-version key is still supported as a fallback.
Add typst-title as a new hotfix key for the theorem title fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug 🐛 Issues related to bugs, errors, or mistakes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant