Skip to content

Commit 22a1428

Browse files
Skip empty title block in Typst template to prevent spurious blank page
When a document has no title, authors, date, or abstract, the article() template unconditionally emitted a place(top, float: true, ...) with an empty block. This counted as content, so a subsequent raw #set page(...) in the document body triggered a page break in Typst, producing a blank first page. Guard the place() call so it is only emitted when there is actual title block content. Fixes #14217
1 parent ffd1914 commit 22a1428

File tree

2 files changed

+80
-49
lines changed

2 files changed

+80
-49
lines changed

src/resources/formats/typst/pandoc/quarto/typst-template.typ

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -61,61 +61,64 @@
6161
}
6262
}
6363

64-
place(
65-
top,
66-
float: true,
67-
scope: "parent",
68-
clearance: 4mm,
69-
block(below: 1em, width: 100%)[
64+
let has-title-block = title != none or (authors != none and authors != ()) or date != none or abstract != none
65+
if has-title-block {
66+
place(
67+
top,
68+
float: true,
69+
scope: "parent",
70+
clearance: 4mm,
71+
block(below: 1em, width: 100%)[
7072

71-
#if title != none {
72-
align(center, block(inset: 2em)[
73-
#set par(leading: heading-line-height) if heading-line-height != none
74-
#set text(font: heading-family) if heading-family != none
75-
#set text(weight: heading-weight)
76-
#set text(style: heading-style) if heading-style != "normal"
77-
#set text(fill: heading-color) if heading-color != black
73+
#if title != none {
74+
align(center, block(inset: 2em)[
75+
#set par(leading: heading-line-height) if heading-line-height != none
76+
#set text(font: heading-family) if heading-family != none
77+
#set text(weight: heading-weight)
78+
#set text(style: heading-style) if heading-style != "normal"
79+
#set text(fill: heading-color) if heading-color != black
7880

79-
#text(size: title-size)[#title #if thanks != none {
80-
footnote(thanks, numbering: "*")
81-
counter(footnote).update(n => n - 1)
82-
}]
83-
#(if subtitle != none {
84-
parbreak()
85-
text(size: subtitle-size)[#subtitle]
86-
})
87-
])
88-
}
81+
#text(size: title-size)[#title #if thanks != none {
82+
footnote(thanks, numbering: "*")
83+
counter(footnote).update(n => n - 1)
84+
}]
85+
#(if subtitle != none {
86+
parbreak()
87+
text(size: subtitle-size)[#subtitle]
88+
})
89+
])
90+
}
8991

90-
#if authors != none and authors != () {
91-
let count = authors.len()
92-
let ncols = calc.min(count, 3)
93-
grid(
94-
columns: (1fr,) * ncols,
95-
row-gutter: 1.5em,
96-
..authors.map(author =>
97-
align(center)[
98-
#author.name \
99-
#author.affiliation \
100-
#author.email
101-
]
92+
#if authors != none and authors != () {
93+
let count = authors.len()
94+
let ncols = calc.min(count, 3)
95+
grid(
96+
columns: (1fr,) * ncols,
97+
row-gutter: 1.5em,
98+
..authors.map(author =>
99+
align(center)[
100+
#author.name \
101+
#author.affiliation \
102+
#author.email
103+
]
104+
)
102105
)
103-
)
104-
}
106+
}
105107

106-
#if date != none {
107-
align(center)[#block(inset: 1em)[
108-
#date
109-
]]
110-
}
108+
#if date != none {
109+
align(center)[#block(inset: 1em)[
110+
#date
111+
]]
112+
}
111113

112-
#if abstract != none {
113-
block(inset: 2em)[
114-
#text(weight: "semibold")[#abstract-title] #h(1em) #abstract
115-
]
116-
}
117-
]
118-
)
114+
#if abstract != none {
115+
block(inset: 2em)[
116+
#text(weight: "semibold")[#abstract-title] #h(1em) #abstract
117+
]
118+
}
119+
]
120+
)
121+
}
119122

120123
if toc {
121124
let title = if toc_title == none {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
format:
3+
typst:
4+
keep-typ: true
5+
_quarto:
6+
tests:
7+
typst:
8+
ensurePdfTextPositions:
9+
- # Body text should be on page 1 (no spurious blank page before it)
10+
- subject: "BODY_CONTENT_START"
11+
relation: above
12+
object:
13+
role: "Page"
14+
page: 1
15+
edge: bottom
16+
- []
17+
noErrors: default
18+
---
19+
20+
```{=typst}
21+
#set page(footer: none)
22+
```
23+
24+
BODY_CONTENT_START
25+
26+
| a | b |
27+
|---|---|
28+
| 1 | 2 |

0 commit comments

Comments
 (0)