-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththeme.typ
More file actions
412 lines (359 loc) · 10.2 KB
/
theme.typ
File metadata and controls
412 lines (359 loc) · 10.2 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
// #import "@preview/chic-hdr:0.4.0": *
#import "lib.typ": *
#let CODE_SIZE=8pt
#let TEXT_SIZE=10pt
#let Heiti = ("Times New Roman", "Heiti SC", "Heiti TC", "SimHei")
#let Songti = ("Times New Roman", "Songti SC", "Songti TC", "SimSun")
#let Zhongsong = ("Times New Roman", "STZhongsong", "SimSun")
#let Xbs = ("Times New Roman", "FZXiaoBiaoSong-B05", "FZXiaoBiaoSong-B05S")
// #let indent() = {
// box(width: 2em)
// }
//
#let info_key(body) = {
rect(width: 100%, inset: 2pt, stroke: none, text(font: Zhongsong, size: 16pt, body))
}
#let info_value(body) = {
rect(
width: 100%,
inset: 2pt,
stroke: (bottom: 1pt + black),
text(font: Zhongsong, size: 16pt, bottom-edge: "descender")[ #body ],
)
}
#let project(
course: "COURSE",
lab_name: "LAB NAME",
stu_name: "NAME",
stu_num: "1234567",
major: "MAJOR",
department: "DEPARTMENT",
date: (2077, 1, 1),
show_content_figure: false,
watermark: "",
body,
) = {
show raw: set text(font: ("Jetbrains Mono NL","PingFang SC","Iosevka", "Fira Mono"), size: CODE_SIZE)
set page("a4",
margin: (x: 1.5cm,y: 2cm)
)
// 封面
align(center)[
#image("./assets/ustc-name.svg", width: 70%)
#v(1em)
// #set text(
// size: 26pt,
// font: Zhongsong,
// weight: "bold",
// )
// 课程名
#text(size: 25pt, font: Xbs)[
_#course _课程实验报告
]
// #v(1em)
// 报告名
#text(size: 22pt, font: Xbs)[
_#lab_name _
]
// #v(0.5em)
#image("./assets/USTC-NO-TEXT.svg", width: 60%)
// #v(0.5em)
// 个人信息
#grid(
columns: (40pt, 270pt,40pt),
rows: (40pt, 40pt),
gutter: 0pt,
info_key("学院"),
info_value(department),
rect(
width: 100%,
inset: 2pt,
stroke: (bottom: 1pt + black),
text(font: Zhongsong, size: 16pt, bottom-edge: "descender", fill: white)[#department.at(0)],
),
info_key("专业"),
info_value(major),
rect(
width: 100%,
inset: 2pt,
stroke: (bottom: 1pt + black),
text(font: Zhongsong, size: 16pt, bottom-edge: "descender", fill: white)[#major.at(0)],
),
info_key("姓名"),
info_value(stu_name),
rect(
width: 100%,
inset: 2pt,
stroke: (bottom: 1pt + black),
text(font: Zhongsong, size: 16pt, bottom-edge: "descender", fill: white)[#stu_name.at(0)],
),
info_key("学号"),
info_value(stu_num),
rect(
width: 100%,
inset: 2pt,
stroke: (bottom: 1pt + black),
text(font: Zhongsong, size: 16pt, bottom-edge: "descender", fill: white)[#stu_num.at(0)],
),
)
#v(2em)
// 日期
#text(font: Zhongsong, size: 14pt)[
#date.at(0) 年 #date.at(1) 月 #date.at(2) 日
]
]
pagebreak()
// 水印
set page(background: rotate(-60deg,
text(240pt, fill: rgb("#034ea10f"), font:"Times New Roman")[
#strong()[#watermark]
]
),
)
// 目录
show outline.entry.where(level: 1): it => {
v(12pt, weak: true)
strong(it)
}
show outline.entry: it => {
set text(
font: Xbs,
size: 12pt,
)
it
}
outline(
title: text(font: Xbs, size: 16pt, fill: rgb("#034ea1"))[目录],
indent: auto,
)
if show_content_figure {
text(font: Xbs, size: 10pt)[
#i-figured.outline(title: [图表])
]
}
pagebreak()
set page(
columns: 2,
header: [
#set text(8pt)
#course -- #lab_name
#h(1fr) #text(font:Xbs,fill:rgb("#034ea1"))[USTC]
],
// number-align: right,
// numbering: "壹 / 壹",
)
set page(
footer: context {
// 获取当前页码
let i = counter(page).at(here()).first()
// 根据奇偶页设置对齐方式
let is-odd = calc.odd(i)
let aln = if is-odd { right } else { left }
// 获取所有一级和二级标题
let level1_headings = heading.where(level: 1)
let level2_headings = heading.where(level: 2)
// 检查当前页是否包含一级标题
if query(level1_headings).any(it => it.location().page() == i) {
// 仅显示页码
return align(aln)[#text(fill: rgb("#034ea1"), size: 2em)[#i]]
}
// 检查当前页是否包含二级标题
if query(level2_headings).any(it => it.location().page() == i) {
// 获取当前的一级标题(在当前位置之前的最后一个)
let previous_level1 = query(level1_headings.before(here())).last()
let gap = 0.5em // 调整间距
let chapter = upper(text(size: 0.68em, previous_level1.body))
// 显示页码和一级标题
if is-odd {
return align(aln)[
#grid(
columns: (40em,2em),
[#chapter],
text(fill: rgb("#034ea1"))[#i],
)
]
} else {
return align(aln)[
#grid(
columns: (2em,40em),
text(fill: rgb("#034ea1"))[#i],
[#chapter],
)
]
}
}
// 当前页既不包含一级标题也不包含二级标题
// 获取当前的一级和二级标题
let previous_level1 = query(level1_headings.before(here())).last()
let previous_level2_query = query(level2_headings.before(here()))
let previous_level2 = if previous_level2_query.len() > 0 {
previous_level2_query.last()
} else {
none
}
// let gap = 0.01em // 调整间距
let chapter = upper(text(size: 0.68em, previous_level1.body))
// 检查是否存在二级标题
if previous_level2 != none {
let section = upper(text(size: 0.6em, previous_level2.body)) // 二级标题字号更小
// 显示页码、一级标题和二级标题,二级标题在一级标题下方
if is-odd {
return align(aln)[
#grid(
columns: (40em,2em),
rows: (1fr,1fr,1fr),
gutter: 0pt,
[#chapter],
grid.cell(
rowspan: 2,
align(horizon)[#text(fill: rgb("#034ea1"))[#i]]
),
[#section],
)
]
} else {
return align(aln)[
#grid(
columns: (2em,40em),
rows: (1fr,1fr,1fr),
gutter: 0pt,
grid.cell(
rowspan: 2,
align(horizon)[#text(fill: rgb("#034ea1"))[#i]]
),
[#chapter],
[#section],
)
]
}
} else {
// 如果没有二级标题,仅显示页码和一级标题
if is-odd {
return align(aln)[
#grid(
columns: (40em,2em),
[#chapter],
text(fill: rgb("#034ea1"))[#i],
)
// #chapter
// #v(gap)
// #i
]
} else {
return align(aln)[
#grid(
columns: (2em,40em),
text(fill: rgb("#034ea1"))[#i],
[#chapter],
)
// #i
// #v(gap)
// #chapter
]
}
}
},
)
// 页眉页脚设置
// show: chic.with(
// chic-header(
// left-side: smallcaps(
// text(size: 10pt, font: Xbs)[
// #course -- #lab_name
// ],
// ),
// right-side: text(size: 10pt, font: Xbs)[
// #chic-heading-name(dir: "prev")
// ],
// side-width: (60%, 0%, 35%),
// ),
// chic-footer(
// center-side: text(size: 11pt, font: Xbs)[
// #chic-page-number()
// ],
// ),
// chic-separator(1pt),
// // chic-separator(on: "header", chic-styled-separator("bold-center")),
// chic-separator(on: "footer", stroke(dash: "loosely-dashed", paint: gray)),
// chic-offset(40%),
// chic-height(2cm),
// )
// 正文设置
//
set heading(numbering: "1.1.1.")
set figure(supplement: [图])
show heading: i-figured.reset-counters.with(level: 2)
show figure: i-figured.show-figure.with(level: 2)
// set math.equation(numbering: none)
// show math.equation: i-figured.show-equation
set text(
font: Songti,
// font:"Linux Libertine",
size: TEXT_SIZE,
)
set par( // 段落设置
justify: false,
// leading: 1.04em,
// first-line-indent: 2em,
)
show heading: it => box(width: 100%)[ // 标题设置
#v(0.45em)
#set text(font: Xbs)
#if it.numbering != none {
counter(heading).display()
}
#h(0.75em)
#it.body
#v(5pt)
]
show link: it => { // 链接
set text(fill: rgb("#034ea1"))
it
}
show: gentle-clues.with( // gentle块
headless: false, // never show any headers
breakable: true, // default breaking behavior
header-inset: 0.4em, // default header-inset
content-inset: 1em, // default content-inset
stroke-width: 2pt, // default left stroke-width
border-radius: 2pt, // default border-radius
border-width: 0.5pt, // default boarder-width
)
show: checklist.with(fill: luma(95%), stroke: blue, radius: .2em) // 复选框
// 代码段设置
show: codly-init.with()
// codly(
// display-icon: true,
// stroke-color: luma(200),
// zebra-color: luma(0).transparentize(96%),
// fill: rgb("ffffff").transparentize(100%),
// enable-numbers: true,
// breakable: true,
// languages: (
// rust: (
// name: "Rust",
// icon: text(font: "tabler-icons", "\u{fa53}"),
// color: rgb("#CE412B")
// ),
// )
// )
codly(
display-icon: true,
// default-color: rgb("#283593"),
fill: rgb("ffffff").transparentize(100%),
stroke: 1pt + luma(200),
// fill:none,
zebra-fill: luma(0).transparentize(96%),
breakable: true,
// number-format: none,
languages: (
rust: (
name: "Rust",
icon: text(font: "tabler-icons", "\u{fa53}"),
color: rgb("#CE412B")
),
)
)
// show raw.where(lang: "pintora"): it => pintorita.render(it.text)
body
}