Skip to content

Commit baf8fec

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. Two changes: - output-typst.ts: resolve relative font-paths against the document directory before passing them to typstCompile - pandoc.ts: ensure brand font directories are absolute so they work regardless of CWD 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 <[email protected]>
1 parent c792ec2 commit baf8fec

17 files changed

Lines changed: 111 additions & 5 deletions

File tree

news/changelog-1.9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ All changes included in 1.9:
5959
- ([#13555](https://github.com/quarto-dev/quarto-cli/issues/13555)): Add support for `icon=false` in callouts when used in `format: typst`.
6060
- ([#13589](https://github.com/quarto-dev/quarto-cli/issues/13589)): Fix callouts with invalid ID prefixes crashing with "attempt to index a nil value". Callouts with unknown reference types now render as non-crossreferenceable callouts with a warning, ignoring the invalid ID.
6161
- ([#13602](https://github.com/quarto-dev/quarto-cli/issues/13602)): Fix support for multiple files set in `bibliography` field in `biblio.typ` template partial.
62+
- ([#13745](https://github.com/quarto-dev/quarto-cli/issues/13745)): Fix relative `font-paths` from extensions or document metadata not resolving correctly for Typst compilation. Relative paths are now resolved against the document directory before being passed to the Typst CLI.
6263
- ([#13775](https://github.com/quarto-dev/quarto-cli/issues/13775)): Fix brand fonts not being applied when using `citeproc: true` with Typst format. Format detection now properly handles Pandoc format variants like `typst-citations`.
6364
- ([#13868](https://github.com/quarto-dev/quarto-cli/issues/13868)): Add image alt text support for PDF/UA accessibility. Alt text from markdown captions and explicit `alt` attributes is now passed to Typst's `image()` function. (Temporary workaround until [jgm/pandoc#11394](https://github.com/jgm/pandoc/pull/11394) is merged.)
6465
- ([#13249](https://github.com/quarto-dev/quarto-cli/pull/13249)): Update to Pandoc's Typst template following Pandoc 3.8.3 and Typst 0.14.2 support:

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],

src/command/render/pandoc.ts

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

7-
import { basename, dirname, isAbsolute, join } from "../../deno_ral/path.ts";
7+
import {
8+
basename,
9+
dirname,
10+
isAbsolute,
11+
join,
12+
resolve,
13+
} from "../../deno_ral/path.ts";
814

915
import { info, warning } from "../../deno_ral/log.ts";
1016

@@ -99,7 +105,6 @@ import {
99105
kFormatResources,
100106
kFrom,
101107
kHighlightStyle,
102-
kSyntaxHighlighting,
103108
kHtmlMathMethod,
104109
kIncludeAfterBody,
105110
kIncludeBeforeBody,
@@ -125,6 +130,7 @@ import {
125130
kSectionTitleAbstract,
126131
kSelfContained,
127132
kSyntaxDefinitions,
133+
kSyntaxHighlighting,
128134
kTemplate,
129135
kTheme,
130136
kTitle,
@@ -1529,7 +1535,7 @@ async function resolveExtras(
15291535
const font = Zod.BrandFontFile.parse(_font);
15301536
for (const file of font.files || []) {
15311537
const path = typeof file === "object" ? file.path : file;
1532-
fontdirs.add(dirname(join(brand.brandDir, path)));
1538+
fontdirs.add(resolve(dirname(join(brand.brandDir, path))));
15331539
}
15341540
} else if (source === "bunny") {
15351541
const font = Zod.BrandFontBunny.parse(_font);
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

0 commit comments

Comments
 (0)