-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.typ
103 lines (90 loc) · 2.02 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
#import "@preview/tablex:0.0.8": gridx, hlinex
#let invoice(
title: none,
vice-title: none,
invoice-date: "始皇帝十七年",
items: none,
pay: none,
recipient: none,
signature: none,
thanks: none,
) = {
set text(lang: "zh", region: "cn")
set page(paper: "a4", margin: (x: 20%, y: 20%, top: 8%, bottom: 5%))
show heading.where(
level: 1
): it => block(width: 100%)[
#set text(20pt, weight: "regular")
#smallcaps(it.body)
]
let format_currency(number, locale: "zh") = {
number
}
set text(2em)
align(center, smallcaps[
#set text(size: 2.5em)
#set par()
*#title*
])
align(center,[
#set par(leading: 0.40em)
#set text(size: 2em)
#vice-title \
])
align(left,[
#set par(leading: 0.40em)
#set text(size: 1em)
#recipient.location \
*#recipient.name*
])
v(0.5em)
let num_to_chinese(id) = {
if id == 1 { "壹" }
else if id == 2 { "贰" }
else if id == 3 { "叁" }
else if id == 4 { "肆" }
else if id == 5 { "伍" }
else if id == 6 { "陆" }
else if id == 7 { "柒" }
else if id == 8 { "捌" }
else if id == 9 { "玖" }
else if id == 10 { "拾" }
else { "" };
}
// 返回空字符串以防止索引超出范围
let items = items.enumerate().map(
((id, item)) => ([#str(num_to_chinese(id + 1))], [#item.description], [#format_currency(item.price)钱],),
).flatten()
[
#set text(number-type: "lining", 1em)
#gridx(
columns: (auto, 10fr, auto),
align: (
(column, row) =>
if column == 0 { center }
else if column == 1 { center }
else { right }
),
hlinex(),
[*编号*],
[*条目*],
[*计*],
hlinex(),
..items,
hlinex(),
[],
align(right,[总计]),
[#format_currency(pay.total)钱],
hlinex(start: 3),
)
]
align(center, [
*#invoice-date*
#set text(size: 1.2em)
])
align(center,[
#thanks \
#signature
#set text(size: 1.2em)
])
}