-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlib.typ
329 lines (297 loc) · 7.84 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// global
#import "@preview/great-theorems:0.1.1": great-theorems-init
#import "@preview/hydra:0.5.2": hydra
#import "@preview/equate:0.3.0": equate
#import "@preview/i-figured:0.2.4": reset-counters, show-equation
#let template(
// personal/subject related stuff
author: "Stuart Dent",
title: "My Very Fancy and Good-Looking Thesis About Interesting Stuff",
supervisor1: "Prof. Dr. Sue Persmart",
supervisor2: "Prof. Dr. Ian Telligent",
degree: "Example",
program: "Example-Studies",
university: "Example University",
institute: "Example Institute",
deadline: datetime.today().display(),
city: "Example City",
// file paths for logos etc.
uni-logo: none,
institute-logo: none,
// formatting settings
body-font: "Libertinus Serif",
cover-font: "Libertinus Serif",
// content that needs to be placed differently then normal chapters
abstract: none,
// colors
cover-color: rgb("#800080"),
heading-color: rgb("#0000ff"),
link-color: rgb("#000000"),
// equation settings
equate-settings: none,
equation-numbering-pattern: "(1.1)",
// the content of the thesis
body
) = {
// ------------------- settings -------------------
set document(author: author, title: title)
set heading(numbering: "1.1") // Heading numbering
set enum(numbering: "(i)") // Enumerated lists
show link: set text(fill: link-color)
show ref: set text(fill: link-color)
// ------------------- Math equation settings -------------------
// either use equate if equate-settings is set or use i-figured if equate-settings is none
// i-figured settings
show math.equation: it => {
if equate-settings == none {
show-equation(prefix: "eq:", only-labeled: true, numbering: equation-numbering-pattern, it)
} else {
it
}
}
set math.equation(supplement: none) if equate-settings == none
// equate settings
show: it => {
if equate-settings != none {
equate(..equate-settings, it)
} else {
it
}
}
set math.equation(numbering: equation-numbering-pattern) if equate-settings != none
// Reference equations with parentheses (for equate)
// cf. https://forum.typst.app/t/how-can-i-set-numbering-for-sub-equations/1603/4
show ref: it => {
let eq = math.equation
let el = it.element
let is-normal-equation = el != none and el.func() == eq
let with-subnumbers = equate-settings != none and equate-settings.keys().contains("sub-numbering") and equate-settings.sub-numbering
let is-sub-equation = el != none and el.func() == figure and el.kind == eq
if equate-settings != none and is-normal-equation {
link(el.location(), numbering(
el.numbering,
..counter(eq).at(el.location())
))
} else if equate-settings != none and not with-subnumbers and is-sub-equation {
link(el.location(), numbering(
el.numbering,
counter(eq).at(el.location()).at(0) - 1
))
} else if equate-settings != none and is-sub-equation {
link(el.location(), numbering(
el.numbering,
..el.body.value
))
} else {
it
}
}
show math.equation: box // no line breaks in inline math
show: great-theorems-init // show rules for theorems
// ------------------- Settings for Chapter headings -------------------
show heading.where(level: 1): set heading(supplement: [Chapter])
show heading.where(
level: 1,
): it => {
if it.numbering != none {
block(width: 100%)[
#line(length: 100%, stroke: 0.6pt + heading-color)
#v(0.1cm)
#set align(left)
#set text(22pt)
#text(heading-color)[Chapter
#counter(heading).display(
"1:" + it.numbering
)]
#it.body
#v(-0.5cm)
#line(length: 100%, stroke: 0.6pt + heading-color)
]
}
else {
block(width: 100%)[
#line(length: 100%, stroke: 0.6pt + heading-color)
#v(0.1cm)
#set align(left)
#set text(22pt)
#it.body
#v(-0.5cm)
#line(length: 100%, stroke: 0.6pt + heading-color)
]
}
}
// Automatically insert a page break before each chapter
show heading.where(
level: 1
): it => {
pagebreak(weak: true)
it
}
// only valid for abstract and declaration
show heading.where(
outlined: false,
level: 2
): it => {
set align(center)
set text(18pt)
it.body
v(0.5cm, weak: true)
}
// Settings for sub-sub-sub-sections e.g. section 1.1.1.1
show heading.where(
level: 4
): it => {
it.body
linebreak()
}
// same for level 5 headings
show heading.where(
level: 5
): it => {
it.body
linebreak()
}
// reset counter from i-figured for section-based equation numbering
show heading: it => {
if equate-settings == none {
reset-counters(it)
} else {
it
}
}
// ------------------- other settings -------------------
// Settings for Chapter in the outline
show outline.entry.where(
level: 1
): it => {
v(14.75pt, weak: true)
strong(it)
}
// table label on top and not below the table
show figure.where(
kind: table
): set figure.caption(position: top)
// ------------------- Cover -------------------
set text(font: cover-font) // cover font
v(1fr)
//logos
if uni-logo != none and institute-logo != none {
grid(
columns: (1fr, 1fr),
rows: (auto),
column-gutter: 100pt,
row-gutter: 7pt,
grid.cell(
colspan: 1,
align: center,
uni-logo,
),
grid.cell(
colspan: 1,
align: center,
institute-logo,
),
grid.cell(
colspan: 1,
align: center,
text(1.5em, weight: 700, university)
),
grid.cell(
colspan: 1,
align: center,
text(1.5em, weight: 700, institute)
)
)
} else if uni-logo != none {
grid(
columns: (0.5fr),
rows: (auto),
column-gutter: 100pt,
row-gutter: 7pt,
grid.cell(
colspan: 1,
align: center,
uni-logo,
),
grid.cell(
colspan: 1,
align: center,
text(1.5em, weight: 700, university)
)
)
} else if institute-logo != none {
grid(
columns: (0.5fr),
rows: (auto),
column-gutter: 100pt,
row-gutter: 7pt,
grid.cell(
colspan: 1,
align: center,
institute-logo,
),
grid.cell(
colspan: 1,
align: center,
text(1.5em, weight: 700, institute)
)
)
}
v(5fr)
//title
line(length: 100%, stroke: cover-color)
align(center, text(3em, weight: 700, title))
line(start: (10%, 0pt), length: 80%, stroke: cover-color)
v(5fr)
//author
align(center, text(1.5em, weight: 500, degree + " Thesis by " + author))
//study program
if program != none {
align(center, text(1.3em, weight: 100, "Study Programme: " + program))
}
//university
align(center, text(1.3em, weight: 100, university + ", " + institute))
//date
let deadline-text = deadline
if city != none {
deadline-text = city + ", " + deadline
}
align(center, text(1.3em, weight: 100, deadline-text))
// supervisors
align(center + bottom, text(1.3em, weight: 100, " supervised by" + linebreak() + supervisor1 + linebreak() + supervisor2))
pagebreak()
// ------------------- Abstract -------------------
set text(font: body-font) // body font
if abstract != none{
abstract
}
set page(
numbering: "1",
number-align: center,
header: context {
align(center, emph(hydra(1)))
v(0.2cm)
},
) // Page numbering after cover & abstract => they have no page number
pagebreak()
// ------------------- Tables of ... -------------------
// Table of contents
outline(depth: 3, indent: 1em, fill: line(length: 100%, stroke: (thickness: 1pt, dash: "loosely-dotted")))
pagebreak()
// List of figures
outline(
title: [List of Figures],
target: figure.where(kind: image),
fill: line(length: 100%, stroke: (thickness: 1pt, dash: "loosely-dotted"))
)
pagebreak()
// List of Tables
outline(
title: [List of Tables],
target: figure.where(kind: table),
fill: line(length: 100%, stroke: (thickness: 1pt, dash: "loosely-dotted"))
)
pagebreak()
// ------------------- Content -------------------
body
}