Skip to content

Commit 200b7c0

Browse files
Add features to typst base template
add linestretch (aka leading) in par add linestretch to test add font pieces add link colors Avoid english "and" -> in favor of "&" fix writer test typst template fix whitespace don't set fonts explicitly better conditional, remove colors too fix brace filecolor / place were lost in merge. fixes that remove duplicate line, fix place spacing should be a block, not a place handle $abstract-title$ Update MANUAL.txt
1 parent 103c26a commit 200b7c0

File tree

4 files changed

+164
-75
lines changed

4 files changed

+164
-75
lines changed

MANUAL.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2728,7 +2728,7 @@ Currently the following pipes are predefined:
27282728
documents
27292729

27302730
`abstract-title`
2731-
: title of abstract, currently used only in HTML, EPUB, and docx.
2731+
: title of abstract, currently used only in HTML, EPUB, docx, and Typst.
27322732
This will be set automatically to a localized value,
27332733
depending on `lang`, but can be manually overridden.
27342734

@@ -3391,6 +3391,19 @@ The `--css` option also affects the output.
33913391
`columns`
33923392
: Number of columns for body text.
33933393

3394+
`thanks`
3395+
: contents of acknowledgments footnote after document title
3396+
3397+
`mathfont`, `codefont`
3398+
: Name of system font to use for math and code, respectively.
3399+
3400+
`linestretch`
3401+
: adjusts line spacing, e.g. `1.25`, `1.5`
3402+
3403+
`linkcolor`, `filecolor`, `citecolor`
3404+
: color for external links, internal links, and citation links,
3405+
respectively: expects a hexadecimal color code
3406+
33943407
### Variables for ms
33953408

33963409
`fontfamily`

data/templates/default.typst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,15 @@ $endif$
7171
$if(region)$
7272
region: "$region$",
7373
$endif$
74+
$if(abstract-title)$
75+
abstract-title: [$abstract-title$],
76+
$endif$
7477
$if(abstract)$
7578
abstract: [$abstract$],
7679
$endif$
80+
$if(thanks)$
81+
thanks: [$thanks$],
82+
$endif$
7783
$if(margin)$
7884
margin: ($for(margin/pairs)$$margin.key$: $margin.value$,$endfor$),
7985
$endif$
@@ -86,10 +92,28 @@ $endif$
8692
$if(fontsize)$
8793
fontsize: $fontsize$,
8894
$endif$
95+
$if(mathfont)$
96+
mathfont: ($for(mathfont)$"$mathfont$",$endfor$),
97+
$endif$
98+
$if(codefont)$
99+
codefont: ($for(codefont)$"$codefont$",$endfor$),
100+
$endif$
101+
$if(linestretch)$
102+
linestretch: $linestretch$,
103+
$endif$
89104
$if(section-numbering)$
90105
sectionnumbering: "$section-numbering$",
91106
$endif$
92107
pagenumbering: $if(page-numbering)$"$page-numbering$"$else$none$endif$,
108+
$if(linkcolor)$
109+
linkcolor: [$linkcolor$],
110+
$endif$
111+
$if(citecolor)$
112+
citecolor: [$citecolor$],
113+
$endif$
114+
$if(filecolor)$
115+
filecolor: [$filecolor$],
116+
$endif$
93117
cols: $if(columns)$$columns$$else$1$endif$,
94118
doc,
95119
)

data/templates/template.typst

Lines changed: 63 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,74 +15,100 @@
1515
authors: (),
1616
keywords: (),
1717
date: none,
18+
abstract-title: none,
1819
abstract: none,
20+
thanks: none,
1921
cols: 1,
2022
margin: (x: 1.25in, y: 1.25in),
2123
paper: "us-letter",
2224
lang: "en",
2325
region: "US",
2426
font: (),
2527
fontsize: 11pt,
28+
mathfont: none,
29+
codefont: none,
30+
linestretch: 1,
2631
sectionnumbering: none,
32+
linkcolor: none,
33+
citecolor: none,
34+
filecolor: none,
2735
pagenumbering: "1",
2836
doc,
2937
) = {
3038
set document(
3139
title: title,
32-
author: authors.map(author => content-to-string(author.name)),
40+
author: authors.map(author => content-to-string(author.name)).join(", ", last: " & "),
3341
keywords: keywords,
3442
)
3543
set page(
3644
paper: paper,
3745
margin: margin,
3846
numbering: pagenumbering,
39-
columns: cols,
40-
)
41-
set par(justify: true)
47+
)
48+
49+
set par(
50+
justify: true,
51+
leading: linestretch * 0.65em
52+
)
4253
set text(lang: lang,
4354
region: region,
4455
font: font,
4556
size: fontsize)
57+
58+
show math.equation: set text(font: mathfont) if mathfont != none
59+
show raw: set text(font: codefont) if codefont != none
60+
4661
set heading(numbering: sectionnumbering)
4762

48-
place(top, float: true, scope: "parent", clearance: 4mm)[
49-
#if title != none {
50-
align(center)[#block(inset: 2em)[
51-
#text(weight: "bold", size: 1.5em)[#title]
52-
#(if subtitle != none {
53-
parbreak()
54-
text(weight: "bold", size: 1.25em)[#subtitle]
55-
})
56-
]]
63+
show link: set text(fill: rgb(content-to-string(linkcolor))) if linkcolor != none
64+
show ref: set text(fill: rgb(content-to-string(citecolor))) if citecolor != none
65+
show link: this => {
66+
if filecolor != none and type(this.dest) == label {
67+
text(this, fill: rgb(content-to-string(filecolor)))
68+
}
5769
}
5870

59-
#if authors != none and authors != [] {
60-
let count = authors.len()
61-
let ncols = calc.min(count, 3)
62-
grid(
63-
columns: (1fr,) * ncols,
64-
row-gutter: 1.5em,
65-
..authors.map(author =>
66-
align(center)[
67-
#author.name \
68-
#author.affiliation \
69-
#author.email
70-
]
71+
block(below: 4mm)[
72+
#if title != none {
73+
align(center)[#block(inset: 2em)[
74+
#text(weight: "bold", size: 1.5em)[#title #if thanks != none {
75+
footnote(thanks, numbering: "*")
76+
counter(footnote).update(n => n - 1)
77+
}]
78+
#(
79+
if subtitle != none {
80+
parbreak()
81+
text(weight: "bold", size: 1.25em)[#subtitle]
82+
}
83+
)
84+
]]
85+
}
86+
87+
#if authors != none and authors != [] {
88+
let count = authors.len()
89+
let ncols = calc.min(count, 3)
90+
grid(
91+
columns: (1fr,) * ncols,
92+
row-gutter: 1.5em,
93+
..authors.map(author => align(center)[
94+
#author.name \
95+
#author.affiliation \
96+
#author.email
97+
])
7198
)
72-
)
73-
}
99+
}
74100

75-
#if date != none {
76-
align(center)[#block(inset: 1em)[
77-
#date
78-
]]
79-
}
101+
#if date != none {
102+
align(center)[#block(inset: 1em)[
103+
#date
104+
]]
105+
}
80106

81-
#if abstract != none {
82-
block(inset: 2em)[
83-
#text(weight: "semibold")[Abstract] #h(1em) #abstract
84-
]
85-
}
107+
#if abstract != none {
108+
block(inset: 2em)[
109+
#text(weight: "semibold")[#abstract-title] #h(1em) #abstract
110+
]
111+
}
86112
]
87113

88114
doc

test/writer.typst

Lines changed: 63 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,74 +39,100 @@
3939
authors: (),
4040
keywords: (),
4141
date: none,
42+
abstract-title: none,
4243
abstract: none,
44+
thanks: none,
4345
cols: 1,
4446
margin: (x: 1.25in, y: 1.25in),
4547
paper: "us-letter",
4648
lang: "en",
4749
region: "US",
4850
font: (),
4951
fontsize: 11pt,
52+
mathfont: none,
53+
codefont: none,
54+
linestretch: 1,
5055
sectionnumbering: none,
56+
linkcolor: none,
57+
citecolor: none,
58+
filecolor: none,
5159
pagenumbering: "1",
5260
doc,
5361
) = {
5462
set document(
5563
title: title,
56-
author: authors.map(author => content-to-string(author.name)),
64+
author: authors.map(author => content-to-string(author.name)).join(", ", last: " & "),
5765
keywords: keywords,
5866
)
5967
set page(
6068
paper: paper,
6169
margin: margin,
6270
numbering: pagenumbering,
63-
columns: cols,
64-
)
65-
set par(justify: true)
71+
)
72+
73+
set par(
74+
justify: true,
75+
leading: linestretch * 0.65em
76+
)
6677
set text(lang: lang,
6778
region: region,
6879
font: font,
6980
size: fontsize)
81+
82+
show math.equation: set text(font: mathfont) if mathfont != none
83+
show raw: set text(font: codefont) if codefont != none
84+
7085
set heading(numbering: sectionnumbering)
7186

72-
place(top, float: true, scope: "parent", clearance: 4mm)[
73-
#if title != none {
74-
align(center)[#block(inset: 2em)[
75-
#text(weight: "bold", size: 1.5em)[#title]
76-
#(if subtitle != none {
77-
parbreak()
78-
text(weight: "bold", size: 1.25em)[#subtitle]
79-
})
80-
]]
87+
show link: set text(fill: rgb(content-to-string(linkcolor))) if linkcolor != none
88+
show ref: set text(fill: rgb(content-to-string(citecolor))) if citecolor != none
89+
show link: this => {
90+
if filecolor != none and type(this.dest) == label {
91+
text(this, fill: rgb(content-to-string(filecolor)))
92+
}
8193
}
8294

83-
#if authors != none and authors != [] {
84-
let count = authors.len()
85-
let ncols = calc.min(count, 3)
86-
grid(
87-
columns: (1fr,) * ncols,
88-
row-gutter: 1.5em,
89-
..authors.map(author =>
90-
align(center)[
91-
#author.name \
92-
#author.affiliation \
93-
#author.email
94-
]
95+
block(below: 4mm)[
96+
#if title != none {
97+
align(center)[#block(inset: 2em)[
98+
#text(weight: "bold", size: 1.5em)[#title #if thanks != none {
99+
footnote(thanks, numbering: "*")
100+
counter(footnote).update(n => n - 1)
101+
}]
102+
#(
103+
if subtitle != none {
104+
parbreak()
105+
text(weight: "bold", size: 1.25em)[#subtitle]
106+
}
107+
)
108+
]]
109+
}
110+
111+
#if authors != none and authors != [] {
112+
let count = authors.len()
113+
let ncols = calc.min(count, 3)
114+
grid(
115+
columns: (1fr,) * ncols,
116+
row-gutter: 1.5em,
117+
..authors.map(author => align(center)[
118+
#author.name \
119+
#author.affiliation \
120+
#author.email
121+
])
95122
)
96-
)
97-
}
123+
}
98124

99-
#if date != none {
100-
align(center)[#block(inset: 1em)[
101-
#date
102-
]]
103-
}
125+
#if date != none {
126+
align(center)[#block(inset: 1em)[
127+
#date
128+
]]
129+
}
104130

105-
#if abstract != none {
106-
block(inset: 2em)[
107-
#text(weight: "semibold")[Abstract] #h(1em) #abstract
108-
]
109-
}
131+
#if abstract != none {
132+
block(inset: 2em)[
133+
#text(weight: "semibold")[#abstract-title] #h(1em) #abstract
134+
]
135+
}
110136
]
111137

112138
doc

0 commit comments

Comments
 (0)