1if not modules then modules = { } end modules [ ' math-spa ' ] = {
2 version = 1 . 001 ,
3 comment = " companion to math-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
9
10
11local penalty_code = nodes . nodecodes . penalty
12local glue_code = nodes . nodecodes . glue
13
14local nuts = nodes . nuts
15local tonut = nodes . tonut
16local tonode = nodes . tonode
17
18local getid = nuts . getid
19local getnext = nuts . getnext
20local getwidth = nuts . getwidth
21local setglue = nuts . setglue
22local getpenalty = nuts . getpenalty
23local setpenalty = nuts . setpenalty
24local getdimensions = nuts . dimensions
25local nextglue = nuts . traversers . glue
26
27local texsetdimen = tex . setdimen
28
29local v_none = interfaces . variables . none
30local v_auto = interfaces . variables . auto
31
32local method = v_none
33local distance = 0
34
35function noads . handlers . align ( h )
36 if method ~ = v_none then
37 if method = = v_auto then
38 local s = h
39 while s do
40 local id = getid ( s )
41 local n = getnext ( s )
42 if id = = penalty_code and getpenalty ( s ) = = 1 then
43 setpenalty ( s , 0 )
44 if n and getid ( n ) = = glue_code then
45 s = n
46 n = getnext ( s )
47 end
48 local w = getdimensions ( h , n ) + distance
49 texsetdimen ( " global " , " d_strc_math_indent " , w )
50 break
51 end
52 s = n
53 end
54 else
55 texsetdimen ( " global " , " d_strc_math_indent " , distance )
56 end
57 for n in nextglue , h do
58 setglue ( n , getwidth ( n ) , 0 , 0 )
59 end
60 else
61
62 end
63end
64
65interfaces . implement {
66 name = " setmathhang " ,
67 arguments = {
68 {
69 { " method " , " string " } ,
70 { " distance " , " dimension " } ,
71 }
72 } ,
73 actions = function ( t )
74 method = t . method or v_none
75 distance = t . distance or 0
76 end
77}
78
79interfaces . implement {
80 name = " resetmathhang " ,
81 actions = function ( t )
82 method = v_none
83 distance = 0
84 end
85}
86
87 |