Skip to content

Commit c1b41be

Browse files
committed
upd
1 parent f81384b commit c1b41be

File tree

1 file changed

+2
-175
lines changed

1 file changed

+2
-175
lines changed

manual/lib.typ

Lines changed: 2 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1-
2-
// ================================
3-
// 字体配置
4-
// ================================
5-
61
#let font = (
7-
// 中文字体
82
zh_shusong: "Noto Serif CJK SC",
93
zh_zhongsong: "Noto Serif CJK SC",
104
zh_kai: "LXGW WenKai",
115
zh_hei: "Noto Sans CJK SC",
12-
// 英文字体
136
en_sans_serif: "New Computer Modern",
147
en_serif: "New Computer Modern",
15-
en_typewriter: "Courier New",
16-
en_code: "Consolas",
8+
en_code: "Courier Prime Code",
179
)
1810

19-
// ================================
20-
// 字号配置
21-
// ================================
22-
2311
#let font-size = (
2412
s2: 18pt, // 二号
2513
n3: 16pt, // 三号
@@ -30,10 +18,6 @@
3018
s5: 9pt, // 小五
3119
)
3220

33-
// ================================
34-
// 样式配置
35-
// ================================
36-
3721
#let config = (
3822
// 字号设置
3923
text-size: font-size.n5,
@@ -60,121 +44,19 @@
6044
block-space: 0.75em,
6145
// 颜色设置
6246
raw-color: rgb("#f0f0f0"),
63-
problem-color: rgb(241, 241, 255),
64-
summary-color: rgb(240, 248, 255),
6547
// 列表样式
6648
list-marker: ([•], [◦], [▶]),
6749
enum-numbering: ("1.", "(1)", "", "a."),
68-
// 表格样式
69-
table-stroke: 0.08em,
70-
table-header-stroke: 0.05em,
7150
)
7251

73-
// ================================
74-
// 全局状态
75-
// ================================
76-
77-
// 全局title状态
7852
#let title-state = state("document-title", "")
7953

80-
// ================================
81-
// 工具函数
82-
// ================================
83-
8454
// 解决首段缩进问题的空白段
8555
#let fake-par = {
8656
par(box())
8757
v(-config.spacing)
8858
}
8959

90-
// 偏微分符号
91-
#let pardiff(x, y) = $frac(partial #x, partial #y)$
92-
93-
// ================================
94-
// 学术组件
95-
// ================================
96-
97-
// 通用框组件
98-
#let custom-block(
99-
title: none,
100-
color: rgb(245, 245, 245),
101-
it,
102-
) = {
103-
set text(font: config.emph-font)
104-
let body = if title != none {
105-
strong(title) + h(config.block-space) + it
106-
} else {
107-
it
108-
}
109-
110-
block(
111-
fill: color,
112-
inset: 8pt,
113-
radius: 2pt,
114-
width: 100%,
115-
body,
116-
)
117-
fake-par
118-
}
119-
120-
// 题目框
121-
#let problem-counter = counter("problem")
122-
#let problem = custom-block.with(
123-
title: [
124-
#problem-counter.step()
125-
题目 #context problem-counter.display().
126-
],
127-
color: config.problem-color,
128-
)
129-
130-
// 解答框
131-
#let solution(it) = {
132-
set enum(numbering: "(1)")
133-
let body = [*解答.*] + h(config.block-space) + it
134-
block(
135-
inset: 8pt,
136-
below: config.leading,
137-
width: 100%,
138-
body,
139-
)
140-
fake-par
141-
}
142-
143-
// 总结框
144-
#let summary = custom-block.with(
145-
title: [总结.],
146-
color: config.summary-color,
147-
)
148-
149-
// 三线表格
150-
#let three-line-table(it) = {
151-
if it.children.any(c => c.func() == table.hline) {
152-
return it
153-
}
154-
155-
let meta = it.fields()
156-
meta.stroke = none
157-
meta.remove("children")
158-
159-
let header = it.children.find(c => c.func() == table.header)
160-
let cells = it.children.filter(c => c.func() == table.cell)
161-
162-
if header == none {
163-
let columns = meta.columns.len()
164-
header = table.header(..cells.slice(0, columns))
165-
cells = cells.slice(columns)
166-
}
167-
168-
return table(
169-
..meta,
170-
table.hline(stroke: config.table-stroke),
171-
header,
172-
table.hline(stroke: config.table-header-stroke),
173-
..cells,
174-
table.hline(stroke: config.table-stroke),
175-
)
176-
}
177-
17860
#let header-style(heading) = {
17961
set text(font: config.header-font)
18062
let title = title-state.get()
@@ -212,10 +94,7 @@
21294
title: "",
21395
author: "",
21496
date: none,
215-
abstract: none,
216-
keywords: (),
21797
) = {
218-
// 主标题
21998
align(center)[
22099
#block(
221100
text(
@@ -228,13 +107,11 @@
228107
#v(0.5em)
229108
]
230109

231-
// 作者
232110
if author != "" {
233111
set text(config.author-size, font: config.author-font)
234112
align(center, author)
235113
}
236114

237-
// 日期
238115
if date != none {
239116
date = if date == auto {
240117
datetime.today().display("[year]年[month]月[day]日")
@@ -244,45 +121,25 @@
244121
set text(config.author-size, font: config.author-font)
245122
align(center, date)
246123
}
247-
248-
// 摘要和关键词
249-
if abstract != none [
250-
#v(2pt)
251-
#fake-par
252-
*摘要:* #abstract
253-
254-
#if keywords != () [
255-
*关键字:* #keywords.join("")
256-
]
257-
#v(2pt)
258-
]
259124
}
260125

261-
// ================================
262-
// 主模板函数
263-
// ================================
264-
265126
#let project(
266127
title: "",
267128
author: "",
268129
date: none,
269-
abstract: none,
270-
keywords: (),
271130
body,
272131
) = {
273132
title-state.update(title)
274133

275134
// 文档设置
276-
set document(author: author, title: title, date: date, keywords: keywords)
135+
set document(author: author, title: title, date: date)
277136

278-
// 页面设置
279137
set page(
280138
numbering: "1",
281139
number-align: center,
282140
header: prev-header,
283141
)
284142

285-
// 基础样式设置
286143
set heading(numbering: "1.1")
287144
set text(
288145
font: config.body-font,
@@ -313,10 +170,6 @@
313170
set math.equation(numbering: "(1)")
314171
set underline(evade: false)
315172

316-
// ================================
317-
// 标题样式
318-
// ================================
319-
320173
show heading: it => {
321174
set text(font: config.heading-font)
322175
let body = if it.numbering != none {
@@ -347,22 +200,6 @@
347200
it
348201
}
349202

350-
// ================================
351-
// 元素样式
352-
// ================================
353-
354-
// 数学公式:无标签则不编号
355-
show math.equation: it => {
356-
set block(breakable: true)
357-
if it.block and not it.has("label") [
358-
#counter(math.equation).update(v => v - 1)
359-
#math.equation(it.body, block: true, numbering: none)#label("")
360-
] else {
361-
it
362-
}
363-
}
364-
365-
// 图表样式
366203
show figure: it => {
367204
set block(breakable: true)
368205
set text(font: config.caption-font)
@@ -374,8 +211,6 @@
374211
it + fake-par
375212
}
376213
show image: it => it + fake-par
377-
378-
// 列表样式
379214
show list: it => {
380215
set list(indent: 0em)
381216
set enum(indent: 0em)
@@ -391,7 +226,6 @@
391226
it + fake-par
392227
}
393228

394-
// 文字样式
395229
show strong: set text(font: config.strong-font)
396230
show emph: set text(font: config.emph-font)
397231
show ref: set text(red)
@@ -400,7 +234,6 @@
400234
underline(it)
401235
}
402236

403-
// 代码样式
404237
show raw.where(block: false): it => {
405238
set text(font: config.raw-font)
406239
box(
@@ -423,17 +256,11 @@
423256
it + fake-par
424257
}
425258

426-
// ================================
427-
// 文档标题部分
428-
// ================================
429259
make-title(
430260
title: title,
431261
author: author,
432262
date: date,
433-
abstract: abstract,
434-
keywords: keywords,
435263
)
436264

437-
// 正文内容
438265
body
439266
}

0 commit comments

Comments
 (0)