summaryrefslogtreecommitdiff
path: root/source/luametatex/source/tex
diff options
context:
space:
mode:
Diffstat (limited to 'source/luametatex/source/tex')
-rw-r--r--source/luametatex/source/tex/texcommands.c14
-rw-r--r--source/luametatex/source/tex/texcommands.h13
-rw-r--r--source/luametatex/source/tex/texconditional.c30
-rw-r--r--source/luametatex/source/tex/texconditional.h3
-rw-r--r--source/luametatex/source/tex/texdumpdata.h2
-rw-r--r--source/luametatex/source/tex/texequivalents.c19
-rw-r--r--source/luametatex/source/tex/texequivalents.h16
-rw-r--r--source/luametatex/source/tex/texfont.h1
-rw-r--r--source/luametatex/source/tex/texmaincontrol.c102
-rw-r--r--source/luametatex/source/tex/texmaincontrol.h1
-rw-r--r--source/luametatex/source/tex/texmath.c12
-rw-r--r--source/luametatex/source/tex/texmlist.c205
-rw-r--r--source/luametatex/source/tex/texnodes.h25
-rw-r--r--source/luametatex/source/tex/texpackaging.c6
-rw-r--r--source/luametatex/source/tex/texprimitive.c11
-rw-r--r--source/luametatex/source/tex/texprinting.c11
-rw-r--r--source/luametatex/source/tex/texprinting.h1
-rw-r--r--source/luametatex/source/tex/texscanning.c489
-rw-r--r--source/luametatex/source/tex/texscanning.h5
-rw-r--r--source/luametatex/source/tex/textoken.c65
-rw-r--r--source/luametatex/source/tex/textoken.h2
-rw-r--r--source/luametatex/source/tex/textypes.h5
22 files changed, 854 insertions, 184 deletions
diff --git a/source/luametatex/source/tex/texcommands.c b/source/luametatex/source/tex/texcommands.c
index 0eb084296..73f509a96 100644
--- a/source/luametatex/source/tex/texcommands.c
+++ b/source/luametatex/source/tex/texcommands.c
@@ -509,6 +509,7 @@ void tex_initialize_commands(void)
tex_primitive(tex_command, "skip", register_cmd, glue_val_level, 0);
tex_primitive(tex_command, "muskip", register_cmd, mu_val_level, 0);
tex_primitive(tex_command, "toks", register_cmd, tok_val_level, 0);
+ tex_primitive(luatex_command, "float", register_cmd, posit_val_level, 0);
tex_primitive(tex_command, "spacefactor", set_auxiliary_cmd, space_factor_code, 0);
tex_primitive(tex_command, "prevdepth", set_auxiliary_cmd, prev_depth_code, 0);
@@ -590,6 +591,7 @@ void tex_initialize_commands(void)
tex_primitive(etex_command, "fontchardp", some_item_cmd, font_char_dp_code, 0);
tex_primitive(etex_command, "fontcharic", some_item_cmd, font_char_ic_code, 0);
tex_primitive(luatex_command, "fontcharta", some_item_cmd, font_char_ta_code, 0);
+ tex_primitive(luatex_command, "fontcharba", some_item_cmd, font_char_ba_code, 0);
tex_primitive(luatex_command, "fontspecid", some_item_cmd, font_spec_id_code, 0);
tex_primitive(luatex_command, "fontspecscale", some_item_cmd, font_spec_scale_code, 0);
tex_primitive(luatex_command, "fontspecxscale", some_item_cmd, font_spec_xscale_code, 0);
@@ -619,6 +621,7 @@ void tex_initialize_commands(void)
tex_primitive(etex_command, "mutoglue", some_item_cmd, mu_to_glue_code, 0);
tex_primitive(etex_command, "gluetomu", some_item_cmd, glue_to_mu_code, 0);
tex_primitive(etex_command, "numexpr", some_item_cmd, numexpr_code, 0);
+ tex_primitive(luatex_command, "posexpr", some_item_cmd, posexpr_code, 0);
tex_primitive(etex_command, "dimexpr", some_item_cmd, dimexpr_code, 0);
tex_primitive(etex_command, "glueexpr", some_item_cmd, glueexpr_code, 0);
tex_primitive(etex_command, "muexpr", some_item_cmd, muexpr_code, 0);
@@ -651,9 +654,11 @@ void tex_initialize_commands(void)
tex_primitive(luatex_command, "fontspecifiedname", convert_cmd, font_specification_code, 0);
tex_primitive(tex_command, "jobname", convert_cmd, job_name_code, 0);
tex_primitive(tex_command, "meaning", convert_cmd, meaning_code, 0);
- tex_primitive(luatex_command, "meaningfull", convert_cmd, meaning_full_code, 0);
- tex_primitive(luatex_command, "meaningless", convert_cmd, meaning_less_code, 0);
+ tex_primitive(luatex_command, "meaningfull", convert_cmd, meaning_full_code, 0); /* full as in fill, maybe some day meaninfulll */
+ tex_primitive(luatex_command, "meaningless", convert_cmd, meaning_less_code, 0); /* less as in fill */
tex_primitive(luatex_command, "meaningasis", convert_cmd, meaning_asis_code, 0); /* for manuals and articles */
+ tex_primitive(luatex_command, "meaningful", convert_cmd, meaning_ful_code, 0); /* full as in fil */
+ tex_primitive(luatex_command, "meaningles", convert_cmd, meaning_les_code, 0); /* less as in fil, can't be less than this */
/*tex Maybe some day also |meaningonly| (no macro: in front). */
tex_primitive(tex_command, "number", convert_cmd, number_code, 0);
tex_primitive(luatex_command, "tointeger", convert_cmd, to_integer_code, 0);
@@ -708,8 +713,11 @@ void tex_initialize_commands(void)
tex_primitive(luatex_command, "ifincsname", if_test_cmd, if_in_csname_code, 0); /* This is obsolete and might be dropped. */
tex_primitive(luatex_command, "ifabsnum", if_test_cmd, if_abs_int_code, 0);
tex_primitive(luatex_command, "ifabsdim", if_test_cmd, if_abs_dim_code, 0);
+ tex_primitive(luatex_command, "iffloat", if_test_cmd, if_posit_code, 0);
+ tex_primitive(luatex_command, "ifabsfloat", if_test_cmd, if_abs_posit_code, 0);
tex_primitive(luatex_command, "ifzeronum", if_test_cmd, if_zero_int_code, 0);
tex_primitive(luatex_command, "ifzerodim", if_test_cmd, if_zero_dim_code, 0);
+ tex_primitive(luatex_command, "ifzerofloat", if_test_cmd, if_zero_posit_code, 0);
tex_primitive(luatex_command, "ifchknum", if_test_cmd, if_chk_int_code, 0);
tex_primitive(luatex_command, "ifchknumber", if_test_cmd, if_chk_integer_code, 0);
tex_primitive(luatex_command, "ifchkdim", if_test_cmd, if_chk_dim_code, 0);
@@ -1013,6 +1021,7 @@ void tex_initialize_commands(void)
tex_primitive(tex_command, "chardef", shorthand_def_cmd, char_def_code, 0);
tex_primitive(tex_command, "countdef", shorthand_def_cmd, count_def_code, 0);
tex_primitive(tex_command, "dimendef", shorthand_def_cmd, dimen_def_code, 0);
+ tex_primitive(luatex_command, "floatdef", shorthand_def_cmd, float_def_code, 0);
tex_primitive(tex_command, "mathchardef", shorthand_def_cmd, math_char_def_code, 0);
tex_primitive(tex_command, "muskipdef", shorthand_def_cmd, mu_skip_def_code, 0);
tex_primitive(tex_command, "skipdef", shorthand_def_cmd, skip_def_code, 0);
@@ -1023,6 +1032,7 @@ void tex_initialize_commands(void)
tex_primitive(luatex_command, "attributedef", shorthand_def_cmd, attribute_def_code, 0);
tex_primitive(luatex_command, "luadef", shorthand_def_cmd, lua_def_code, 0);
tex_primitive(luatex_command, "integerdef", shorthand_def_cmd, integer_def_code, 0);
+ tex_primitive(luatex_command, "positdef", shorthand_def_cmd, posit_def_code, 0);
tex_primitive(luatex_command, "dimensiondef", shorthand_def_cmd, dimension_def_code, 0);
tex_primitive(luatex_command, "gluespecdef", shorthand_def_cmd, gluespec_def_code, 0);
tex_primitive(luatex_command, "mugluespecdef", shorthand_def_cmd, mugluespec_def_code, 0);
diff --git a/source/luametatex/source/tex/texcommands.h b/source/luametatex/source/tex/texcommands.h
index faeb38247..d90456f25 100644
--- a/source/luametatex/source/tex/texcommands.h
+++ b/source/luametatex/source/tex/texcommands.h
@@ -202,6 +202,8 @@ typedef enum tex_command_code {
register_int_cmd, /*tex user-defined integers */
internal_attribute_cmd, /*tex */
register_attribute_cmd, /*tex user-defined attributes */
+ internal_posit_cmd,
+ register_posit_cmd,
internal_dimen_cmd, /*tex length (|\hsize|, etc.) */
register_dimen_cmd, /*tex user-defined dimensions */
internal_glue_cmd, /*tex glue (|\baselineskip|, etc.) */
@@ -221,6 +223,7 @@ typedef enum tex_command_code {
set_font_cmd, /*tex set current font (font identifiers) */
define_font_cmd, /*tex define a font file (|\font|) */
integer_cmd, /*tex the equivalent is a halfword number */
+ posit_cmd,
dimension_cmd, /*tex the equivalent is a halfword number representing a dimension */
gluespec_cmd, /*tex the equivalent is a halfword reference to glue */
mugluespec_cmd, /*tex the equivalent is a halfword reference to glue with math units */
@@ -305,6 +308,8 @@ typedef enum tex_command_code {
register_int_reference_cmd,
internal_attribute_reference_cmd,
register_attribute_reference_cmd,
+ internal_posit_reference_cmd,
+ register_posit_reference_cmd,
internal_dimen_reference_cmd,
register_dimen_reference_cmd,
/*tex
@@ -456,9 +461,11 @@ typedef enum convert_codes {
detokenized_code, /*tex command code for |\detokenized| */
roman_numeral_code, /*tex command code for |\romannumeral| */
meaning_code, /*tex command code for |\meaning| */
- meaning_full_code, /*tex command code for |\meaningfull| */
+ meaning_full_code, /*tex command code for |\meaningfull| */
meaning_less_code, /*tex command code for |\meaningless| */
meaning_asis_code, /*tex command code for |\meaningasis| */
+ meaning_ful_code, /*tex command code for |\meaningful| */
+ meaning_les_code, /*tex command code for |\meaningles| */
uchar_code, /*tex command code for |\Uchar| */
lua_escape_string_code, /*tex command code for |\luaescapestring| */
/* lua_token_string_code, */ /*tex command code for |\luatokenstring| */
@@ -517,6 +524,7 @@ typedef enum some_item_codes {
font_char_dp_code, /*tex |\fontchardp| */
font_char_ic_code, /*tex |\fontcharic| */
font_char_ta_code, /*tex |\fontcharta| */
+ font_char_ba_code, /*tex |\fontcharba| */
font_spec_id_code, /*tex |\fontspecid| */
font_spec_scale_code, /*tex |\fontspecscale| */
font_spec_xscale_code, /*tex |\fontspecxscale| */
@@ -553,6 +561,7 @@ typedef enum some_item_codes {
mu_to_glue_code, /*tex |\mutoglue| */
glue_to_mu_code, /*tex |\gluetomu| */
numexpr_code, /*tex |\numexpr| */
+ posexpr_code,
/* attrexpr_code, */ /*tex not used */
dimexpr_code, /*tex |\dimexpr| */
glueexpr_code, /*tex |\glueexpr| */
@@ -686,6 +695,7 @@ typedef enum shorthand_def_codes {
math_char_def_code, /*tex |\mathchardef| */
math_xchar_def_code, /*tex |\Umathchardef| */
math_dchar_def_code, /*tex |\Umathdictdef| */
+ float_def_code,
count_def_code, /*tex |\countdef| */
attribute_def_code, /*tex |\attributedef| */
dimen_def_code, /*tex |\dimendef| */
@@ -695,6 +705,7 @@ typedef enum shorthand_def_codes {
/* string_def_code, */
lua_def_code, /*tex |\luadef| */
integer_def_code,
+ posit_def_code,
dimension_def_code,
gluespec_def_code,
mugluespec_def_code,
diff --git a/source/luametatex/source/tex/texconditional.c b/source/luametatex/source/tex/texconditional.c
index 40c704492..b2219e2ab 100644
--- a/source/luametatex/source/tex/texconditional.c
+++ b/source/luametatex/source/tex/texconditional.c
@@ -578,6 +578,36 @@ void tex_conditional_if(halfword code, int unless)
case if_zero_int_code:
result = tex_scan_int(0, NULL) == 0;
goto RESULT;
+ case if_abs_posit_code:
+ case if_posit_code:
+ {
+ halfword n1 = tex_scan_posit(0);
+ halfword cp = tex_aux_scan_comparison(code);
+ halfword n2 = tex_scan_posit(0);
+ if (code == if_abs_posit_code) {
+ tex_posit zero = tex_integer_to_posit(0);
+ if (tex_posit_lt(n1,zero.v)) {
+ n1 = tex_posit_neg(n1);
+ }
+ if (tex_posit_lt(n2,zero.v)) {
+ n2 = tex_posit_neg(n2);
+ }
+ }
+ switch (cp) {
+ case 0: result = tex_posit_eq(n1,n2); break;
+ case 1: result = tex_posit_lt(n1,n2); break;
+ case 2: result = tex_posit_gt(n1,n2); break;
+ case 3: result = tex_posit_ne(n1,n2); break;
+ case 4: result = tex_posit_gt(n1,n2); break;
+ case 5: result = tex_posit_lt(n1,n2); break;
+ case 6: result = tex_posit_eq(tex_integer_to_posit(tex_posit_to_integer(n1) & tex_posit_to_integer(n2)).v,n1); break;
+ case 7: result = tex_posit_ne(tex_integer_to_posit(tex_posit_to_integer(n1) & tex_posit_to_integer(n2)).v,n1); break;
+ }
+ }
+ goto RESULT;
+ case if_zero_posit_code:
+ result = tex_posit_eq_zero(tex_scan_posit(0));
+ goto RESULT;
case if_abs_dim_code:
case if_dim_code:
{
diff --git a/source/luametatex/source/tex/texconditional.h b/source/luametatex/source/tex/texconditional.h
index 36f86f6a5..41b33dc36 100644
--- a/source/luametatex/source/tex/texconditional.h
+++ b/source/luametatex/source/tex/texconditional.h
@@ -55,6 +55,9 @@ typedef enum if_test_codes {
if_int_code, /*tex |\ifnum| */
if_abs_int_code, /*tex |\ifabsnum| */
if_zero_int_code, /*tex |\ifzeronum|*/
+ if_posit_code,
+ if_abs_posit_code,
+ if_zero_posit_code,
if_dim_code, /*tex |\ifdim| */
if_abs_dim_code, /*tex |\ifabsdim| */
if_zero_dim_code, /*tex |\ifzerodim| */
diff --git a/source/luametatex/source/tex/texdumpdata.h b/source/luametatex/source/tex/texdumpdata.h
index a7b51e924..e21177713 100644
--- a/source/luametatex/source/tex/texdumpdata.h
+++ b/source/luametatex/source/tex/texdumpdata.h
@@ -55,7 +55,7 @@
*/
-# define luametatex_format_fingerprint 687
+# define luametatex_format_fingerprint 689
/* These end up in the string pool. */
diff --git a/source/luametatex/source/tex/texequivalents.c b/source/luametatex/source/tex/texequivalents.c
index 56d14a54f..c3cbf087d 100644
--- a/source/luametatex/source/tex/texequivalents.c
+++ b/source/luametatex/source/tex/texequivalents.c
@@ -1017,6 +1017,7 @@ inline static int tex_aux_equal_eq(halfword p, singleword cmd, singleword flag,
}
case dimension_cmd:
case integer_cmd:
+ case posit_cmd:
if (eq_type(p) == cmd && eq_value(p) == chr) {
// if (eq_type(p) == cmd && eq_value(p) == chr && eq_level(p) == cur_level) {
return 1;
@@ -1307,6 +1308,7 @@ void tex_define_swapped(int g, halfword p1, halfword p2, int force)
return;
} else {
switch (t1) {
+ case register_posit_cmd:
case register_int_cmd:
case register_attribute_cmd:
case register_dimen_cmd:
@@ -1315,6 +1317,7 @@ void tex_define_swapped(int g, halfword p1, halfword p2, int force)
case internal_mu_glue_cmd: /* unchecked */
case integer_cmd:
case dimension_cmd:
+ case posit_cmd:
tex_aux_just_define(g, p1, v2);
tex_aux_just_define(g, p2, v1);
return;
@@ -1335,6 +1338,10 @@ void tex_define_swapped(int g, halfword p1, halfword p2, int force)
tex_assign_internal_attribute_value(g, p1, v2);
tex_assign_internal_attribute_value(g, p2, v1);
return;
+ case internal_posit_cmd:
+ tex_assign_internal_posit_value(g, p1, v2);
+ tex_assign_internal_posit_value(g, p2, v1);
+ return;
case internal_dimen_cmd:
tex_assign_internal_dimen_value(g, p1, v2);
tex_assign_internal_dimen_value(g, p2, v1);
@@ -1900,6 +1907,16 @@ void tex_aux_show_eqtb(halfword n)
tex_print_char('=');
tex_print_int(eq_value(n));
break;
+ case internal_posit_reference_cmd:
+ tex_print_cmd_chr(internal_posit_cmd, n);
+ goto POSIT;
+ case register_posit_reference_cmd:
+ tex_print_str_esc("posit");
+ tex_print_int(register_posit_number(n));
+ POSIT:
+ tex_print_char('=');
+ tex_print_posit(eq_value(n));
+ break;
case internal_dimen_reference_cmd:
tex_print_cmd_chr(internal_dimen_cmd, n);
goto DIMEN;
@@ -1991,6 +2008,8 @@ void tex_initialize_equivalents(void)
tex_aux_set_eq(register_int_base, level_one, register_int_reference_cmd, 0, max_int_register_index);
tex_aux_set_eq(internal_attribute_base, level_one, internal_attribute_reference_cmd, unused_attribute_value, number_attribute_pars);
tex_aux_set_eq(register_attribute_base, level_one, register_attribute_reference_cmd, unused_attribute_value, max_attribute_register_index);
+ tex_aux_set_eq(internal_posit_base, level_one, internal_posit_reference_cmd, 0, number_posit_pars);
+ tex_aux_set_eq(register_posit_base, level_one, register_posit_reference_cmd, 0, max_posit_register_index);
tex_aux_set_eq(internal_dimen_base, level_one, internal_dimen_reference_cmd, 0, number_dimen_pars);
tex_aux_set_eq(register_dimen_base, level_one, register_dimen_reference_cmd, 0, max_dimen_register_index);
tex_aux_set_eq(internal_specification_base, level_one, specification_reference_cmd, null, number_specification_pars);
diff --git a/source/luametatex/source/tex/texequivalents.h b/source/luametatex/source/tex/texequivalents.h
index c93c1dd04..a2ea8762d 100644
--- a/source/luametatex/source/tex/texequivalents.h
+++ b/source/luametatex/source/tex/texequivalents.h
@@ -650,6 +650,11 @@ typedef enum attribute_codes {
number_attribute_pars,
} attribute_codes;
+typedef enum posit_codes {
+ /*tex total number of posit parameters */
+ number_posit_pars,
+} posit_codes;
+
// typedef enum special_sequence_codes {
// // current_font_sequence_code,
// undefined_control_sequence_code,
@@ -717,7 +722,14 @@ typedef enum attribute_codes {
# define internal_dimen_number(a) ((a) - internal_dimen_base)
# define register_dimen_number(a) ((a) - register_dimen_base)
-# define internal_specification_base (register_dimen_base + max_n_of_dimen_registers)
+# define internal_posit_base (register_dimen_base + max_n_of_dimen_registers)
+# define register_posit_base (internal_posit_base + number_posit_pars + 1)
+# define internal_posit_location(a) (internal_posit_base + (a))
+# define register_posit_location(a) (register_posit_base + (a))
+# define internal_posit_number(a) ((a) - internal_posit_base)
+# define register_posit_number(a) ((a) - register_posit_base)
+
+# define internal_specification_base (register_posit_base + max_n_of_posit_registers)
# define internal_specification_location(a) (internal_specification_base + (a))
# define internal_specification_number(a) ((a) - internal_specification_base)
@@ -940,6 +952,7 @@ typedef enum save_types {
# define int_parameter(A) eq_value(internal_int_location(A))
# define count_parameter(A) eq_value(internal_int_location(A))
+# define posit_parameter(A) eq_value(internal_posit_location(A))
# define attribute_parameter(A) eq_value(internal_attribute_location(A))
# define dimen_parameter(A) eq_value(internal_dimen_location(A))
# define toks_parameter(A) eq_value(internal_toks_location(A))
@@ -1671,6 +1684,7 @@ typedef enum auto_migration_mode_bits {
# define auto_migrating_mode_permitted(what,flag) ((what & flag) == flag)
# define attribute_register(j) eq_value(register_attribute_location(j))
+# define posit_register(j) eq_value(register_posit_location(j))
# define box_register(j) eq_value(register_box_location(j))
# define count_register(j) eq_value(register_int_location(j))
# define dimen_register(j) eq_value(register_dimen_location(j))
diff --git a/source/luametatex/source/tex/texfont.h b/source/luametatex/source/tex/texfont.h
index 2adadf45d..2656d2b59 100644
--- a/source/luametatex/source/tex/texfont.h
+++ b/source/luametatex/source/tex/texfont.h
@@ -482,6 +482,7 @@ typedef enum char_tag_codes {
n_ary_tag = 0x04000,
radical_tag = 0x08000,
punctuation_tag = 0x10000,
+ keep_base_tag = 0x20000,
} char_tag_codes;
/*tex
diff --git a/source/luametatex/source/tex/texmaincontrol.c b/source/luametatex/source/tex/texmaincontrol.c
index c93011ad9..d043209e5 100644
--- a/source/luametatex/source/tex/texmaincontrol.c
+++ b/source/luametatex/source/tex/texmaincontrol.c
@@ -3443,6 +3443,11 @@ inline static halfword tex_aux_get_register_index(int level)
halfword index = tex_scan_attribute_register_number();
return register_attribute_location(index);
}
+ case posit_val_level:
+ {
+ halfword index = tex_scan_posit_register_number();
+ return register_posit_location(index);
+ }
case glue_val_level:
{
halfword index = tex_scan_glue_register_number();
@@ -3469,6 +3474,8 @@ inline static halfword tex_aux_get_register_value(int level, int optionalequal)
case int_val_level:
case attr_val_level:
return tex_scan_int(optionalequal, NULL);
+ case posit_val_level:
+ return tex_scan_posit(optionalequal);
case dimen_val_level:
return tex_scan_dimen(0, 0, 0, optionalequal, NULL);
default:
@@ -3495,6 +3502,12 @@ static int tex_aux_valid_arithmic(int cmd, int *index, int *level, int *varcmd,
*level = attr_val_level;
*original = eq_value(*index);
return 1;
+ case register_posit_cmd:
+ case internal_posit_cmd:
+ *index = cur_chr;
+ *level = posit_val_level;
+ *original = eq_value(*index);
+ return 1;
case register_dimen_cmd:
case internal_dimen_cmd:
*index = cur_chr;
@@ -3530,6 +3543,12 @@ static int tex_aux_valid_arithmic(int cmd, int *index, int *level, int *varcmd,
*original = cur_chr;
*simple = dimension_cmd;
return 1;
+ case posit_cmd:
+ *index = cur_cs;
+ *level = posit_val_level;
+ *original = cur_chr;
+ *simple = posit_cmd;
+ return 1;
case gluespec_cmd:
*index = cur_cs;
*level = glue_val_level;
@@ -3582,6 +3601,12 @@ inline static void tex_aux_update_register(int a, int level, halfword index, hal
tex_change_attribute_register(a, index, value);
tex_word_define(a, index, value);
break;
+ case posit_val_level:
+ tex_word_define(a, index, value);
+ if (is_frozen(a) && cmd == internal_posit_cmd && cur_mode == hmode) {
+ tex_update_par_par(internal_posit_cmd, index - lmt_primitive_state.prim_data[cmd].offset);
+ }
+ break;
case dimen_val_level:
tex_word_define(a, index, value);
if (is_frozen(a) && cmd == internal_dimen_cmd && cur_mode == hmode) {
@@ -3647,6 +3672,13 @@ static void tex_aux_arithmic_register(int a, int code)
} else {
return;
}
+ case posit_val_level:
+ if (tex_posit_eq_zero(amount)) {
+ return;
+ } else {
+ value = tex_posit_add(original, amount);
+ break;
+ }
case glue_val_level:
case mu_val_level:
if (tex_glue_is_zero(amount)) {
@@ -3704,6 +3736,9 @@ static void tex_aux_arithmic_register(int a, int code)
case attr_val_level:
value = tex_multiply_integers(original, amount);
break;
+ case posit_val_level:
+ value = tex_posit_mul(original, amount);
+ break;
case dimen_val_level:
value = tex_nx_plus_y(original, amount, 0);
break;
@@ -3746,6 +3781,9 @@ static void tex_aux_arithmic_register(int a, int code)
case dimen_val_level:
value = tex_x_over_n(original, amount);
break;
+ case posit_val_level:
+ value = tex_posit_div(original, amount);
+ break;
case glue_val_level:
case mu_val_level:
{
@@ -4256,6 +4294,12 @@ static void tex_aux_set_shorthand_def(int a, int force)
tex_define_again(a, p, register_attribute_cmd, register_attribute_location(n));
break;
}
+ case float_def_code:
+ {
+ scaled n = tex_scan_posit_register_number();
+ tex_define_again(a, p, register_posit_cmd, register_posit_location(n));
+ break;
+ }
case dimen_def_code:
{
scaled n = tex_scan_dimen_register_number();
@@ -4300,6 +4344,13 @@ static void tex_aux_set_shorthand_def(int a, int force)
tex_define_again(a, p, dimension_cmd, v);
}
break;
+ case posit_def_code:
+ /* case posit_def_csname_code: */
+ {
+ scaled v = tex_scan_posit(1);
+ tex_define_again(a, p, posit_cmd, v);
+ }
+ break;
case gluespec_def_code:
{
halfword v = tex_scan_glue(glue_val_level, 1);
@@ -5318,6 +5369,20 @@ static void tex_aux_set_register_int(int a)
tex_word_define(a, p, v);
}
+static void tex_aux_set_internal_posit(int a)
+{
+ halfword p = cur_chr;
+ scaled v = tex_scan_posit(1);
+ tex_assign_internal_int_value(a, p, v);
+}
+
+static void tex_aux_set_register_posit(int a)
+{
+ halfword p = cur_chr;
+ scaled v = tex_scan_posit(1);
+ tex_word_define(a, p, v);
+}
+
static void tex_aux_set_internal_attr(int a)
{
halfword p = cur_chr;
@@ -5450,6 +5515,9 @@ static void tex_aux_set_constant_register(halfword cmd, halfword cs, halfword fl
case dimension_cmd:
v = tex_scan_dimen(0, 0, 0, 1, NULL);
break;
+ case posit_cmd:
+ v = tex_scan_posit(1);
+ break;
case gluespec_cmd:
v = tex_scan_glue(glue_val_level, 1);
break;
@@ -5542,6 +5610,12 @@ static void tex_run_prefixed_command(void)
case register_attribute_cmd:
tex_aux_set_register_attr(flags);
break;
+ case internal_posit_cmd:
+ tex_aux_set_internal_posit(flags);
+ break;
+ case register_posit_cmd:
+ tex_aux_set_register_posit(flags);
+ break;
case internal_dimen_cmd:
tex_aux_set_internal_dimen(flags);
break;
@@ -5619,6 +5693,7 @@ static void tex_run_prefixed_command(void)
break;
case integer_cmd:
case dimension_cmd:
+ case posit_cmd:
case gluespec_cmd:
case mugluespec_cmd:
tex_aux_set_constant_register(cur_cmd, cur_cs, flags);
@@ -5964,6 +6039,14 @@ void tex_assign_internal_attribute_value(int a, halfword p, int val)
tex_word_define(a, p, val);
}
+void tex_assign_internal_posit_value(int a, halfword p, int val)
+{
+ tex_word_define(a, p, val);
+ // if (is_frozen(a) && cur_mode == hmode) {
+ // tex_update_par_par(internal_posit_cmd, internal_posit_number(p));
+ // }
+}
+
void tex_assign_internal_dimen_value(int a, halfword p, int val)
{
tex_word_define(a, p, val);
@@ -6316,23 +6399,25 @@ static void tex_aux_run_show_whatever(void)
inline static void tex_aux_big_switch(int mode, int cmd)
{
-
+ /* todo: order */
switch (cmd) {
case arithmic_cmd:
- case register_attribute_cmd:
+ case internal_int_cmd :
+ case register_int_cmd :
case internal_attribute_cmd:
- case register_dimen_cmd:
+ case register_attribute_cmd:
+ case internal_posit_cmd:
+ case register_posit_cmd:
case internal_dimen_cmd:
+ case register_dimen_cmd:
case set_font_property_cmd :
- case register_glue_cmd:
case internal_glue_cmd:
- case register_int_cmd :
- case internal_int_cmd :
- case register_mu_glue_cmd:
+ case register_glue_cmd:
case internal_mu_glue_cmd:
- case register_toks_cmd:
+ case register_mu_glue_cmd:
case internal_toks_cmd:
+ case register_toks_cmd:
case define_char_code_cmd:
case def_cmd:
case define_family_cmd:
@@ -6353,6 +6438,7 @@ inline static void tex_aux_big_switch(int mode, int cmd)
case lua_value_cmd:
case integer_cmd:
case dimension_cmd:
+ case posit_cmd:
case gluespec_cmd:
case mugluespec_cmd:
case combine_toks_cmd:
diff --git a/source/luametatex/source/tex/texmaincontrol.h b/source/luametatex/source/tex/texmaincontrol.h
index d46eddc5c..558db148f 100644
--- a/source/luametatex/source/tex/texmaincontrol.h
+++ b/source/luametatex/source/tex/texmaincontrol.h
@@ -68,6 +68,7 @@ extern void tex_handle_assignments (void); /*tex Used in math.
extern void tex_assign_internal_int_value (int a, halfword p, int val);
extern void tex_assign_internal_attribute_value (int a, halfword p, int val);
+extern void tex_assign_internal_posit_value (int a, halfword p, int val);
extern void tex_assign_internal_dimen_value (int a, halfword p, int val);
extern void tex_assign_internal_skip_value (int a, halfword p, int val);
diff --git a/source/luametatex/source/tex/texmath.c b/source/luametatex/source/tex/texmath.c
index f4d962d68..00e67942c 100644
--- a/source/luametatex/source/tex/texmath.c
+++ b/source/luametatex/source/tex/texmath.c
@@ -506,6 +506,11 @@ scaled tex_get_math_parameter(int style, int param, halfword *type)
*type = dimen_val_level;
}
return eq_value(value);
+ } else if (eq_type(value) == posit_cmd) {
+ if (type) {
+ *type = dimen_val_level;
+ }
+ return tex_posit_to_dimension(eq_value(value));
} else {
goto MISMATCH;
}
@@ -2940,7 +2945,7 @@ void tex_run_math_accent(void)
case math_uaccent_code:
/*tex |\Umathaccent| */
while (1) {
- switch (tex_scan_character("abcnsftoABCNSFTO", 0, 1, 0)) {
+ switch (tex_scan_character("abcnsftokABCNSFTOK", 0, 1, 0)) {
case 'a': case 'A':
if (tex_scan_mandate_keyword("attr", 1)) {
attrlist = tex_scan_attribute(attrlist);
@@ -2991,6 +2996,11 @@ void tex_run_math_accent(void)
tex_aux_show_keyword_error("fraction|fixed");
goto DONE;
}
+ case 'k': case 'K':
+ if (tex_scan_mandate_keyword("keepbase", 1)) {
+ noad_options(accent) |= noad_option_keep_base;
+ }
+ break;
case 'n': case 'N':
if (tex_scan_mandate_keyword("nooverflow", 1)) {
/*tex
diff --git a/source/luametatex/source/tex/texmlist.c b/source/luametatex/source/tex/texmlist.c
index a3154df62..c5613d90a 100644
--- a/source/luametatex/source/tex/texmlist.c
+++ b/source/luametatex/source/tex/texmlist.c
@@ -897,7 +897,7 @@ static halfword tex_aux_underbar(halfword box, scaled gap, scaled height, scaled
*/
-static halfword tex_aux_char_box(halfword fnt, int chr, halfword att, scaled *ic, quarterword subtype, scaled target, int style, int shrink, int stretch)
+static halfword tex_aux_char_box(halfword fnt, int chr, halfword att, scaled *ic, quarterword subtype, scaled target, int style, int shrink, int stretch, int *isscaled)
{
/*tex The new box and its character node. */
halfword glyph = tex_aux_new_math_glyph(fnt, chr, subtype);
@@ -909,6 +909,9 @@ static halfword tex_aux_char_box(halfword fnt, int chr, halfword att, scaled *ic
box_height(box) = whd.ht;
box_depth(box) = whd.dp;
box_list(box) = glyph;
+ if (isscaled) {
+ *isscaled = 0;
+ }
if (tex_has_glyph_option(glyph, glyph_option_no_italic_correction)) {
whd.ic = 0;
}
@@ -932,15 +935,21 @@ static halfword tex_aux_char_box(halfword fnt, int chr, halfword att, scaled *ic
if (amount > 0) {
glyph_x_scale(glyph) = lround((double) glyph_x_scale(glyph) * amount/whd.wd);
glyph_x_offset(glyph) = (whd.wd - amount)/2;
+ if (isscaled) {
+ *isscaled = 1;
+ }
}
return box;
}
- if ((shrink && (whd.wd > target)) || (stretch && (whd.wd < target))) { // we need to keep an eye on it
- glyph_x_scale(glyph) = lround((double) glyph_x_scale(glyph) * target/whd.wd);
- // glyph_x_offset(glyph) = (whd.wd - target)/2;
- whd = tex_char_whd_from_glyph(glyph);
- box_width(box) = whd.wd;
- }
+ if ((shrink && (whd.wd > target)) || (stretch && (whd.wd < target))) { // we need to keep an eye on it
+ glyph_x_scale(glyph) = lround((double) glyph_x_scale(glyph) * target/whd.wd);
+ // glyph_x_offset(glyph) = (whd.wd - target)/2;
+ whd = tex_char_whd_from_glyph(glyph);
+ box_width(box) = whd.wd;
+ if (isscaled) {
+ *isscaled = 1;
+ }
+ }
}
return box;
}
@@ -1429,6 +1438,7 @@ static halfword tex_aux_make_delimiter(halfword target, halfword delimiter, int
/*tex are we trying the large variant? */
int large_attempt = 0;
int do_parts = 0;
+ int isscaled = 0;
int shrink = flat && has_noad_option_shrink(target);
int stretch = flat && has_noad_option_stretch(target);
/*tex to save the current attribute list */
@@ -1581,7 +1591,7 @@ static halfword tex_aux_make_delimiter(halfword target, halfword delimiter, int
added. See (**).
*/
HERE:
- result = tex_aux_char_box(fnt, chr, att, delta, glyph_math_delimiter_subtype, flat ? targetsize : 0, style, shrink, stretch);
+ result = tex_aux_char_box(fnt, chr, att, delta, glyph_math_delimiter_subtype, flat ? targetsize : 0, style, shrink, stretch, &isscaled);
if (flat) {
/* This will be done when we have a reasonable example. */
} else {
@@ -2393,20 +2403,16 @@ static void tex_aux_set_radical_kerns(delimiterextremes *extremes, kernset *kern
{
if (kerns && extremes->tfont) {
if (tex_math_has_class_option(radical_noad_subtype, carry_over_left_top_kern_class_option)) {
-// kerns->topleft = tex_char_top_left_kern_from_font(extremes->tfont, extremes->tchar);
-kerns->topleft = tex_aux_math_x_size_scaled(extremes->tfont, tex_char_top_left_kern_from_font(extremes->tfont, extremes->tchar), size);
+ kerns->topleft = tex_aux_math_x_size_scaled(extremes->tfont, tex_char_top_left_kern_from_font(extremes->tfont, extremes->tchar), size);
}
if (tex_math_has_class_option(radical_noad_subtype, carry_over_left_bottom_kern_class_option)) {
-// kerns->bottomleft = tex_char_bottom_left_kern_from_font(extremes->bfont, extremes->bchar);
-kerns->bottomleft = tex_aux_math_x_size_scaled(extremes->bfont, tex_char_bottom_left_kern_from_font(extremes->bfont, extremes->bchar), size);
+ kerns->bottomleft = tex_aux_math_x_size_scaled(extremes->bfont, tex_char_bottom_left_kern_from_font(extremes->bfont, extremes->bchar), size);
}
if (tex_math_has_class_option(radical_noad_subtype, carry_over_right_top_kern_class_option)) {
-// kerns->topright = tex_char_top_right_kern_from_font(extremes->tfont, extremes->tchar);
-kerns->topright = tex_aux_math_x_size_scaled(extremes->tfont, tex_char_top_right_kern_from_font(extremes->tfont, extremes->tchar), size);
+ kerns->topright = tex_aux_math_x_size_scaled(extremes->tfont, tex_char_top_right_kern_from_font(extremes->tfont, extremes->tchar), size);
}
if (tex_math_has_class_option(radical_noad_subtype, carry_over_right_bottom_kern_class_option)) {
-// kerns->bottomright = tex_char_bottom_right_kern_from_font(extremes->bfont, extremes->bchar);
-kerns->bottomright = tex_aux_math_x_size_scaled(extremes->bfont, tex_char_bottom_right_kern_from_font(extremes->bfont, extremes->bchar), size);
+ kerns->bottomright = tex_aux_math_x_size_scaled(extremes->bfont, tex_char_bottom_right_kern_from_font(extremes->bfont, extremes->bchar), size);
}
if (tex_math_has_class_option(radical_noad_subtype, prefer_delimiter_dimensions_class_option)) {
kerns->height = extremes->height;
@@ -2973,10 +2979,14 @@ static void tex_aux_do_make_math_accent(halfword target, halfword accentfnt, hal
halfword stretch = (flags & stretch_accent_code) == stretch_accent_code;
halfword basefnt = null_font;
halfword basechr = 0;
+ halfword accentbasefnt = accentfnt;
+ halfword accentbasechr = accentchr;
int found = 0;
+ int isscaled = 0;
+ int keep = 0;
/*tex
Compute the amount of skew, or set |skew| to an alignment point. This will be true if a
- top-accent has been determined.
+ top-accent has been determined. This concerns the base!
*/
int absolute = tex_aux_compute_accent_skew(target, flags, &skew, size);
{
@@ -2995,6 +3005,7 @@ static void tex_aux_do_make_math_accent(halfword target, halfword accentfnt, hal
// basedepth = box_depth(base);
}
if (base) {
+ /*tex We always have a base anyway. */
halfword list = box_list(base);
if (list && node_type(list) == glyph_node) {
basefnt = glyph_font(list);
@@ -3073,25 +3084,36 @@ static void tex_aux_do_make_math_accent(halfword target, halfword accentfnt, hal
accentchr = next;
}
}
+
+ }
+ keep = (accentfnt == accentbasefnt) && (accentchr == accentbasechr) && (has_noad_option_keep_base(target) || tex_char_has_tag_from_font(accentfnt, accentchr, keep_base_tag));
+ if (accent) {
/*tex
- So here we then need to package the offsets.
+ We have an extensible that already has been boxed
*/
- }
- if (! accent) {
- /*tex Italic gets added to width for traditional fonts (no italic anyway): */
- accent = tex_aux_char_box(accentfnt, accentchr, attrlist, NULL, glyph_math_accent_subtype, usedwidth, style, has_noad_option_stretch(target), has_noad_option_shrink(target)); // basewidth
+ } else {
+ /*tex
+ We have a base char or a variant. For traditional fonts the italic correction gets
+ added to width (not that we have these in \CONTEXT).
+ */
+ accent = tex_aux_char_box(accentfnt, accentchr, attrlist, NULL, glyph_math_accent_subtype, usedwidth, style, keep ? 0 : has_noad_option_shrink(target), keep ? 0 : has_noad_option_stretch(target), &isscaled); // basewidth
found = 1;
}
if (flags & top_accent_code) {
scaled b = tex_get_math_y_parameter(style, math_parameter_accent_base_height);
- scaled u = found ? tex_get_math_y_parameter(style, stretch ? math_parameter_flattened_accent_top_shift_up : math_parameter_accent_top_shift_up) : undefined_math_parameter;
+ scaled u = tex_get_math_y_parameter(style, math_parameter_accent_top_shift_up);
if (found && ! tex_aux_math_engine_control(accentfnt, math_control_ignore_flat_accents)) {
scaled f = tex_get_math_y_parameter(style, math_parameter_flattened_accent_base_height);
if (f != undefined_math_parameter && baseheight > f) {
+ int keep = (accentfnt == accentbasefnt) && (accentchr == accentbasechr) && (has_noad_option_keep_base(target) || tex_char_has_tag_from_font(accentfnt, accentchr, keep_base_tag));
halfword flatchr = tex_char_flat_accent_from_font(accentfnt, accentchr);
- if (flatchr != INT_MIN && flatchr != accentchr) {
+ if (flatchr && flatchr != INT_MIN && flatchr != accentchr) {
+ scaled uf = tex_get_math_y_parameter(style, math_parameter_flattened_accent_top_shift_up);
+ if (uf != undefined_math_parameter) {
+ u = uf;
+ }
tex_flush_node(accent);
- accent = tex_aux_char_box(accentfnt, flatchr, attrlist, NULL, glyph_math_accent_subtype, usedwidth, style, 0, 0);
+ accent = tex_aux_char_box(accentfnt, flatchr, attrlist, NULL, glyph_math_accent_subtype, usedwidth, style, keep ? 0 : has_noad_option_shrink(target), keep ? 0 : has_noad_option_stretch(target), &isscaled);
if (tracing_math_par >= 2) {
tex_begin_diagnostic();
tex_print_format("[math: flattening accent, old %x, new %x]", accentchr, flatchr);
@@ -3155,45 +3177,63 @@ static void tex_aux_do_make_math_accent(halfword target, halfword accentfnt, hal
/*tex The top accents of both characters are aligned. */
{
halfword accentwidth = box_width(accent);
- if (absolute) {
- scaled anchor = 0;
- if (extended) {
- /*tex If the accent is extensible just take the center. */
- anchor = tex_half_scaled(accentwidth);
- } else {
- if (flags & top_accent_code) {
- anchor = tex_char_unchecked_top_anchor_from_font(accentfnt, accentchr); /* no bot accent key */
- } else if (flags & bot_accent_code) {
- anchor = tex_char_unchecked_bottom_anchor_from_font(accentfnt, accentchr); /* no bot accent key */
- } else {
- anchor = INT_MIN;
- }
- if (anchor == INT_MIN || has_noad_option_center(target)) {
- /*tex just take the center */
+ if (accentwidth > basewidth && has_noad_option_nooverflow(target)) {
+ /*tex
+ This likely only happens with (too wide base) rules so centering is quite okay then and a
+ bit like scaling. But it could be an accent option (weren't it that we ran out of bits).
+ In that case a topaccent is also unlikely.
+ */
+ scaled leftkern = tex_half_scaled(accentwidth - basewidth);
+ if (leftkern > 0) {
+ halfword kern = tex_new_kern_node(leftkern, horizontal_math_kern_subtype);
+ tex_attach_attribute_list_copy(kern, target);
+ tex_try_couple_nodes(kern, base);
+ base = tex_hpack(kern, 0, packing_additional, direction_unknown, holding_none_option);
+ basewidth = accentwidth;
+ box_width(base) = accentwidth;
+ }
+ } else {
+ if (absolute) {
+ scaled anchor = 0; /* maybe: INT_MIN */
+ if (extended || isscaled) {
+ /*tex If the accent is extensible just take the center. */
anchor = tex_half_scaled(accentwidth);
} else {
- anchor = tex_aux_math_x_size_scaled(accentfnt, anchor, size);
+ /*tex When we scale we center. */
+ if (flags & top_accent_code) {
+ anchor = tex_char_unchecked_top_anchor_from_font(accentfnt, accentchr); /* no bot accent key */
+ } else if (flags & bot_accent_code) {
+ anchor = tex_char_unchecked_bottom_anchor_from_font(accentfnt, accentchr); /* no bot accent key */
+ } else {
+ anchor = INT_MIN;
+ }
+ if (anchor == INT_MIN || has_noad_option_center(target)) {
+ /*tex just take the center */
+ anchor = tex_half_scaled(accentwidth);
+ } else {
+ anchor = tex_aux_math_x_size_scaled(accentfnt, anchor, size);
+ }
+ }
+ if (math_direction_par == dir_righttoleft) {
+ skew += anchor - accentwidth;
+ } else {
+ skew -= anchor;
}
- }
- if (math_direction_par == dir_righttoleft) {
- skew += anchor - accentwidth;
+ } else if (accentwidth == 0) {
+ skew += basewidth;
+ } else if (math_direction_par == dir_righttoleft) {
+ skew += accentwidth; /* ok? */
} else {
- skew -= anchor;
+ skew += tex_half_scaled(basewidth - accentwidth);
+ }
+ box_shift_amount(accent) = skew;
+ box_width(accent) = 0; /* in gyre zero anyway */
+ if (accentwidth) {
+ overshoot = accentwidth + skew - basewidth;
+ }
+ if (overshoot < 0) {
+ overshoot = 0;
}
- } else if (accentwidth == 0) {
- skew += basewidth;
- } else if (math_direction_par == dir_righttoleft) {
- skew += accentwidth; /* ok? */
- } else {
- skew += tex_half_scaled(basewidth - accentwidth);
- }
- box_shift_amount(accent) = skew;
- box_width(accent) = 0; /* in gyre zero anyway */
- if (accentwidth) {
- overshoot = accentwidth + skew - basewidth;
- }
- if (overshoot < 0) {
- overshoot = 0;
}
}
if (flags & (top_accent_code)) {
@@ -3354,20 +3394,16 @@ static void tex_aux_wrap_fraction_result(halfword target, int style, int size, h
right = tex_aux_make_delimiter(target, right_delimiter, size, delta, 0, style, 1, NULL, NULL, 0, has_noad_option_nooverflow(target), &extremes, 0);
if (kerns && extremes.tfont) {
if (tex_math_has_class_option(fraction_noad_subtype, carry_over_left_top_kern_class_option)) {
-// kerns->topleft = tex_char_top_left_kern_from_font(extremes.tfont, extremes.tchar);
-kerns->topleft = tex_aux_math_x_size_scaled(extremes.tfont, tex_char_top_left_kern_from_font(extremes.tfont, extremes.tchar), size);
+ kerns->topleft = tex_aux_math_x_size_scaled(extremes.tfont, tex_char_top_left_kern_from_font(extremes.tfont, extremes.tchar), size);
}
if (tex_math_has_class_option(fraction_noad_subtype, carry_over_left_bottom_kern_class_option)) {
-// kerns->bottomleft = tex_char_bottom_left_kern_from_font(extremes.bfont, extremes.bchar);
-kerns->bottomleft = tex_aux_math_x_size_scaled(extremes.bfont, tex_char_bottom_left_kern_from_font(extremes.bfont, extremes.bchar), size);
+ kerns->bottomleft = tex_aux_math_x_size_scaled(extremes.bfont, tex_char_bottom_left_kern_from_font(extremes.bfont, extremes.bchar), size);
}
if (tex_math_has_class_option(fraction_noad_subtype, carry_over_right_top_kern_class_option)) {
-// kerns->topright = tex_char_top_right_kern_from_font(extremes.tfont, extremes.tchar);
-kerns->topright = tex_aux_math_x_size_scaled(extremes.tfont, tex_char_top_right_kern_from_font(extremes.tfont, extremes.tchar), size);
+ kerns->topright = tex_aux_math_x_size_scaled(extremes.tfont, tex_char_top_right_kern_from_font(extremes.tfont, extremes.tchar), size);
}
if (tex_math_has_class_option(fraction_noad_subtype, carry_over_right_bottom_kern_class_option)) {
-// kerns->bottomright = tex_char_bottom_right_kern_from_font(extremes.bfont, extremes.bchar);
-kerns->bottomright = tex_aux_math_x_size_scaled(extremes.bfont, tex_char_bottom_right_kern_from_font(extremes.bfont, extremes.bchar), size);
+ kerns->bottomright = tex_aux_math_x_size_scaled(extremes.bfont, tex_char_bottom_right_kern_from_font(extremes.bfont, extremes.bchar), size);
}
if (tex_math_has_class_option(fraction_noad_subtype, prefer_delimiter_dimensions_class_option)) {
kerns->height = extremes.height;
@@ -3600,14 +3636,15 @@ static halfword tex_aux_make_skewed_fraction(halfword target, int style, int siz
box_depth(fraction) = box_depth(middle) > maxdepth ? box_depth(middle) : maxdepth;
ngap = hgap;
dgap = hgap;
- if (tex_math_has_class_option(fraction_noad_subtype, carry_over_left_top_kern_class_option)) {
-// ngap += tex_char_top_left_kern_from_font(extremes.tfont, extremes.tchar);
-ngap += tex_aux_math_x_size_scaled(extremes.tfont, tex_char_top_left_kern_from_font(extremes.tfont, extremes.tchar), size);
- }
- if (tex_math_has_class_option(fraction_noad_subtype, carry_over_right_bottom_kern_class_option)) {
-// dgap += tex_char_bottom_right_kern_from_font(extremes.bfont, extremes.bchar);
-dgap += tex_aux_math_x_size_scaled(extremes.bfont, tex_char_bottom_right_kern_from_font(extremes.bfont, extremes.bchar), size);
- }
+ /*tex Better not do this, as we now have factors to control it and can fix the parameters. */
+ /*
+ if (tex_math_has_class_option(fraction_noad_subtype, carry_over_left_top_kern_class_option)) {
+ ngap += tex_aux_math_x_size_scaled(extremes.tfont, tex_char_top_left_kern_from_font(extremes.tfont, extremes.tchar), size);
+ }
+ if (tex_math_has_class_option(fraction_noad_subtype, carry_over_right_bottom_kern_class_option)) {
+ dgap += tex_aux_math_x_size_scaled(extremes.bfont, tex_char_bottom_right_kern_from_font(extremes.bfont, extremes.bchar), size);
+ }
+ */
if (ngap || dgap) {
// todo: only add when non zero
halfword nkern = tex_new_kern_node(ngap, horizontal_math_kern_subtype);
@@ -5646,12 +5683,10 @@ static halfword tex_aux_make_left_right(halfword target, int style, scaled max_d
/* maybe elsewhere as the above case */
if (extremes && extremes->tfont) {
if (tex_math_has_class_option(fenced_noad_subtype, carry_over_right_top_kern_class_option)) {
-// kerns.topright = tex_char_top_right_kern_from_font(extremes->tfont, extremes->tchar);
-kerns.topright = tex_aux_math_x_size_scaled(extremes->tfont, tex_char_top_right_kern_from_font(extremes->tfont, extremes->tchar), size);
+ kerns.topright = tex_aux_math_x_size_scaled(extremes->tfont, tex_char_top_right_kern_from_font(extremes->tfont, extremes->tchar), size);
}
if (tex_math_has_class_option(fenced_noad_subtype, carry_over_right_bottom_kern_class_option)) {
-// kerns.bottomright = tex_char_bottom_right_kern_from_font(extremes->bfont, extremes->bchar);
-kerns.bottomright = tex_aux_math_x_size_scaled(extremes->bfont, tex_char_bottom_right_kern_from_font(extremes->bfont, extremes->bchar), size);
+ kerns.bottomright = tex_aux_math_x_size_scaled(extremes->bfont, tex_char_bottom_right_kern_from_font(extremes->bfont, extremes->bchar), size);
}
if (tex_math_has_class_option(fenced_noad_subtype, prefer_delimiter_dimensions_class_option)) {
kerns.height = extremes->height;
@@ -6217,12 +6252,10 @@ static void tex_aux_finish_fenced(halfword current, halfword main_style, scaled
case left_fence_side:
case extended_left_fence_side:
if (tex_math_has_class_option(fenced_noad_subtype, carry_over_left_top_kern_class_option)) {
- // kerns->topleft = tex_char_top_left_kern_from_font(extremes.tfont, extremes.tchar);
- kerns->topleft = tex_aux_math_x_size_scaled(extremes.tfont, tex_char_top_left_kern_from_font(extremes.tfont, extremes.tchar), main_style);
+ kerns->topleft = tex_aux_math_x_size_scaled(extremes.tfont, tex_char_top_left_kern_from_font(extremes.tfont, extremes.tchar), main_style);
}
if (tex_math_has_class_option(fenced_noad_subtype, carry_over_left_bottom_kern_class_option)) {
- // kerns->bottomleft = tex_char_bottom_left_kern_from_font(extremes.bfont, extremes.bchar);
- kerns->bottomleft = tex_aux_math_x_size_scaled(extremes.bfont, tex_char_bottom_left_kern_from_font(extremes.bfont, extremes.bchar), main_style);
+ kerns->bottomleft = tex_aux_math_x_size_scaled(extremes.bfont, tex_char_bottom_left_kern_from_font(extremes.bfont, extremes.bchar), main_style);
}
if (tex_math_has_class_option(fenced_noad_subtype, prefer_delimiter_dimensions_class_option)) {
kerns->height = extremes.height;
@@ -6236,12 +6269,10 @@ static void tex_aux_finish_fenced(halfword current, halfword main_style, scaled
case left_operator_side:
case no_fence_side:
if (tex_math_has_class_option(fenced_noad_subtype, carry_over_right_top_kern_class_option)) {
-// kerns->topright = tex_char_top_right_kern_from_font(extremes.tfont, extremes.tchar);
-kerns->topright = tex_aux_math_x_size_scaled(extremes.tfont, tex_char_top_right_kern_from_font(extremes.tfont, extremes.tchar), main_style);
+ kerns->topright = tex_aux_math_x_size_scaled(extremes.tfont, tex_char_top_right_kern_from_font(extremes.tfont, extremes.tchar), main_style);
}
if (tex_math_has_class_option(fenced_noad_subtype, carry_over_right_bottom_kern_class_option)) {
-// kerns->bottomright = tex_char_bottom_right_kern_from_font(extremes.bfont, extremes.bchar);
-kerns->bottomright = tex_aux_math_x_size_scaled(extremes.bfont, tex_char_bottom_right_kern_from_font(extremes.bfont, extremes.bchar), main_style);
+ kerns->bottomright = tex_aux_math_x_size_scaled(extremes.bfont, tex_char_bottom_right_kern_from_font(extremes.bfont, extremes.bchar), main_style);
}
if (tex_math_has_class_option(fenced_noad_subtype, prefer_delimiter_dimensions_class_option)) {
kerns->height = extremes.height;
diff --git a/source/luametatex/source/tex/texnodes.h b/source/luametatex/source/tex/texnodes.h
index f8766c430..7fa050428 100644
--- a/source/luametatex/source/tex/texnodes.h
+++ b/source/luametatex/source/tex/texnodes.h
@@ -1784,21 +1784,22 @@ typedef enum noad_options {
/*tex The Microsoft compiler truncates to int, so: */
-# define noad_option_source_on_nucleus 0x0100000000
-# define noad_option_fixed_super_or_sub_script 0x0200000000
-# define noad_option_fixed_super_and_sub_script 0x0400000000
-# define noad_option_auto_base 0x0800000000
-# define noad_option_stretch 0x1000000000
-# define noad_option_shrink 0x2000000000
-# define noad_option_center 0x4000000000
-# define noad_option_scale 0x8000000000
+# define noad_option_source_on_nucleus (uint64_t) 0x00100000000
+# define noad_option_fixed_super_or_sub_script (uint64_t) 0x00200000000
+# define noad_option_fixed_super_and_sub_script (uint64_t) 0x00400000000
+# define noad_option_auto_base (uint64_t) 0x00800000000
+# define noad_option_stretch (uint64_t) 0x01000000000
+# define noad_option_shrink (uint64_t) 0x02000000000
+# define noad_option_center (uint64_t) 0x04000000000
+# define noad_option_scale (uint64_t) 0x08000000000
+# define noad_option_keep_base (uint64_t) 0x10000000000
# define has_option(a,b) (((a) & (b)) == (b))
# define unset_option(a,b) ((a) & ~(b))
-inline static void tex_add_noad_option (halfword a, long long r) { noad_options(a) |= r; }
-inline static void tex_remove_noad_option (halfword a, long long r) { noad_options(a) &= ~(r | noad_options(a)); }
-inline static int tex_has_noad_option (halfword a, long long r) { return (noad_options(a) & r) == r; }
+inline static void tex_add_noad_option (halfword a, uint64_t r) { noad_options(a) |= r; }
+inline static void tex_remove_noad_option (halfword a, uint64_t r) { noad_options(a) &= ~(r | noad_options(a)); }
+inline static int tex_has_noad_option (halfword a, uint64_t r) { return (noad_options(a) & r) == r; }
inline static int has_noad_no_script_option(halfword n, halfword option)
{
@@ -1853,8 +1854,8 @@ inline static int has_noad_no_script_option(halfword n, halfword option)
# define has_noad_option_stretch(a) (has_option(noad_options(a), noad_option_stretch))
# define has_noad_option_shrink(a) (has_option(noad_options(a), noad_option_shrink))
# define has_noad_option_auto_base(a) (has_option(noad_options(a), noad_option_auto_base))
-# define has_noad_option_center(a) (has_option(noad_options(a), noad_option_center))
# define has_noad_option_scale(a) (has_option(noad_options(a), noad_option_scale))
+# define has_noad_option_keep_base(a) (has_option(noad_options(a), noad_option_keep_base))
/*tex
In the meantime the codes and subtypes are in sync. The variable component does not really
diff --git a/source/luametatex/source/tex/texpackaging.c b/source/luametatex/source/tex/texpackaging.c
index c4af153fc..ad1db455c 100644
--- a/source/luametatex/source/tex/texpackaging.c
+++ b/source/luametatex/source/tex/texpackaging.c
@@ -1454,7 +1454,7 @@ halfword tex_hpack(halfword p, scaled w, int m, singleword pack_direction, int r
tex_current_input_file_name(),
&rule
);
- if (rule) {
+ if (rule && rule != r) {
tex_aux_append_diagnostic_rule(r, rule);
}
}
@@ -1511,7 +1511,7 @@ halfword tex_hpack(halfword p, scaled w, int m, singleword pack_direction, int r
rule = tex_new_rule_node(normal_rule_subtype);
rule_width(rule) = overfull_rule_par;
}
- if (rule) {
+ if (rule && rule != r) {
tex_aux_append_diagnostic_rule(r, rule);
}
if (callback_id == 0) {
@@ -1536,7 +1536,7 @@ halfword tex_hpack(halfword p, scaled w, int m, singleword pack_direction, int r
lmt_input_state.input_line,
tex_current_input_file_name(),
&rule);
- if (rule) {
+ if (rule && rule != r) {
tex_aux_append_diagnostic_rule(r, rule);
}
} else {
diff --git a/source/luametatex/source/tex/texprimitive.c b/source/luametatex/source/tex/texprimitive.c
index cab68f841..027f62d23 100644
--- a/source/luametatex/source/tex/texprimitive.c
+++ b/source/luametatex/source/tex/texprimitive.c
@@ -818,6 +818,13 @@ void tex_print_cmd_chr(singleword cmd, halfword chr)
tex_print_str_esc("attribute");
tex_print_int(register_attribute_number(chr));
break;
+ case register_posit_cmd:
+ tex_print_str_esc("posit");
+ tex_print_int(register_posit_number(chr));
+ break;
+ case internal_posit_cmd:
+ tex_aux_prim_cmd_chr(cmd, chr);
+ break;
case internal_dimen_cmd:
tex_aux_prim_cmd_chr(cmd, chr);
break;
@@ -851,6 +858,10 @@ void tex_print_cmd_chr(singleword cmd, halfword chr)
tex_print_str("dimension ");
tex_print_dimension(chr, pt_unit);
break;
+ case posit_cmd:
+ tex_print_str("posit ");
+ tex_print_posit(chr);
+ break;
case gluespec_cmd:
tex_print_str("gluespec ");
tex_print_spec(chr, pt_unit);
diff --git a/source/luametatex/source/tex/texprinting.c b/source/luametatex/source/tex/texprinting.c
index 1e384a9cd..9e502fbdf 100644
--- a/source/luametatex/source/tex/texprinting.c
+++ b/source/luametatex/source/tex/texprinting.c
@@ -585,6 +585,17 @@ void tex_print_sparse_dimension(scaled s, int unit)
}
}
+/*tex
+ Good enough.
+*/
+
+void tex_print_posit(halfword s)
+{
+ char b[32];
+ sprintf(b, "%.20g", tex_posit_to_double(s));
+ tex_print_str(b);
+}
+
/*tex
Hexadecimal printing of nonnegative integers is accomplished by |print_hex|. We have a few
diff --git a/source/luametatex/source/tex/texprinting.h b/source/luametatex/source/tex/texprinting.h
index 745b8eeb0..cfa50fbf5 100644
--- a/source/luametatex/source/tex/texprinting.h
+++ b/source/luametatex/source/tex/texprinting.h
@@ -69,6 +69,7 @@ extern void tex_print_cs (halfword p); /
extern void tex_print_cs_name (halfword p); /*tex Only prints known ones. */
extern void tex_print_str (const char *s);
extern void tex_print_str_esc (const char *s);
+extern void tex_print_posit (halfword d);
extern void tex_print_dimension (scaled d, int unit); /*tex prints a dimension with pt */
extern void tex_print_sparse_dimension (scaled d, int unit); /*tex prints a dimension with pt */
extern void tex_print_unit (int unit); /*tex prints a glue component */
diff --git a/source/luametatex/source/tex/texscanning.c b/source/luametatex/source/tex/texscanning.c
index aae30c6f0..5b60c15c0 100644
--- a/source/luametatex/source/tex/texscanning.c
+++ b/source/luametatex/source/tex/texscanning.c
@@ -155,6 +155,62 @@ scanner_state_info lmt_scanner_state = {
*/
+// inline static void tex_aux_downgrade_cur_val(int level, int succeeded, int negative)
+// {
+// switch (cur_val_level) {
+// case tok_val_level:
+// case font_val_level:
+// case mathspec_val_level:
+// case fontspec_val_level:
+// /*tex
+// This test pays back as this actually happens, but we also need it for the
+// |none_lua_function| handling. We end up here in |ident_val_level| and |tok_val_level|
+// and they don't downgrade, nor negate which saves a little testing.
+// */
+// break;
+// case int_val_level:
+// case attr_val_level:
+// case dimen_val_level:
+// case posit_val_level:
+// while (cur_val_level > level) {
+// --cur_val_level;
+// }
+// if (negative) {
+// cur_val = -cur_val;
+// }
+// break;
+// default:
+// /*tex There is no real need for it being a loop, a test would do. */
+// while (cur_val_level > level) {
+// /*tex Convert |cur_val| to a lower level. */
+// switch (cur_val_level) {
+// case glue_val_level:
+// case mu_val_level :
+// cur_val = glue_amount(cur_val);
+// break;
+// // case mu_val_level :
+// // tex_aux_mu_error(1);
+// // break;
+// }
+// --cur_val_level;
+// }
+// if (cur_val_level == glue_val_level || cur_val_level == mu_val_level) {
+// if (succeeded == 1) {
+// cur_val = tex_new_glue_spec_node(cur_val);
+// }
+// if (negative) {
+// glue_amount(cur_val) = -glue_amount(cur_val);
+// glue_stretch(cur_val) = -glue_stretch(cur_val);
+// glue_shrink(cur_val) = -glue_shrink(cur_val);
+// }
+// } else if (negative) {
+// cur_val = -cur_val;
+// }
+// break;
+// }
+// }
+
+
inline static void tex_aux_downgrade_cur_val(int level, int succeeded, int negative)
{
switch (cur_val_level) {
@@ -168,45 +224,97 @@ inline static void tex_aux_downgrade_cur_val(int level, int succeeded, int negat
and they don't downgrade, nor negate which saves a little testing.
*/
break;
- case int_val_level:
- case attr_val_level:
- case dimen_val_level:
- while (cur_val_level > level) {
- --cur_val_level;
- }
- if (negative) {
- cur_val = -cur_val;
- }
- break;
- default:
- /*tex There is no real need for it being a loop, a test would do. */
- while (cur_val_level > level) {
- /*tex Convert |cur_val| to a lower level. */
- switch (cur_val_level) {
- case glue_val_level:
- case mu_val_level :
- cur_val = glue_amount(cur_val);
- break;
- // case mu_val_level :
- // tex_aux_mu_error(1);
- // break;
- }
- --cur_val_level;
- }
- if (cur_val_level == glue_val_level || cur_val_level == mu_val_level) {
- if (succeeded == 1) {
- cur_val = tex_new_glue_spec_node(cur_val);
- }
- if (negative) {
- glue_amount(cur_val) = -glue_amount(cur_val);
- glue_stretch(cur_val) = -glue_stretch(cur_val);
- glue_shrink(cur_val) = -glue_shrink(cur_val);
- }
- } else if (negative) {
- cur_val = -cur_val;
- }
- break;
- }
+ case int_val_level:
+// while (cur_val_level > level) {
+// --cur_val_level;
+// }
+while (cur_val_level > level) {
+ cur_val_level = level;
+}
+ if (negative) {
+ cur_val = -cur_val;
+ }
+ if (level == posit_val_level) {
+ cur_val = tex_integer_to_posit(cur_val).v;
+ }
+ break;
+ case attr_val_level:
+// while (cur_val_level > level) {
+// --cur_val_level;
+// }
+while (cur_val_level > level) {
+ cur_val_level = level;
+}
+ if (negative) {
+ cur_val = -cur_val;
+ }
+ if (level == posit_val_level) {
+ cur_val = tex_integer_to_posit(cur_val).v;
+ }
+ break;
+ case dimen_val_level:
+// while (cur_val_level > level) {
+// --cur_val_level;
+// }
+while (cur_val_level > level) {
+ cur_val_level = level;
+}
+ if (negative) {
+ cur_val = -cur_val;
+ }
+ if (level == posit_val_level) {
+ cur_val = tex_dimension_to_posit(cur_val).v;
+ }
+ break;
+ case posit_val_level:
+ switch (cur_val_level) {
+ case dimen_val_level:
+ cur_val = tex_dimension_to_posit(cur_val).v;
+ break;
+ case int_val_level:
+ case attr_val_level:
+ cur_val = tex_integer_to_posit(cur_val).v;
+ break;
+ }
+// while (cur_val_level > level) {
+// --cur_val_level;
+// }
+while (cur_val_level > level) {
+ cur_val_level = level;
+}
+ if (negative) {
+ cur_val = tex_posit_neg(cur_val);
+ }
+ break;
+ default:
+ /*tex There is no real need for it being a loop, a test would do. */
+ while (cur_val_level > level) {
+ /*tex Convert |cur_val| to a lower level. */
+ switch (cur_val_level) {
+ case glue_val_level:
+ case mu_val_level :
+ cur_val = glue_amount(cur_val);
+ break;
+ // case mu_val_level :
+ // tex_aux_mu_error(1);
+ // break;
+ }
+ --cur_val_level;
+ }
+ if (cur_val_level == glue_val_level || cur_val_level == mu_val_level) {
+ if (succeeded == 1) {
+ cur_val = tex_new_glue_spec_node(cur_val);
+ }
+ if (negative) {
+ glue_amount(cur_val) = -glue_amount(cur_val);
+ glue_stretch(cur_val) = -glue_stretch(cur_val);
+ glue_shrink(cur_val) = -glue_shrink(cur_val);
+ }
+ } else if (negative) {
+ cur_val = -cur_val;
+ }
+ break;
+ }
}
/*tex
@@ -214,10 +322,6 @@ inline static void tex_aux_downgrade_cur_val(int level, int succeeded, int negat
Some of the internal items can be fetched both routines, and these have been split off into the
next routine, that returns true if the command code was understood.
-*/
-
-/*tex
-
The |last_item_cmd| branch has been flattened a bit because we don't need to treat \ETEX\
specific thingies special any longer.
@@ -571,6 +675,7 @@ static int tex_aux_set_cur_val_by_some_cmd(int code)
case font_char_dp_code:
case font_char_ic_code:
case font_char_ta_code:
+ case font_char_ba_code:
{
halfword fnt = tex_scan_font_identifier(NULL);
halfword chr = tex_scan_char_number(0);
@@ -591,6 +696,9 @@ static int tex_aux_set_cur_val_by_some_cmd(int code)
case font_char_ta_code:
cur_val = tex_char_top_anchor_from_font(fnt, chr);
break;
+ case font_char_ba_code:
+ cur_val = tex_char_bottom_anchor_from_font(fnt, chr);
+ break;
}
} else {
cur_val = 0;
@@ -803,6 +911,9 @@ static int tex_aux_set_cur_val_by_some_cmd(int code)
/* case attrexpr_code: */
tex_aux_scan_expr(int_val_level);
return 1;
+ case posexpr_code:
+ tex_aux_scan_expr(posit_val_level);
+ return 1;
case dimexpr_code:
tex_aux_scan_expr(dimen_val_level);
return 1;
@@ -1148,6 +1259,11 @@ void tex_scan_something_simple(halfword cmd, halfword chr)
cur_val = eq_value(chr);
cur_val_level = int_val_level;
break;
+ case internal_posit_cmd:
+ case register_posit_cmd:
+ cur_val = eq_value(chr);
+ cur_val_level = posit_val_level;
+ break;
case internal_dimen_cmd:
case register_dimen_cmd:
cur_val = eq_value(chr);
@@ -1300,11 +1416,22 @@ static halfword tex_aux_scan_something_internal(halfword cmd, halfword chr, int
case register_attribute_cmd:
cur_val = eq_value(chr);
cur_val_level = int_val_level;
+ if (level == posit_val_level) {
+ cur_val = tex_posit_to_integer(cur_val);
+ }
+ break;
+ case internal_posit_cmd:
+ case register_posit_cmd:
+ cur_val = eq_value(chr);
+ cur_val_level = posit_val_level;
break;
case internal_dimen_cmd:
case register_dimen_cmd:
cur_val = eq_value(chr);
cur_val_level = dimen_val_level;
+ if (level == posit_val_level) {
+ cur_val = tex_posit_to_dimension(cur_val);
+ }
break;
case internal_glue_cmd:
case register_glue_cmd:
@@ -1656,6 +1783,12 @@ static halfword tex_aux_scan_something_internal(halfword cmd, halfword chr, int
cur_val = attribute_register(n);
break;
}
+ case posit_val_level:
+ {
+ halfword n = tex_scan_posit_register_number();
+ cur_val = posit_register(n);
+ break;
+ }
case dimen_val_level:
{
scaled n = tex_scan_dimen_register_number();
@@ -1701,6 +1834,10 @@ static halfword tex_aux_scan_something_internal(halfword cmd, halfword chr, int
cur_val = chr;
cur_val_level = dimen_val_level;
break;
+ case posit_cmd:
+ cur_val = chr;
+ cur_val_level = posit_val_level;
+ break;
case gluespec_cmd:
cur_val = chr;
cur_val_level = glue_val_level;
@@ -1829,6 +1966,7 @@ inline static halfword tex_aux_scan_limited_int(int optional_equal, int min, int
halfword tex_scan_int_register_number (void) { return tex_aux_scan_limited_int(0, 0, max_int_register_index, "Integer register index"); }
halfword tex_scan_dimen_register_number (void) { return tex_aux_scan_limited_int(0, 0, max_dimen_register_index, "Dimension register index"); }
halfword tex_scan_attribute_register_number (void) { return tex_aux_scan_limited_int(0, 0, max_attribute_register_index, "Attribute register index"); }
+halfword tex_scan_posit_register_number (void) { return tex_aux_scan_limited_int(0, 0, max_posit_register_index, "Posit register index"); }
halfword tex_scan_glue_register_number (void) { return tex_aux_scan_limited_int(0, 0, max_glue_register_index, "Glue register index"); }
halfword tex_scan_mu_glue_register_number (void) { return tex_aux_scan_limited_int(0, 0, max_mu_glue_register_index, "Mu glue register index"); }
halfword tex_scan_toks_register_number (void) { return tex_aux_scan_limited_int(0, 0, max_toks_register_index, "Toks register index"); }
@@ -2120,12 +2258,22 @@ halfword tex_scan_int(int optional_equal, int *radix)
return cur_val;
}
-int tex_scan_cardinal(unsigned *value, int dontbark)
+int tex_scan_cardinal(int optional_equal, unsigned *value, int dontbark)
{
long long result = 0;
- do {
+ // do {
+ // tex_get_x_token();
+ // } while (cur_cmd == spacer_cmd);
+ while (1) {
tex_get_x_token();
- } while (cur_cmd == spacer_cmd);
+ if (cur_cmd != spacer_cmd) {
+ if (optional_equal && (cur_tok == equal_token)) {
+ optional_equal = 0;
+ } else {
+ break;
+ }
+ }
+ }
if (cur_cmd >= min_internal_cmd && cur_cmd <= max_internal_cmd) {
result = tex_aux_scan_something_internal(cur_cmd, cur_chr, int_val_level, 0, 0);
} else {
@@ -2711,6 +2859,9 @@ halfword tex_scan_dimen(int mu, int inf, int shortcut, int optional_equal, halfw
}
} else if (cur_val_level == dimen_val_level) {
goto ATTACH_SIGN;
+ } else if (cur_val_level == posit_val_level) {
+ cur_val = tex_posit_to_dimension(cur_val);
+ goto ATTACH_SIGN;
}
} else {
int has_fraction = tex_token_is_seperator(cur_tok);
@@ -3031,6 +3182,14 @@ halfword tex_the_value_toks(int code, halfword *tail, halfword property) /* mayb
pop_selector;
return tex_cur_str_toks(tail);
}
+ case posit_val_level:
+ {
+ int saved_selector;
+ push_selector;
+ tex_print_posit(cur_val);
+ pop_selector;
+ return tex_cur_str_toks(tail);
+ }
case dimen_val_level:
{
int saved_selector;
@@ -3166,6 +3325,9 @@ strnumber tex_the_scanned_result(void)
case attr_val_level:
tex_print_int(cur_val);
break;
+ case posit_val_level:
+ tex_print_posit(cur_val);
+ break;
case dimen_val_level:
tex_print_dimension(cur_val, pt_unit);
break;
@@ -3360,10 +3522,10 @@ halfword tex_scan_font_identifier(halfword *spec)
}
default:
{
- /*tex We abuse |scan_cardinal| here btu we have to push back. */
+ /*tex We abuse |scan_cardinal| here but we have to push back. */
unsigned fnt = null_font;
tex_back_input(cur_tok);
- if (tex_scan_cardinal(&fnt, 1)) {
+ if (tex_scan_cardinal(0, &fnt, 1)) {
if (tex_is_valid_font((halfword) fnt)) {
return (halfword) fnt;
}
@@ -3731,7 +3893,7 @@ static int tex_aux_valid_macro_preamble(halfword *p, int *counter, halfword *has
}
} else if (cur_tok >= A_token_l && cur_tok <= F_token_l) {
++*counter;
- if ((cur_tok - letter_token - 'A' - gap_match_count) == *counter) {
+ if ((cur_tok - A_token_l + 10) == *counter) {
cur_tok += match_token - letter_token;
break;
}
@@ -4227,7 +4389,8 @@ static void tex_aux_scan_expr(halfword level)
int error_b = 0;
/*tex top of expression stack */
halfword top = null;
-int braced = 0;
+ int braced = 0;
+ int nonelevel = level == posit_val_level ? posit_val_level : int_val_level;
/*tex Scan and evaluate an expression |e| of type |l|. */
cur_val_level = level; /* for now */
lmt_scanner_state.expression_depth++;
@@ -4241,7 +4404,8 @@ int braced = 0;
term = 0;
numerator = 0;
CONTINUE:
- operation = state == expression_none ? level : int_val_level; /* we abuse operation */
+// operation = state == expression_none ? level : int_val_level; /* we abuse operation */
+ operation = state == expression_none ? level : nonelevel; /* we abuse operation */
/*tex
Scan a factor |f| of type |o| or start a subexpression. Get the next non-blank non-call
token.
@@ -4283,6 +4447,9 @@ int braced = 0;
case attr_val_level:
factor = tex_scan_int(0, NULL);
break;
+ case posit_val_level:
+ factor = tex_scan_posit(0);
+ break;
case dimen_val_level:
factor = tex_scan_dimen(0, 0, 0, 0, NULL);
break;
@@ -4348,6 +4515,12 @@ int braced = 0;
factor = 0;
}
break;
+ case posit_val_level:
+ if ((factor > max_cardinal) || (factor < min_cardinal)) {
+ lmt_scanner_state.arithmic_error = 1;
+ factor = 0;
+ }
+ break;
case dimen_val_level:
if (abs(factor) > max_dimen) {
lmt_scanner_state.arithmic_error = 1;
@@ -4398,6 +4571,9 @@ int braced = 0;
case attr_val_level:
term = tex_multiply_integers(term, factor);
break;
+ case posit_val_level:
+ term = tex_posit_mul(term, factor);
+ break;
case dimen_val_level:
term = tex_nx_plus_y(term, factor, 0);
break;
@@ -4426,6 +4602,9 @@ int braced = 0;
case attr_val_level:
term = tex_fract(term, numerator, factor, max_integer);
break;
+ case posit_val_level:
+ term = tex_posit_div(tex_posit_mul(term, factor), numerator);
+ break;
case dimen_val_level:
term = tex_fract(term, numerator, factor, max_dimen);
break;
@@ -4463,6 +4642,16 @@ int braced = 0;
case attr_val_level:
expression = tex_aux_add_or_sub(expression, term, max_integer, result);
break;
+ case posit_val_level:
+ switch (result) {
+ case expression_subtract:
+ expression = tex_posit_sub(expression, term);
+ break;
+ case expression_add:
+ expression = tex_posit_add(expression, term);
+ break;
+ }
+ break;
case dimen_val_level:
expression = tex_aux_add_or_sub(expression, term, max_dimen, result);
break;
@@ -5174,7 +5363,7 @@ static void tex_aux_trace_expression(stack_info stack, halfword level, halfword
tex_end_diagnostic();
}
-/* This one is not yet okay ... work in progress. */
+/* This one is not yet okay ... work in progress. We might go for posits here. */
static void tex_aux_scan_expression(int level)
{
@@ -5803,6 +5992,202 @@ halfword tex_scan_scale(int optional_equal)
return cur_val;
}
+/* todo: share with lmttokenlib.scan_float */
+
+# define max_posit_size 60
+
+halfword tex_scan_posit(int optional_equal)
+{
+ int hexadecimal = 1;
+ int exponent = 1;
+ int negative = 0;
+ int b = 0;
+ char buffer[max_posit_size+4] = { 0 };
+ do {
+ while (1) {
+ tex_get_x_token();
+ if (cur_cmd != spacer_cmd) {
+ if (optional_equal && (cur_tok == equal_token)) {
+ optional_equal = 0;
+ } else {
+ break;
+ }
+ }
+ }
+ if (cur_tok == minus_token) {
+ negative = ! negative;
+ cur_tok = plus_token;
+ }
+ } while (cur_tok == plus_token);
+ if (cur_cmd >= min_internal_cmd && cur_cmd <= max_internal_cmd) {
+ cur_val = tex_aux_scan_something_internal(cur_cmd, cur_chr, posit_val_level, 0, 0);
+ } else {
+ if (negative) {
+ buffer[b++] = '-';
+ }
+ /*tex we accept |[.,]digits| */
+ if (hexadecimal && (cur_tok == zero_token)) {
+ buffer[b++] = '0';
+ tex_get_x_token();
+ if (tex_token_is_hexadecimal(cur_tok)) {
+ buffer[b++] = 'x';
+ goto SCANHEXADECIMAL;
+ } else {
+ goto PICKUPDECIMAL;
+ }
+ } else {
+ goto SCANDECIMAL;
+ }
+ SCANDECIMAL:
+ if (tex_token_is_seperator(cur_tok)) {
+ buffer[b++] = '.';
+ while (1) {
+ tex_get_x_token();
+ if (tex_token_is_digit(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ } else if (exponent) {
+ goto DECIMALEXPONENT;
+ } else {
+ tex_back_input(cur_tok);
+ goto DONE;
+ }
+ if (b >= 60) {
+ goto TOOBIG;
+ }
+ }
+ } else {
+ goto PICKUPDECIMAL;
+ }
+ while (1) {
+ tex_get_x_token();
+ PICKUPDECIMAL:
+ if (tex_token_is_digit(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ } else if (tex_token_is_seperator(cur_tok)) {
+ buffer[b++] = '.';
+ while (1) {
+ tex_get_x_token();
+ if (tex_token_is_digit(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ } else {
+ tex_back_input(cur_tok);
+ break;
+ }
+ }
+ } else if (exponent) {
+ goto DECIMALEXPONENT;
+ } else {
+ tex_back_input(cur_tok);
+ goto DONE;
+ }
+ if (b >= max_posit_size) {
+ goto TOOBIG;
+ }
+ }
+ DECIMALEXPONENT:
+ if (tex_token_is_exponent(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ tex_get_x_token();
+ if (tex_token_is_sign(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ } else if (tex_token_is_digit(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ }
+ while (1) {
+ tex_get_x_token();
+ if (tex_token_is_digit(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ } else {
+ break;
+ }
+ if (b >= max_posit_size) {
+ goto TOOBIG;
+ }
+ }
+ }
+ tex_back_input(cur_tok);
+ goto DONE;
+ SCANHEXADECIMAL:
+ tex_get_x_token();
+ if (tex_token_is_seperator(cur_tok)) {
+ buffer[b++] = '.';
+ while (1) {
+ tex_get_x_token();
+ if (tex_token_is_xdigit(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ } else if (exponent) {
+ goto HEXADECIMALEXPONENT;
+ } else {
+ tex_back_input(cur_tok);
+ goto DONE;
+ }
+ if (b >= max_posit_size) {
+ goto TOOBIG;
+ }
+ }
+ } else {
+ /* hm, we could avoid this pushback */
+ tex_back_input(cur_tok);
+ while (1) {
+ tex_get_x_token();
+ if (tex_token_is_xdigit(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ } else if (tex_token_is_seperator(cur_tok)) {
+ buffer[b++] = '.';
+ while (1) {
+ tex_get_x_token();
+ if (tex_token_is_xdigit(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ } else {
+ tex_back_input(cur_tok);
+ break;
+ }
+ }
+ } else if (exponent) {
+ goto HEXADECIMALEXPONENT;
+ } else {
+ tex_back_input(cur_tok);
+ goto DONE;
+ }
+ if (b >= max_posit_size) {
+ goto TOOBIG;
+ }
+ }
+ }
+ HEXADECIMALEXPONENT:
+ if (tex_token_is_xexponent(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ tex_get_x_token();
+ if (tex_token_is_sign(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ } else if (tex_token_is_xdigit(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ }
+ while (1) {
+ tex_get_x_token();
+ if (tex_token_is_xdigit(cur_tok)) {
+ buffer[b++] = (unsigned char) cur_chr;
+ } else {
+ break;
+ }
+ if (b >= max_posit_size) {
+ goto TOOBIG;
+ }
+ }
+ }
+ tex_back_input(cur_tok);
+ DONE:
+ {
+ double d = strtof(buffer, NULL);
+ cur_val = tex_double_to_posit(d).v;
+ return cur_val;
+ }
+ TOOBIG:
+ cur_val = tex_integer_to_posit(0).v;
+ }
+ return cur_val;
+}
+
int tex_scan_tex_value(halfword level, halfword *value)
{
tex_aux_scan_expr(level);
diff --git a/source/luametatex/source/tex/texscanning.h b/source/luametatex/source/tex/texscanning.h
index 3415c27dd..34e118d93 100644
--- a/source/luametatex/source/tex/texscanning.h
+++ b/source/luametatex/source/tex/texscanning.h
@@ -6,6 +6,7 @@
# define LMT_SCANNING_H
typedef enum value_level_code {
+ posit_val_level,
int_val_level, /*tex integer values */
attr_val_level, /*tex integer values */
dimen_val_level, /*tex dimension values */
@@ -77,9 +78,10 @@ inline static void tex_unsave_full_scanner_status(full_scanner_status a)
extern void tex_scan_something_simple (halfword cmd, halfword code);
extern void tex_scan_left_brace (void);
extern void tex_scan_optional_equals (void);
-extern int tex_scan_cardinal (unsigned *value, int dontbark);
+extern int tex_scan_cardinal (int optional_equal, unsigned *value, int dontbark);
extern halfword tex_scan_int (int optional_equal, int *radix);
extern halfword tex_scan_scale (int optional_equal);
+extern halfword tex_scan_posit (int optional_equal);
extern halfword tex_scan_dimen (int mu, int inf, int shortcut, int optional_equal, halfword *order);
extern halfword tex_scan_glue (int level, int optional_equal);
extern halfword tex_scan_font (int optional_equal);
@@ -107,6 +109,7 @@ extern int tex_scanned_expression (int level);
extern halfword tex_scan_int_register_number (void);
extern halfword tex_scan_dimen_register_number (void);
extern halfword tex_scan_attribute_register_number (void);
+extern halfword tex_scan_posit_register_number (void);
extern halfword tex_scan_glue_register_number (void);
extern halfword tex_scan_mu_glue_register_number (void);
extern halfword tex_scan_toks_register_number (void);
diff --git a/source/luametatex/source/tex/textoken.c b/source/luametatex/source/tex/textoken.c
index b07bf02f1..e3aa90c0f 100644
--- a/source/luametatex/source/tex/textoken.c
+++ b/source/luametatex/source/tex/textoken.c
@@ -453,8 +453,9 @@ void tex_print_meaning(halfword code)
switch (code) {
case meaning_code:
case meaning_full_code:
+ case meaning_ful_code:
case meaning_asis_code:
- tex_print_cmd_flags(cur_cs, cur_cmd, (code == meaning_full_code || code == meaning_asis_code), code == meaning_asis_code);
+ tex_print_cmd_flags(cur_cs, cur_cmd, (code != meaning_code), code == meaning_asis_code);
break;
}
}
@@ -473,11 +474,16 @@ void tex_print_meaning(halfword code)
switch (code) {
case meaning_code:
case meaning_full_code:
+ case meaning_ful_code:
if (constant) {
tex_print_str("constant ");
}
tex_print_str("macro");
- goto FOLLOWUP;
+ if (code == meaning_ful_code) {
+ return;
+ } else {
+ goto FOLLOWUP;
+ }
case meaning_asis_code:
if (constant) {
tex_print_str_esc("constant ");
@@ -491,6 +497,11 @@ void tex_print_meaning(halfword code)
tex_show_token_list(token_link(cur_chr), get_token_preamble(cur_chr));
}
return;
+ case meaning_les_code:
+ if (cur_chr && token_link(cur_chr)) {
+ tex_show_token_list(token_link(cur_chr), 2);
+ }
+ return;
}
goto DETAILS;
}
@@ -644,10 +655,17 @@ void tex_show_token_list(halfword p, int asis)
break;
}
case end_match_cmd:
- if (asis) {
- tex_print_char('{');
- } else if (chr == 0) {
- tex_print_str("->");
+ switch (asis) {
+ case 1:
+ tex_print_char('{');
+ break;
+ case 2:
+ return;
+ default:
+ if (chr == 0) {
+ tex_print_str("->");
+ }
+ break;
}
break;
case ignore_something_cmd:
@@ -668,7 +686,7 @@ void tex_show_token_list(halfword p, int asis)
}
p = token_link(p);
}
- if (asis) {
+ if (asis == 1) {
tex_print_char('}');
}
}
@@ -2950,6 +2968,8 @@ void tex_run_convert_tokens(halfword code)
case meaning_code:
case meaning_full_code:
case meaning_less_code:
+ case meaning_ful_code:
+ case meaning_les_code:
case meaning_asis_code:
{
int saved_selector;
@@ -3274,7 +3294,7 @@ char *tex_tokenlist_to_tstring(int pp, int inhibit_par, int *siz, int skippreamb
lmt_token_state.bufmax = default_buffer_size;
}
lmt_token_state.bufloc = 0;
- if (skippreamble) {
+ if (skippreamble == 1) {
skip = get_token_preamble(pp);
}
while (p) {
@@ -3338,19 +3358,21 @@ char *tex_tokenlist_to_tstring(int pp, int inhibit_par, int *siz, int skippreamb
++n;
}
if (! skip) {
- // tex_aux_append_char_to_buffer(chr ? chr : '0');
- if (chr <= 9) {
- tex_aux_append_char_to_buffer(chr + '0');
- } else if (chr <= max_match_count) {
- tex_aux_append_char_to_buffer(chr + '0' + gap_match_count);
- }
+ tex_aux_append_char_to_buffer(chr ? chr : '0');
+ // if (chr <= 9) {
+ // tex_aux_append_char_to_buffer(chr + '0');
+ // } else if (chr <= max_match_count) {
+ // tex_aux_append_char_to_buffer(chr + '0' + gap_match_count);
+ // }
}
if (n > max_match_count) {
goto EXIT;
}
break;
case end_match_cmd:
- if (chr == 0) {
+ if (skippreamble ==2) {
+ goto EXIT;
+ } else if (chr == 0) {
if (! skip) {
tex_aux_append_char_to_buffer('-');
tex_aux_append_char_to_buffer('>');
@@ -3468,6 +3490,7 @@ halfword tex_get_tex_dimen_register (int j, int internal) { return internal
halfword tex_get_tex_skip_register (int j, int internal) { return internal ? glue_parameter(j) : skip_register(j) ; }
halfword tex_get_tex_mu_skip_register (int j, int internal) { return internal ? mu_glue_parameter(j) : mu_skip_register(j); }
halfword tex_get_tex_count_register (int j, int internal) { return internal ? count_parameter(j) : count_register(j) ; }
+halfword tex_get_tex_posit_register (int j, int internal) { return internal ? posit_parameter(j) : posit_register(j) ; }
halfword tex_get_tex_attribute_register (int j, int internal) { return internal ? attribute_parameter(j) : attribute_register(j) ; }
halfword tex_get_tex_box_register (int j, int internal) { return internal ? box_parameter(j) : box_register(j) ; }
@@ -3514,6 +3537,18 @@ void tex_set_tex_count_register(int j, halfword v, int flags, int internal)
tex_word_define(flags, register_int_location(j), v);
}
}
+void tex_set_tex_posit_register(int j, halfword v, int flags, int internal)
+{
+ if (global_defs_par) {
+ flags = add_global_flag(flags);
+ }
+ if (internal) {
+ tex_assign_internal_posit_value(flags, internal_posit_location(j), v);
+ } else {
+ tex_word_define(flags, register_posit_location(j), v);
+ }
+}
+
void tex_set_tex_attribute_register(int j, halfword v, int flags, int internal)
{
diff --git a/source/luametatex/source/tex/textoken.h b/source/luametatex/source/tex/textoken.h
index 20885ee66..51c61dc4f 100644
--- a/source/luametatex/source/tex/textoken.h
+++ b/source/luametatex/source/tex/textoken.h
@@ -387,6 +387,7 @@ extern halfword tex_get_tex_dimen_register (int j, int internal);
extern halfword tex_get_tex_skip_register (int j, int internal);
extern halfword tex_get_tex_mu_skip_register (int j, int internal);
extern halfword tex_get_tex_count_register (int j, int internal);
+extern halfword tex_get_tex_posit_register (int j, int internal);
extern halfword tex_get_tex_attribute_register (int j, int internal);
extern halfword tex_get_tex_box_register (int j, int internal);
extern halfword tex_get_tex_toks_register (int j, int internal);
@@ -395,6 +396,7 @@ extern void tex_set_tex_dimen_register (int j, halfword v, int flags,
extern void tex_set_tex_skip_register (int j, halfword v, int flags, int internal);
extern void tex_set_tex_mu_skip_register (int j, halfword v, int flags, int internal);
extern void tex_set_tex_count_register (int j, halfword v, int flags, int internal);
+extern void tex_set_tex_posit_register (int j, halfword v, int flags, int internal);
extern void tex_set_tex_attribute_register (int j, halfword v, int flags, int internal);
extern void tex_set_tex_box_register (int j, halfword v, int flags, int internal);
diff --git a/source/luametatex/source/tex/textypes.h b/source/luametatex/source/tex/textypes.h
index c4f917d4f..d2bb77972 100644
--- a/source/luametatex/source/tex/textypes.h
+++ b/source/luametatex/source/tex/textypes.h
@@ -147,6 +147,8 @@ extern halfword tex_badness(
# define min_cardinal 0
# define max_integer 0x7FFFFFFF /*tex aka |infinity| */
# define min_integer -0x7FFFFFFF /*tex aka |min_infinity| */
+# define max_posit max_cardinal
+# define min_posit min_cardinal
# define max_dimen 0x3FFFFFFF
# define min_dimen -0x3FFFFFFF
# define min_data_value 0
@@ -236,6 +238,7 @@ extern halfword tex_badness(
# define max_box_register_index 0xFFFF /* 0xFFFF 0xFFFF 0x7FFF */ /* 64 64 32 */
# define max_int_register_index 0xFFFF /* 0xFFFF 0xFFFF 0x3FFF */ /* 64 64 16 */
# define max_dimen_register_index 0xFFFF /* 0xFFFF 0xFFFF 0x3FFF */ /* 64 64 16 */
+ # define max_posit_register_index 0xFFFF /* 0xFFFF 0x7FFF 0x1FFF */ /* 64 32 8 */
# define max_attribute_register_index 0xFFFF /* 0xFFFF 0x7FFF 0x1FFF */ /* 64 32 8 */
# define max_glue_register_index 0xFFFF /* 0xFFFF 0x7FFF 0x1FFF */ /* 64 32 8 */
# define max_mu_glue_register_index 0xFFFF /* 0xFFFF 0x3FFF 0x1FFF */ /* 64 16 8 */
@@ -246,6 +249,7 @@ extern halfword tex_badness(
# define max_box_register_index 0x7FFF
# define max_int_register_index 0x1FFF
# define max_dimen_register_index 0x1FFF
+ # define max_posit_register_index 0x1FFF
# define max_attribute_register_index 0x1FFF
# define max_glue_register_index 0x1FFF
# define max_mu_glue_register_index 0x1FFF
@@ -257,6 +261,7 @@ extern halfword tex_badness(
# define max_n_of_int_registers (max_int_register_index + 1)
# define max_n_of_dimen_registers (max_dimen_register_index + 1)
# define max_n_of_attribute_registers (max_attribute_register_index + 1)
+# define max_n_of_posit_registers (max_posit_register_index + 1)
# define max_n_of_glue_registers (max_glue_register_index + 1)
# define max_n_of_mu_glue_registers (max_mu_glue_register_index + 1)