-
Notifications
You must be signed in to change notification settings - Fork 0
/
t-math.typ
97 lines (90 loc) · 2.79 KB
/
t-math.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
#let annotated-symbol(
sym, annot,
breakpoints: 2/5,
breakpoint-padding: 0%,
scale-mid: 1
) = {
assert(
type(sym) == "symbol",
message: "Input needs to be a symbol, is actually " + type(sym)
)
assert(
type(annot) == "content",
message: "Annotation needs to be of type content, is actually " +
type(annot)
)
assert(
(type(breakpoints) == "integer" or type(breakpoints) == "float")
and breakpoints < 0.5,
message: "breakpoints must be a number less than 1/2, is actually " +
str(breakpoints) +
", of type " +
type(breakpoints)
)
assert(
type(breakpoint-padding) == "length" or
type(breakpoint-padding) == "relative length" or
type(breakpoint-padding) == "ratio",
message: "breakpoint-padding must be a length, relative length or ratio, is actually " +
type(breakpoint-padding)
)
assert(
type(scale-mid) == "integer" or type(scale-mid) == "float",
message: "scale-mid must be a number, is actually " +
type(scale-mid)
)
let sym-content = [#sym]
style(styles => {
let s = measure(sym-content, styles)
let a = measure(math.script(annot), styles)
let out-segment-length = s.width * breakpoints
let mid-segment-length = s.width * (1 - 2 * breakpoints)
let factor = a.width / mid-segment-length * scale-mid
let sym-back = box(
width: out-segment-length,
height: s.height,
clip: true,
place(left,
sym-content
)
)
let sym-middle = box(
width: mid-segment-length,
height: s.height,
clip:true,
place(left,
dx: -out-segment-length,
sym-content
)
)
let sym-front = box(
width: out-segment-length,
height: s.height,
clip: true,
place(left,
dx: -(out-segment-length + mid-segment-length),
sym-content
)
)
let scaled-sym = box(
width: 2 * out-segment-length + factor * mid-segment-length,
height: s.height
)[
#place(left + top,
sym-back
)
#place(left + top,
dx: out-segment-length + breakpoint-padding,
scale(x: factor * 100%, origin: left, sym-middle)
)
#place(left + top,
dx: out-segment-length + factor * mid-segment-length + 2 * breakpoint-padding,
sym-front
)
]
math.attach(
math.limits(scaled-sym),
t: annot
)
})
}