diff --git a/news/changelog-1.9.md b/news/changelog-1.9.md index 14f341aa6d9..30679e759b0 100644 --- a/news/changelog-1.9.md +++ b/news/changelog-1.9.md @@ -41,6 +41,7 @@ All changes included in 1.9: - ([#13555](https://github.com/quarto-dev/quarto-cli/issues/13555)): Add support for `icon=false` in callouts when used in `format: typst`. - ([#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. - ([#13602](https://github.com/quarto-dev/quarto-cli/issues/13602)): Fix support for multiple files set in `bibliography` field in `biblio.typ` template partial. +- ([#13745](https://github.com/quarto-dev/quarto-cli/issues/13745)): Fix relative `font-paths` in custom Typst format extensions not working when the input document is in a subdirectory. Extension font paths are now resolved relative to the input file directory. - ([#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`. - ([#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: - Code syntax highlighting now uses Skylighting by default. diff --git a/src/command/render/output-typst.ts b/src/command/render/output-typst.ts index 83a5b3f9cac..956560f91df 100644 --- a/src/command/render/output-typst.ts +++ b/src/command/render/output-typst.ts @@ -4,7 +4,13 @@ * Copyright (C) 2020-2022 Posit Software, PBC */ -import { dirname, join, normalize, relative } from "../../deno_ral/path.ts"; +import { + dirname, + isAbsolute, + join, + normalize, + relative, +} from "../../deno_ral/path.ts"; import { ensureDirSync, safeRemoveSync } from "../../deno_ral/fs.ts"; import { @@ -63,9 +69,26 @@ export function typstPdfOutputRecipe( // run typst await validateRequiredTypstVersion(); const pdfOutput = join(inputDir, inputStem + ".pdf"); + // Resolve extension font paths to absolute paths since typst compile runs + // from the project root, not the input file's directory. Extension paths + // (containing _extensions or starting with ..) need resolution relative to + // inputDir, while other paths (like .quarto/font-cache) should remain + // relative to the working directory. + const fontPaths = asArray(format.metadata?.[kFontPaths]).map((p) => { + const fontPath = p as string; + if (isAbsolute(fontPath)) { + return fontPath; + } + // Extension-resolved paths need to be resolved relative to input file + if (fontPath.includes("_extensions") || fontPath.startsWith("..")) { + return join(inputDir, fontPath); + } + // Other relative paths (like .quarto/...) stay relative to working dir + return fontPath; + }); const typstOptions: TypstCompileOptions = { quiet: options.flags?.quiet, - fontPaths: asArray(format.metadata?.[kFontPaths]) as string[], + fontPaths, }; if (project?.dir) { typstOptions.rootDir = project.dir; diff --git a/tests/docs/smoke-all/typst/extension-font-paths/_extensions/test-fonts/_extension.yml b/tests/docs/smoke-all/typst/extension-font-paths/_extensions/test-fonts/_extension.yml new file mode 100644 index 00000000000..b5e682eeca9 --- /dev/null +++ b/tests/docs/smoke-all/typst/extension-font-paths/_extensions/test-fonts/_extension.yml @@ -0,0 +1,9 @@ +title: test-fonts +author: Quarto +version: 1.0.0 +quarto-required: ">=1.4.0" +contributes: + formats: + typst: + font-paths: + - fonts diff --git a/tests/docs/smoke-all/typst/extension-font-paths/_extensions/test-fonts/fonts/Amaranth-Regular.ttf b/tests/docs/smoke-all/typst/extension-font-paths/_extensions/test-fonts/fonts/Amaranth-Regular.ttf new file mode 100644 index 00000000000..944ccf7d0a5 Binary files /dev/null and b/tests/docs/smoke-all/typst/extension-font-paths/_extensions/test-fonts/fonts/Amaranth-Regular.ttf differ diff --git a/tests/docs/smoke-all/typst/extension-font-paths/_quarto.yml b/tests/docs/smoke-all/typst/extension-font-paths/_quarto.yml new file mode 100644 index 00000000000..b8bae5830fa --- /dev/null +++ b/tests/docs/smoke-all/typst/extension-font-paths/_quarto.yml @@ -0,0 +1,2 @@ +project: + type: default diff --git a/tests/docs/smoke-all/typst/extension-font-paths/subdir/doc.qmd b/tests/docs/smoke-all/typst/extension-font-paths/subdir/doc.qmd new file mode 100644 index 00000000000..4e2df733d6d --- /dev/null +++ b/tests/docs/smoke-all/typst/extension-font-paths/subdir/doc.qmd @@ -0,0 +1,16 @@ +--- +title: Extension Font Paths Test +format: test-fonts-typst +_quarto: + tests: + typst: + printsMessage: + level: INFO + regex: 'warning: unknown font family' + negate: true +--- + +```{=typst} +#set text(font: "Amaranth") +Testing font from extension with relative font-paths. +```