1if not modules then modules = { } end modules [ ' math-frc ' ] = {
2 version = 1 . 001 ,
3 comment = " companion to math-frc.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 utfchar = utf . char
10
11local context = context
12local variables = interfaces . variables
13
14local v_no = variables . no
15local v_yes = variables . yes
16local v_hidden = variables . hidden
17
18local resolved = {
19 [ 0x007B ] = " \\{ " ,
20 [ 0x007D ] = " \\} " ,
21}
22
23table . setmetatableindex ( resolved , function ( t , k )
24 local v = utfchar ( k )
25 t [ k ] = v
26 return v
27end )
28
29local ctx_normalatop = context . normalatop
30local ctx_normalover = context . normalover
31
32local function mathfraction ( how , left , right , width )
33 if how = = v_no then
34 if left = = 0x002E and right = = 0x002E then
35 ctx_normalatop ( )
36 else
37 context ( " \\atopwithdelims%s%s " , resolved [ left ] , resolved [ right ] )
38 end
39 elseif how = = v_yes or how = = v_hidden then
40 local norule = how = = v_hidden and LUATEXFUNCTIONALITY > 7361 and " norule " or " "
41 if left = = 0x002E and right = = 0x002E then
42 context ( " \\normalabove%s%s%ssp " , norule , width )
43 else
44 context ( " \\abovewithdelims%s%s%s%s%ssp " , norule , resolved [ left ] , resolved [ right ] , width )
45 end
46 else
47 if left = = 0x002E and right = = 0x002E then
48 ctx_normalover ( )
49 else
50 context ( " \\overwithdelims%s%s " , resolved [ left ] , resolved [ right ] )
51 end
52 end
53end
54
55interfaces . implement {
56 name = " mathfraction " ,
57 actions = mathfraction ,
58 arguments = { " string " , " number " , " number " , " dimen " }
59}
60
61
62
63if CONTEXTLMTXMODE > 0 then
64
65 local ctx_Uatop = context . Uatop
66 local ctx_Uover = context . Uover
67
68 local function umathfraction ( how , left , right , width )
69 if how = = v_no then
70 if left = = 0x002E and right = = 0x002E then
71 ctx_Uatop ( )
72 else
73 context ( " \\Uatopwithdelims%s%s " , resolved [ left ] , resolved [ right ] )
74 end
75 elseif how = = v_yes or how = = v_hidden then
76 local norule = how = = v_hidden and " norule " or " "
77 if left = = 0x002E and right = = 0x002E then
78 context ( " \\Uabove%s%ssp " , norule , width )
79 else
80 context ( " \\Uabovewithdelims%s%s%s%ssp " , norule , resolved [ left ] , resolved [ right ] , width )
81 end
82 else
83 if left = = 0x002E and right = = 0x002E then
84 ctx_Uover ( )
85 else
86 context ( " \\Uoverwithdelims%s%s " , resolved [ left ] , resolved [ right ] )
87 end
88 end
89 end
90
91 interfaces . implement {
92 name = " umathfraction " ,
93 actions = umathfraction ,
94 arguments = { " string " , " number " , " number " , " dimen " }
95 }
96
97end
98 |