texmath.h /size: 39 Kb    last modification: 2024-01-16 10:22
1/*
2    See license.txt in the root of this project.
3*/
4
5# ifndef LMT_TEXMATH_H
6# define LMT_TEXMATH_H
7
8/*tex
9    This module also deals with math parameters. That code has been cleaned up a lot, and it
10    worked out well, but at some point Mikael Sundqvist and I entered \quutation {alternative
11    spacing models mode} and a more generic model was implemented. As a consequence new code
12    showed up and already cleaned up code (the many parameters) could be thrown out. That's how
13    it goed and it is in retrospect good that we had not yet released.
14
15*/
16
17# define MATHPARAMSTACK   8
18# define MATHPARAMDEFAULT undefined_math_parameter
19
20# define MATHFONTSTACK   8
21# define MATHFONTDEFAULT 0
22
23typedef struct math_state_info {
24    int      size;        /*tex Size code corresponding to |cur_style|. */
25    int      level;       /*tex Maybe we should expose this one. */
26    sa_tree  par_head;
27    sa_tree  fam_head;
28    halfword last_left;
29    halfword last_right;
30    scaled   last_atom;  
31    scaled   scale;        
32    halfword single;
33    halfword padding;
34} math_state_info;
35
36extern math_state_info lmt_math_state;
37
38typedef enum math_sizes {
39    text_size,
40    script_size,
41    script_script_size
42} math_sizes;
43
44# define last_math_size script_script_size
45
46# define undefined_math_parameter max_dimension
47
48typedef enum math_indirect_types {
49    indirect_math_unset,
50    indirect_math_regular,
51    indirect_math_integer,
52    indirect_math_dimension,
53    indirect_math_gluespec,
54    indirect_math_mugluespec,
55    indirect_math_register_integer,
56    indirect_math_register_dimension,
57    indirect_math_register_gluespec,
58    indirect_math_register_mugluespec,
59    indirect_math_internal_integer,
60    indirect_math_internal_dimension,
61    indirect_math_internal_gluespec,
62    indirect_math_internal_mugluespec,
63} math_indirect_types;
64
65# define last_math_indirect indirect_math_internal_mugluespec
66
67typedef enum math_parameter_types {
68    math_integer_parameter,
69    math_dimension_parameter,
70    math_muglue_parameter,
71    math_style_parameter,
72    math_pair_parameter,
73} math_parameter_types;
74
75typedef enum math_parameters {
76    math_parameter_quad,
77    math_parameter_exheight,
78    math_parameter_axis,
79    math_parameter_accent_base_height,
80    math_parameter_accent_base_depth,
81    math_parameter_flattened_accent_base_height,
82    math_parameter_flattened_accent_base_depth,
83    math_parameter_x_scale,
84    math_parameter_y_scale,
85    math_parameter_operator_size,
86    math_parameter_overbar_kern,
87    math_parameter_overbar_rule,
88    math_parameter_overbar_vgap,
89    math_parameter_underbar_kern,
90    math_parameter_underbar_rule,
91    math_parameter_underbar_vgap,
92    math_parameter_radical_kern,
93    math_parameter_radical_rule,
94    math_parameter_radical_vgap,
95    math_parameter_radical_degree_before,
96    math_parameter_radical_degree_after,
97    math_parameter_radical_degree_raise,
98    math_parameter_radical_extensible_after,
99    math_parameter_radical_extensible_before,
100    math_parameter_stack_vgap,
101    math_parameter_stack_num_up,
102    math_parameter_stack_denom_down,
103    math_parameter_fraction_rule,
104    math_parameter_fraction_num_vgap,
105    math_parameter_fraction_num_up,
106    math_parameter_fraction_denom_vgap,
107    math_parameter_fraction_denom_down,
108    math_parameter_fraction_del_size,
109    math_parameter_skewed_fraction_hgap,
110    math_parameter_skewed_fraction_vgap,
111    math_parameter_limit_above_vgap,
112    math_parameter_limit_above_bgap,
113    math_parameter_limit_above_kern,
114    math_parameter_limit_below_vgap,
115    math_parameter_limit_below_bgap,
116    math_parameter_limit_below_kern,
117    math_parameter_nolimit_sub_factor, /*tex bonus */
118    math_parameter_nolimit_sup_factor, /*tex bonus */
119    math_parameter_under_delimiter_vgap,
120    math_parameter_under_delimiter_bgap,
121    math_parameter_over_delimiter_vgap,
122    math_parameter_over_delimiter_bgap,
123    math_parameter_subscript_shift_drop,
124    math_parameter_superscript_shift_drop,
125    math_parameter_subscript_shift_down,
126    math_parameter_subscript_superscript_shift_down,
127    math_parameter_subscript_top_max,
128    math_parameter_superscript_shift_up,
129    math_parameter_superscript_bottom_min,
130    math_parameter_superscript_subscript_bottom_max,
131    math_parameter_subscript_superscript_vgap,
132    math_parameter_space_before_script,
133    math_parameter_space_after_script,
134    math_parameter_connector_overlap_min,
135    math_parameter_superscript_snap, /* bonus */
136    math_parameter_subscript_snap,   /* bonus */
137    /* */
138    math_parameter_extra_superscript_shift,
139    math_parameter_extra_subscript_shift,
140    math_parameter_extra_superprescript_shift,
141    math_parameter_extra_subprescript_shift,
142    /* */
143    math_parameter_prime_raise,
144    math_parameter_prime_raise_composed,
145    math_parameter_prime_shift_up,
146    math_parameter_prime_shift_drop,
147    math_parameter_prime_space_after,
148    math_parameter_prime_width,
149    /* */
150    math_parameter_rule_height,
151    math_parameter_rule_depth,
152    /* */
153    math_parameter_superscript_shift_distance,
154    math_parameter_subscript_shift_distance,
155    math_parameter_superprescript_shift_distance,
156    math_parameter_subprescript_shift_distance,
157    /* */
158    math_parameter_extra_superscript_space,
159    math_parameter_extra_subscript_space,
160    math_parameter_extra_superprescript_space,
161    math_parameter_extra_subprescript_space,
162    /* */
163    math_parameter_skewed_delimiter_tolerance,
164    /* */
165    math_parameter_accent_top_shift_up,
166    math_parameter_accent_bottom_shift_down,
167    math_parameter_accent_top_overshoot,
168    math_parameter_accent_bottom_overshoot,
169    math_parameter_accent_superscript_drop,
170    math_parameter_accent_superscript_percent,
171    math_parameter_accent_extend_margin,
172    math_parameter_flattened_accent_top_shift_up,
173    math_parameter_flattened_accent_bottom_shift_down,
174    /* */
175    math_parameter_delimiter_percent,
176    math_parameter_delimiter_shortfall,
177    math_parameter_delimiter_extend_margin,
178    /* */
179    math_parameter_over_line_variant,
180    math_parameter_under_line_variant,
181    math_parameter_over_delimiter_variant,
182    math_parameter_under_delimiter_variant,
183    math_parameter_delimiter_over_variant,
184    math_parameter_delimiter_under_variant,
185    math_parameter_h_extensible_variant,
186    math_parameter_v_extensible_variant,
187    math_parameter_fraction_variant,
188    math_parameter_radical_variant,
189    math_parameter_accent_variant,
190    math_parameter_degree_variant,
191    math_parameter_top_accent_variant,
192    math_parameter_bottom_accent_variant,
193    math_parameter_overlay_accent_variant,
194    math_parameter_numerator_variant,
195    math_parameter_denominator_variant,
196    math_parameter_superscript_variant,
197    math_parameter_subscript_variant,
198    math_parameter_prime_variant,
199    math_parameter_stack_variant,
200    /* */
201    /*tex The growing list of |math_parameter_ATOM1_ATOM2_spacing| is gone. */
202    /* */
203    math_parameter_last = 255,
204    math_parameter_atom_pairs_first = math_parameter_last             + 1,
205    math_parameter_atom_pairs_last  = math_parameter_atom_pairs_first + (max_n_of_math_classes * max_n_of_math_classes),
206    math_parameter_atom_rules_first = math_parameter_atom_pairs_last  + 1,
207    math_parameter_atom_rules_last  = math_parameter_atom_rules_first + (max_n_of_math_classes * max_n_of_math_classes),
208    /* a special private one */
209    math_parameter_reset_spacing,
210    math_parameter_set_spacing,
211    math_parameter_let_spacing,
212    math_parameter_copy_spacing,
213    math_parameter_set_atom_rule,
214    math_parameter_let_atom_rule,
215    math_parameter_copy_atom_rule,
216    math_parameter_let_parent,
217    math_parameter_copy_parent,
218    math_parameter_set_pre_penalty,
219    math_parameter_set_post_penalty,
220    math_parameter_set_display_pre_penalty,
221    math_parameter_set_display_post_penalty,
222    math_parameter_ignore,
223    math_parameter_options,
224    math_parameter_set_defaults,
225} math_parameters;
226
227# define math_parameter_max_range (16 * 1024)  // 4 * (max_n_of_math_classes * max_n_of_math_classes)
228
229# define math_parameter_spacing_pair(l,r) (math_parameter_atom_pairs_first + (l * max_n_of_math_classes) + r)
230# define math_parameter_rules_pair(l,r)   (math_parameter_atom_rules_first + (l * max_n_of_math_classes) + r)
231
232# define math_parameter_spacing_left(n)  ((n - math_parameter_atom_pairs_first) / max_n_of_math_classes)
233# define math_parameter_spacing_right(n) ((n - math_parameter_atom_pairs_first) % max_n_of_math_classes)
234
235# define math_parameter_rules_left(n)    ((n - math_parameter_atom_rules_first) / max_n_of_math_classes)
236# define math_parameter_rules_right(n)   ((n - math_parameter_atom_rules_first) % max_n_of_math_classes)
237
238# define ignore_math_parameter(n)   (integer_parameter(first_math_ignore_code + n))
239# define options_math_parameter(n)  (integer_parameter(first_math_options_code + n))
240
241# define math_all_class    (max_n_of_math_classes - 3)
242# define math_begin_class  (max_n_of_math_classes - 2)
243# define math_end_class    (max_n_of_math_classes - 1)
244
245# define valid_math_class_code(n)  (n >= 0 && n < max_n_of_math_classes)
246
247# define last_math_parameter               math_parameter_stack_variant
248# define math_parameter_first_variant      math_parameter_over_line_variant
249# define math_parameter_last_variant       math_parameter_stack_variant
250# define math_default_spacing_parameter    math_parameter_spacing_pair(ordinary_noad_subtype,ordinary_noad_subtype)
251# define math_default_rules_parameter      0
252
253typedef enum math_class_options {
254    no_pre_slack_class_option                 = 0x00000001,
255    no_post_slack_class_option                = 0x00000002,
256    left_top_kern_class_option                = 0x00000004,
257    right_top_kern_class_option               = 0x00000008,
258    left_bottom_kern_class_option             = 0x00000010,
259    right_bottom_kern_class_option            = 0x00000020,
260    look_ahead_for_end_class_option           = 0x00000040,
261    no_italic_correction_class_option         = 0x00000080,
262    check_ligature_class_option               = 0x00000100,
263    check_italic_correction_class_option      = 0x00000200,
264    check_kern_pair_class_option              = 0x00000400,
265    flatten_class_option                      = 0x00000800,
266    omit_penalty_class_option                 = 0x00001000,
267    unpack_class_option                       = 0x00002000,
268    raise_prime_option                        = 0x00004000,
269 // open_fence_class_option                   = 0x00000100,
270 // close_fence_class_option                  = 0x00000200,
271 // middle_fence_class_option                 = 0x00000400,
272    carry_over_left_top_kern_class_option     = 0x00008000,
273    carry_over_right_top_kern_class_option    = 0x00010000,
274    carry_over_left_bottom_kern_class_option  = 0x00020000,
275    carry_over_right_bottom_kern_class_option = 0x00040000,
276    prefer_delimiter_dimensions_class_option  = 0x00080000,
277    auto_inject_class_option                  = 0x00100000,
278    remove_italic_correction_class_option     = 0x00200000,
279    operator_italic_correction_class_option   = 0x00400000,
280    short_inline_class_option                 = 0x00800000,
281    push_nesting_class_option                 = 0x01000000,
282    pop_nesting_class_option                  = 0x02000000,
283    obey_nesting_class_option                 = 0x04000000,
284    no_class_options                          = 0xF0000000,
285} math_class_options;
286
287extern int tex_math_has_class_option(halfword cls, int option);
288extern int tex_math_has_class_parent(halfword cls);
289
290typedef enum math_atom_font_options {
291    math_atom_no_font_option   = 0,
292    math_atom_text_font_option = 1,
293    math_atom_math_font_option = 2,
294} math_atom_font_options;
295
296static inline int math_parameter_value_type(int n)
297{
298    if (n < last_math_parameter) {
299        return lmt_interface.math_parameter_values[n].type;
300    } else if (n >= math_parameter_atom_rules_first && n <= math_parameter_atom_rules_last) {
301        return math_pair_parameter;
302    } else {
303        return math_muglue_parameter;
304    }
305}
306
307/*tex
308    We used to have a lot of defines like:
309
310    \starttyping
311    # define math_parameter_A_B_spacing  math_parameter_spacing_pair(A_noad_subtype,B_noad_subtype)
312    \stoptyping
313
314    but we now inline them as they are only used once.
315
316*/
317
318/*tex
319
320    We also need to compute the change in style between mlists and their subsidiaries. The following
321    macros define the subsidiary style for an overlined nucleus (|cramped_style|), for a subscript
322    or a superscript (|sub_style| or |sup_style|), or for a numerator or denominator (|num_style| or
323    |denom_style|). We now delegate that to a helper function so that eventually we can symbolic
324    presets.
325
326*/
327
328typedef enum math_style_variants {
329    math_normal_style_variant,
330    math_cramped_style_variant,
331    math_subscript_style_variant,
332    math_superscript_style_variant,
333    math_small_style_variant,
334    math_smaller_style_variant,
335    math_numerator_style_variant,
336    math_denominator_style_variant,
337    math_double_superscript_variant,
338} math_style_variants;
339
340# define last_math_style_variant math_double_superscript_variant
341
342/*
343
344These are the mandate font parameters: % https://docs.microsoft.com/en-us/typography/opentype/spec/math
345
346\starttabulate[|T|p|]
347\NC ScriptPercentScaleDown                   \NC Percentage of scaling down for level 1 superscripts and subscripts. Suggested value: 80 pct. \NC \NR
348\NC ScriptScriptPercentScaleDown             \NC Percentage of scaling down for level 2 (scriptScript) superscripts and subscripts. Suggested value: 60 pct. \NC \NR
349\NC DelimitedSubFormulaMinHeight             \NC Minimum height required for a delimited expression (contained within parentheses, etc.) to be treated as a sub-formula. Suggested value: normal line height × 1.5. \NC \NR
350\NC DisplayOperatorMinHeight                 \NC Minimum height of n-ary operators (such as integral and summation) for formulas in display mode (that is, appearing as standalone page elements, not embedded inline within text). \NC \NR
351\NC MathLeading                              \NC White space to be left between math formulas to ensure proper line spacing. For example, for applications that treat line gap as a part of line ascender, formulas with ink going above (os2.sTypoAscender + os2.sTypoLineGap - MathLeading) or with ink going below os2.sTypoDescender will result in increasing line height. \NC \NR
352\NC AxisHeight                               \NC Axis height of the font. In math typesetting, the term axis refers to a horizontal reference line used for positioning elements in a formula. The math axis is similar to but distinct from the baseline for regular text layout. For example, in a simple equation, a minus symbol or fraction rule would be on the axis, but a string for a variable name would be set on a baseline that is offset from the axis. The axisHeight value determines the amount of that offset. \NC \NR
353\NC AccentBaseHeight                         \NC Maximum (ink) height of accent base that does not require raising the accents. Suggested: x‑height of the font (os2.sxHeight) plus any possible overshots. \NC \NR
354\NC FlattenedAccentBaseHeight                \NC Maximum (ink) height of accent base that does not require flattening the accents. Suggested: cap height of the font (os2.sCapHeight). \NC \NR
355\NC SubscriptShiftDown                       \NC The standard shift down applied to subscript elements. Positive for moving in the downward direction. Suggested: os2.ySubscriptYOffset. \NC \NR
356\NC SubscriptTopMax                          \NC Maximum allowed height of the (ink) top of subscripts that does not require moving subscripts further down. Suggested: 4/5 x- height. \NC \NR
357\NC SubscriptBaselineDropMin                 \NC Minimum allowed drop of the baseline of subscripts relative to the (ink) bottom of the base. Checked for bases that are treated as a box or extended shape. Positive for subscript baseline dropped below the base bottom. \NC \NR
358\NC SuperscriptShiftUp                       \NC Standard shift up applied to superscript elements. Suggested: os2.ySuperscriptYOffset. \NC \NR
359\NC SuperscriptShiftUpCramped                \NC Standard shift of superscripts relative to the base, in cramped style. \NC \NR
360\NC SuperscriptBottomMin                     \NC Minimum allowed height of the (ink) bottom of superscripts that does not require moving subscripts further up. Suggested: ¼ x-height. \NC \NR
361\NC SuperscriptBaselineDropMax               \NC Maximum allowed drop of the baseline of superscripts relative to the (ink) top of the base. Checked for bases that are treated as a box or extended shape. Positive for superscript baseline below the base top. \NC \NR
362\NC SubSuperscriptGapMin                     \NC Minimum gap between the superscript and subscript ink. Suggested: 4 × default rule thickness. \NC \NR
363\NC SuperscriptBottomMaxWithSubscript        \NC The maximum level to which the (ink) bottom of superscript can be pushed to increase the gap between superscript and subscript, before subscript starts being moved down. Suggested: 4/5 x-height. \NC \NR
364\NC SpaceAfterScript                         \NC Extra white space to be added after each subscript and superscript. Suggested: 0.5 pt for a 12 pt font. (Note that, in some math layout implementations, a constant value, such as 0.5 pt, may be used for all text sizes. Some implementations may use a constant ratio of text size, such as 1/24 of em.) \NC \NR
365\NC UpperLimitGapMin                         \NC Minimum gap between the (ink) bottom of the upper limit, and the (ink) top of the base operator. \NC \NR
366\NC UpperLimitBaselineRiseMin                \NC Minimum distance between baseline of upper limit and (ink) top of the base operator. \NC \NR
367\NC LowerLimitGapMin                         \NC Minimum gap between (ink) top of the lower limit, and (ink) bottom of the base operator. \NC \NR
368\NC LowerLimitBaselineDropMin                \NC Minimum distance between baseline of the lower limit and (ink) bottom of the base operator. \NC \NR
369\NC StackTopShiftUp                          \NC Standard shift up applied to the top element of a stack. \NC \NR
370\NC StackTopDisplayStyleShiftUp              \NC Standard shift up applied to the top element of a stack in display style. \NC \NR
371\NC StackBottomShiftDown                     \NC Standard shift down applied to the bottom element of a stack. Positive for moving in the downward direction. \NC \NR
372\NC StackBottomDisplayStyleShiftDown         \NC Standard shift down applied to the bottom element of a stack in display style. Positive for moving in the downward direction. \NC \NR
373\NC StackGapMin                              \NC Minimum gap between (ink) bottom of the top element of a stack, and the (ink) top of the bottom element. Suggested: 3 × default rule thickness. \NC \NR
374\NC StackDisplayStyleGapMin                  \NC Minimum gap between (ink) bottom of the top element of a stack, and the (ink) top of the bottom element in display style. Suggested: 7 × default rule thickness. \NC \NR
375\NC StretchStackTopShiftUp                   \NC Standard shift up applied to the top element of the stretch stack. \NC \NR
376\NC StretchStackBottomShiftDown              \NC Standard shift down applied to the bottom element of the stretch stack. Positive for moving in the downward direction. \NC \NR
377\NC StretchStackGapAboveMin                  \NC Minimum gap between the ink of the stretched element, and the (ink) bottom of the element above. Suggested: same value as upperLimitGapMin. \NC \NR
378\NC StretchStackGapBelowMin                  \NC Minimum gap between the ink of the stretched element, and the (ink) top of the element below. Suggested: same value as lowerLimitGapMin. \NC \NR
379\NC FractionNumeratorShiftUp                 \NC Standard shift up applied to the numerator. \NC \NR
380\NC FractionNumeratorDisplayStyleShiftUp     \NC Standard shift up applied to the numerator in display style. Suggested: same value as stackTopDisplayStyleShiftUp. \NC \NR
381\NC FractionDenominatorShiftDown             \NC Standard shift down applied to the denominator. Positive for moving in the downward direction. \NC \NR
382\NC FractionDenominatorDisplayStyleShiftDown \NC Standard shift down applied to the denominator in display style. Positive for moving in the downward direction. Suggested: same value as stackBottomDisplayStyleShiftDown. \NC \NR
383\NC FractionNumeratorGapMin                  \NC Minimum tolerated gap between the (ink) bottom of the numerator and the ink of the fraction bar. Suggested: default rule thickness. \NC \NR
384\NC FractionNumDisplayStyleGapMin            \NC Minimum tolerated gap between the (ink) bottom of the numerator and the ink of the fraction bar in display style. Suggested: 3 × default rule thickness. \NC \NR
385\NC FractionRuleThickness                    \NC Thickness of the fraction bar. Suggested: default rule thickness. \NC \NR
386\NC FractionDenominatorGapMin                \NC Minimum tolerated gap between the (ink) top of the denominator and the ink of the fraction bar. Suggested: default rule thickness. \NC \NR
387\NC FractionDenomDisplayStyleGapMin          \NC Minimum tolerated gap between the (ink) top of the denominator and the ink of the fraction bar in display style. Suggested: 3 × default rule thickness. \NC \NR
388\NC SkewedFractionHorizontalGap              \NC Horizontal distance between the top and bottom elements of a skewed fraction. \NC \NR
389\NC SkewedFractionVerticalGap                \NC Vertical distance between the ink of the top and bottom elements of a skewed fraction. \NC \NR
390\NC OverbarVerticalGap                       \NC Distance between the overbar and the (ink) top of he base. Suggested: 3 × default rule thickness. \NC \NR
391\NC OverbarRuleThickness                     \NC Thickness of overbar. Suggested: default rule thickness. \NC \NR
392\NC OverbarExtraAscender                     \NC Extra white space reserved above the overbar. Suggested: default rule thickness. \NC \NR
393\NC UnderbarVerticalGap                      \NC Distance between underbar and (ink) bottom of the base. Suggested: 3 × default rule thickness. \NC \NR
394\NC UnderbarRuleThickness                    \NC Thickness of underbar. Suggested: default rule thickness. \NC \NR
395\NC UnderbarExtraDescender                   \NC Extra white space reserved below the underbar. Always positive. Suggested: default rule thickness. \NC \NR
396\NC RadicalVerticalGap                       \NC Space between the (ink) top of the expression and the bar over it. Suggested: 1¼ default rule thickness. \NC \NR
397\NC RadicalDisplayStyleVerticalGap           \NC Space between the (ink) top of the expression and the bar over it. Suggested: default rule thickness + ¼ x-height. \NC \NR
398\NC RadicalRuleThickness                     \NC Thickness of the radical rule. This is the thickness of the rule in designed or constructed radical signs. Suggested: default rule thickness. \NC \NR
399\NC RadicalExtraAscender                     \NC Extra white space reserved above the radical. Suggested: same value as radicalRuleThickness. \NC \NR
400\NC RadicalKernBeforeDegree                  \NC Extra horizontal kern before the degree of a radical, if such is present. Suggested: 5/18 of em. \NC \NR
401\NC RadicalKernAfterDegree                   \NC Negative kern after the degree of a radical, if such is present. Suggested: −10/18 of em. \NC \NR
402\NC RadicalDegreeBottomRaisePercent          \NC Height of the bottom of the radical degree, if such is present, in proportion to the ascender of the radical sign. Suggested: 60 pct. \NC \NR
403\stoptabulate
404
405And these are our own, some are a bit older already but most were introduced when we (Mikael and 
406Hans) overhauled the math engine. 
407
408\starttabulate[|T|c|p|]
409\NC MinConnectorOverlap               \NC 0         \NC \NC \NR
410\NC SubscriptShiftDownWithSuperscript \NC inherited \NC \NC \NR
411\NC FractionDelimiterSize             \NC undefined \NC \NC \NR
412\NC FractionDelimiterDisplayStyleSize \NC undefined \NC \NC \NR
413\NC NoLimitSubFactor                  \NC 0         \NC \NC \NR     
414\NC NoLimitSupFactor                  \NC 0         \NC \NC \NR     
415\NC AccentBaseDepth                   \NC reserved  \NC \NC \NR 
416\NC FlattenedAccentBaseDepth          \NC reserved  \NC \NC \NR 
417\NC SpaceBeforeScript                 \NC 0         \NC \NC \NR     
418\NC PrimeRaisePercent                 \NC 0         \NC \NC \NR     
419\NC PrimeShiftUp                      \NC 0         \NC \NC \NR     
420\NC PrimeShiftUpCramped               \NC 0         \NC \NC \NR     
421\NC PrimeSpaceAfter                   \NC 0         \NC \NC \NR     
422\NC PrimeBaselineDropMax              \NC 0         \NC \NC \NR     
423\NC PrimeWidthPercent                 \NC 0         \NC \NC \NR     
424\NC SkewedDelimiterTolerance          \NC 0         \NC \NC \NR     
425\NC AccentTopShiftUp                  \NC undefined \NC \NC \NR     
426\NC AccentBottomShiftDown             \NC undefined \NC \NC \NR     
427\NC AccentTopOvershoot                \NC 0         \NC \NC \NR     
428\NC AccentBottomOvershoot             \NC 0         \NC \NC \NR     
429\NC AccentSuperscriptDrop             \NC 0         \NC \NC \NR     
430\NC AccentSuperscriptPercent          \NC 0         \NC \NC \NR     
431\NC FlattenedAccentTopShiftUp         \NC undefined \NC \NC \NR     
432\NC FlattenedAccentBottomShiftDown    \NC undefined \NC \NC \NR     
433\NC DelimiterPercent                  \NC           \NC \NC \NR     
434\NC DelimiterShortfall                \NC           \NC \NC \NR     
435\NC DelimiterExtendMargin             \NC           \NC \NC \NR
436\stoptabulate
437
438*/
439
440typedef enum math_parameter_codes {
441    /* official */
442    ScriptPercentScaleDown = 1,
443    ScriptScriptPercentScaleDown,
444    DelimitedSubFormulaMinHeight,
445    DisplayOperatorMinHeight,
446    MathLeading,
447    AxisHeight,
448    AccentBaseHeight,
449    FlattenedAccentBaseHeight,
450    SubscriptShiftDown,
451    SubscriptTopMax,
452    SubscriptBaselineDropMin,
453    SuperscriptShiftUp,
454    SuperscriptShiftUpCramped,
455    SuperscriptBottomMin,
456    SuperscriptBaselineDropMax,
457    SubSuperscriptGapMin,
458    SuperscriptBottomMaxWithSubscript,
459    SpaceAfterScript,
460    UpperLimitGapMin,
461    UpperLimitBaselineRiseMin,
462    LowerLimitGapMin,
463    LowerLimitBaselineDropMin,
464    StackTopShiftUp,
465    StackTopDisplayStyleShiftUp,
466    StackBottomShiftDown,
467    StackBottomDisplayStyleShiftDown,
468    StackGapMin,
469    StackDisplayStyleGapMin,
470    StretchStackTopShiftUp,
471    StretchStackBottomShiftDown,
472    StretchStackGapAboveMin,
473    StretchStackGapBelowMin,
474    FractionNumeratorShiftUp,
475    FractionNumeratorDisplayStyleShiftUp,
476    FractionDenominatorShiftDown,
477    FractionDenominatorDisplayStyleShiftDown,
478    FractionNumeratorGapMin,
479    FractionNumeratorDisplayStyleGapMin,
480    FractionRuleThickness,
481    FractionDenominatorGapMin,
482    FractionDenominatorDisplayStyleGapMin,
483    SkewedFractionHorizontalGap,
484    SkewedFractionVerticalGap,
485    OverbarVerticalGap,
486    OverbarRuleThickness,
487    OverbarExtraAscender,
488    UnderbarVerticalGap,
489    UnderbarRuleThickness,
490    UnderbarExtraDescender,
491    RadicalVerticalGap,
492    RadicalDisplayStyleVerticalGap,
493    RadicalRuleThickness,
494    RadicalExtraAscender,
495    RadicalKernBeforeDegree,
496    RadicalKernAfterDegree,
497    RadicalDegreeBottomRaisePercent,
498    RadicalKernAfterExtensible,
499    RadicalKernBeforeExtensible,
500    /* unofficial */
501    MinConnectorOverlap,
502    SuperscriptSnap,
503    SubscriptSnap,
504    SubscriptShiftDownWithSuperscript,
505    FractionDelimiterSize,
506    FractionDelimiterDisplayStyleSize,
507    NoLimitSubFactor,                         
508    NoLimitSupFactor,                         
509    AccentBaseDepth,          /* reserved */
510    FlattenedAccentBaseDepth, /* reserved */
511    SpaceBeforeScript,                        
512    PrimeRaisePercent,                        
513    PrimeRaiseComposedPercent,                        
514    PrimeShiftUp,                             
515    PrimeShiftUpCramped,                      
516    PrimeBaselineDropMax,                     
517    PrimeSpaceAfter,                          
518    PrimeWidthPercent,                        
519    SkewedDelimiterTolerance,                 
520    AccentTopShiftUp,                         
521    AccentBottomShiftDown,                    
522    AccentTopOvershoot,                       
523    AccentBottomOvershoot,                    
524    AccentSuperscriptDrop,                    
525    AccentSuperscriptPercent,                 
526    AccentExtendMargin,                 
527    FlattenedAccentTopShiftUp,                
528    FlattenedAccentBottomShiftDown,           
529    DelimiterPercent,                       
530    DelimiterShortfall,
531    DelimiterDisplayPercent,                       
532    DelimiterDisplayShortfall,
533    DelimiterExtendMargin,
534    /* done */
535    math_parameter_last_code,
536} math_parameter_codes;
537
538# define math_parameter_last_font_code    NoLimitSupFactor
539# define math_parameter_first_engine_code SpaceBeforeScript
540
541typedef enum display_skip_modes {
542    display_skip_default,
543    display_skip_always,
544    display_skip_non_zero,
545    display_skip_ignore,
546} display_skip_modes;
547
548typedef enum math_skip_modes {
549    math_skip_surround_when_zero = 0, /*tex obey mathsurround when zero glue */
550    math_skip_always_left        = 1,
551    math_skip_always_right       = 2,
552    math_skip_always_both        = 3,
553    math_skip_always_surround    = 4, /*tex ignore, obey marthsurround */
554    math_skip_ignore             = 5, /*tex all spacing disabled */
555    math_skip_only_when_skip     = 6,
556    math_skip_only_when_no_skip  = 7,
557} math_skip_modes;
558
559/*tex All kind of helpers: */
560
561# define math_use_current_family_code math_component_variable_code
562# define fam_par_in_range(fam)        ((fam >= 0) && (cur_fam_par < max_n_of_math_families))
563# define cur_fam_par_in_range         ((cur_fam_par >= 0) && (cur_fam_par < max_n_of_math_families))
564
565extern halfword tex_size_of_style                (halfword style);
566
567extern halfword tex_to_math_spacing_parameter    (halfword left, halfword right);
568extern halfword tex_to_math_rules_parameter      (halfword left, halfword right);
569
570extern halfword tex_math_style_variant           (halfword style, halfword param);
571
572extern void     tex_def_math_parameter           (int style, int param, scaled value, int level, int indirect, int fixup);
573extern scaled   tex_get_math_parameter           (int style, int param, halfword *type);
574extern int      tex_has_math_parameter           (int style, int param);
575extern scaled   tex_get_math_parameter_checked   (int style, int param);
576extern scaled   tex_get_math_parameter_default   (int style, int param, scaled dflt);
577
578extern scaled   tex_get_math_x_parameter         (int style, int param);
579extern scaled   tex_get_math_x_parameter_checked (int style, int param);
580extern scaled   tex_get_math_x_parameter_default (int style, int param, scaled dflt);
581
582extern scaled   tex_get_math_y_parameter         (int style, int param);
583extern scaled   tex_get_math_y_parameter_checked (int style, int param);
584extern scaled   tex_get_math_y_parameter_default (int style, int param, scaled dflt);
585
586extern scaled   tex_get_font_math_parameter      (int font, int size, int param);
587extern scaled   tex_get_font_math_x_parameter    (int font, int size, int param);
588extern scaled   tex_get_font_math_y_parameter    (int font, int size, int param);
589
590extern void     tex_fixup_math_parameters        (int fam, int size, int fnt, int level);
591extern void     tex_finalize_math_parameters     (void);
592extern scaled   tex_get_math_quad_style          (int style);
593extern scaled   tex_math_axis_size               (int size);
594extern scaled   tex_get_math_quad_size           (int size);
595extern scaled   tex_get_math_quad_size_scaled    (int size);
596extern scaled   tex_get_math_quad_size_unscaled  (int size);
597
598extern void     tex_initialize_math              (void);
599extern void     tex_initialize_math_spacing      (void);
600
601extern void     tex_set_display_styles           (halfword code, halfword value, halfword level, halfword indirect);
602extern void     tex_set_text_styles              (halfword code, halfword value, halfword level, halfword indirect);
603extern void     tex_set_main_styles              (halfword code, halfword value, halfword level, halfword indirect);
604extern void     tex_set_script_styles            (halfword code, halfword value, halfword level, halfword indirect);
605extern void     tex_set_script_script_styles     (halfword code, halfword value, halfword level, halfword indirect);
606extern void     tex_set_all_styles               (halfword code, halfword value, halfword level, halfword indirect);
607extern void     tex_set_split_styles             (halfword code, halfword value, halfword level, halfword indirect);
608extern void     tex_set_unsplit_styles           (halfword code, halfword value, halfword level, halfword indirect);
609extern void     tex_set_uncramped_styles         (halfword code, halfword value, halfword level, halfword indirect);
610extern void     tex_set_cramped_styles           (halfword code, halfword value, halfword level, halfword indirect);
611extern void     tex_reset_all_styles             (halfword level);
612
613extern void     tex_dump_math_data               (dumpstream f);
614extern void     tex_undump_math_data             (dumpstream f);
615extern void     tex_unsave_math_data             (int level);
616
617extern void     tex_math_copy_char_data          (halfword target, halfword source, int wipelist);
618
619extern int      tex_show_math_node               (halfword n, int threshold, int max);
620extern void     tex_flush_math                   (void);
621extern int      tex_is_math_disc                 (halfword n);
622extern halfword tex_math_make_disc               (halfword n);
623extern int      tex_in_main_math_style           (halfword style);
624
625extern halfword tex_new_sub_box                  (halfword n);
626//     halfword tex_math_vcenter_group           (halfword n);
627extern int      tex_fam_fnt                      (int fam, int size);
628extern void     tex_def_fam_fnt                  (int fam, int size, int fnt, int level);
629extern void     tex_scan_extdef_del_code         (int level, int extcode);
630extern void     tex_scan_extdef_math_code        (int level, int extcode);
631extern int      tex_current_math_style           (void);
632extern int      tex_current_math_main_style      (void);
633extern int      tex_scan_math_code_val           (halfword code, mathcodeval *mval, mathdictval *dval);
634extern int      tex_scan_math_cmd_val            (mathcodeval *mval, mathdictval *dval);
635
636extern halfword    tex_scan_math_spec            (int optional_equal);
637extern halfword    tex_new_math_spec             (mathcodeval m, quarterword code);
638extern halfword    tex_new_math_dict_spec        (mathdictval d, mathcodeval m, quarterword code);
639extern mathcodeval tex_get_math_spec             (halfword s);
640extern mathdictval tex_get_math_dict             (halfword s);
641extern void        tex_run_math_math_spec        (void);
642extern void        tex_run_text_math_spec        (void);
643
644extern void     tex_set_default_math_codes       (void);
645
646extern int      tex_check_active_math_char       (int character);
647extern int      tex_pass_active_math_char        (int character);
648
649/*tex The runners in maincontrol: */
650
651extern void     tex_run_math_left_brace        (void);
652extern void     tex_run_math_math_component    (void);
653extern void     tex_run_math_modifier          (void);
654extern void     tex_run_math_radical           (void);
655extern void     tex_run_math_accent            (void);
656extern void     tex_run_math_style             (void);
657extern void     tex_run_math_choice            (void);
658extern void     tex_run_math_script            (void);
659extern void     tex_run_math_fraction          (void);
660extern void     tex_run_math_fence             (void);
661extern void     tex_run_math_initialize        (void);
662extern void     tex_run_math_letter            (void);
663extern void     tex_run_math_math_char_number  (void);
664extern void     tex_run_text_math_char_number  (void);
665extern void     tex_run_math_char_number       (void);
666extern void     tex_run_math_delimiter_number  (void);
667extern void     tex_run_math_equation_number   (void);
668extern void     tex_run_math_shift             (void);
669extern void     tex_run_math_italic_correction (void);
670
671extern void     tex_finish_math_group          (void);
672extern void     tex_finish_math_choice         (void);
673extern void     tex_finish_math_fraction       (void);
674extern void     tex_finish_math_radical        (void);
675extern void     tex_finish_math_operator       (void);
676extern void     tex_finish_display_alignment   (halfword head, halfword tail, halfword prevdepth);
677
678extern void     tex_show_math_fraction_group   (void);
679extern void     tex_show_math_radical_group    (void);
680extern void     tex_show_math_operator_group   (void);
681extern void     tex_show_math_choice_group     (void);
682extern void     tex_show_math_number_group     (void);
683
684extern int      tex_show_math_record           (void);
685extern int      tex_show_math_fraction_record  (void);
686extern int      tex_show_math_radical_record   (void);
687extern int      tex_show_math_operator_record  (void);
688extern int      tex_show_math_group_record     (void);
689extern int      tex_show_math_choice_record    (void);
690extern int      tex_show_math_number_record    (void);
691
692typedef enum math_control_codes {
693    math_control_use_font_control            = 0x0000001, /* use the font flag, maybe for traditional, might go */
694    math_control_over_rule                   = 0x0000002,
695    math_control_under_rule                  = 0x0000004,
696    math_control_radical_rule                = 0x0000008,
697    math_control_fraction_rule               = 0x0000010,
698    math_control_accent_skew_half            = 0x0000020,
699    math_control_accent_skew_apply           = 0x0000040,
700    math_control_apply_ordinary_kern_pair    = 0x0000080,
701    math_control_apply_vertical_italic_kern  = 0x0000100,
702    math_control_apply_ordinary_italic_kern  = 0x0000200,
703    math_control_apply_char_italic_kern      = 0x0000400, /* traditional */
704    math_control_rebox_char_italic_kern      = 0x0000800, /* traditional */
705    math_control_apply_boxed_italic_kern     = 0x0001000,
706    math_control_staircase_kern              = 0x0002000,
707    math_control_apply_text_italic_kern      = 0x0004000,
708    math_control_check_text_italic_kern      = 0x0008000,
709    math_control_check_space_italic_kern     = 0x0010000,
710    math_control_apply_script_italic_kern    = 0x0020000,
711    math_control_analyze_script_nucleus_char = 0x0040000,
712    math_control_analyze_script_nucleus_list = 0x0080000,
713    math_control_analyze_script_nucleus_box  = 0x0100000, 
714    math_control_accent_top_skew_with_offset = 0x0200000, 
715    math_control_ignore_kern_dimensions      = 0x0400000, /* for bad fonts (like xits fence depths) */
716    math_control_ignore_flat_accents         = 0x0800000, 
717    math_control_extend_accents              = 0x1000000, 
718    math_control_extend_delimiters           = 0x2000000, 
719} math_control_codes;
720
721/*tex This is what we use for \OPENTYPE\ in \CONTEXT: */
722
723# define assumed_math_control ( \
724    math_control_over_rule \
725  | math_control_under_rule \
726  | math_control_radical_rule \
727  | math_control_fraction_rule \
728  | math_control_accent_skew_half \
729  | math_control_accent_skew_apply \
730  | math_control_apply_ordinary_kern_pair \
731  | math_control_apply_vertical_italic_kern \
732  | math_control_apply_ordinary_italic_kern \
733  | math_control_apply_boxed_italic_kern \
734  | math_control_staircase_kern \
735  | math_control_apply_text_italic_kern \
736  | math_control_check_text_italic_kern \
737  | math_control_apply_script_italic_kern \
738  | math_control_analyze_script_nucleus_char \
739  | math_control_analyze_script_nucleus_list \
740  | math_control_analyze_script_nucleus_box \
741  | math_control_accent_top_skew_with_offset \
742)
743
744/*tex
745    In the process of improving the math engine several intermediate features have been
746    added that were removed later. They were mostly an aid for testing but in the end it
747    made no sense to keep them around. To some extend they could enforce compatibility
748    but with most fonts being opentype now that is no longer feasible.
749
750    \starttyping
751    typedef enum math_flatten_codes {
752        math_flatten_ordinary    = 0x01,
753        math_flatten_binary      = 0x02,
754        math_flatten_relation    = 0x04,
755        math_flatten_punctuation = 0x08,
756        math_flatten_inner       = 0x10,
757    } math_flatten_codes;
758    \stoptyping
759
760*/
761
762# endif
763