From d6a61669b596318a8b61d04562ffa9259b2604c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Fri, 13 Feb 2026 12:27:32 +0100 Subject: [PATCH 1/6] fix: Title misaligned in Typst output Fixes #14031 --- .../typst/pandoc/quarto/typst-template.typ | 93 ++++++++++--------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/src/resources/formats/typst/pandoc/quarto/typst-template.typ b/src/resources/formats/typst/pandoc/quarto/typst-template.typ index a1c80798c60..0a2e69bc55a 100644 --- a/src/resources/formats/typst/pandoc/quarto/typst-template.typ +++ b/src/resources/formats/typst/pandoc/quarto/typst-template.typ @@ -61,54 +61,61 @@ } } - place(top, float: true, scope: "parent", clearance: 4mm)[ - #if title != none { - align(center, block(inset: 2em)[ - #set par(leading: heading-line-height) if heading-line-height != none - #set text(font: heading-family) if heading-family != none - #set text(weight: heading-weight) - #set text(style: heading-style) if heading-style != "normal" - #set text(fill: heading-color) if heading-color != black + place( + top, + float: true, + scope: "parent", + clearance: 4mm, + block(below: 1em, width: 100%)[ - #text(size: title-size)[#title #if thanks != none { - footnote(thanks, numbering: "*") - counter(footnote).update(n => n - 1) - }] - #(if subtitle != none { - parbreak() - text(size: subtitle-size)[#subtitle] - }) - ]) - } + #if title != none { + align(center, block(inset: 2em)[ + #set par(leading: heading-line-height) if heading-line-height != none + #set text(font: heading-family) if heading-family != none + #set text(weight: heading-weight) + #set text(style: heading-style) if heading-style != "normal" + #set text(fill: heading-color) if heading-color != black + + #text(size: title-size)[#title #if thanks != none { + footnote(thanks, numbering: "*") + counter(footnote).update(n => n - 1) + }] + #(if subtitle != none { + parbreak() + text(size: subtitle-size)[#subtitle] + }) + ]) + } - #if authors != none and authors != () { - let count = authors.len() - let ncols = calc.min(count, 3) - grid( - columns: (1fr,) * ncols, - row-gutter: 1.5em, - ..authors.map(author => - align(center)[ - #author.name \ - #author.affiliation \ - #author.email - ] + #if authors != none and authors != () { + let count = authors.len() + let ncols = calc.min(count, 3) + grid( + columns: (1fr,) * ncols, + row-gutter: 1.5em, + ..authors.map(author => + align(center)[ + #author.name \ + #author.affiliation \ + #author.email + ] + ) ) - ) - } + } - #if date != none { - align(center)[#block(inset: 1em)[ - #date - ]] - } + #if date != none { + align(center)[#block(inset: 1em)[ + #date + ]] + } - #if abstract != none { - block(inset: 2em)[ - #text(weight: "semibold")[#abstract-title] #h(1em) #abstract - ] - } - ] + #if abstract != none { + block(inset: 2em)[ + #text(weight: "semibold")[#abstract-title] #h(1em) #abstract + ] + } + ] + ) if toc { let title = if toc_title == none { From bee3739256d377a68f625fe2fab8856cc220bd9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Fri, 13 Feb 2026 12:58:58 +0100 Subject: [PATCH 2/6] test: update pattern --- tests/docs/smoke-all/typst/columns/basic-two-column.qmd | 2 +- tests/docs/smoke-all/typst/columns/two-column-landscape.qmd | 2 +- tests/docs/smoke-all/typst/columns/two-column-title-block.qmd | 2 +- tests/docs/smoke-all/typst/columns/two-column-toc.qmd | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/docs/smoke-all/typst/columns/basic-two-column.qmd b/tests/docs/smoke-all/typst/columns/basic-two-column.qmd index de3e923e0b5..fedc6c7b496 100644 --- a/tests/docs/smoke-all/typst/columns/basic-two-column.qmd +++ b/tests/docs/smoke-all/typst/columns/basic-two-column.qmd @@ -12,7 +12,7 @@ _quarto: # Page columns set via set page() - 'columns: 2,' # Title block wrapped with place(scope: "parent") for column spanning - - 'place\(top, float: true, scope: "parent", clearance: 4mm\)' + - 'place\(top, float: true, scope: "parent", clearance: 4mm, block\(below: 1em, width: 100%\)' - # Patterns that must NOT be found # Should NOT have columns() function call wrapping doc at end of article() - 'columns\(cols, doc\)\n\}' diff --git a/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd b/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd index fb33b2582f1..897afced718 100644 --- a/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd +++ b/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd @@ -22,7 +22,7 @@ _quarto: # Page columns set via set page() - 'columns: 2,' # Title block wrapped with place(scope: "parent") for column spanning - - 'place\(top, float: true, scope: "parent", clearance: 4mm\)' + - 'place\(top, float: true, scope: "parent", clearance: 4mm, block\(below: 1em, width: 100%\)' # Landscape page start - '#set page\(flipped: true\)' # Landscape page end diff --git a/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd b/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd index f7c2addf061..c1e7aa93a32 100644 --- a/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd +++ b/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd @@ -30,7 +30,7 @@ _quarto: # Page columns set via set page() - 'columns: 2,' # Title block wrapped with place(scope: "parent") for column spanning - - 'place\(top, float: true, scope: "parent", clearance: 4mm\)' + - 'place\(top, float: true, scope: "parent", clearance: 4mm, block\(below: 1em, width: 100%\)' # Title passed to article() - 'title: \[Two Column with Full Title Block\]' # Subtitle passed to article() diff --git a/tests/docs/smoke-all/typst/columns/two-column-toc.qmd b/tests/docs/smoke-all/typst/columns/two-column-toc.qmd index e3e2f6c29a1..443ed894904 100644 --- a/tests/docs/smoke-all/typst/columns/two-column-toc.qmd +++ b/tests/docs/smoke-all/typst/columns/two-column-toc.qmd @@ -16,7 +16,7 @@ _quarto: # Page columns set via set page() - 'columns: 2,' # Title block wrapped with place(scope: "parent") for column spanning - - 'place\(top, float: true, scope: "parent", clearance: 4mm\)' + - 'place\(top, float: true, scope: "parent", clearance: 4mm, block\(below: 1em, width: 100%\)' # TOC enabled in article() call - 'toc: true' # TOC title passed From cf0d8e03b0a83eef9a8f73a27412f634e86c9bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Fri, 13 Feb 2026 12:59:22 +0100 Subject: [PATCH 3/6] test: PDF utility for vertical/horizontal centering --- tests/smoke/verify/pdf-text-position.test.ts | 37 ++++++++++++++++++++ tests/verify-pdf-text-position.ts | 6 +++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/smoke/verify/pdf-text-position.test.ts b/tests/smoke/verify/pdf-text-position.test.ts index 3a967b56b2f..a414535badb 100644 --- a/tests/smoke/verify/pdf-text-position.test.ts +++ b/tests/smoke/verify/pdf-text-position.test.ts @@ -53,6 +53,7 @@ testQuartoCmd("render", [fixtureQmd, "--to", "typst"], [], { await runDistanceConstraintTests(); await runDistanceConstraintErrorTests(); await runPageRoleWithEdgeTests(); + await runCenterEdgeTests(); // Cleanup if (safeExistsSync(fixturePdf)) { @@ -575,3 +576,39 @@ async function runPageRoleWithEdgeTests() { ]); await headerNearPageTop.verify([]); } + +/** + * Test centerX and centerY edge functionality + */ +async function runCenterEdgeTests() { + // Test: centerX - title's horizontal centre should align with page's horizontal centre + const centerXPageTest = ensurePdfTextPositions(fixturePdf, [ + { + subject: { text: "FIXTURE_TITLE_TEXT", edge: "centerX" }, + relation: "leftAligned", + object: { role: "Page", page: 1, edge: "centerX" }, + tolerance: 20, + }, + ]); + await centerXPageTest.verify([]); + + // Test: centerY directional - header decoration's centerY should be above title's centerY + const centerYDirectionalTest = ensurePdfTextPositions(fixturePdf, [ + { + subject: { text: "FIXTURE_HEADER_TEXT", role: "Decoration", edge: "centerY" }, + relation: "above", + object: { text: "FIXTURE_TITLE_TEXT", edge: "centerY" }, + }, + ]); + await centerYDirectionalTest.verify([]); + + // Test: centerX directional - a left-aligned heading's centerX should be leftOf page centerX + const centerXDirectionalTest = ensurePdfTextPositions(fixturePdf, [ + { + subject: { text: "FIXTURE_H1_TEXT", edge: "centerX" }, + relation: "leftOf", + object: { role: "Page", page: 1, edge: "centerX" }, + }, + ]); + await centerXDirectionalTest.verify([]); +} diff --git a/tests/verify-pdf-text-position.ts b/tests/verify-pdf-text-position.ts index 7a60ee2ee9c..86dab3273f3 100644 --- a/tests/verify-pdf-text-position.ts +++ b/tests/verify-pdf-text-position.ts @@ -40,7 +40,7 @@ import { ExecuteOutput, Verify } from "./test.ts"; // ============================================================================ // Edge schema for precise bbox edge selection -export const EdgeSchema = z.enum(["left", "right", "top", "bottom"]); +export const EdgeSchema = z.enum(["left", "right", "top", "bottom", "centerX", "centerY"]); export type Edge = z.infer; // Relation schemas @@ -215,6 +215,10 @@ function getEdgeValue(bbox: BBox, edge: Edge): number { return bbox.y; case "bottom": return bbox.y + bbox.height; + case "centerX": + return bbox.x + bbox.width / 2; + case "centerY": + return bbox.y + bbox.height / 2; } } From 33dccadb422f5cf8e27c1e691f2b70bc1f30c116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Fri, 13 Feb 2026 12:59:40 +0100 Subject: [PATCH 4/6] test: horizontal centering checks --- .../typst/columns/basic-two-column.qmd | 10 ++++++++++ .../typst/columns/two-column-landscape.qmd | 19 +++++++++++++++++++ .../typst/columns/two-column-title-block.qmd | 19 +++++++++++++++++++ .../typst/columns/two-column-toc.qmd | 10 ++++++++++ 4 files changed, 58 insertions(+) diff --git a/tests/docs/smoke-all/typst/columns/basic-two-column.qmd b/tests/docs/smoke-all/typst/columns/basic-two-column.qmd index fedc6c7b496..bf8b2e4409b 100644 --- a/tests/docs/smoke-all/typst/columns/basic-two-column.qmd +++ b/tests/docs/smoke-all/typst/columns/basic-two-column.qmd @@ -16,6 +16,16 @@ _quarto: - # Patterns that must NOT be found # Should NOT have columns() function call wrapping doc at end of article() - 'columns\(cols, doc\)\n\}' + ensurePdfTextPositions: + - - subject: + text: "Basic Two Column Layout" + edge: centerX + relation: leftAligned + object: + role: Page + page: 1 + edge: centerX + tolerance: 5 --- ## Introduction diff --git a/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd b/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd index 897afced718..778e6d2cc05 100644 --- a/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd +++ b/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd @@ -30,6 +30,25 @@ _quarto: - # Patterns that must NOT be found # Should NOT have columns() function call wrapping doc at end of article() - 'columns\(cols, doc\)\n\}' + ensurePdfTextPositions: + - - subject: + text: "Two Column with Landscape Section" + edge: centerX + relation: leftAligned + object: + role: Page + page: 1 + edge: centerX + tolerance: 5 + - subject: + text: "Testing Column Layout with Page Orientation Changes" + edge: centerX + relation: leftAligned + object: + role: Page + page: 1 + edge: centerX + tolerance: 5 --- ## Introduction diff --git a/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd b/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd index c1e7aa93a32..edcadada639 100644 --- a/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd +++ b/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd @@ -44,6 +44,25 @@ _quarto: - # Patterns that must NOT be found # Should NOT have columns() function call wrapping doc at end of article() - 'columns\(cols, doc\)\n\}' + ensurePdfTextPositions: + - - subject: + text: "Two Column with Full Title Block" + edge: centerX + relation: leftAligned + object: + role: Page + page: 1 + edge: centerX + tolerance: 5 + - subject: + text: "Testing Column-Spanning Title Elements" + edge: centerX + relation: leftAligned + object: + role: Page + page: 1 + edge: centerX + tolerance: 5 --- ## Introduction diff --git a/tests/docs/smoke-all/typst/columns/two-column-toc.qmd b/tests/docs/smoke-all/typst/columns/two-column-toc.qmd index 443ed894904..fc1de233543 100644 --- a/tests/docs/smoke-all/typst/columns/two-column-toc.qmd +++ b/tests/docs/smoke-all/typst/columns/two-column-toc.qmd @@ -28,6 +28,16 @@ _quarto: - # Patterns that must NOT be found # Should NOT have columns() function call wrapping doc at end of article() - 'columns\(cols, doc\)\n\}' + ensurePdfTextPositions: + - - subject: + text: "Two Column with Table of Contents" + edge: centerX + relation: leftAligned + object: + role: Page + page: 1 + edge: centerX + tolerance: 5 --- ## Introduction From 67a1352064b09f9ffcc3e98d4345847376171345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Fri, 13 Feb 2026 14:07:01 +0100 Subject: [PATCH 5/6] test: update regex and tolerance for inset --- tests/docs/smoke-all/typst/columns/basic-two-column.qmd | 2 +- tests/docs/smoke-all/typst/columns/two-column-landscape.qmd | 6 +++--- .../docs/smoke-all/typst/columns/two-column-title-block.qmd | 6 +++--- tests/docs/smoke-all/typst/columns/two-column-toc.qmd | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/docs/smoke-all/typst/columns/basic-two-column.qmd b/tests/docs/smoke-all/typst/columns/basic-two-column.qmd index bf8b2e4409b..8b2c0920952 100644 --- a/tests/docs/smoke-all/typst/columns/basic-two-column.qmd +++ b/tests/docs/smoke-all/typst/columns/basic-two-column.qmd @@ -12,7 +12,7 @@ _quarto: # Page columns set via set page() - 'columns: 2,' # Title block wrapped with place(scope: "parent") for column spanning - - 'place\(top, float: true, scope: "parent", clearance: 4mm, block\(below: 1em, width: 100%\)' + - 'place\(\s+top,\s+float: true,\s+scope: "parent",\s+clearance: 4mm,\s+block\(below: 1em, width: 100%\)' - # Patterns that must NOT be found # Should NOT have columns() function call wrapping doc at end of article() - 'columns\(cols, doc\)\n\}' diff --git a/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd b/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd index 778e6d2cc05..c9853ef144d 100644 --- a/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd +++ b/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd @@ -22,7 +22,7 @@ _quarto: # Page columns set via set page() - 'columns: 2,' # Title block wrapped with place(scope: "parent") for column spanning - - 'place\(top, float: true, scope: "parent", clearance: 4mm, block\(below: 1em, width: 100%\)' + - 'place\(\s+top,\s+float: true,\s+scope: "parent",\s+clearance: 4mm,\s+block\(below: 1em, width: 100%\)' # Landscape page start - '#set page\(flipped: true\)' # Landscape page end @@ -39,7 +39,7 @@ _quarto: role: Page page: 1 edge: centerX - tolerance: 5 + tolerance: 22 - subject: text: "Testing Column Layout with Page Orientation Changes" edge: centerX @@ -48,7 +48,7 @@ _quarto: role: Page page: 1 edge: centerX - tolerance: 5 + tolerance: 22 --- ## Introduction diff --git a/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd b/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd index edcadada639..391d8029261 100644 --- a/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd +++ b/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd @@ -30,7 +30,7 @@ _quarto: # Page columns set via set page() - 'columns: 2,' # Title block wrapped with place(scope: "parent") for column spanning - - 'place\(top, float: true, scope: "parent", clearance: 4mm, block\(below: 1em, width: 100%\)' + - 'place\(\s+top,\s+float: true,\s+scope: "parent",\s+clearance: 4mm,\s+block\(below: 1em, width: 100%\)' # Title passed to article() - 'title: \[Two Column with Full Title Block\]' # Subtitle passed to article() @@ -53,7 +53,7 @@ _quarto: role: Page page: 1 edge: centerX - tolerance: 5 + tolerance: 22 - subject: text: "Testing Column-Spanning Title Elements" edge: centerX @@ -62,7 +62,7 @@ _quarto: role: Page page: 1 edge: centerX - tolerance: 5 + tolerance: 22 --- ## Introduction diff --git a/tests/docs/smoke-all/typst/columns/two-column-toc.qmd b/tests/docs/smoke-all/typst/columns/two-column-toc.qmd index fc1de233543..05b867a5a8d 100644 --- a/tests/docs/smoke-all/typst/columns/two-column-toc.qmd +++ b/tests/docs/smoke-all/typst/columns/two-column-toc.qmd @@ -16,7 +16,7 @@ _quarto: # Page columns set via set page() - 'columns: 2,' # Title block wrapped with place(scope: "parent") for column spanning - - 'place\(top, float: true, scope: "parent", clearance: 4mm, block\(below: 1em, width: 100%\)' + - 'place\(\s+top,\s+float: true,\s+scope: "parent",\s+clearance: 4mm,\s+block\(below: 1em, width: 100%\)' # TOC enabled in article() call - 'toc: true' # TOC title passed @@ -37,7 +37,7 @@ _quarto: role: Page page: 1 edge: centerX - tolerance: 5 + tolerance: 22 --- ## Introduction From 140436c7a3620aff867cc0185e14be5b43ad084c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Fri, 13 Feb 2026 14:07:45 +0100 Subject: [PATCH 6/6] fix: adjust tolerance for centerX alignment test --- tests/smoke/verify/pdf-text-position.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/smoke/verify/pdf-text-position.test.ts b/tests/smoke/verify/pdf-text-position.test.ts index a414535badb..2f40fa0e26d 100644 --- a/tests/smoke/verify/pdf-text-position.test.ts +++ b/tests/smoke/verify/pdf-text-position.test.ts @@ -581,13 +581,13 @@ async function runPageRoleWithEdgeTests() { * Test centerX and centerY edge functionality */ async function runCenterEdgeTests() { - // Test: centerX - title's horizontal centre should align with page's horizontal centre + // Test: centerX - title's horizontal centre should be near page's horizontal centre (inset tolerance for minor misalignment) const centerXPageTest = ensurePdfTextPositions(fixturePdf, [ { subject: { text: "FIXTURE_TITLE_TEXT", edge: "centerX" }, relation: "leftAligned", object: { role: "Page", page: 1, edge: "centerX" }, - tolerance: 20, + tolerance: 35, }, ]); await centerXPageTest.verify([]);