-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlib.typ
194 lines (173 loc) · 4.56 KB
/
lib.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
#import "nord.typ": *
#let en_text(size, body, fill: nord3, style: "italic") = text(
font: "Ysabeau Infant",
size: size,
style: style,
fill: fill,
weight: "light",
)[#body]
#let zh_text(size, body, fill: nord0) = text(
font: "LXGW Wenkai",
size: size,
fill: fill,
weight: "light",
)[#body]
#let cuisine(name_zh, name_en) = align(center)[
#v(.5em)
#zh_text(16pt)[#name_zh] \ #en_text(10pt)[#name_en]
#v(.3em)
]
#let item(name_zh, name_en) = box[
#zh_text(14pt)[#name_zh #h(1fr)] \
#v(-.7em)#h(.14em)#en_text(10pt)[#name_en]#v(.3em)
]
#let caidan(
title: none,
cover_image: none,
update_date: none,
page_height: 595.28pt,
page_width: 841.89pt,
num_columns: 3,
body,
) = {
let frame_font_size = 40pt
let frame_format = c => text(
c,
font: "WebOMints GD",
size: frame_font_size,
fill: nord3,
)
let frame = (
chars: ([E], [F], [G], [H]),
dx: 1em,
dy: 2em,
)
let dx = (1, -1, 1, -1)
let dy = (1, 1, -1, -1)
let border_x = (left, right, left, right)
let border_y = (top, top, bottom, bottom)
let column_width = page_width / num_columns
let frame_vert_line = line(
length: page_height - 2 * (frame.dy + frame_font_size),
angle: 90deg,
stroke: 1pt + nord3,
)
let frame_vert_line_dy = frame.dy + frame_font_size + .5em
let frame_horiz_line = line(
length: column_width - 2 * (frame.dx + frame_font_size) - .6em,
stroke: 1pt + nord3,
)
let frame_horiz_line_dx = frame.dx + frame_font_size + .3em
let separator_vert_line = line(
length: page_height,
angle: 90deg,
stroke: (paint: nord0, thickness: .5pt, dash: "dashed"),
)
set page(
fill: nord6,
height: page_height,
width: page_width,
margin: (x: frame.dx + 2em, y: frame.dy + 4em),
background: [
// separator lines
#for i in range(num_columns - 1) {
place(
top + left,
dx: (i + 1) * column_width,
separator_vert_line,
)
}
// frame
#for i in range(num_columns) {
let offset_xl = i * column_width
let offset_xr = (num_columns - i - 1) * column_width
// frame characters
for j in range(4) {
place(
border_x.at(j) + border_y.at(j),
dx: dx.at(j) * (offset_xl + frame.dx),
dy: dy.at(j) * frame.dy,
frame_format(frame.chars.at(j)),
)
}
// left frame line
place(
top + left,
dx: offset_xl + frame.dx + 7pt,
dy: frame_vert_line_dy,
frame_vert_line,
)
// right frame line
place(
top + right,
dx: -(offset_xr + 2 * frame.dx) + 4pt,
dy: frame_vert_line_dy,
frame_vert_line,
)
// top frame line
place(
top + left,
dx: offset_xl + frame_horiz_line_dx,
dy: frame.dy + 4pt,
frame_horiz_line,
)
// bottom frame line
place(
bottom + left,
dx: offset_xl + frame_horiz_line_dx,
dy: -frame.dy + 4pt,
frame_horiz_line,
)
// page numbering
place(
bottom + left,
dx: offset_xl + 0.5 * column_width,
dy: -frame.dy - 1em,
context {
let num = (counter(page).get().at(0) - 1) * 3 + i
if num != 0 {
en_text(10pt, style: "normal")[#numbering("I", num)]
}
},
)
}
],
)
let title_page = context {
set align(center)
let title_content = {
title
if cover_image != none {
v(3em)
let img_width = measure(cover_image).width
let max_img_width = column_width - 2 * frame.dx - 6em
if img_width.pt() > max_img_width.abs.pt() {
set image(width: column_width - 2 * frame.dx - 6em)
cover_image
} else {
cover_image
}
}
if update_date != none {
v(5em)
zh_text(10pt)[
更新于:#update_date.display("[year]年[month padding:none]月[day padding:none]日") ]
linebreak()
en_text(8pt)[
Updated on #update_date.display("[month repr:long] [day], [year]")]
}
}
let text_dy = (
page_height - measure(title_content).height
) / 2 - frame.dy - 2em
if title != none or cover_image != none or update_date != none {
v(text_dy)
title_content
}
}
set list(marker: [#v(.7em)#en_text(16pt, fill: nord3)[☐]])
columns(
num_columns,
gutter: frame.dx * 2 + 4em,
)[#title_page #colbreak(weak: true) #body]
}