generated from typst-community/typst-package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.typ
227 lines (194 loc) · 5.85 KB
/
lib.typ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#import "@preview/ctheorems:1.1.2": *
#let theorem = thmbox(
"theorem",
"Theorem",
supplement: "Thm.",
inset: 0pt,
titlefmt: title => [#smallcaps(title)],
bodyfmt: body => [_ #body _],
)
#let definition = thmbox(
"definition",
"Definition",
supplement: "Def.",
inset: 0pt,
titlefmt: title => [#smallcaps(title)],
bodyfmt: body => [#body],
)
#let lemma = thmbox(
"lemma",
"Lemma",
supplement: "Lem.",
inset: 0pt,
titlefmt: title => [#smallcaps(title)],
bodyfmt: body => [_ #body _],
)
#let proof(body) = block[
_Proof._ #body #h(2em) #sym.rect.v
]
// Reference figures with just "Fig."...
#set figure(numbering: "1", supplement: "Fig.")
// ...but display the full word "Figure" in the figure caption
// (`Figure` instead of `#it.supplement` below)
#show figure.caption : it => [Figure #it.counter.display(it.numbering)#it.separator#it.body]
#import "@preview/lovelace:0.3.0": *
// Thanks @Julian-Wassmann https://github.com/typst/typst/discussions/2280#discussioncomment-7612699
// Use (2.3) for the global 3rd algorithm, in the 2nd section
#let customAlgoNumbering(n, loc) = {
let level1HeadingNumber = counter(heading).at(loc).at(0)
let headingNumbering = numbering("1", level1HeadingNumber)
let algorithmNumbering = numbering("1", n)
text(weight: "thin")[#headingNumbering.#algorithmNumbering] // "thin" seems to cancel out a hard-coded bold formatting somewhere...
}
#let ALGO_SUPPLEMENT = smallcaps(text(weight: "thin")[Algorithm]) // "thin" seems to cancel out a hard-coded bold formatting somewhere...
// outside conf() to be imported in main.typ
#let algorithm(body) = figure(
kind: "algorithm",
supplement: ALGO_SUPPLEMENT,
numbering: n => locate(loc => {
customAlgoNumbering(n, loc)
}),
box[
#body
]
)
#let conf(
title: none,
authors: none,
abstract: none,
doc
) = {
set page(
paper: "us-letter",
margin: 0.85in,
footer: align(
right + top,
text(size: 7pt)[ // https://www.sascha-frank.com/latex-font-size.html for `\scriptsize` & the `article` documentclass
Copyright © 2025 by SIAM\
Unauthorized reproduction of this article is prohibited
]
)
)
set par(justify: true) // sadly, `par` does not have a `all-but-first-line-indent` parameter
set text(
font: "New Computer Modern",
size: 9pt,
)
set footnote(numbering: "*")
set footnote.entry(
separator: line(length: 3em, stroke: 0.5pt)
)
align(center)[
#v(0.7in) // increase top margin on the first page
#text(
size: 14pt, // https://www.sascha-frank.com/latex-font-size.html for `\Large` & the `article` documentclass
title
)
#text(
size: 11pt,
)[
#if type(authors) == str or type(authors) == content {
authors
} else if type(authors) == array {
// from https://typst.app/docs/tutorial/making-a-template/
let count = authors.len()
let ncols = calc.min(count, 3)
grid(
columns: ncols,
column-gutter: 50pt,
row-gutter: 24pt,
..authors.map(author => [
#author.name#footnote(author.affiliation)
]),
)
} else {
panic(str(type(authors)) + " is not a valid type for authors")
}
]
#v(1em)
]
set footnote(numbering: "1")
set heading(numbering: "1.1")
let SPACE_BETWEEN_HEADING_AND_ITS_NUMBER = 0.7em
show heading.where(level: 1): header => {
set text(size: 9pt, weight: "bold")
block(breakable: false)[
// No number in front of "References"
// thanks @laurmaedje https://github.com/typst/typst/discussions/1055#discussioncomment-5770540
#if header.numbering != none [ #counter(heading).display() #h(SPACE_BETWEEN_HEADING_AND_ITS_NUMBER) ]
#header.body
#v(0.5em)
]
}
show heading.where(level: 2): header => {
set text(size: 9pt, weight: "bold")
let number = context counter(heading).display()
box[
#number
#h(SPACE_BETWEEN_HEADING_AND_ITS_NUMBER)
#header.body
] // a box and not a block, to be able to write text on the same line
}
show heading.where(level: 3): header => {
set text(size: 9pt, weight: "bold")
let number = context counter(heading).display()
box[
#number
#h(SPACE_BETWEEN_HEADING_AND_ITS_NUMBER)
#header.body
] // a box and not a block, to be able to write text on the same line
}
// Thanks @Julian-Wassmann https://github.com/typst/typst/discussions/2280#discussioncomment-7612699
// Use (2.3) for the global 3rd equation, in the 2nd section
let customEqNumbering(n, loc) = {
let level1HeadingNumber = counter(heading).at(loc).at(0)
let headingNumbering = numbering("1", level1HeadingNumber)
let equationNumbering = numbering("1", n)
[(#headingNumbering.#equationNumbering)]
}
set math.equation(
numbering: n => locate(loc => {
customEqNumbering(n, loc)
}),
supplement: "Eq.",
number-align: left
)
show: thmrules
show ref: it => {
let el = it.element
if el != none and el.func() == math.equation {
// Override equation references.
let loc = el.location()
let n = counter(math.equation).at(loc).first()
customEqNumbering(n, loc)
}
else if el != none and el.func() == figure {
let fig = el.func()
// strangely, fig.kind is auto, not "figure" or "algorithm"
if el.supplement == ALGO_SUPPLEMENT {
// Override algorithm references.
let loc = el.location()
let n = counter(figure.where(kind: algorithm)).at(loc).first()+1
"Algorithm " + customAlgoNumbering(n, loc)
}
else {
// Reference of other kinds of figures as usual.
it
}
}
else {
// Other references as usual.
it
}
}
columns(
2,
gutter: 10pt
)[
#block(breakable: false)[
#text(weight: "bold")[Abstract]
]
#abstract
#doc
]
}