-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.typ
More file actions
295 lines (249 loc) · 9.44 KB
/
lib.typ
File metadata and controls
295 lines (249 loc) · 9.44 KB
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
// uqosnotes — multi-discipline academic notes template
// https://github.com/UQOSNotes/template
#import "@preview/cetz:0.4.2": canvas, draw
// ── Colour palette ────────────────────────────────────────────────────────────
#let _c = (
theorem: rgb("#2563eb"),
definition: rgb("#0d9488"),
proof: rgb("#7c3aed"),
example: rgb("#d97706"),
remark: rgb("#6b7280"),
note: rgb("#0891b2"),
important: rgb("#dc2626"),
algorithm: rgb("#6d28d9"),
code: rgb("#1e293b"),
diagram: rgb("#374151"),
exercise: rgb("#ea580c"),
solution: rgb("#16a34a"),
)
// ── Counters ──────────────────────────────────────────────────────────────────
// Theorem, lemma, corollary, and proposition share one counter.
#let _thm-ctr = counter("uqosnotes:thm")
#let _def-ctr = counter("uqosnotes:def")
#let _ex-ctr = counter("uqosnotes:ex")
#let _exr-ctr = counter("uqosnotes:exr")
// ── Internal helpers ──────────────────────────────────────────────────────────
#let _make-box(color, label, body) = {
block(
width: 100%,
breakable: true,
inset: (left: 14pt, right: 12pt, top: 10pt, bottom: 10pt),
fill: color.lighten(91%),
stroke: (left: 3pt + color),
radius: (right: 2pt),
)[
#block(
spacing: 0pt,
sticky: true,
)[#text(weight: "bold", fill: color)[#label]]
#v(5pt)
#body
]
}
// Resolves (title, body) from ..args, supporting three call styles:
// #box[body] — no title
// #box("Title")[body] — positional title
// #box(title: "Title")[body] — keyword title
#let _resolve-args(args) = {
let pos = args.pos()
let title = if pos.len() > 1 {
pos.first()
} else {
args.named().at("title", default: none)
}
let body = pos.last()
(title, body)
}
#let _numbered(name, color, ctr, title, body) = {
ctr.step()
context {
let n = ctr.get().first()
let label = if title == none { [#name #n] } else { [#name #n (#title)] }
_make-box(color, label, body)
}
}
// ── Template ──────────────────────────────────────────────────────────────────
/// Set up the document. Call as:
/// ```typ
/// #show: notes.with(
/// course: "MATH1061",
/// title: "Discrete Mathematics",
/// year: "Semester 1, 2026",
/// authors: ("Alice Smith",),
/// )
/// ```
#let _in_body = state("in-body", false)
#let notes(
course: "",
title: "Notes",
year: "",
authors: (),
preface: none,
body,
) = {
let authors = if type(authors) == str { (authors,) } else { authors }
show heading.where(level: 1): it => {
_thm-ctr.update(0)
_def-ctr.update(0)
_ex-ctr.update(0)
_exr-ctr.update(0)
it
}
set document(title: title, author: authors)
set page(
paper: "a4",
margin: (top: 2.5cm, bottom: 2.5cm, left: 2.5cm, right: 2.5cm),
header: context {
if _in_body.at(here()) {
set text(size: 9pt, fill: luma(130))
let h1s = query(heading.where(level: 1).before(here())).filter(h => h.numbering != none)
let h2s = query(heading.where(level: 2).before(here()))
let chapter = if h1s.len() > 0 { h1s.last().body } else { none }
let section = if h2s.len() > 0 { h2s.last().body } else { none }
let rparts = (chapter, section).filter(x => x != none)
if course != "" { course }
h(1fr)
if rparts.len() > 0 { rparts.join([ · ]) }
}
},
footer: context {
if _in_body.at(here()) {
set text(size: 9pt, fill: luma(130))
datetime.today().display("[day] [month repr:long] [year]")
h(1fr)
counter(page).display()
}
},
)
set text(size: 12pt, lang: "en", font: "New Computer Modern")
set heading(numbering: "1.1")
set par(justify: true, leading: 0.7em)
show heading: it => {
v(0.8em, weak: true)
it
v(0.4em, weak: true)
}
// Title block
v(2cm)
align(center)[
#block(text(size: 26pt, weight: "bold")[#title])
#if course != "" or year != "" {
v(0.4em)
let subtitle = (course, year).filter(s => s != "").join(" \u{00b7} ")
text(size: 13pt, fill: luma(80))[#subtitle]
}
#if authors.len() > 0 {
v(0.4em)
text(size: 11pt)[#authors.join(", ")]
}
#v(0.8em)
#line(length: 50%, stroke: 0.5pt + luma(160))
]
v(1.5cm)
pagebreak()
{
show outline.entry.where(level: 1): it => {
v(0.8em, weak: true)
strong(it)
}
outline(depth: 2, indent: 1em)
}
pagebreak()
_in_body.update(true)
if preface != none {
heading(level: 1, numbering: none)[Preface]
preface
pagebreak()
}
body
}
// ── Theorem family ────────────────────────────────────────────────────────────
/// Theorem box. `#theorem[...]`, `#theorem("Title")[...]`, or `#theorem(title: "Title")[...]`
#let theorem(..args) = {
let (title, body) = _resolve-args(args)
_numbered("Theorem", _c.theorem, _thm-ctr, title, body)
}
/// Lemma box. Shares the theorem counter.
#let lemma(..args) = {
let (title, body) = _resolve-args(args)
_numbered("Lemma", _c.theorem, _thm-ctr, title, body)
}
/// Corollary box. Shares the theorem counter.
#let corollary(..args) = {
let (title, body) = _resolve-args(args)
_numbered("Corollary", _c.theorem, _thm-ctr, title, body)
}
/// Proposition box. Shares the theorem counter.
#let proposition(..args) = {
let (title, body) = _resolve-args(args)
_numbered("Proposition", _c.theorem, _thm-ctr, title, body)
}
// ── Definition ────────────────────────────────────────────────────────────────
/// Definition box. Has its own counter.
#let definition(..args) = {
let (title, body) = _resolve-args(args)
_numbered("Definition", _c.definition, _def-ctr, title, body)
}
// ── Proof ─────────────────────────────────────────────────────────────────────
/// Proof box. Ends with a QED symbol.
#let proof(body) = {
_make-box(_c.proof, [Proof], [#body #h(1fr) $square$])
}
// ── Example ───────────────────────────────────────────────────────────────────
/// Example box. Has its own counter.
#let example(..args) = {
let (title, body) = _resolve-args(args)
_numbered("Example", _c.example, _ex-ctr, title, body)
}
// ── Unnumbered callouts ───────────────────────────────────────────────────────
/// Remark box.
#let remark(body) = { _make-box(_c.remark, [Remark], body) }
/// Note box.
#let note(body) = { _make-box(_c.note, [Note], body) }
/// Important box.
#let important(body) = { _make-box(_c.important, [Important], body) }
// ── Exercise & Solution ───────────────────────────────────────────────────────
/// Exercise box. Has its own counter.
#let exercise(..args) = {
let (title, body) = _resolve-args(args)
_numbered("Exercise", _c.exercise, _exr-ctr, title, body)
}
/// Solution box.
#let solution(body) = { _make-box(_c.solution, [Solution], body) }
// ── Algorithm ─────────────────────────────────────────────────────────────────
/// Algorithm box. `#algorithm[...]` or `#algorithm("Name")[...]`
#let algorithm(..args) = {
let (title, body) = _resolve-args(args)
let label = if title == none { [Algorithm] } else { [Algorithm \u{2014} #title] }
_make-box(_c.algorithm, label, body)
}
// ── Code ──────────────────────────────────────────────────────────────────────
/// Code block wrapper. Place a fenced raw block inside.
#let code-block(body) = {
block(
width: 100%,
breakable: true,
inset: (x: 14pt, y: 10pt),
fill: _c.code.lighten(93%),
stroke: (left: 3pt + _c.code),
radius: (right: 2pt),
body,
)
}
// ── Diagram ───────────────────────────────────────────────────────────────────
/// Diagram container with a dashed border. Optional `caption:` label.
#let diagram(caption: none, body) = {
block(
width: 100%,
inset: 16pt,
stroke: (paint: _c.diagram, dash: "dashed", thickness: 0.5pt),
radius: 3pt,
)[
#set align(center)
#body
#if caption != none {
v(6pt)
text(size: 9pt, fill: luma(90), style: "italic")[#caption]
}
]
}