-
Notifications
You must be signed in to change notification settings - Fork 6
/
boxes.typ
332 lines (299 loc) · 9.59 KB
/
boxes.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#import "themes.typ": *
#import "layouts.typ": *
#let _calculate-width(b1, b2) = {
// Get positions and width of box
let p1 = b1.location().position()
let p2 = b2.location().position()
let width = p2.at("x") - p1.at("x")
width
}
#let _calculate-vertical-distance(current-position, box, spacing) = {
let p = box.location().position()
// calculate distance
let bottom-y = p.y
let without-spacing = p.y - current-position.y
let dist = p.y - current-position.y - spacing
(dist, without-spacing)
}
#let _calculate-vertical-distance-to-page-end(m-loc, spacing) = {
// Get position of end of page
pt.at("heading-text-args", default: (:))
100% - m-loc.y - spacing
}
// We have two boxes b1 and b2 and want to know if they will
// intersect if we increase the vertical size of box b1 while
// leaving the beginning position intact.
#let _boxes-would-intersect(b1-left, b1-right, b2-left, b2-right) = {
let b1l = b1-left.location().position()
let b1r = b1-right.location().position()
let b2l = b2-left.location().position()
let b2r = b2-right.location().position()
// If the intervals [b1-left.x, b1-right.x] and [b2-left.x, b2-right.x]
// do not intersect, they will never intersect when stretching the box
if not ((b1l.at("x") <= b2r.at("x")) and (b2l.at("x") <= b1r.at("x"))) {
return false
} else {
// If the x-intervals do intersect,
return true
}
let p = b1-right.location().position()
let q = b2-left.location().position()
let filt1 = p.at("x") > q.at("x")
let filt2 = p.at("y") < q.at("y")
let filt3 = b1-right.location().page() == b2-left.location().page()
filt1 and filt2
}
#let stretch-box-to-next(box-function, location-heading-box, spacing: 1.2em, ..r) = locate(loc => {
// Get current y location
let m-loc = loc.position()
let b1 = query(<COLUMN-BOX>, loc)
let b2 = query(<COLUMN-BOX-RIGHT>, loc)
// Find current box in all these queries
let cb = b1.zip(b2).filter(b => {
let (c-box, c-box-end) = b
c-box.location().position() == location-heading-box.position()
}).first()
let target = b1
.zip(b2)
.map(b => {
let (c-box, c-box-end) = b
let c-loc = c-box.location().position()
let filt = _boxes-would-intersect(cb.at(0), cb.at(1), c-box, c-box-end)
let (dist, dist-without-spacing) = _calculate-vertical-distance(m-loc, c-box, spacing)
(dist, filt, dist-without-spacing)
})
.filter(dist-filt => {dist-filt.at(1) and dist-filt.at(2) > 0.0mm})
.sorted(key: dist-filt => {dist-filt.at(2)})
// If we found a target, expand towards this target
if target.len() > 0 {
let (dist, _, _) = target.first()
box-function(..r, height: dist)
// Else determine the end of the page
} else {
let pl = _state-poster-layout.at(loc)
let (_, height) = pl.at("size")
let dist = height - m-loc.y - spacing
box-function(..r, height: dist)
}
})
// A common box that makes up all other boxes
#let common-box(
body: none,
heading: none,
heading-size: none,
heading-box-args: none,
heading-text-args: none,
heading-box-function: none,
body-size: none,
body-box-args: none,
body-text-args: none,
body-box-function: none,
stretch-to-next: false,
spacing: none,
bottom-box: false,
) = {
locate(loc => {
let pt = _state-poster-theme.at(loc)
let pl = _state-poster-layout.at(loc)
let spacing = if spacing==none {pl.at("spacing")} else {spacing}
/// #####################################################
/// ###################### HEADING ######################
/// #####################################################
// Sort out arguments for heading box
let heading-box-args = heading-box-args
if heading-box-args==none {
heading-box-args = pt.at("heading-box-args", default: (:))
if body!=none {
heading-box-args = pt.at("heading-box-args-with-body", default: heading-box-args)
}
}
// Sort out arguments for heading text
let heading-text-args = heading-text-args
if heading-text-args==none {
heading-text-args = pt.at("heading-text-args", default: (:))
if body!=none {
heading-text-args = pt.at("heading-text-args-with-body", default: heading-text-args)
}
}
// Define which function to use for heading box
let heading-box-function = heading-box-function
if heading-box-function==none {
heading-box-function = pt.at("heading-box-function", default: rect)
}
// Determine the size of the heading
let heading-size = pl.at("heading-size", default: heading-size)
if heading-size!=none {
heading-text-args.insert("size", heading-size)
}
/// CONSTRUCT HEADING IF NOT EMPTY
let heading-box = box(width: 0%, height: 0%)
let heading = if heading!=none {
[
#set text(..heading-text-args)
#heading
]
} else {
none
}
if heading!=none {
heading-box = heading-box-function(
..heading-box-args,
)[#heading]
}
/// #####################################################
/// ####################### BODY ########################
/// #####################################################
// Sort out arguments for body box
let body-box-args = body-box-args
if body-box-args==none {
body-box-args = pt.at("body-box-args", default: (:))
if heading==none {
body-box-args = pt.at("body-box-args-with-heading", default: body-box-args)
}
}
// Sort out arguments for body text
let body-text-args = body-text-args
if body-text-args==none {
body-text-args = pt.at("body-text-args", default: (:))
if heading==none {
body-text-args = pt.at("body-text-args-with-heading", default: body-text-args)
}
}
// Define which function to use for body box
let body-box-function = body-box-function
if body-box-function==none {
body-box-function = pt.at("body-box-function", default: rect)
}
// Determine the size of the body
let body-size = pl.at("body-size", default: body-size)
if body-size!=none {
body-text-args.insert("size", body-size)
}
/// CONSTRUCT BODY IF NOT EMPTY
let body-box = box(width: 0%, height: 0%)
let body = if body!=none {
[
#set text(..body-text-args)
#body
]
} else {
none
}
if body!=none {
body-box = body-box-function(
..body-box-args,
)[#body]
}
/// #####################################################
/// ##################### COMBINE #######################
/// #####################################################
/// IF THIS BOX SHOULD BE STRETCHED TO THE NEXT POSSIBLE POINT WE HAVE TO ADJUST ITS SIZE
if stretch-to-next==true {
if body!=none {
body-box = stretch-box-to-next(
body-box-function,
loc,
spacing: spacing,
body,
..body-box-args,
)
} else {
heading-box = stretch-box-to-next(
heading-box-function,
loc,
spacing: spacing,
heading,
..heading-box-args,
)
}
}
box([#stack(dir: ltr, [#stack(dir:ttb,
heading-box,
body-box,
)], [#box(width: 0pt, height: 0pt)<COLUMN-BOX-RIGHT>])<COLUMN-BOX>])
})
}
// Write a function to creata a box with heading
#let column-box(
body,
..args
) = {
common-box(body: body, ..args)
}
// Function to display the title of the document
#let title-box(
title,
subtitle: none,
authors: none,
institutes: none,
keywords: none,
image: none,
text-relative-width: 80%,
spacing: 5%,
title-size: none,
subtitle-size: none,
authors-size: none,
keywords-size: none,
) = {
locate(loc => {
let text-relative-width = text-relative-width
/// Get theme and layout state
let pl = _state-poster-layout.at(loc)
/// Layout specific options
let title-size = if title-size==none {pl.at("title-size")} else {title-size}
let subtitle-size = if subtitle-size==none {pl.at("subtitle-size")} else {subtitle-size}
let authors-size = if authors-size==none {pl.at("authors-size")} else {authors-size}
let keywords-size = if keywords-size==none {pl.at("keywords-size")} else {keywords-size}
/// Generate body of box
let text-content = [
#set text(size: title-size)
#title\
#set text(size: subtitle-size)
#if subtitle!=none {[#subtitle\ ]}
#v(1.25em, weak: true)
#set text(size: authors-size)
#if authors!=none {[#authors\ ]}
#if institutes!=none {[#institutes\ ]}
#if keywords!=none {[
#v(1em, weak: true)
#set text(size: keywords-size)
#keywords
]}
]
/// Expand to full width of no image is specified
if image==none {
text-relative-width=100%
}
/// Finally construct the main rectangle
common-box(heading:
stack(dir: ltr,
box(text-content, width: text-relative-width),
align(right, box(image, width: 100% - spacing - text-relative-width))
))
})
}
#let bottom-box(body, text-relative-width: 70%, logo: none, ..args) = {
let body = [
#set align(top+left)
#if logo==none {
box(width: 100%, body)
} else {
stack(dir: ltr,
box(width: text-relative-width, body),
align(right+horizon, logo),
)
}
]
let r = common-box(heading: body, bottom-box: true, ..args)
align(bottom, r)
}
/// TODO
#let bibliography-box(bib-file, body-size: 24pt, title: none, style: "ieee", stretch-to-next: false) = {
if title==none {
title = "References"
}
column-box(heading: title, stretch-to-next: stretch-to-next)[
#set text(size: body-size)
#bibliography(bib-file, title: none, style: style)
]
}