-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.typ
More file actions
473 lines (424 loc) · 11.7 KB
/
template.typ
File metadata and controls
473 lines (424 loc) · 11.7 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
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
#import "@preview/tablex:0.0.8": tablex, colspanx, rowspanx, hlinex, vlinex, cellx
#let font_song = ("New Computer Modern", "Source Han Serif SC", "Simsun", "STSong")
#let font_fangsong = ("FangSong", "STFangSong")
#let font_hei = ("Calibri", "Source Han Sans SC", "Source Han Sans HW SC", "SimHei", "Microsoft YaHei", "STHeiti")
#let font_kai = ("KaiTi_GB2312", "KaiTi", "STKaiti")
#let definition_counter = state("definition_counter", 0)
#let theorem_counter = state("theorem_counter", 0)
#let problem_counter = state("problem_counter", 0)
#let indent = 0em
#let force-indent = 2em
#let fake_par = [#text()[#v(0pt, weak: true)];#text()[#h(0em)]]
#let project(
course: "",
title: "",
authors: (),
date: none,
body,
course_fullname: "",
semester: "",
course_code: "",
page-margin: (left: 4mm, right: 4mm, top: 12mm, bottom: 12mm),
show-header: true,
) = {
if (course_fullname == "") {
course_fullname = course
}
if (course_code != "") {
course_fullname = course_fullname + " (" + course_code + ")"
}
// 文档基本信息
set document(author: authors.map(a => a.name), title: title)
set page(
paper: "a4",
margin: page-margin,
numbering: "1",
number-align: center,
)
// 页眉
set page(
header: context {
if show-header {
if (counter(page).get().at(0) == 1) {
return none
}
set text(font: font_song, 10pt, baseline: 8pt, spacing: 3pt)
grid(
columns: (1fr, 1fr, 1fr),
align(left, course),
[] /* align(center, title)*/,
align(right, date),
)
line(length: 100%, stroke: 0.5pt)
}
},
)
// 页脚
set page(
footer: context {
set text(font: font_song, 10pt, baseline: 8pt, spacing: 3pt)
set align(center)
grid(
columns: (1fr, 1fr),
align(left, authors.map(a => a.name).join(", ")), align(right, counter(page).display("1/1", both: true)),
)
},
)
set text(font: font_song, lang: "en", size: 11pt)
show math.equation: set text(weight: 400)
// set heading(numbering: "1.1)")
set par(leading: 0.75em)
show heading: set block(below: 1em)
block(
below: 2em,
stroke: 0.5pt + black,
radius: 2pt,
width: 100%,
inset: 1em,
outset: -0.2em,
)[
#text(size: 0.84em)[#grid(
columns: (auto, 1fr, auto),
align(left, strong(course_fullname)), [], align(right, strong(semester)),
)]
#v(0.75em)
#align(center)[#text(size: 1.5em)[#title]]
#v(0.75em)
#block(
..authors.map(author => align(center)[
#text(size: 0.84em)[#grid(
columns: (auto, 1fr, auto),
align(
left,
{
author.name
if "id" in author {
" (" + author.id + ")"
}
},
),
[],
align(right, author.email),
)]
]),
)
]
// Main body.
set par(justify: true)
set text(font: "Noto Sans SC", weight: "regular")
show math.equation: set text(font: "Cambria Math")
show raw: set text(size: 1.2em, font: "Consolas")
show "。": "."
show heading.where(level: 1): it => [
#definition_counter.update(x => 0)
#theorem_counter.update(x => 0)
#it
]
show heading.where(level: 1): it => block(it, above: 1.25em, below: 1em)
show heading.where(level: 2): it => [
#theorem_counter.update(x => 0)
#it
]
show heading.where(level: 2): it => block(it, above: 1.25em, below: 1em)
set par(first-line-indent: indent)
set table(inset: 5pt, stroke: 0.5pt, align: horizon + center)
set columns(gutter: 1em)
show raw.where(block: true): it => {
set par(justify: false)
it
}
set heading(numbering: "1.1.")
body
}
#let song(it) = text(it, font: font_song)
#let fangsong(it) = text(it, font: font_fangsong)
#let hei(it) = text(it, font: font_hei)
#let kai(it) = text(it, font: font_kai)
#let bb = it => [#strong[#it]]
#let hl(x) = strong(text(x, font: ("Cambria", ..font_hei), number-type: "old-style"))
#let hw(name, it, jt) = {
block(width: 100%)[
#v(0.4em)
#problem_counter.update(x => (x + 1))
#block(inset: 0.6em, stroke: 0.5pt + gray, radius: 0.3em, width: 100%, fill: luma(250))[
#hl[Exercise #name:]
#it#fake_par#fake_par
]
#jt
#v(0.5em)
]
}
#let named_block(it, title: none, name: "", color: red, inset: 11pt) = block(
below: 1em,
stroke: 0.5pt + color,
radius: 3pt,
width: 100%,
inset: inset,
{
place(
top + left,
dy: -6pt - inset, // Account for inset of block
dx: 8pt - inset,
block(fill: white, inset: 2pt)[
#set text(font: "Noto Sans", fill: color)
#strong[#name]
],
)
let fontcolor = color.darken(20%)
set text(fill: fontcolor)
// #set par(first-line-indent_width: 0em)
if (title != none) {
par(strong(title))
}
it
},
)
#let example(it, title: none) = named_block(it, title: title, name: "Example", color: gray.darken(60%))
#let proof(it, title: none) = named_block(it, title: title, name: "Proof", color: rgb(120, 120, 120))
#let abstract(it, title: none) = named_block(it, title: title, name: "Abstract", color: rgb(0, 133, 143))
#let summary(it, title: none) = named_block(it, title: title, name: "Summary", color: rgb(0, 133, 143))
#let info(it, title: none) = named_block(it, title: title, name: "Info", color: rgb(68, 115, 218))
#let note(it, title: none) = named_block(it, title: title, name: "Note", color: rgb(68, 115, 218))
#let tip(it, title: none) = named_block(it, title: title, name: "Tip", color: rgb(0, 133, 91))
#let hint(it, title: none) = named_block(it, title: title, name: "Hint", color: rgb(0, 133, 91))
#let success(it, title: none) = named_block(it, title: title, name: "Success", color: rgb(62, 138, 0))
#let help(it, title: none) = named_block(it, title: title, name: "Help", color: rgb(153, 110, 36))
#let warning(it, title: none) = named_block(it, title: title, name: "Warning", color: rgb(184, 95, 0))
#let attention(it, title: none) = named_block(it, title: title, name: "Attention", color: rgb(216, 58, 49))
#let caution(it, title: none) = named_block(it, title: title, name: "Caution", color: rgb(216, 58, 49))
#let failure(it, title: none) = named_block(it, title: title, name: "Failure", color: rgb(216, 58, 49))
#let danger(it, title: none) = named_block(it, title: title, name: "Danger", color: rgb(216, 58, 49))
#let error(it, title: none) = named_block(it, title: title, name: "Error", color: rgb(216, 58, 49))
#let bug(it, title: none) = named_block(it, title: title, name: "Bug", color: rgb(204, 51, 153))
#let quote(it, title: none) = named_block(it, title: title, name: "Quote", color: rgb(132, 90, 231))
#let cite(it, title: none) = named_block(it, title: title, name: "Cite", color: rgb(132, 90, 231))
#let table3-global-align = align
#let table3(
..args,
inset: 0.5em,
stroke: 0.5pt,
width: 100%,
align: center + horizon,
columns: 1,
) = {
set table3-global-align(center)
if type(columns) == int {
let new_columns = ()
for i in range(columns) {
new_columns.push(1fr)
}
columns = new_columns
}
block(
width: width,
stack(
tablex(
..args,
inset: inset,
stroke: stroke,
align: align,
columns: columns,
map-hlines: h => {
if (h.y == 0) {
(..h, stroke: (stroke * 2) + black)
} else if (h.y == 1) {
(..h, stroke: stroke + black)
} else {
(..h, stroke: 0pt)
}
},
auto-vlines: false,
),
line(stroke: (stroke * 2) + black, length: 100%),
),
)
}
#let parts(columns: 1, gutter: 1em, ..it) = {
let buffer = ()
for (id, sol) in it.named() {
buffer.push(align(right, [#v((gutter - 1em) / 2)#hl(id + ".")#h(0.2em)]))
buffer.push(block(width: 100%, breakable: true, sol))
}
v((gutter - 1em) / 2)
grid(
columns: 2 * columns,
column-gutter: 0.25em,
row-gutter: gutter,
..buffer,
)
v((gutter - 1em) / 2)
}
#let indent-box(it, radio: 1) = grid(
columns: (force-indent * radio, 1fr),
column-gutter: 0pt,
[], it,
)
#let idt = indent-box
#let named_block(it, name: "", color: red, inset: 11pt) = {
block(
below: 1em,
stroke: 0.5pt + color,
radius: 3pt,
width: 100%,
inset: inset,
)[
#place(
top + left,
dy: -6pt - inset, // Account for inset of block
dx: 8pt - inset,
block(fill: white, inset: 2pt)[
#set text(font: "Noto Sans", fill: color)
#strong[#name]
],
)
#let fontcolor = color.darken(0%)
#set text(fill: fontcolor)
#set par(first-line-indent: 0em)
#it
]
fake_par
}
#let correction(it) = named_block(it, name: "Correction", color: rgb(216, 58, 49))
#let hr = line(length: 100%, stroke: 0.5pt + luma(200))
#let _current-color_default = luma(150)
#let current-topic = state("current-topic", none)
#let current-color = state("current-color", _current-color_default)
#let slide-width = state("slide-width", 16)
#let slide-height = state("slide-height", 10)
#let slide-header-height = state("slide-header-height", 0.15)
#let _h = h
#let no-par-margin = v(-0.6em)
#let slide2x(
page,
img1,
img2,
crop: none,
header: true,
h: none,
ct: none,
cb: none,
) = {
let note-width = 2em
let slide1x(
img,
border-color: black,
) = {
let crop-top = 0 // within [0, 1)
let crop-bottom = 0 // within [0, 1)
if h == false or header == false {
crop-top += slide-header-height.get()
}
if crop != none {
crop-bottom += 1 - crop
}
if ct != none {
if ct >= 1 {
crop-top += ct / 100.
} else {
crop-top += ct
}
}
if cb != none {
if cb >= 1 {
crop-bottom += cb / 100.
} else {
crop-bottom += cb
}
}
set image(width: 100%)
context box(
width: 100%,
stroke: current-color.get() + 0.5pt,
inset: 0.5pt,
if crop-top == 0 and crop-bottom == 0 {
img
} else {
let page-width = 595.28pt // a4
let w = (page-width - 16mm * 2 - note-width * 2 - 1.5pt) / 2
let h = w / slide-width.get() * slide-height.get()
box(
width: 100%,
height: (1 - crop-top - crop-bottom) * h,
clip: true,
inset: (
top: -crop-top * h,
bottom: -crop-bottom * h,
),
img,
)
},
)
}
set align(center)
no-par-margin
_h(-1em)
context {
set text(fill: current-color.get())
box(
width: 100%,
grid(
columns: (note-width, 1fr, 1fr, note-width),
grid(
columns: (3fr, 1fr),
{
set align(right)
v(0.25em)
page
},
),
slide1x(img1), // left
slide1x(img2), // right
grid(
columns: (1fr, 3fr),
{},
{
set align(left)
context current-topic.get()
},
)
),
)
set text(fill: black)
}
_h(-1em)
no-par-margin
}
#let topic(name, color, content) = {
current-topic.update(x => {
for ch in name {
par(if ch == "(" {
"﹁"
} else if ch == ")" {
"﹂"
} else {
ch
})
v(-0.9em)
}
})
current-color.update(x => color)
content
current-topic.update(x => none)
current-color.update(x => _current-color_default)
}
#let boxed(it) = {
set text(top-edge: "ascender", bottom-edge: "descender")
box(
stroke: black + 0.5pt,
inset: 1pt,
it,
)
}
#let mark(it) = {
box(
fill: yellow,
it,
)
}
#let important(it) = {
set text(fill: red)
it
}
#let callout(it, width: 100%) = {
align(center, box(width: width, it))
}