node-tst.lmt /size: 3023 b    last modification: 2021-10-28 13:51
1if not modules then modules = { } end modules ['node-tst'] = {
2    version   = 1.001,
3    comment   = "companion to node-ini.mkiv",
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 nodes, node = nodes, node
10
11local chardata                   = characters.data
12local nodecodes                  = nodes.nodecodes
13local gluecodes                  = nodes.gluecodes
14
15local glue_code                  = nodecodes.glue
16local penalty_code               = nodecodes.penalty
17local kern_code                  = nodecodes.kern
18local glyph_code                 = nodecodes.glyph
19
20local abovedisplayshortskip_code = gluecodes.abovedisplayshortskip
21local belowdisplayshortskip_code = gluecodes.belowdisplayshortskip
22
23local nuts                       = nodes.nuts
24
25local getnext                    = nuts.getnext
26local getprev                    = nuts.getprev
27local getid                      = nuts.getid
28local getchar                    = nuts.getchar
29local getsubtype                 = nuts.getsubtype
30local getkern                    = nuts.getkern
31local getpenalty                 = nuts.getpenalty
32local getwidth                   = nuts.getwidth
33
34function nuts.somespace(n,all)
35    if n then
36        local id = getid(n)
37        if id == glue_code then
38            return (all or (getwidth(n) ~= 0)) and glue_code -- temp: or 0
39        elseif id == kern_code then
40            return (all or (getkern(n) ~= 0)) and kern_code
41        elseif id == glyph_code then
42         -- maybe more category checks are needed
43            return (chardata[getchar(n)].category == "zs") and glyph_code
44        end
45    end
46    return false
47end
48
49function nuts.somepenalty(n,value)
50    if n then
51        local id = getid(n)
52        if id == penalty_code then
53            if value then
54                return getpenalty(n) == value
55            else
56                return true
57            end
58        end
59    end
60    return false
61end
62
63function nuts.is_display_math(head)
64    local n = getprev(head)
65    while n do
66        local id = getid(n)
67        if id == penalty_code then
68        elseif id == glue_code then
69            if getsubtype(n) == abovedisplayshortskip_code then
70                return true
71            end
72        else
73            break
74        end
75        n = getprev(n)
76    end
77    n = getnext(head)
78    while n do
79        local id = getid(n)
80        if id == penalty_code then
81        elseif id == glue_code then
82            if getsubtype(n) == belowdisplayshortskip_code then
83                return true
84            end
85        else
86            break
87        end
88        n = getnext(n)
89    end
90    return false
91end
92
93nodes.leftmarginwidth  = nodes.vianuts(nuts.leftmarginwidth)
94nodes.rightmarginwidth = nodes.vianuts(nuts.rightmarginwidth)
95nodes.somespace        = nodes.vianuts(nuts.somespace)
96nodes.somepenalty      = nodes.vianuts(nuts.somepenalty)
97nodes.is_display_math  = nodes.vianuts(nuts.is_display_math)
98