Skip to content

Commit 35a1646

Browse files
committed
Extract typst title block into a partial
1 parent 241155a commit 35a1646

File tree

4 files changed

+82
-48
lines changed

4 files changed

+82
-48
lines changed

src/format/typst/format-typst.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export function typstFormat(): Format {
9292
"definitions.typ",
9393
"typst-template.typ",
9494
"typst-show.typ",
95+
"typst-title.typ",
9596
"notes.typ",
9697
"biblio.typ",
9798
].map((partial) => join(templateDir, partial)),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
$definitions.typ()$
22

3+
$typst-title.typ()$
4+
35
$typst-template.typ()$
46

57
$for(header-includes)$

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

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,55 +39,21 @@
3939
font: font,
4040
size: fontsize)
4141
set heading(numbering: sectionnumbering)
42-
if title != none {
43-
align(center)[#block(inset: 2em)[
44-
#set par(leading: heading-line-height)
45-
#if (heading-family != none or heading-weight != "bold" or heading-style != "normal"
46-
or heading-color != black or heading-decoration == "underline"
47-
or heading-background-color != none) {
48-
set text(font: heading-family, weight: heading-weight, style: heading-style, fill: heading-color)
49-
text(size: title-size)[#title]
50-
if subtitle != none {
51-
parbreak()
52-
text(size: subtitle-size)[#subtitle]
53-
}
54-
} else {
55-
text(weight: "bold", size: title-size)[#title]
56-
if subtitle != none {
57-
parbreak()
58-
text(weight: "bold", size: subtitle-size)[#subtitle]
59-
}
60-
}
61-
]]
62-
}
63-
64-
if authors != none {
65-
let count = authors.len()
66-
let ncols = calc.min(count, 3)
67-
grid(
68-
columns: (1fr,) * ncols,
69-
row-gutter: 1.5em,
70-
..authors.map(author =>
71-
align(center)[
72-
#author.name \
73-
#author.affiliation \
74-
#author.email
75-
]
76-
)
77-
)
78-
}
79-
80-
if date != none {
81-
align(center)[#block(inset: 1em)[
82-
#date
83-
]]
84-
}
8542

86-
if abstract != none {
87-
block(inset: 2em)[
88-
#text(weight: "semibold")[#abstract-title] #h(1em) #abstract
89-
]
90-
}
43+
title_block(
44+
title: title,
45+
subtitle: subtitle,
46+
authors: authors,
47+
date: date,
48+
abstract: abstract,
49+
title-size: title-size,
50+
subtitle-size: subtitle-size,
51+
heading-family: heading-family,
52+
heading-weight: heading-weight,
53+
heading-style: heading-style,
54+
heading-color: heading-color,
55+
heading-line-height: heading-line-height
56+
)
9157

9258
if toc {
9359
let title = if toc_title == none {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#let title_block(
2+
title: none,
3+
subtitle: none,
4+
authors: none,
5+
date: none,
6+
abstract: none,
7+
title-size: none,
8+
subtitle-size: none,
9+
heading-family: none,
10+
heading-weight: none,
11+
heading-style: none,
12+
heading-color: none,
13+
heading-line-height: none
14+
) = {
15+
if title != none {
16+
align(center)[#block(inset: 2em)[
17+
#set par(leading: heading-line-height)
18+
#if (heading-family != none or heading-weight != "bold" or heading-style != "normal"
19+
or heading-color != black or heading-decoration == "underline"
20+
or heading-background-color != none) {
21+
set text(font: heading-family, weight: heading-weight, style: heading-style, fill: heading-color)
22+
text(size: title-size)[#title]
23+
if subtitle != none {
24+
parbreak()
25+
text(size: subtitle-size)[#subtitle]
26+
}
27+
} else {
28+
text(weight: "bold", size: title-size)[#title]
29+
if subtitle != none {
30+
parbreak()
31+
text(weight: "bold", size: subtitle-size)[#subtitle]
32+
}
33+
}
34+
]]
35+
}
36+
37+
if authors != none {
38+
let count = authors.len()
39+
let ncols = calc.min(count, 3)
40+
grid(
41+
columns: (1fr,) * ncols,
42+
row-gutter: 1.5em,
43+
..authors.map(author =>
44+
align(center)[
45+
#author.name \
46+
#author.affiliation \
47+
#author.email
48+
]
49+
)
50+
)
51+
}
52+
53+
if date != none {
54+
align(center)[#block(inset: 1em)[
55+
#date
56+
]]
57+
}
58+
59+
if abstract != none {
60+
block(inset: 2em)[
61+
#text(weight: "semibold")[#abstract-title] #h(1em) #abstract
62+
]
63+
}
64+
}
65+

0 commit comments

Comments
 (0)