diff options
Diffstat (limited to 'source/luametatex/source/tex/texmlist.c')
-rw-r--r-- | source/luametatex/source/tex/texmlist.c | 259 |
1 files changed, 111 insertions, 148 deletions
diff --git a/source/luametatex/source/tex/texmlist.c b/source/luametatex/source/tex/texmlist.c index b5412872a..83a8a8a96 100644 --- a/source/luametatex/source/tex/texmlist.c +++ b/source/luametatex/source/tex/texmlist.c @@ -4289,125 +4289,69 @@ static halfword tex_aux_analyze_script(halfword init, scriptdata *data) /*tex These prescripts are kind of special. For instance, should top and bottom scripts be aligned? - When there is are two top or two bottom, should we then just use the maxima? + When there is are two top or two bottom, should we then just use the maxima? Watch out, the + implementation changed wrt \LUATEX. */ -static void tex_aux_get_math_sup_shifts(halfword sup, halfword style, scaled *shift_up) +static void tex_aux_get_math_sup_shifts(halfword target, halfword sup, halfword style, scaled *shift_up) { - switch (math_scripts_mode_par) { - case 1: - *shift_up = tex_get_math_y_parameter_checked(style, math_parameter_superscript_shift_up); - break; - case 2: - *shift_up = tex_get_math_y_parameter_checked(style, math_parameter_superscript_shift_up); - break; - case 3: - *shift_up = tex_get_math_y_parameter_checked(style, math_parameter_superscript_shift_up) - + tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down) - - tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down); - break; - case 4: - *shift_up = tex_get_math_y_parameter_checked(style, math_parameter_superscript_shift_up) - + tex_half_scaled(tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down) - - tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down)); - break; - case 5: - *shift_up = tex_get_math_y_parameter_checked(style, math_parameter_superscript_shift_up) - + tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down) - - tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down); - break; - default: - { - scaled clr = tex_get_math_y_parameter_checked(style, math_parameter_superscript_shift_up); - scaled bot = tex_get_math_y_parameter_checked(style, math_parameter_superscript_bottom_min); - if (*shift_up < clr) { - *shift_up = clr; - } - clr = box_depth(sup) + bot; - if (*shift_up < clr) { - *shift_up = clr; - } - break; - } + if (has_noad_option_fixed_super_or_sub_script(target) || has_noad_option_fixed_super_and_sub_script(target)) { + *shift_up = tex_get_math_y_parameter_checked(style, math_parameter_superscript_shift_up); + } else { + scaled clr = tex_get_math_y_parameter_checked(style, math_parameter_superscript_shift_up); + scaled bot = tex_get_math_y_parameter_checked(style, math_parameter_superscript_bottom_min); + if (*shift_up < clr) { + *shift_up = clr; + } + clr = box_depth(sup) + bot; + if (*shift_up < clr) { + *shift_up = clr; + } } } -static void tex_aux_get_math_sub_shifts(halfword sub, halfword style, scaled *shift_down) +static void tex_aux_get_math_sub_shifts(halfword target, halfword sub, halfword style, scaled *shift_down) { - switch (math_scripts_mode_par) { - case 1: - *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down); - break; - case 2: - *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down); - break; - case 3: - *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down); - break; - case 4: - *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down) - + tex_half_scaled(tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down) - - tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down)) ; - break; - case 5: - *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down); - break; - default: - { - scaled clr = tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down); - scaled top = tex_get_math_y_parameter_checked(style, math_parameter_subscript_top_max); - if (*shift_down < clr) { - *shift_down = clr; - } - clr = box_height(sub) - top; - if (*shift_down < clr) { - *shift_down = clr; - } - break; - } + if (has_noad_option_fixed_super_or_sub_script(target)) { + *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down); + } else if (has_noad_option_fixed_super_and_sub_script(target)) { + *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down); + } else { + scaled clr = tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down); + scaled top = tex_get_math_y_parameter_checked(style, math_parameter_subscript_top_max); + if (*shift_down < clr) { + *shift_down = clr; + } + clr = box_height(sub) - top; + if (*shift_down < clr) { + *shift_down = clr; + } } } -static void tex_aux_get_math_sup_sub_shifts(halfword sup, halfword sub, halfword style, scaled *shift_up, scaled *shift_down) +static void tex_aux_get_math_sup_sub_shifts(halfword target, halfword sup, halfword sub, halfword style, scaled *shift_up, scaled *shift_down) { - switch (math_scripts_mode_par) { - case 1: - *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down); - break; - case 2: - *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down); - break; - case 3: - *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down); - break; - case 4: - *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down) - + tex_half_scaled(tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down) - - tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down)); - break; - case 5: - *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down); - break; - default: - { - scaled clr = tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down); - scaled gap = tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_vgap); - scaled bot = tex_get_math_y_parameter_checked(style, math_parameter_superscript_subscript_bottom_max); - if (*shift_down < clr) { - *shift_down = clr; - } - clr = gap - ((*shift_up - box_depth(sup)) - (box_height(sub) - *shift_down)); - if (clr > 0) { - *shift_down += clr; - clr = bot - (*shift_up - box_depth(sup)); - if (clr > 0) { - *shift_up += clr; - *shift_down -= clr; - } - } - break; + if (has_noad_option_fixed_super_or_sub_script(target)) { + *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_shift_down); + } else if (has_noad_option_fixed_super_and_sub_script(target)) { + *shift_down = tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down); + } else { + scaled clr = tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_shift_down); + scaled gap = tex_get_math_y_parameter_checked(style, math_parameter_subscript_superscript_vgap); + scaled bot = tex_get_math_y_parameter_checked(style, math_parameter_superscript_subscript_bottom_max); + if (*shift_down < clr) { + *shift_down = clr; + } + clr = gap - ((*shift_up - box_depth(sup)) - (box_height(sub) - *shift_down)); + if (clr > 0) { + *shift_down += clr; + clr = bot - (*shift_up - box_depth(sup)); + if (clr > 0) { + *shift_up += clr; + *shift_down -= clr; } + } } } @@ -4802,6 +4746,24 @@ inline static int tex_aux_raise_prime_composed(halfword target) return mainclass >= 0 ? tex_math_has_class_option(mainclass, raise_prime_option) : 0; } +static halfword tex_aux_shift_to_kern(halfword target, halfword box, scaled shift) +{ + halfword result; + if (box_source_anchor(box)) { + halfword kern = tex_new_kern_node(shift, vertical_math_kern_subtype); + tex_attach_attribute_list_copy(kern, target); + tex_couple_nodes(kern, box); + result = tex_vpack(kern, 0, packing_additional, max_dimen, (singleword) math_direction_par, holding_none_option); + tex_attach_attribute_list_copy(result, target); + node_subtype(result) = math_scripts_list; + box_shift_amount(result) = shift; + } else { + box_shift_amount(box) = shift; + result = box; + } + return result; +} + static void tex_aux_make_scripts(halfword target, halfword kernel, scaled italic, int style, scaled supshift, scaled subshift, scaled supdrop, kernset *kerns) { halfword result = null; @@ -5178,9 +5140,9 @@ static void tex_aux_make_scripts(halfword target, halfword kernel, scaled italic /* */ if (postsupdata.box) { /* Do we still want to chain these sups or should we combine it? */ - tex_aux_get_math_sup_shifts(postsupdata.box, style, &shift_up); /* maybe only in else branch */ + tex_aux_get_math_sup_shifts(target, postsupdata.box, style, &shift_up); /* maybe only in else branch */ if (postsubdata.box) { - tex_aux_get_math_sup_sub_shifts(postsupdata.box, postsubdata.box, style, &shift_up, &shift_down); + tex_aux_get_math_sup_sub_shifts(target, postsupdata.box, postsubdata.box, style, &shift_up, &shift_down); tex_aux_get_sup_kern(kernel, &postsupdata, shift_up, supshift, &supkern, kerns); tex_aux_get_sub_kern(kernel, &postsubdata, shift_down, subshift, &subkern, kerns); if (primestate == prime_at_begin_location) { @@ -5225,23 +5187,21 @@ static void tex_aux_make_scripts(halfword target, halfword kernel, scaled italic } else if (supkern) { tex_aux_prepend_hkern_to_box_list(postsupdata.box, supkern, math_shape_kern_subtype, "post sup shape"); } - box_shift_amount(postsupdata.box) = -shift_up; - result = postsupdata.box; + result = tex_aux_shift_to_kern(target, postsupdata.box, -shift_up); if (presupdata.kern) { kern_amount(presupdata.kern) += -supkern - subkern - italicmultiplier * italic; kern_amount(postsupdata.kern) += supkern + subkern + italicmultiplier * italic; } } } else { - tex_aux_get_math_sub_shifts(postsubdata.box, style, &shift_down); + tex_aux_get_math_sub_shifts(target, postsubdata.box, style, &shift_down); tex_aux_get_sub_kern(kernel, &postsubdata, shift_down, subshift, &subkern, kerns); if (primestate == prime_at_begin_location) { subkern = 0; } else if (subkern) { tex_aux_prepend_hkern_to_box_list(postsubdata.box, subkern, math_shape_kern_subtype, "post sub shape"); } - box_shift_amount(postsubdata.box) = shift_down; - result = postsubdata.box; + result = tex_aux_shift_to_kern(target, postsubdata.box, shift_down); if (presubdata.kern) { kern_amount(presubdata.kern) += -subkern; kern_amount(postsubdata.kern) += subkern; @@ -5275,8 +5235,8 @@ static void tex_aux_make_scripts(halfword target, halfword kernel, scaled italic if (presubdata.box) { if (presupdata.box) { /* Do we still want to chain these sups or should we combine it? */ - tex_aux_get_math_sup_shifts(presupdata.box, style, &shift_up); - tex_aux_get_math_sup_sub_shifts(presupdata.box, presubdata.box, style, &shift_up, &shift_down); + tex_aux_get_math_sup_shifts(target, presupdata.box, style, &shift_up); + tex_aux_get_math_sup_sub_shifts(target, presupdata.box, presubdata.box, style, &shift_up, &shift_down); prekern = box_width(presupdata.box); // test: what with negative extra kerns and what with a negative width if (! splitscripts) { @@ -5297,7 +5257,7 @@ static void tex_aux_make_scripts(halfword target, halfword kernel, scaled italic box_shift_amount(preresult) = shift_down; } } else { - tex_aux_get_math_sub_shifts(presubdata.box, style, &shift_down); + tex_aux_get_math_sub_shifts(target, presubdata.box, style, &shift_down); if (! splitscripts) { prekern = box_width(presubdata.box); presubdata.box = tex_aux_combine_script(target, kernelsize.wd, presubdata.box, null, &presubdata.kern, &postsubdata.kern); @@ -5306,7 +5266,7 @@ static void tex_aux_make_scripts(halfword target, halfword kernel, scaled italic preresult = presubdata.box; } } else if (presupdata.box) { - tex_aux_get_math_sup_shifts(presupdata.box, style, &shift_up); + tex_aux_get_math_sup_shifts(target, presupdata.box, style, &shift_up); if (! splitscripts) { prekern = box_width(presupdata.box); presupdata.box = tex_aux_combine_script(target, kernelsize.wd, presupdata.box, null, &presupdata.kern, &postsupdata.kern); @@ -6231,22 +6191,46 @@ static void tex_aux_show_math_list(const char *fmt, halfword list) tex_end_diagnostic(); } -static void tex_aux_wrapup_nucleus_and_add_scripts(halfword current, halfword nxt, int current_style, halfword *italic, kernset *kerns) +static halfword tex_aux_check_source(halfword current, halfword list, int repack) { - halfword p = tex_aux_check_nucleus_complexity(current, italic, current_style, lmt_math_state.size, kerns); - if (p && noad_source(current)) { - switch (node_type(p)) { + if (list && noad_source(current)) { + switch (node_type(list)) { case hlist_node: case vlist_node: - if (! box_source_anchor(p)) { - box_source_anchor(p) = noad_source(current); - tex_set_box_geometry(p, anchor_geometry); - } + // printf("anchoring to list: %i\n", noad_source(current)); + box_source_anchor(list) = noad_source(current); + tex_set_box_geometry(list, anchor_geometry); + noad_source(current) = 0; break; default: - /*tex Todo: maybe pack and assign! */ + if (repack) { + if (tracing_math_par >= 2) { + tex_begin_diagnostic(); + tex_print_format("[math: packing due to source field %D]", noad_source(current)); + tex_end_diagnostic(); + } + list = tex_hpack(list, 0, packing_additional, direction_unknown, holding_none_option); + // printf("anchoring to wrapped list: %i\n", noad_source(current)); + tex_attach_attribute_list_copy(list, current); + box_source_anchor(list) = noad_source(current); + noad_source(current) = 0; + tex_set_box_geometry(list, anchor_geometry); + noad_new_hlist(current) = list; + node_subtype(list) = math_pack_list; + } break; } + } else { + /* can't happen as we already checked before the call */ + } + return list; +} + +static void tex_aux_wrapup_nucleus_and_add_scripts(halfword current, halfword nxt, int current_style, halfword *italic, kernset *kerns) +{ + halfword p = tex_aux_check_nucleus_complexity(current, italic, current_style, lmt_math_state.size, kerns); + if (p && noad_source(current)) { + p = tex_aux_check_source(current, p, has_noad_option_source_on_nucleus(current)); } if (noad_has_scripts(current)) { scaled drop = 0; @@ -6730,28 +6714,7 @@ static void tex_mlist_to_hlist_finalize_list(mliststate *state) current_subtype = disc_class(box_list(list)); } if (list && noad_source(current)) { - if (tracing_math_par >= 2) { - tex_begin_diagnostic(); - tex_print_format("[math: packing due to source field %D]", noad_source(current)); - tex_end_diagnostic(); - } - switch (node_type(list)) { - case hlist_node: - case vlist_node: - if (! box_source_anchor(list)) { - box_source_anchor(list) = noad_source(current); - tex_set_box_geometry(list, anchor_geometry); - } - break; - default: - list = tex_hpack(list, 0, packing_additional, direction_unknown, holding_none_option); - tex_attach_attribute_list_copy(list, current); - box_source_anchor(list) = noad_source(current); - tex_set_box_geometry(list, anchor_geometry); - noad_new_hlist(current) = list; - node_subtype(list) = math_pack_list; - break; - } + tex_aux_check_source(current, list, 1); } break; } |