-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.typ
58 lines (56 loc) · 1.5 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
#let zine(
zine_page_margin: 8pt,
draw_border: true,
digital: false,
contents: ()
) = {
if digital {
set page(height: 4.25in, width: 2.75in, margin: zine_page_margin)
for (i, page) in contents.enumerate() {
if i > 0 { pagebreak() }
page
}
} else {
// set printer page size (typst's page) and a zine page size (pages in the zine)
set page("us-letter", margin: zine_page_margin, flipped: true)
let zine_page_height = (8.5in-zine_page_margin)/2 - zine_page_margin;
let zine_page_width = (11in-zine_page_margin)/4 - zine_page_margin;
let contents = (
// reorder the pages so the order in the grid aligns with a zine template
contents.slice(1,5).rev()+contents.slice(5,8)+contents.slice(0,1)
).map(
// wrap the contents in blocks the size of the zine pages so that we can
// maneuver them at will
elem => block(
width: zine_page_width,
height: zine_page_height,
spacing: 0em,
elem
)
).enumerate().map(
// flip if on top row
elem => {
if elem.at(0) < 4 {
rotate(
180deg,
origin: center,
elem.at(1)
)
} else {
elem.at(1)
}
}
)
let zine_grid = grid.with(
columns: 4 * (zine_page_width, ),
rows: zine_page_height,
gutter: zine_page_margin,
)
if draw_border {
zine_grid = zine_grid.with(
stroke: luma(0)
)
}
zine_grid(..contents)
}
}