-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate.typ
More file actions
217 lines (196 loc) · 5.36 KB
/
template.typ
File metadata and controls
217 lines (196 loc) · 5.36 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
#import "@preview/digestify:0.1.0": *
#import "@preview/mitex:0.2.5": *
#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: 1.5*margin, top: 1.25cm ),
header-ascent: 40%,
header: context {
let headings = query(
selector(heading.where(level: 2, outlined: true)).after(here())
)
let this = headings
.filter((it) => it.location().position().page == here().position().page)
.map((it) => it.body);
return [
#grid(
columns: (auto, 1fr, auto),
text("UCH", size: 9pt, weight: "semibold"),
align(center, text(this.join(", "), size: 9pt, weight: "semibold")),
text(counter(page).display("1"), size: 9pt, weight: "semibold"),
)
]
},
)
set text(font: "New Computer Modern", lang: "en")
set par(justify: true)
show heading: set block(sticky: true)
show heading.where(level: 1): it => [
#set block(sticky: true, above: 1em)
#set text(size: 1.1em)
#block[
#smallcaps[
#it.body
]
]
]
show heading.where(level: 2): it => [
#set text(weight: "regular")
#it.body
]
show outline.entry: it => link(
it.element.location(),
it.indented([], [#it.body() #h(1fr) #it.page()]),
)
show raw.where(block: true): it => {
set text(6.5pt)
set par(justify: false)
it
}
set raw(theme: "theme.xml")
block(width: 100%, height: 100%, {
set align(horizon + center)
set par(spacing: 0em)
image("logo.svg", height: 128pt)
[
#set text(size: 2.5em)
#v(0.5em)
*University of Chile*
#v(1em)
sin globito no hay fiesta
#v(0.5em)
#set text(size: 0.5em)
Diego Arias, Gabriel Carmona, Martín Ruiz-Tagle
#set align(bottom + center)
#datetime.today().display()
]
})
pagebreak()
set page(
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))
]
)
show: columns.with(3, gutter: gutter)
body
}
#let index() = {
return outline(title: none, depth: 1)
}
#let depends-unique(items) = {
let deps = (:)
for it in items {
if "dependsOn" in it {
for d in it.dependsOn {
deps.insert(d, true)
}
}
}
return deps
}
#let verified-files = depends-unique(json.decode(read("stats.json")))
#let insert(filename) = {
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 full_filename = "lib/" + filename
let contents = read(full_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[
#if (metadata.at("type", default: "cpp") == "tex") {
v(1em);
}
#block(breakable: false, width: 100%, fill: gray.transparentize(80%), inset: 3pt, outset: 3pt)[
#set text(8pt)
== #eval(metadata.name, mode: "markup")
#if full_filename in verified-files [
#set text(fill: olive.mix(lime), baseline: -2pt)
#h(1fr)
#sym.circle.filled
]
#linebreak()
#for (key, value) in metadata.info {
text(key + ": ", weight: "bold")
eval(value, mode: "markup")
linebreak()
}
]
#v(-4pt)
#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
}
}
#if (metadata.at("type", default: "cpp") == "typst") {
set par(spacing: 0.5em)
set text(size: 8pt)
eval(code, mode: "markup")
} else if (metadata.at("type", default: "cpp") == "tex") {
show heading.where(level: 2): it => [
#v(0.5em)
#it.body
]
set par(spacing: 0.5em)
set text(size: 8pt)
set heading(outlined: false)
mitext(code)
set heading(outlined: true)
} else {
if code != "" {
block(raw(code, lang: "cpp", block: true))
}
}
#v(-4pt)
]
}