-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtemplate.typ
More file actions
287 lines (255 loc) · 7.53 KB
/
template.typ
File metadata and controls
287 lines (255 loc) · 7.53 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
#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 = ("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 = 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: "",
) = {
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: (left: 12mm, right: 12mm, top: 20mm, bottom: 20mm),
numbering: "1",
number-align: center,
)
// 页眉
set page(header: {
locate(loc => {
if (counter(page).at(loc).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: {
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: "zh", size: 12pt)
show math.equation: set text(weight: 400)
// Set paragraph spacing.
show par: set block(above: 1.05em, below: 1.05em)
set heading(numbering: "1.1.")
set par(leading: 0.75em)
block(
below: 4em,
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 + " (" + author.id + ")"),
[],
align(right, author.email),
)]
]),
)
]
// Main body.
set par(justify: true)
show "。": "."
show heading.where(level: 1): it => [
#definition_counter.update(x => 0)
#theorem_counter.update(x => 0)
#set text(size: 1.2em)
#it
#v(0.15em)
]
show heading.where(level: 2): it => [
#theorem_counter.update(x => 0)
#it
]
set par(first-line-indent: indent)
show heading: it => {
text()[#v(1.6em, weak: true)]
it
fake_par
}
/* { slot: before-body } */
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 def = it => [#strong[#it]]
#let definition(it, name: "") = {
block(width: 100%)[
#definition_counter.update(x => (x + 1))
#strong[
#hei[定义]#locate(loc => [#counter(heading).at(loc).at(0)]).#definition_counter.display()
]
#if (name != "") [(#kai[#name])]
#math.space.thin#it
]
fake_par
}
#let theorem(it, name: "", tag: "定理") = {
block(width: 100%)[
#theorem_counter.update(x => (x + 1))
#strong[
#hei[#tag]#locate(loc => [#counter(heading).at(loc).at(0).#counter(heading).at(loc).at(1)]).#theorem_counter.display()
]
#if (name != "") [(#kai[#name])]
#math.space.thin#it
]
fake_par
}
#let lemma(it, name: "") = theorem(it, name: name, tag: "引理")
#let corollary(it, name: "") = theorem(it, name: name, tag: "推论")
#let property(it, name: "") = theorem(it, name: name, tag: "性质")
#let conclusion(it, name: "") = theorem(it, name: name, tag: "结论")
#let problem(it, name: "") = {
block(width: 100%)[
#problem_counter.update(x => (x + 1))
#strong[
#hei[例]#problem_counter.display()
]
#if (name != "") [(#kai[#name])]
#math.space.thin#it
]
fake_par
}
#let solution(it, tag: "解") = {
block(width: 100%)[
#strong[#hei[#tag:]]
#math.space.thin#it
]
fake_par
}
#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 example(it) = named_block(it, name: "Example", color: gray.darken(60%))
#let proof(it) = named_block(it, name: "Proof", color: rgb(120, 120, 120))
#let abstract(it) = named_block(it, name: "Abstract", color: rgb(0, 133, 143))
#let summary(it) = named_block(it, name: "Summary", color: rgb(0, 133, 143))
#let info(it) = named_block(it, name: "Info", color: rgb(68, 115, 218))
#let note(it) = named_block(it, name: "Note", color: rgb(68, 115, 218))
#let tip(it) = named_block(it, name: "Tip", color: rgb(0, 133, 91))
#let hint(it) = named_block(it, name: "Hint", color: rgb(0, 133, 91))
#let success(it) = named_block(it, name: "Success", color: rgb(62, 138, 0))
#let important(it) = named_block(it, name: "Important", color: rgb(62, 138, 0))
#let help(it) = named_block(it, name: "Help", color: rgb(153, 110, 36))
#let warning(it) = named_block(it, name: "Warning", color: rgb(184, 95, 0))
#let attention(it) = named_block(it, name: "Attention", color: rgb(216, 58, 49))
#let caution(it) = named_block(it, name: "Caution", color: rgb(216, 58, 49))
#let failure(it) = named_block(it, name: "Failure", color: rgb(216, 58, 49))
#let danger(it) = named_block(it, name: "Danger", color: rgb(216, 58, 49))
#let error(it) = named_block(it, name: "Error", color: rgb(216, 58, 49))
#let bug(it) = named_block(it, name: "Bug", color: rgb(204, 51, 153))
#let quote(it) = named_block(it, name: "Quote", color: rgb(132, 90, 231))
#let cite(it) = named_block(it, name: "Cite", color: rgb(132, 90, 231))
#let correction(it) = named_block(it, name: "Correction", color: rgb(216, 58, 49))
#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
}
box(
width: width,
clip: true,
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%),
),
)
}
#import "./functions.typ": *