Skip to content

Commit ee3417f

Browse files
claude: resolve relative font-paths to absolute for typst
Fixes #13745 Relative font-paths (from extensions, document metadata, or project config) were passed unchanged to the typst CLI --font-path argument. Typst resolves these relative to its CWD, not the document directory, causing "unknown font family" errors when documents are in project subdirectories. Resolve relative font-paths against the document directory in output-typst.ts before passing them to typstCompile. Absolute paths (from brand.yaml or already-resolved project-absolute paths) pass through unchanged. Adds three smoke tests covering extension font-paths, document font-paths from a subdirectory, and brand font-paths from a subdirectory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c792ec2 commit ee3417f

15 files changed

Lines changed: 101 additions & 2 deletions

File tree

‎src/command/render/output-typst.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
* Copyright (C) 2020-2022 Posit Software, PBC
55
*/
66

7-
import { dirname, join, normalize, relative } from "../../deno_ral/path.ts";
7+
import {
8+
dirname,
9+
isAbsolute,
10+
join,
11+
normalize,
12+
relative,
13+
resolve,
14+
} from "../../deno_ral/path.ts";
815
import {
916
copySync,
1017
ensureDirSync,
@@ -146,7 +153,9 @@ export function typstPdfOutputRecipe(
146153
const pdfOutput = join(inputDir, inputStem + ".pdf");
147154
const typstOptions: TypstCompileOptions = {
148155
quiet: options.flags?.quiet,
149-
fontPaths: asArray(format.metadata?.[kFontPaths]) as string[],
156+
fontPaths: (asArray(format.metadata?.[kFontPaths]) as string[]).map(
157+
(p) => isAbsolute(p) ? p : resolve(inputDir, p),
158+
),
150159
pdfStandard: normalizePdfStandardForTypst(
151160
asArray(
152161
format.render?.[kPdfStandard] ?? format.metadata?.[kPdfStandard],
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.quarto/
2+
**/*.quarto_ipynb
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project:
2+
type: default
3+
brand: branding/brand.yml
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
typography:
2+
fonts:
3+
- family: "Amaranth"
4+
source: file
5+
files:
6+
- fonts/Amaranth-Regular.ttf
7+
base:
8+
family: Amaranth
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: "Brand font-paths from subdirectory"
3+
format: typst
4+
include-in-header:
5+
text: |
6+
#set text(fallback: false)
7+
_quarto:
8+
tests:
9+
typst:
10+
printsMessage:
11+
level: INFO
12+
regex: 'warning: unknown font family'
13+
negate: true
14+
---
15+
16+
```{=typst}
17+
#set text(font: "Amaranth")
18+
Testing brand font-paths from a subdirectory.
19+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.quarto/
2+
**/*.quarto_ipynb
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
title: Font Provider Extension
2+
author: Test
3+
version: 1.0.0
4+
quarto-required: ">=99.9.0"
5+
contributes:
6+
formats:
7+
typst:
8+
font-paths:
9+
- fonts
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project:
2+
type: default

0 commit comments

Comments
 (0)