-
Notifications
You must be signed in to change notification settings - Fork 2
/
matrix.satyh
48 lines (45 loc) · 1.71 KB
/
matrix.satyh
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
@require: math
@require: table
module Matrix : sig
direct \matrix : [(math list) list] math-cmd
direct \matrix-body : [(math list) list] math-cmd
end = struct
let matrix-body mss =
let center ctx m = inline-fil ++ embed-math ctx m ++ inline-fil in
let body = text-in-math MathInner (fun ctx -> (
let size = get-font-size ctx in
let pads-normal = (0pt, 0pt, size *' 0.25, size *' 0.25) in
let pads-top = (0pt, 0pt, 0pt, size *' 0.25) in
let pads-bottom = (0pt, 0pt, size *' 0.25, 0pt) in
let pads-single = (0pt, 0pt, 0pt, 0pt) in
let cell-of-m pads m = NormalCell(pads, inline-skip size ++ center ctx m) in
let cells-of-ms pads ms =
(match ms with
| [] -> []
| m :: ms ->
(let leftmost = NormalCell(pads, center ctx m) in
let rest = List.map (cell-of-m pads) ms in
leftmost :: rest))
in
let-rec cellss-of-mss-tail mss =
(match mss with
| [] -> []
| ms :: [] -> [cells-of-ms pads-bottom ms]
| ms :: mss -> (cells-of-ms pads-normal ms) :: (cellss-of-mss-tail mss))
in
let cellss =
(match mss with
| [] -> []
| ms :: [] -> [cells-of-ms pads-single ms]
| ms :: mss -> (cells-of-ms pads-top ms) :: (cellss-of-mss-tail mss))
in
let grf = fun _ _ -> [] in
let ib = tabular cellss grf in
let (_, height, depth) = get-natural-metrics ib in
let hgtaxis = get-axis-height ctx in
let rising = hgtaxis -' (height +' depth) *' 0.5 in
raise-inline rising ib))
in body
let-math \matrix mss = math-paren Math.paren-left Math.paren-right (matrix-body mss)
let-math \matrix-body mss = matrix-body mss
end