math-dim.lua /size: 19 Kb    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
math-dim
'
]
=
{
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
-- The radical_rule value is also used as a trigger. In luatex the accent
10
-- placement happens either the opentype way (using top_accent cum suis) or the
11
-- traditional way. In order to determine what method to use the \Umathradicalrule
12
-- setting is consulted to determine what method to use. This is more efficient
13
-- than analyzing the (potentially spread over multiple families) situation. For
14
-- this reason we need to set the radical_rule here. It used to be "<unset>" in
15
-- which case the engine takes the rulethickness. In c-speak:
16
--
17
-- int compat_mode = (radical_rule(cur_style) == undefined_math_parameter) ;
18
--
19
-- In the meantime things have been updated and we now have two code paths.
20 21
local
abs
,
next
=
math
.
abs
,
next
22 23
local
defaults
=
{
24
axis
=
{
default
=
{
"
AxisHeight
"
,
"
axis_height
"
}
,
}
,
25
accent_base_height
=
{
default
=
{
"
AccentBaseHeight
"
,
"
x_height
"
}
,
}
,
26
fraction_del_size
=
{
default
=
{
"
FractionDelimiterSize
"
,
"
delim2
"
}
,
27
cramped_display_style
=
{
"
FractionDelimiterDisplayStyleSize
"
,
"
delim1
"
}
,
28
display_style
=
{
"
FractionDelimiterDisplayStyleSize
"
,
"
delim1
"
}
,
}
,
29
fraction_denom_down
=
{
default
=
{
"
FractionDenominatorShiftDown
"
,
"
denom2
"
}
,
30
cramped_display_style
=
{
"
FractionDenominatorDisplayStyleShiftDown
"
,
"
denom1
"
}
,
31
display_style
=
{
"
FractionDenominatorDisplayStyleShiftDown
"
,
"
denom1
"
}
,
}
,
32
fraction_denom_vgap
=
{
default
=
{
"
FractionDenominatorGapMin
"
,
"
default_rule_thickness
"
}
,
33
cramped_display_style
=
{
"
FractionDenominatorDisplayStyleGapMin
"
,
"
3*default_rule_thickness
"
}
,
34
display_style
=
{
"
FractionDenominatorDisplayStyleGapMin
"
,
"
3*default_rule_thickness
"
}
,
}
,
35
fraction_num_up
=
{
default
=
{
"
FractionNumeratorShiftUp
"
,
"
num2
"
}
,
36
cramped_display_style
=
{
"
FractionNumeratorDisplayStyleShiftUp
"
,
"
num1
"
}
,
37
display_style
=
{
"
FractionNumeratorDisplayStyleShiftUp
"
,
"
num1
"
}
,
}
,
38
fraction_num_vgap
=
{
default
=
{
"
FractionNumeratorGapMin
"
,
"
default_rule_thickness
"
}
,
39
cramped_display_style
=
{
"
FractionNumeratorDisplayStyleGapMin
"
,
"
3*default_rule_thickness
"
}
,
40
display_style
=
{
"
FractionNumeratorDisplayStyleGapMin
"
,
"
3*default_rule_thickness
"
}
,
}
,
41
skewed_fraction_hgap
=
{
default
=
{
"
SkewedFractionHorizontalGap
"
,
"
math_quad/2
"
}
,
42
cramped_display_style
=
{
"
SkewedFractionHorizontalGap
"
,
"
math_quad/2
"
}
,
43
display_style
=
{
"
SkewedFractionHorizontalGap
"
,
"
math_quad/2
"
}
,
}
,
44
skewed_fraction_vgap
=
{
default
=
{
"
SkewedFractionVerticalGap
"
,
"
x_height
"
}
,
45
cramped_display_style
=
{
"
SkewedFractionVerticalGap
"
,
"
x_height
"
}
,
46
display_style
=
{
"
SkewedFractionVerticalGap
"
,
"
x_height
"
}
,
}
,
47
fraction_rule
=
{
default
=
{
"
FractionRuleThickness
"
,
"
default_rule_thickness
"
}
,
}
,
48
limit_above_bgap
=
{
default
=
{
"
UpperLimitBaselineRiseMin
"
,
"
big_op_spacing3
"
}
,
}
,
49
limit_above_vgap
=
{
default
=
{
"
UpperLimitGapMin
"
,
"
big_op_spacing1
"
}
,
}
,
50
limit_above_kern
=
{
default
=
{
"
0
"
,
"
big_op_spacing5
"
}
,
}
,
51
limit_below_bgap
=
{
default
=
{
"
LowerLimitBaselineDropMin
"
,
"
big_op_spacing4
"
}
,
}
,
52
limit_below_vgap
=
{
default
=
{
"
LowerLimitGapMin
"
,
"
big_op_spacing2
"
}
,
}
,
53
limit_below_kern
=
{
default
=
{
"
0
"
,
"
big_op_spacing5
"
}
,
}
,
54
math_operator_size
=
{
default
=
{
"
DisplayOperatorMinHeight
"
,
"
math_x_height*3
"
}
,
}
,
-- 2
55
overbar_kern
=
{
default
=
{
"
OverbarExtraAscender
"
,
"
default_rule_thickness
"
}
,
}
,
56
overbar_rule
=
{
default
=
{
"
OverbarRuleThickness
"
,
"
default_rule_thickness
"
}
,
}
,
57
overbar_vgap
=
{
default
=
{
"
OverbarVerticalGap
"
,
"
3*default_rule_thickness
"
}
,
}
,
58
quad
=
{
default
=
{
"
font_size(f)
"
,
"
math_quad
"
}
,
}
,
59
radical_kern
=
{
default
=
{
"
RadicalExtraAscender
"
,
"
default_rule_thickness
"
}
,
}
,
60
radical_rule
=
{
default
=
{
"
RadicalRuleThickness
"
,
"
default_rule_thickness
"
}
,
}
,
61
-- default = { "surd_height(f)", "default_rule_thickness" },
62
radical_vgap
=
{
default
=
{
"
RadicalVerticalGap
"
,
"
default_rule_thickness+(abs(default_rule_thickness)/4)
"
}
,
63
display_style
=
{
"
RadicalDisplayStyleVerticalGap
"
,
"
default_rule_thickness+(abs(math_x_height)/4)
"
}
,
}
,
64
space_after_script
=
{
default
=
{
"
SpaceAfterScript
"
,
"
script_space
"
}
,
}
,
65
space_before_script
=
{
default
=
{
"
SpaceAfterScript
"
,
"
script_space
"
}
,
}
,
66
stack_denom_down
=
{
default
=
{
"
StackBottomShiftDown
"
,
"
denom2
"
}
,
67
cramped_display_style
=
{
"
StackBottomDisplayStyleShiftDown
"
,
"
denom1
"
}
,
68
display_style
=
{
"
StackBottomDisplayStyleShiftDown
"
,
"
denom1
"
}
,
}
,
69
stack_num_up
=
{
default
=
{
"
StackTopShiftUp
"
,
"
num3
"
}
,
70
cramped_display_style
=
{
"
StackTopDisplayStyleShiftUp
"
,
"
num1
"
}
,
71
display_style
=
{
"
StackTopDisplayStyleShiftUp
"
,
"
num1
"
}
,
}
,
72
stack_vgap
=
{
default
=
{
"
StackGapMin
"
,
"
3*default_rule_thickness
"
}
,
73
cramped_display_style
=
{
"
StackDisplayStyleGapMin
"
,
"
7*default_rule_thickness
"
}
,
74
display_style
=
{
"
StackDisplayStyleGapMin
"
,
"
7*default_rule_thickness
"
}
,
}
,
75
sub_shift_down
=
{
default
=
{
"
SubscriptShiftDown
"
,
"
sub1
"
}
,
}
,
76
sub_shift_drop
=
{
default
=
{
"
SubscriptBaselineDropMin
"
,
"
sub_drop
"
}
,
}
,
77
sub_sup_shift_down
=
{
default
=
{
"
SubscriptShiftDown
"
,
"
sub2
"
}
,
}
,
78
sub_top_max
=
{
default
=
{
"
SubscriptTopMax
"
,
"
abs(math_x_height*4)/5
"
}
,
}
,
79
subsup_vgap
=
{
default
=
{
"
SubSuperscriptGapMin
"
,
"
4*default_rule_thickness
"
}
,
}
,
80
sup_bottom_min
=
{
default
=
{
"
SuperscriptBottomMin
"
,
"
abs(math_x_height)/4
"
}
,
}
,
81
sup_shift_drop
=
{
default
=
{
"
SuperscriptBaselineDropMax
"
,
"
sup_drop
"
}
,
}
,
82
sup_shift_up
=
{
cramped_display_style
=
{
"
SuperscriptShiftUpCramped
"
,
"
sup3
"
}
,
83
cramped_script_script_style
=
{
"
SuperscriptShiftUpCramped
"
,
"
sup3
"
}
,
84
cramped_script_style
=
{
"
SuperscriptShiftUpCramped
"
,
"
sup3
"
}
,
85
cramped_text_style
=
{
"
SuperscriptShiftUpCramped
"
,
"
sup3
"
}
,
86
display_style
=
{
"
SuperscriptShiftUp
"
,
"
sup1
"
}
,
87
script_script_style
=
{
"
SuperscriptShiftUp
"
,
"
sup2
"
}
,
88
script_style
=
{
"
SuperscriptShiftUp
"
,
"
sup2
"
}
,
89
text_style
=
{
"
SuperscriptShiftUp
"
,
"
sup2
"
}
,
}
,
90
sup_sub_bottom_max
=
{
default
=
{
"
SuperscriptBottomMaxWithSubscript
"
,
"
abs(math_x_height*4)/5
"
}
,
}
,
91
underbar_kern
=
{
default
=
{
"
UnderbarExtraDescender
"
,
"
0
"
}
,
}
,
92
underbar_rule
=
{
default
=
{
"
UnderbarRuleThickness
"
,
"
default_rule_thickness
"
}
,
}
,
93
underbar_vgap
=
{
default
=
{
"
UnderbarVerticalGap
"
,
"
3*default_rule_thickness
"
}
,
}
,
94
connector_overlap_min
=
{
default
=
{
"
MinConnectorOverlap
"
,
"
0.25*default_rule_thickness
"
}
,
}
,
95
over_delimiter_vgap
=
{
default
=
{
"
StretchStackGapBelowMin
"
,
"
big_op_spacing1
"
}
,
}
,
96
over_delimiter_bgap
=
{
default
=
{
"
StretchStackTopShiftUp
"
,
"
big_op_spacing3
"
}
,
}
,
97
under_delimiter_vgap
=
{
default
=
{
"
StretchStackGapAboveMin
"
,
"
big_op_spacing2
"
}
,
}
,
98
under_delimiter_bgap
=
{
default
=
{
"
StretchStackBottomShiftDown
"
,
"
big_op_spacing4
"
}
,
}
,
99
radical_degree_before
=
{
default
=
{
"
RadicalKernBeforeDegree
"
,
"
(5/18)*quad
"
}
,
}
,
100
radical_degree_after
=
{
default
=
{
"
RadicalKernAfterDegree
"
,
"
(-10/18)*quad
"
}
,
}
,
101
radical_degree_raise
=
{
default
=
{
"
RadicalDegreeBottomRaisePercent
"
,
"
60
"
}
,
}
,
102
no_limit_sub_factor
=
{
default
=
{
"
NoLimitSubFactor
"
,
"
0
"
}
,
}
,
103
no_limit_sup_factor
=
{
default
=
{
"
NoLimitSupFactor
"
,
"
0
"
}
,
}
,
104
}
105 106
local
styles
=
{
107
'
cramped_display_style
'
,
108
'
cramped_script_script_style
'
,
109
'
cramped_script_style
'
,
110
'
cramped_text_style
'
,
111
'
display_style
'
,
112
'
script_script_style
'
,
113
'
script_style
'
,
114
'
text_style
'
,
115
}
116 117
for
k
,
v
in
next
,
defaults
do
118
for
_
,
s
in
next
,
styles
do
119
if
not
v
[
s
]
then
120
v
[
s
]
=
v
.
default
121
end
122
end
123
end
124 125
-- we cannot use a metatable because we do a copy (takes a bit more work)
126
--
127
-- local mt = { } setmetatable(defaults,mt)
128
--
129
-- mt.__index = function(t,s)
130
-- return t.default or t.text_style or 0
131
-- end
132 133
function
mathematics
.
dimensions
(
dimens
)
-- beware, dimens get spoiled
134
if
dimens
.
SpaceAfterScript
then
135
dimens
.
SubscriptShiftDownWithSuperscript
=
dimens
.
SubscriptShiftDown
*
1
.
5
-- move this one
136
return
table
.
fastcopy
(
dimens
)
,
{
}
137
elseif
dimens
.
AxisHeight
or
dimens
.
axis_height
then
138
local
t
=
{
}
139
local
math_x_height
=
dimens
.
x_height
or
10
*
65536
140
local
math_quad
=
dimens
.
quad
or
10
*
65536
141
local
default_rule_thickness
=
dimens
.
FractionDenominatorGapMin
or
dimens
.
default_rule_thickness
or
0
.
4
*
65536
142
dimens
[
"
0
"
]
=
0
143
dimens
[
"
60
"
]
=
60
144
dimens
[
"
0.25*default_rule_thickness
"
]
=
default_rule_thickness
/
4
145
dimens
[
"
3*default_rule_thickness
"
]
=
3
*
default_rule_thickness
146
dimens
[
"
4*default_rule_thickness
"
]
=
4
*
default_rule_thickness
147
dimens
[
"
7*default_rule_thickness
"
]
=
7
*
default_rule_thickness
148
dimens
[
"
(5/18)*quad
"
]
=
(
math_quad
*
5
)
/
18
149
dimens
[
"
(-10/18)*quad
"
]
=
-
(
math_quad
*
10
)
/
18
150
dimens
[
"
math_x_height*3
"
]
=
math_x_height
*
3
-- needs checking
151
dimens
[
"
abs(math_x_height*4)/5
"
]
=
abs
(
math_x_height
*
4
)
/
5
152
dimens
[
"
default_rule_thickness+(abs(default_rule_thickness)/4)
"
]
=
default_rule_thickness
+
(
abs
(
default_rule_thickness
)
/
4
)
153
dimens
[
"
default_rule_thickness+(abs(math_x_height)/4)
"
]
=
default_rule_thickness
+
(
abs
(
math_x_height
)
/
4
)
154
dimens
[
"
abs(math_x_height)/4
"
]
=
abs
(
math_x_height
)
/
4
155
dimens
[
"
abs(math_x_height*4)/5
"
]
=
abs
(
math_x_height
*
4
)
/
5
156
dimens
[
"
<not set>
"
]
=
false
157
dimens
[
"
script_space
"
]
=
false
-- at macro level
158
for
variable
,
styles
in
next
,
defaults
do
159
local
tt
=
{
}
160
for
style
,
default
in
next
,
styles
do
161
local
one
=
default
[
1
]
162
local
two
=
default
[
2
]
163
local
value
=
dimens
[
one
]
164
if
value
then
165
tt
[
style
]
=
value
166
else
167
value
=
dimens
[
two
]
168
if
value
=
=
false
then
169
tt
[
style
]
=
nil
170
else
171
tt
[
style
]
=
value
or
0
172
end
173
end
174
end
175
t
[
variable
]
=
tt
176
end
177
local
d
=
{
178
AccentBaseHeight
=
t
.
accent_base_height
.
text_style
,
179
AxisHeight
=
t
.
axis
.
text_style
,
180
-- DelimitedSubFormulaMinHeight
181
DisplayOperatorMinHeight
=
t
.
math_operator_size
.
text_style
,
-- no longer let tex decide (weird values)
182
-- FlattenedAccentBaseHeight
183
FractionDenominatorDisplayStyleGapMin
=
t
.
fraction_denom_vgap
.
display_style
,
184
FractionDenominatorDisplayStyleShiftDown
=
t
.
fraction_denom_down
.
display_style
,
185
FractionDenominatorGapMin
=
t
.
fraction_denom_vgap
.
text_style
,
186
FractionDenominatorShiftDown
=
t
.
fraction_denom_down
.
text_style
,
187
FractionNumeratorDisplayStyleGapMin
=
t
.
fraction_num_vgap
.
display_style
,
188
FractionNumeratorDisplayStyleShiftUp
=
t
.
fraction_num_up
.
display_style
,
189
FractionNumeratorGapMin
=
t
.
fraction_num_vgap
.
text_style
,
190
FractionNumeratorShiftUp
=
t
.
fraction_num_up
.
text_style
,
191
FractionRuleThickness
=
t
.
fraction_rule
.
text_style
,
192
FractionDelimiterSize
=
t
.
fraction_del_size
.
text_style
,
193
FractionDelimiterDisplayStyleSize
=
t
.
fraction_del_size
.
display_style
,
194
LowerLimitBaselineDropMin
=
t
.
limit_below_bgap
.
text_style
,
195
LowerLimitGapMin
=
t
.
limit_below_vgap
.
text_style
,
196
-- MathLeading
197
MinConnectorOverlap
=
t
.
connector_overlap_min
.
text_style
,
198
OverbarExtraAscender
=
t
.
overbar_kern
.
text_style
,
199
OverbarRuleThickness
=
t
.
overbar_rule
.
text_style
,
200
OverbarVerticalGap
=
t
.
overbar_vgap
.
text_style
,
201
RadicalDisplayStyleVerticalGap
=
t
.
radical_vgap
.
display_style
,
202
RadicalExtraAscender
=
t
.
radical_kern
.
text_style
,
203
RadicalRuleThickness
=
t
.
radical_rule
.
text_style
,
204
RadicalVerticalGap
=
t
.
radical_vgap
.
text_style
,
205
RadicalKernBeforeDegree
=
t
.
radical_degree_before
.
display_style
,
206
RadicalKernAfterDegree
=
t
.
radical_degree_after
.
display_style
,
207
RadicalDegreeBottomRaisePercent
=
t
.
radical_degree_raise
.
display_style
,
208
-- ScriptPercentScaleDown
209
-- ScriptScriptPercentScaleDown
210
-- SkewedFractionHorizontalGap
211
-- SkewedFractionVerticalGap
212
SpaceAfterScript
=
t
.
space_after_script
.
text_style
,
213
StackBottomDisplayStyleShiftDown
=
t
.
stack_denom_down
.
display_style
,
214
StackBottomShiftDown
=
t
.
stack_denom_down
.
text_style
,
215
StackDisplayStyleGapMin
=
t
.
stack_vgap
.
display_style
,
216
StackGapMin
=
t
.
stack_vgap
.
text_style
,
217
StackTopDisplayStyleShiftUp
=
t
.
stack_num_up
.
display_style
,
218
StackTopShiftUp
=
t
.
stack_num_up
.
text_style
,
219
StretchStackGapBelowMin
=
t
.
over_delimiter_vgap
.
text_style
,
220
StretchStackTopShiftUp
=
t
.
over_delimiter_bgap
.
text_style
,
221
StretchStackGapAboveMin
=
t
.
under_delimiter_vgap
.
text_style
,
222
StretchStackBottomShiftDown
=
t
.
under_delimiter_bgap
.
text_style
,
223
SubSuperscriptGapMin
=
t
.
subsup_vgap
.
text_style
,
224
SubscriptBaselineDropMin
=
t
.
sub_shift_drop
.
text_style
,
225
SubscriptShiftDown
=
t
.
sub_shift_down
.
text_style
,
226
SubscriptShiftDownWithSuperscript
=
t
.
sub_sup_shift_down
.
text_style
,
227
SubscriptTopMax
=
t
.
sub_top_max
.
text_style
,
228
SuperscriptBaselineDropMax
=
t
.
sup_shift_drop
.
text_style
,
229
SuperscriptBottomMaxWithSubscript
=
t
.
sup_sub_bottom_max
.
text_style
,
230
SuperscriptBottomMin
=
t
.
sup_bottom_min
.
text_style
,
231
SuperscriptShiftUp
=
t
.
sup_shift_up
.
text_style
,
232
SuperscriptShiftUpCramped
=
t
.
sup_shift_up
.
cramped_text_style
,
233
UnderbarExtraDescender
=
t
.
underbar_kern
.
text_style
,
234
UnderbarRuleThickness
=
t
.
underbar_rule
.
text_style
,
235
UnderbarVerticalGap
=
t
.
underbar_vgap
.
text_style
,
236
UpperLimitBaselineRiseMin
=
t
.
limit_above_bgap
.
text_style
,
237
UpperLimitGapMin
=
t
.
limit_above_vgap
.
text_style
,
238
}
239 240
-- too fragile for tx/px ... even the same values give different results
241
d
.
DisplayOperatorMinHeight
=
nil
242
--
243
d
.
AccentBaseHeight
=
0
-- here? still?
244
return
d
,
t
-- t only for diagnostics
245
else
246
return
{
}
,
{
}
247
end
248
end
249 250