-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.typ
152 lines (138 loc) · 3.69 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
#let project(body) = {
let vertical-line(anchor, x) = {
place(
top + anchor,
line(
start: (x, 5%),
end: (x, 97%),
stroke: 0.5pt + black
),
)
}
set document(title: "Notebook")
let margin = 0.6cm
let gutter = 1.5%
set page(
paper: "us-letter",
flipped: true,
margin: ( left: margin, right: margin, bottom: margin, top: 1.25cm ),
header-ascent: 40%,
header: context {
let headings = query(
selector(heading.where(level: 2)).after(here())
)
let this = headings
.filter((it) => it.location().position().page == here().position().page)
.map((it) => it.body);
return align(right, text(this.join(", "), size: 9pt, weight: "semibold"))
},
background: [
#vertical-line(left, margin + gutter/2 + (100% - 2*margin - 2*gutter) / 3)
#vertical-line(right, -(margin + gutter/2 + (100% - 2*margin - 2*gutter) / 3))
]
)
set text(font: "Libertinus Serif", lang: "en")
set par(justify: true)
show: columns.with(3, gutter: gutter)
show heading.where(level: 1): it => [
#set block(above: 0em)
#smallcaps[
#it.body
]
]
show heading.where(level: 2): it => [
#set text(weight: "regular")
#it.body
]
show raw.where(block: true): it => {
set text(6.5pt)
set par(justify: false)
it
}
set raw(theme: "theme.xml")
body
}
#let title() = {
return {
block(width: 100%, height: 2.5em, {
set text(size: 1.25em)
align(bottom)[
= Team Notebook
]
place(top + right)[
#image("logo.svg", height: 32pt)
]
})
line(length: 100%, stroke: 0.5pt)
}
}
#let extract-code(contents) = {
return contents.split("- */\n").at(-1).trim("\n")
}
#let extract-metadata(contents) = {
return toml(bytes(contents.split("- */\n").at(0).split("/* -\n").at(-1)))
}
#let hash-lines(text, end) = {
bytes-to-hex(md5(
text.split("\n")
.slice(0, end)
.join("")
.replace(regex("\s+"), "")
)
).slice(0, 6)
}
#let insert(filename) = {
let contents = read("lib/" + filename)
let hash-metadata = toml("hashes/" + filename + ".toml")
let metadata = extract-metadata(contents)
let code = extract-code(contents)
let line-count = code.split("\n").len()
return block[
#block(breakable: false, width: 100%, fill: gray.transparentize(80%), inset: 3pt, outset: 3pt)[
#set text(9pt)
== #metadata.name
#linebreak()
#for (key, value) in metadata.info {
text(key + ": ", weight: "bold")
eval(value, mode: "markup")
linebreak()
}
]
#show raw.line: it => {
set box(
width: 100%,
outset: par.leading / 2,
)
let body = it.body
if it.text == "" {
body = " "
}
if hash-metadata.positions.contains(it.number) {
let index = hash-metadata.positions.position(i => i == it.number)
let hash = hash-metadata.hashes.at(index)
let prefix-hash = hash-metadata.prefix-hashes.at(index)
let stroke = (paint: gray.lighten(50%), thickness: 0.5pt, dash: "dashed")
if it.number == line-count {
stroke = 0.5pt + black
}
let divisor-padding = 1.5pt
box(inset: (bottom: divisor-padding))[
#body
#v(divisor-padding)
#place(bottom + left, dy: 2.5pt)[
#line(stroke: stroke, length: 100% - 40pt)
]
#place(bottom + right, dy: 4pt)[
#rect(fill: white, inset: 0pt)[
#set text(size: 5pt)
#hash,#text(prefix-hash, weight: "bold")
]
]
]
} else {
body
}
}
#block(raw(code, lang: "cpp", block: true))
]
}