-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.typ
333 lines (300 loc) · 8.36 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
330
331
332
333
#import "@preview/subpar:0.1.1"
#import "@preview/physica:0.9.3": *
#let stroke-color = luma(200)
#let std-bibliography = bibliography
#let isappendix = state("isappendix", false)
#let front-matter(body) = {
set page(numbering: "i")
set heading(numbering: none)
body
}
#let main-matter(body) = {
set page(numbering: "1")
counter(page).update(1)
counter(heading).update(0)
set heading(numbering: "1.1")
body
}
#let subfigure = {
subpar.grid.with(
numbering: n => if isappendix.get() {numbering("A.1", counter(heading).get().first(), n)
} else {
numbering("1.1", counter(heading).get().first(), n)
},
numbering-sub-ref: (m, n) => if isappendix.get() {numbering("A.1a", counter(heading).get().first(), m, n)
} else {
numbering("a", m, n)
}
)
}
#let nifty-ntnu-thesis(
title: [Title],
short-title: [],
authors: ("Author"),
short-author: none,
font: "Charter",
raw-font: "DejaVu Sans Mono",
paper-size: "a4",
date: datetime.today(),
date-format: "[day padding:zero]/[month repr:numerical]/[year repr:full]",
abstract-en: none,
abstract-no: none,
preface: none,
table-of-contents: outline(),
titlepage: true,
bibliography: none,
chapter-pagebreak: true,
chapters-on-odd: false,
figure-index: (
enabled: true,
title: "Figures",
),
table-index: (
enabled: true,
title: "Tables",
),
listing-index: (
enabled: true,
title: "Code listings",
),
body,
) = {
set document(title: title, author: authors)
// Set text fonts and sizes
set text(font: font, size: 11pt)
show raw: set text(font: raw-font, size: 9pt)
//Paper setup
set page(
paper: paper-size,
margin: (bottom: 4.5cm, top:4cm, left:4cm, right: 4cm),
)
// Cover page
if titlepage {
page(align(center + horizon, block(width: 90%)[
#let v-space = v(2em, weak: true)
#text(2em)[*#title*]
#v-space
#for author in authors {
text(1.1em, author)
v(0.7em, weak: true)
}
#if date != none {
v-space
// Display date as MMMM DD, YYYY
text(1.1em, date.display(date-format))
}
]))
}
//Paragraph properties
set par(spacing: 0.7em, leading: 0.7em, justify: true, linebreaks: "optimized", first-line-indent: 1.2em)
//Properties for all headings (incl. subheadings)
set heading(numbering: "1.1")
set heading(supplement: [Chapter ])
show heading: set text(hyphenate: false)
show heading: it => {
v(2.5em, weak: true)
it
v(1.5em, weak: true)
}
show: front-matter
// Properties for main headings (i.e "Chapters")
show heading.where(level: 1): it => {
//Show chapters only on odd pages:
if chapters-on-odd {
pagebreak(to: "odd", weak: false)
}
else if chapter-pagebreak {
//Show chapters on new page
colbreak(weak: true)
}
//Display heading as two lines, a "Chapter # \n heading"
v(10%)
if it.numbering != none {
set text(size: 20pt)
set par(first-line-indent: 0em)
text("Chapter ")
numbering("1.1", ..counter(heading).at(it.location()))
}
v(1.4em, weak: true)
set text(size: 24pt)
block(it.body)
v(1.8em, weak: true)
}
//Show abstract
if abstract-en != none {
page([
= Abstract
#abstract-en
])
}
//Show abstract
if abstract-no != none {
page([
= Sammendrag
#abstract-no
])
}
//Show preface
if preface != none {
page([
= Preface
#preface
])
}
// Display table of contents.
if table-of-contents != none {
set par(leading: 10pt, justify: true, linebreaks: "optimized")
show outline.entry.where(level: 1): it => {
strong(it)
}
set outline(indent: true, depth: 3)
table-of-contents
}
// Display list of figures
if figure-index.enabled {
outline(target: figure.where(kind: image), title: figure-index.title)
}
// Display list of tables
if table-index.enabled {
outline(target: figure.where(kind: table), title: table-index.title)
}
// Display list of code listings
if listing-index.enabled {
outline(target: figure.where(kind: raw), title: listing-index.title)
}
// Configure page numbering and footer.
set page(
header: context {
// Get current page number.
let i = counter(page).at(here()).first()
// Align right for even pages and left for odd.
let is-odd = calc.odd(i)
let aln = if is-odd { right } else { left }
// Are we on a page that starts a chapter?
let target = heading.where(level: 1)
// Find the chapter of the section we are currently in.
let before = query(target.before(here()))
if before.len() > 0 {
let current = before.last()
if query(target).any(it => it.location().page() == current.location().page() + 1) {
return
}
let chapter_number = counter(heading).at(here()).first()
if isappendix.get() {
chapter_number = numbering("A.1", chapter_number)
}
let chapter = emph(text(size: 10pt, current.supplement + [ #chapter_number: ] + current.body))
let display-title = []
if short-title != [] {
display-title = emph(text(size: 10pt, short-title))
} else {
display-title = emph(text(size: 10pt, title))
}
if short-author != none {
display-title = emph(text(size: 10pt, short-author)) + [: ] + display-title
}
if current.numbering != none {
if is-odd {
grid(
columns: (4fr, 1fr),
align(left)[#chapter],
align(right)[#i],
)
} else {
grid(
columns: (1fr, 4fr),
align(left)[#i],
align(right)[#display-title],
)
}
}
}
},
footer: ""
)
// Style code snippets
// Display inline code in a small box that retains the correct baseline.
show raw.where(block: false): box.with(
inset: (x: 3pt, y: 0pt),
outset: (y: 3pt),
radius: 2pt,
)
// Display block code with padding.
show raw.where(block: true): block.with(
inset: (x: 5pt, y: 10pt),
stroke: stroke-color,
width: 100%,
)
show raw.where(block: true): set align(start)
show figure.where(
kind: raw
): set figure.caption(position: top)
// Configure proper numbering of figures and equations.
let numbering-fig = n => {
let h1 = counter(heading).get().first()
numbering("1.1", h1, n)
}
show figure: set figure(numbering: numbering-fig)
let numbering-eq = n => {
let h1 = counter(heading).get().first()
numbering("(1.1)", h1, n)
}
set math.equation(numbering: numbering-eq)
//Set table caption on top
show figure.where(
kind: table
): set figure.caption(position: top)
//Style lists
set enum(numbering: "1.a.i.", spacing: 0.8em, indent: 1.2em)
set list(spacing: 0.8em, indent: 1.2em, marker: ([•], [◦], [--]))
show: main-matter
body
//Style bibliography
if bibliography != none {
pagebreak()
show std-bibliography: set text(0.95em)
// Use default paragraph properties for bibliography.
show std-bibliography: set par(leading: 0.65em, justify: false, linebreaks: auto)
bibliography
}
}
//Style appendix
#let appendix(chapters-on-odd: false, body) = {
set heading(numbering: "A.1")
set heading(supplement: [Appendix ])
show heading: it => {
if chapters-on-odd {
pagebreak(to: "odd", weak: true)
} else {
colbreak(weak: true)
}
v(10%)
if it.numbering != none {
set text(size: 20pt)
set par(first-line-indent: 0em)
text("Appendix ")
numbering("A.1", ..counter(heading).at(it.location()))
}
v(1.4em, weak: true)
set text(size: 24pt)
block(it.body)
v(1.8em, weak: true)
}
// Reset heading counter
counter(heading).update(0)
// Equation numbering
let numbering-eq = n => {
let h1 = counter(heading).get().first()
numbering("(A.1)", h1, n)
}
set math.equation(numbering: numbering-eq)
// Figure and Table numbering
let numbering-fig = n => {
let h1 = counter(heading).get().first()
numbering("A.1", h1, n)
}
show figure.where(kind: image): set figure(numbering: numbering-fig)
show figure.where(kind: table): set figure(numbering: numbering-fig)
isappendix.update(true)
body
}