-
Notifications
You must be signed in to change notification settings - Fork 6
/
template.typ
449 lines (376 loc) · 10.4 KB
/
template.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
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
#import "@preview/showybox:2.0.1": showybox
#import "@preview/codelst:2.0.1": sourcecode
#import "@preview/ctheorems:1.1.2": *
#import "resource.typ": *
/*
本模板修改自 jsk-lecnotes
+ 添加中文环境
+ 修改封面布局
+ 添加必要字体
*/
#let template(
// 笔记标题
title: "Lecture Notes Title",
short-title: none,
description: none,
date: none,
authors: (
),
affiliations: (
),
bibliography-file: none,
bibstyle: "gb-7714-2015-numeric",
paper-size: "a4",
fonts: (
(
en-font: "Linux Libertine",
zh-font: "Noto Sans CJK SC",
code-font: "DejaVu Sans Mono",
)
),
accent: "#000000",
cover-image: none,
background-color: none,
body
) = {
let accent-color = rgb(accent)
// 使用 ctheorems 包
show: thmrules
// 设置正文和代码的字体
set text(font: (fonts.en-font, fonts.zh-font), size: 12pt, lang: "zh", region: "cn")
show raw: set text(font: fonts.code-font, 10pt)
// 设置中文粗体,斜体
show strong: set text(fill: accent-color, font: (fonts.en-font, fonts.zh-font))
show emph: set text(font: (fonts.en-font, fonts.zh-font))
// 设置文档元数据
set document(title: title, author: authors.map(author => author.name))
// 将链接设置蓝色并加下划线,并且对于作者列表禁用此设置。
show link: it => {
let author-names = ()
for author in authors {
author-names.push(author.name)
}
if it.body.has("text") and it.body.text in author-names {
it
} else {
underline(stroke: (dash: "densely-dotted"), text(fill: blue, it))
}
}
// 文本高亮
// set highlight(fill: accent-color.lighten(50%))
// 计数器
let chaptercounter = counter("chapter")
// 配置页面
set page(
paper: paper-size,
numbering: "1 / 1",
number-align: center,
// 页边距
margin: (x:1.6cm, y:2.3cm),
// 封面图片和背景图片
background: context {
if here().page() == 1 and cover-image != none {
block(width:100%, height: 100%)[#image(cover-image, width: 100%, height: 100%)]
} else if background-color != none{
block(width:100%, height:100%, fill: rgb(background-color))
}
},
header: context {
if here().page() == 1 {
return
}
let elems = query(heading.where(level: 1).after(here()))
let chapter-title = ""
if (elems == () or elems.first().location().page() != here().page()) {
let elems = query(heading.where(level: 1).before(here()))
chapter-title = elems.last().body
} else {
chapter-title = elems.first().body
}
let head-title = text()[
#if short-title != none {
short-title
} else {
title
}
]
if calc.even(here().page()) == true {
emph(chapter-title) + h(1fr) + emph(head-title)
} else {
emph(head-title) + h(1fr) + emph(chapter-title)
}
v(-8pt)
align(center)[#line(length: 105%, stroke: (thickness: 1pt, dash: "solid"))]
},
footer: context {
if here().page() == 1 {return}
[
#if calc.even(here().page()) == true {
align(left)[#counter(page).display("1 / 1",both: true,)]
}else{
align(right)[#counter(page).display("1 / 1",both: true,)]
}
]
})
// 配置列表
set list(tight: true, indent: 2em)
show list: it => [
#set text(top-edge: "ascender")
#it
]
set enum(tight: true, indent: 2em)
show enum: it => [
#set text(top-edge: "ascender")
#it
]
// 配置标题
set heading(numbering: "1.1.1.1.1.")
show heading: it => box(width: 100%)[
#if it.numbering != none { counter(heading).display() }
#it.body
#if it.level == 1 and it.numbering != none{
chaptercounter.step()
counter(math.equation).update(0)
}
]
// 配置一级标题
show heading.where(
level: 1
): it => box(width: 100%)[
#set align(left)
#set text(fill: accent-color)
#set heading(numbering: "章节 1. ")
#it
#v(-12pt)
#line(length:100%, stroke: gray)
]
// 配置公式的编号和间距
set math.equation(numbering: (..nums) => (
context {
numbering("(1.1)", chaptercounter.at(here()).first(), ..nums)
}
))
show math.equation: eq => {
set block(spacing: 0.65em)
eq
}
// 配置图像和图像编号
set figure(
numbering: (..nums) => context {
numbering("1.1", chaptercounter.at(here()).first(), ..nums)
})
// 配置表格
set table(
fill: (_, row) => if row == 0 {accent-color.lighten(40%)} else {accent-color.lighten(80%)},
stroke: 1pt + white
)
// set figure(placement: auto)
show figure.where(
kind: table
): set figure.caption(position: bottom)
show figure.where(
kind: raw
): it => {
set block(width: 100%, breakable: true)
it
}
// 配置行内代码块
show raw.where(
block: false,
): it => box(fill: luma(245), inset: (x: 2pt), outset: (y: 3pt), radius: 1pt)[#it]
show raw.where(block: true): it => sourcecode[#it]
//------------------------------------------------------------------
box(width: 100%, height: 40%)[
// 显示论文的标题和描述。
#align(right+bottom)[
#text(36pt, weight: "bold")[#title]
#parbreak()
#if description != none {
text(size: 16pt, style: "italic")[#description]
}
]
]
box(width: 100%, height: 50%)[
#align(right+top)[
#if authors.len() > 0 {
box(inset: (y: 10pt), {
authors.map(author => {
text(16pt, weight: "semibold")[
#if "homepage" in author {
[#link(author.homepage)[#author.name]]
} else { author.name }]
if "affiliations" in author {
super(author.affiliations)
}
if "github" in author {
link(author.github, box(height: 1.1em, baseline: 13.5%)[#image.decode(githubSvg)])
}
}).join(", ", last: {
if authors.len() > 2 {
", and"
} else {
" and"
}
})
})
}
#v(-2pt, weak: true)
#if affiliations.len() > 0 {
box(inset: (bottom: 10pt), {
affiliations.map(affiliation => {
text(12pt)[
#super(affiliation.id)#h(1pt)#affiliation.name
]
}).join(", ")
})
}
]
]
box(width: 100%)[
#if date != none {
text(size: 12pt, "最初写作于:")
text(
size: 12pt,
fill: accent-color,
weight: "semibold",
date.display("[year]年[month]月[day]日")
)
parbreak()
text(size: 12pt, "最后更新于:")
text(
size: 12pt,
fill: accent-color,
weight: "semibold",
datetime.today().display("[year]年[month]月[day]日")
)
} else {
text(size: 11pt)[最后更新于:#h(5pt)] + text(
size: 11pt,
fill: accen-color,
weight: "semibold",
datetime.today().display("[month repr:long] [day padding:zero], [year repr:full]")
)
}
]
pagebreak()
// 显示笔记的目录
outline(indent: auto)
v(24pt, weak: true)
// 将段落设置为两端对齐,并设置换行。
set par(justify: true, linebreaks: "optimized", first-line-indent:2em, leading: 0.8em)
pagebreak()
// 显示笔记的内容
body
// 显示参考文献
if bibliography-file != none {
pagebreak()
show bibliography: set text(10.5pt)
bibliography(bibliography-file, title: "参考文献", style: "gb-7714-2015-numeric")
}
}
// 函数===========================================================
// 配置块引用
#let blockquote(cite: none, body) = [
#set text(size: 10.5pt)
#pad(left: 0.5em)[
#block(
breakable: true,
width: 100%,
fill: gray.lighten(95%),
radius: (left: 4pt, right: 4pt),
stroke: (left: 4pt + eastern.darken(20%), rest: 1pt + silver),
inset: 1em
)[#body]
]
]
// 水平标尺
#let horizontalrule = [#v(0.5em) #line(start: (20%,0%), end: (80%,0%)) #v(0.5em)]
// 另外的水平标尺
#let sectionline = align(center)[#v(0.5em) * \* #sym.space.quad \* #sym.space.quad \* * #v(0.5em)]
// ==== 使用 showybox 和 ctheorems 包创建盒子 ====
//
// | 环境 | 强调色 |
// |---------|-----------------------|
// | 定义 | orange |
// | 示例 | blue |
// | 提示 | olive |
// | 注意 | red |
// | 引用 | eastern |
// | 定理 | yellow |
// | 命题 | navy |
#let boxnumbering = "1.1.1.1.1.1"
#let boxcounting = "heading"
#let notebox(name, number, body, ntype, nicon, ncolor) = {
showybox(
title-style: (
weight: 1000,
color: ncolor.darken(20%),
sep-thickness: 0pt,
),
frame: (
border-color: ncolor.darken(20%),
title-color: ncolor.lighten(80%),
body-color: ncolor.lighten(80%),
thickness: (left: 4pt),
radius: 4pt
),
title: [#box(height: 0.85em)[#image.decode(nicon)] #name #h(1fr) #ntype #number],
body
)
}
#let definition = thmenv(
"definition",
boxcounting, //base counter name
2, // number of base number levels to use
(name, number, body) => {
notebox(name, number, body, "定义", defSvg, orange)
}
).with(numbering: boxnumbering)
#let example = thmenv(
"example",
boxcounting,
2,
(name, number, body, ..args) => {
notebox(name, number, body, "示例", egSvg, blue)
}
).with(numbering: boxnumbering)
#let tip = thmenv(
"tip",
boxcounting,
2,
(name, number, body) => {
notebox(name, number, body, "提示", tipSvg, olive)
}
).with(numbering: boxnumbering)
#let attention = thmenv(
"attention",
boxcounting,
2,
(name, number, body) => {
notebox(name, number, body, "注意", cautionSvg, red)
}
).with(numbering: boxnumbering)
#let quote = thmenv(
"quote",
boxcounting,
2,
(name, number, body) => {
notebox(name, number, body, "引用", quoteSvg, eastern)
}
).with(numbering: boxnumbering)
#let theorem = thmenv(
"theorem",
boxcounting,
2,
(name, number, body) => {
notebox(name, number, body, "定理", thmSvg, yellow)
}
).with(numbering: boxnumbering)
#let proposition = thmenv(
"proposition",
boxcounting,
2,
(name, number, body) => {
notebox(name, number, body, "命题", propSvg, navy)
}
).with(numbering: boxnumbering)