summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/math-spa.lmt
blob: 35684847f37faf774f74b822e543a31631e49c15 (plain)
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
if not modules then modules = { } end modules ['math-spa'] = {
    version   = 1.001,
    comment   = "companion to math-ini.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

-- for the moment (when testing) we use a penalty 1

local boundary_code = nodes.nodecodes.boundary
local glue_code     = nodes.nodecodes.glue

local nuts          = nodes.nuts
local tonut         = nodes.tonut
local tonode        = nodes.tonode

local getid         = nuts.getid
local getnext       = nuts.getnext
local getwidth      = nuts.getwidth
local setglue       = nuts.setglue
local getdimensions = nuts.dimensions
local nextglue      = nuts.traversers.glue

local texsetdimen   = tex.setdimen

local v_none = interfaces.variables.none
local v_auto = interfaces.variables.auto

local method   = v_none
local distance = 0

function noads.handlers.align(h)
    if method ~= v_none then
        if method == v_auto then
            local s = h
            while s do
                local id = getid(s)
                local n  = getnext(s)
                if id == boundary_code then -- check some type
                    if n and getid(n) == glue_code then
                        s = n
                        n = getnext(s)
                    end
                    local w = getdimensions(h,n) + distance
                    texsetdimen("global","d_strc_math_indent",w)
                    break
                end
                s = n
            end
        else
            texsetdimen("global","d_strc_math_indent",distance)
        end
        for n in nextglue, h do
            setglue(n,getwidth(n),0,0)
        end
    else
     -- texsetdimen("global","d_strc_math_indent",0)
    end
end

interfaces.implement {
    name      = "setmathhang",
    arguments = {
        {
            { "method", "string" },
            { "distance", "dimension" },
        }
    },
    actions   = function(t)
        method   = t.method or v_none
        distance = t.distance or 0
    end
}

interfaces.implement {
    name      = "resetmathhang",
    actions   = function(t)
        method   = v_none
        distance = 0
    end
}