tabl-ali.lmt /size: 2216 b    last modification: 2024-01-16 10:22
1if not modules then modules = { } end modules ['tabl-ali'] = {
2    version   = 1.001,
3    comment   = "companion to tabl-ali.mkxl",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9local next, tonumber = next, tonumber
10local find, match = string.find, string.match
11
12local data = false
13local user = false
14
15local dimension_code = tokens.values.dimension
16
17local function align_point_delta(n,m)
18
19    -- better use the official position interface
20
21    if not data then
22        user = (job.positions.collected or { }).user or { }
23        data = { }
24     -- for k, v in table.sortedhash(user) do
25        for k, v in next, user do
26            if find(k,"^ap::") then
27                local p = v.p
28                local n = tonumber(match(k,"ap::(%d+):"))
29                if n then
30                    local dn = data[n]
31                    if not dn then
32                        dn = { }
33                        data[n] = dn
34                    end
35                    local dp = dn[p]
36                    if not dp then
37                        dp = { }
38                        dn[p] = dp
39                    end
40                    dp[#dp+1] = v.x
41                end
42            end
43        end
44
45        for k, v in next, data do
46            local max = false
47            for kk, vv in next, v do
48                for i=1,#vv do
49                    local x = vv[i]
50                    if not max or x > max then
51                        max = x
52                    end
53                end
54                v[kk] = max
55            end
56        end
57
58    end
59
60    local d = data[n]
61
62    if d then
63        local u = user["ap::"..n..":"..m]
64        if u then
65            -- we could clean up previous pages but it's not worth the trouble
66            local x = u.x
67            local p = u.p
68            local m = d[p]
69            if m and m > x then
70                return dimension_code, m - x
71            end
72        end
73    end
74    return dimension_code, 0
75end
76
77interfaces.implement {
78    name      = "align_point_delta",
79    arguments = "2 integers",
80    usage     = "value",
81    actions   = align_point_delta
82}
83