-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreset.typ
More file actions
293 lines (293 loc) · 6.45 KB
/
Copy pathpreset.typ
File metadata and controls
293 lines (293 loc) · 6.45 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
#let math-state-counter=counter("math-state")
#let is-clear=()=>{
let chapters=query(selector(<题集篇>).or(<讲义篇>))
chapters.any(c=>{
c.location().page()==here().page()
})
}
#let is-chap-page=()=>{
let chapters=query(
heading.where(level:1).or(
heading.where(level:2).after(<题集篇>).before(<积分常见结论>)
)
)
chapters.any(c=>{
c.location().page()==here().page()
})
}
#let book-header=()=>context{
if is-clear() {
none
} else if is-chap-page() {
none
} else {
block(
stroke:(
bottom:.5pt,
),
inset:(
bottom:3pt,
),
{
if calc.odd(counter(page).get().first()) {
let heading-2=query(selector(heading.where(level:2).after(here()))).filter(h=>{
h.location().page()==here().page()
}).first(default:none)
let heading-2=if heading-2==none {
query(selector(heading.where(level:2).before(here()))).last()
} else {
heading-2
}
link(
heading-2.location(),
{
counter(heading).display(heading-2.numbering)
" "
heading-2.body
},
)
h(1fr)
link(
<outline>,
counter(page).display(),
)
} else {
let heading-1=query(selector(heading.where(level:1).after(here()))).filter(h=>{
h.location().page()==here().page()
}).first(default:none)
let heading-1=if heading-1==none {
query(selector(heading.where(level:1).before(here()))).last()
} else {
heading-1
}
link(
<outline>,
counter(page).display(),
)
h(1fr)
link(
heading-1.location(),
{
if heading-1.numbering!=none{
counter(heading.where(level:1)).display(heading-1.numbering)
}
heading-1.body
},
)
}
}
)
}
}
#let book-footer=()=>context{
if is-clear() {
none
} else if is-chap-page() {
set align(center)
link(
<outline>,
counter(page).display(),
)
} else {
none
}
}
#let collection-foreground=()=>context{
set text(size:9pt)
let alignment=if calc.odd(counter(page).get().first()) {
right+top
}
else {
left+top
}
let section=counter(heading).get().at(1)
let match=query(metadata).filter(data=>{
data.value.keys().contains("kind") and data.value.kind=="question" and data.location().page()==here().page()
}).first(default:none)
let match=if match==none {
query(metadata).filter(data=>{
data.value.keys().contains("kind") and data.value.kind=="question" and data.location().page()<=here().page()
}).last(default:none)
} else {
match
}
place(
alignment,
dy:25mm+5.4em*(section -1)*2.6,
rotate(
90deg,
reflow:true,
link(
match.location(),
box(
height:1.4em,
width:5.4em,
fill:color.rgb("#e8d0d0"),
align(
center+horizon,
numbering("Q1",match.value.number)
),
)
)
)
)
}
#let preset(body)={
set page(
paper:"a4",
margin:(
top:25mm,
bottom:30mm,
outside:22mm,
inside:32mm,
),
numbering:"1",
header:book-header(),
footer:book-footer(),
number-align:center+bottom,
)
set text(
lang:"zh",
region:"CN",
font:(
"Noto Serif CJK SC",
"Noto Serif",
),
size:10.5pt,
top-edge:"bounds",
bottom-edge:"bounds",
costs:(
widow:0%,
orphan:0%,
),
)
set par(
justify:true,
leading:1.2em,
spacing:1.2em,
)
//句号应使用句点,且需维持标点挤压
show regex("[,。.、:;?!》)』」】〗〕〉]}“‘《(『「【〖〔〈[{,。.、:;]+"):it=>it.text.replace("。",".")
show math.equation:set text(
font:"New Computer Modern Math",
)
show math.equation:it=>math.display(it)
//令行内数学公式保持CJK间距
show math.equation.where(block:false):it=>{
let ghost=text(font:"Adobe Blank","\u{375}")
ghost;it;ghost
}
show math.equation:set block(breakable:true)
show math.equation.where(block:true):it=>block({
math-state-counter.step()
let pagenum=state(str(math-state-counter.get().first()))
context if here().page()!=pagenum.final(){
set text(fill:silver,size:16pt)
place(
center+bottom,
dy:10mm,
sym.arrow.b.filled,
)
}
it
context pagenum.update(here().page())
})
show heading:set align(center)
show heading:set text(weight:"extrabold")
show heading.where(level:1):set text(size:30pt)
show heading.where(level:2):set text(size:21pt)
show heading.where(level:3):set text(size:16pt)
show figure.where(kind:"question"):set block(breakable:true)
body
}
#let preset-frontmatter(body)={
set page(
numbering:"i",
)
body
}
#let preset-collection(body)={
show:preset
set page(
numbering:"1",
foreground:collection-foreground(),
)
show heading.where(level:2):set heading(
numbering:(..nums)=>numbering("难度一",nums.at(1)),
)
body
}
#let preset-lecture(body)={
show:preset
set page(
foreground:context{
set text(size:9pt)
let alignment=if calc.odd(counter(page).get().first()) {
right+top
}
else {
left+top
}
let section=counter(heading).get().at(1)
place(
alignment,
dy:25mm+(6.4em+20pt)*(section -1)*2.4,
link(
query(selector(heading.where(level:3)).before(here())).last().location(),
box(
height:6.4em+20pt,
width:1.4em,
fill:color.rgb("#d0d0e8"),
{
set text(
top-edge:"cap-height",
bottom-edge:"baseline",
)
set align(center+horizon)
set par(leading:3pt)
query(selector(heading.where(level:3)).before(here())).last().body
},
)
)
)
},
)
set par(
first-line-indent:(
amount:2em,
all:true,
),
)
show heading.where(level:2):set heading(
numbering:(..nums)=>numbering("阶段一",nums.at(1)),
)
show heading.where(level:3):set heading(
numbering:(..nums)=>numbering("一、1",..nums.pos().slice(1)),
)
show heading.where(level:4):set heading(
numbering:(..nums)=>numbering("1.1",..nums.pos().slice(2)),
)
show heading.where(level:4):set align(left)
show regex("[,。.、:;?!》』」】〗〕〉]}“‘《『「【〖〔〈[{,。.、:;]+"):it=>it.text.replace("。",".")
show regex("(.*?)"):emph
show emph:set text(
font:"Zhuque Fangsong (technical preview)",
size:10pt,
)
body
}
#let preset-appendix(body)={
show:preset
set par(
first-line-indent:(
amount:2em,
all:true,
)
)
show heading.where(level:1):set text(size:21pt)
show heading.where(level:1):set heading(numbering:"附录A")
show heading.where(level:2):set text(size:18pt)
show heading.where(level:2):set heading(numbering:"A.1")
set heading(supplement:"附录")
body
}