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