summaryrefslogtreecommitdiff
path: root/source/luametatex/source/lua
diff options
context:
space:
mode:
Diffstat (limited to 'source/luametatex/source/lua')
-rw-r--r--source/luametatex/source/lua/lmtcallbacklib.c13
-rw-r--r--source/luametatex/source/lua/lmtcallbacklib.h4
-rw-r--r--source/luametatex/source/lua/lmtinterface.c14
-rw-r--r--source/luametatex/source/lua/lmtinterface.h7
-rw-r--r--source/luametatex/source/lua/lmtnodelib.c71
-rw-r--r--source/luametatex/source/lua/lmtstatuslib.c2
-rw-r--r--source/luametatex/source/lua/lmttexlib.c27
-rw-r--r--source/luametatex/source/lua/lmttokenlib.c50
8 files changed, 161 insertions, 27 deletions
diff --git a/source/luametatex/source/lua/lmtcallbacklib.c b/source/luametatex/source/lua/lmtcallbacklib.c
index a971b5e57..ec9788c13 100644
--- a/source/luametatex/source/lua/lmtcallbacklib.c
+++ b/source/luametatex/source/lua/lmtcallbacklib.c
@@ -54,6 +54,7 @@ static const char *callbacklib_names[total_callbacks] = {
"show_warning_message",
"hpack_quality",
"vpack_quality",
+ "show_break",
"insert_par",
"append_line_filter",
"build_page_insert",
@@ -307,7 +308,7 @@ static int callbacklib_aux_run(lua_State *L, int id, int special, const char *va
return tex_formatted_error("callback", "string expected, not: %s\n", lua_typename(L, t));
}
break;
- case callback_result_key:
+ case callback_result_s_key:
switch (t) {
case LUA_TNIL:
*va_arg(vl, int *) = 0;
@@ -342,6 +343,16 @@ static int callbacklib_aux_run(lua_State *L, int id, int special, const char *va
return tex_formatted_error("callback", "string, false or nil expected, not: %s\n", lua_typename(L, t));
}
break;
+ case callback_result_i_key:
+ switch (t) {
+ case LUA_TNUMBER:
+ *va_arg(vl, int *) = lmt_tointeger(L, nres);
+ break;
+ default:
+ /* *va_arg(vl, int *) = 0; */ /*tex We keep the value! */
+ break;
+ }
+ break;
default:
return tex_formatted_error("callback", "invalid value type returned\n");
}
diff --git a/source/luametatex/source/lua/lmtcallbacklib.h b/source/luametatex/source/lua/lmtcallbacklib.h
index 7801e1a70..50b1cb4d1 100644
--- a/source/luametatex/source/lua/lmtcallbacklib.h
+++ b/source/luametatex/source/lua/lmtcallbacklib.h
@@ -40,6 +40,7 @@ typedef enum callback_callback_types {
show_warning_message_callback,
hpack_quality_callback,
vpack_quality_callback,
+ show_break_callback,
insert_par_callback,
append_line_filter_callback,
build_page_insert_callback,
@@ -80,7 +81,8 @@ typedef enum callback_keys {
callback_lstring_key = 'L', /*tex a \LUA\ string (struct) */
callback_node_key = 'N', /*tex a \TEX\ node (halfword) */
callback_string_key = 'S', /*tex a \CCODE\ string */
- callback_result_key = 'R', /*tex a string (return value) but nil is also okay */
+ callback_result_s_key = 'R', /*tex a string (return value) but nil is also okay */
+ callback_result_i_key = 'r', /*tex a number (return value) but nil is also okay */
} callback_keys;
inline static int lmt_callback_defined (int a) { return lmt_callback_state.values[a]; }
diff --git a/source/luametatex/source/lua/lmtinterface.c b/source/luametatex/source/lua/lmtinterface.c
index 2c94feb6f..5132606de 100644
--- a/source/luametatex/source/lua/lmtinterface.c
+++ b/source/luametatex/source/lua/lmtinterface.c
@@ -174,6 +174,20 @@ void lmt_initialize_interface(void)
set_alignment_context_value(package_pass_alignment_context, package);
set_alignment_context_value(wrapup_pass_alignment_context, wrapup);
+ lmt_interface.break_context_values = lmt_aux_allocate_value_info(wrapup_show_breaks_context);
+
+ # define set_break_context_value(n,k) lmt_interface.break_context_values[n] = (value_info) { .lua = lua_key_index(k), .name = lua_key(k), .id = n }
+
+ set_break_context_value(initialize_show_breaks_context, initialize);
+ set_break_context_value(start_show_breaks_context, start);
+ set_break_context_value(list_show_breaks_context, list);
+ set_break_context_value(stop_show_breaks_context, stop);
+ set_break_context_value(collect_show_breaks_context, collect);
+ set_break_context_value(line_show_breaks_context, line);
+ set_break_context_value(delete_show_breaks_context, delete);
+ set_break_context_value(report_show_breaks_context, report);
+ set_break_context_value(wrapup_show_breaks_context, wrapup);
+
lmt_interface.par_begin_values = lmt_aux_allocate_value_info(vrule_char_par_begin);
# define set_par_begin_value(n,k) lmt_interface.par_begin_values[n] = (value_info) { .lua = lua_key_index(k), .name = lua_key(k), .id = n }
diff --git a/source/luametatex/source/lua/lmtinterface.h b/source/luametatex/source/lua/lmtinterface.h
index 47460acac..ea6ead4ab 100644
--- a/source/luametatex/source/lua/lmtinterface.h
+++ b/source/luametatex/source/lua/lmtinterface.h
@@ -341,6 +341,7 @@ typedef struct lmt_interface_info {
value_info *page_context_values;
value_info *append_line_context_values;
value_info *alignment_context_values;
+ value_info *break_context_values;
value_info *par_begin_values;
value_info *par_mode_values;
value_info *math_style_name_values;
@@ -540,6 +541,7 @@ make_lua_key(L, clubpenalty);\
make_lua_key(L, cmd);\
make_lua_key(L, cmdname);\
make_lua_key(L, collapse);\
+make_lua_key(L, collect);\
make_lua_key(L, combine_toks);\
make_lua_key(L, command);\
make_lua_key(L, comment);\
@@ -576,6 +578,7 @@ make_lua_key(L, define_font);\
make_lua_key(L, define_lua_call);\
make_lua_key(L, degree);\
make_lua_key(L, degreevariant);\
+make_lua_key(L, delete);\
make_lua_key(L, delimited);\
make_lua_key(L, DelimitedSubFormulaMinHeight);\
make_lua_key(L, delimiter);\
@@ -762,6 +765,7 @@ make_lua_key(L, index);\
make_lua_key(L, info);\
make_lua_key(L, Info);\
make_lua_key(L, inherited);\
+make_lua_key(L, initialize);\
make_lua_key(L, inner);\
make_lua_key(L, innerlocation);\
make_lua_key(L, innerxoffset);\
@@ -1113,6 +1117,7 @@ make_lua_key(L, relax);\
make_lua_key(L, remove_item);\
make_lua_key(L, repeat);\
make_lua_key(L, replace);\
+make_lua_key(L, report);\
make_lua_key(L, reserved);\
make_lua_key(L, reset);\
make_lua_key(L, rhmin);\
@@ -1170,6 +1175,7 @@ make_lua_key(L, shrink);\
make_lua_key(L, shrinkorder);\
make_lua_key(L, simple);\
make_lua_key(L, size);\
+make_lua_key(L, single);\
make_lua_key(L, skewchar);\
make_lua_key(L, SkewedDelimiterTolerance);\
make_lua_key(L, skeweddelimitertolerance);\
@@ -1222,6 +1228,7 @@ make_lua_key(L, stackvgap);\
make_lua_key(L, start);\
make_lua_key(L, state);\
make_lua_key(L, step);\
+make_lua_key(L, stop);\
make_lua_key(L, stretch);\
make_lua_key(L, stretchorder);\
make_lua_key(L, StretchStackBottomShiftDown);\
diff --git a/source/luametatex/source/lua/lmtnodelib.c b/source/luametatex/source/lua/lmtnodelib.c
index 7896eff65..ba2d0f0ba 100644
--- a/source/luametatex/source/lua/lmtnodelib.c
+++ b/source/luametatex/source/lua/lmtnodelib.c
@@ -548,7 +548,7 @@ static int nodelib_direct_setfont(lua_State *L)
case rule_node:
tex_set_rule_font(n, lmt_tohalfword(L, 2));
if (lua_type(L, 3) == LUA_TNUMBER) {
- rule_character(n) = lmt_tohalfword(L, 3);
+ rule_strut_character(n) = lmt_tohalfword(L, 3);
}
break;
case glue_node:
@@ -617,7 +617,7 @@ static int nodelib_direct_getchar(lua_State *L)
lua_pushinteger(L, glyph_character(n));
break;
case rule_node:
- lua_pushinteger(L, rule_character(n));
+ lua_pushinteger(L, rule_strut_character(n));
break;
case math_char_node:
case math_text_char_node:
@@ -646,7 +646,7 @@ static int nodelib_direct_setchar(lua_State *L)
glyph_character(n) = lmt_tohalfword(L, 2);
break;
case rule_node:
- rule_character(n) = lmt_tohalfword(L, 2);
+ rule_strut_character(n) = lmt_tohalfword(L, 2);
break;
case math_char_node:
case math_text_char_node:
@@ -674,7 +674,7 @@ static int nodelib_direct_getcharspec(lua_State *L)
lua_pushinteger(L, glyph_font(n));
return 2;
case rule_node:
- lua_pushinteger(L, rule_character(n));
+ lua_pushinteger(L, rule_strut_character(n));
lua_pushinteger(L, tex_get_rule_font(n, text_style));
break;
case simple_noad:
@@ -1489,8 +1489,8 @@ static int nodelib_direct_getoffsets(lua_State *L)
case rule_node:
lua_pushinteger(L, rule_x_offset(n));
lua_pushinteger(L, rule_y_offset(n));
- lua_pushinteger(L, rule_left(n));
- lua_pushinteger(L, rule_right(n));
+ lua_pushinteger(L, tex_get_rule_left(n));
+ lua_pushinteger(L, tex_get_rule_right(n));
return 4;
}
}
@@ -1537,10 +1537,10 @@ static int nodelib_direct_setoffsets(lua_State *L)
rule_y_offset(n) = (halfword) lmt_roundnumber(L, 3);
}
if (lua_type(L, 4) == LUA_TNUMBER) {
- rule_left(n) = (halfword) lmt_roundnumber(L, 4);
+ tex_set_rule_left(n, (halfword) lmt_roundnumber(L, 4));
}
if (lua_type(L, 5) == LUA_TNUMBER) {
- rule_right(n) = (halfword) lmt_roundnumber(L, 5);
+ tex_set_rule_right(n, (halfword) lmt_roundnumber(L, 5));
}
break;
}
@@ -1610,10 +1610,10 @@ static int nodelib_direct_addmargins(lua_State *L)
break;
case rule_node:
if (lua_type(L, 2) == LUA_TNUMBER) {
- rule_left(n) += (halfword) lmt_roundnumber(L, 2);
+ tex_set_rule_left(n, tex_get_rule_left(n) + (halfword) lmt_roundnumber(L, 2));
}
if (lua_type(L, 3) == LUA_TNUMBER) {
- rule_right(n) += (halfword) lmt_roundnumber(L, 3);
+ tex_set_rule_right(n, tex_get_rule_right(n) + (halfword) lmt_roundnumber(L, 3));
}
break;
}
@@ -2907,9 +2907,9 @@ static int nodelib_direct_getruledimensions(lua_State *L)
halfword n = nodelib_valid_direct_from_index(L, 1);
if (n && node_type(n) == rule_node) {
if (node_subtype(n) == virtual_rule_subtype) {
- lua_pushinteger(L, rule_data(n));
- lua_pushinteger(L, rule_left(n));
- lua_pushinteger(L, rule_right(n));
+ lua_pushinteger(L, rule_virtual_width(n));
+ lua_pushinteger(L, rule_virtual_height(n));
+ lua_pushinteger(L, rule_virtual_depth(n));
lua_pushboolean(L, 1);
} else {
lua_pushinteger(L, rule_width(n));
@@ -2923,6 +2923,32 @@ static int nodelib_direct_getruledimensions(lua_State *L)
}
}
+static int nodelib_direct_setruledimensions(lua_State *L)
+{
+ halfword n = nodelib_valid_direct_from_index(L, 1);
+ if (n && node_type(n) == rule_node) {
+ scaled wd = (scaled) lmt_roundnumber(L, 2);
+ scaled ht = (scaled) lmt_roundnumber(L, 3);
+ scaled dp = (scaled) lmt_roundnumber(L, 4);
+ if (node_subtype(n) == virtual_rule_subtype) {
+ rule_virtual_width(n) = wd;
+ rule_virtual_height(n) = ht;
+ rule_virtual_depth(n) = dp;
+ rule_width(n) = 0;
+ rule_height(n) = 0;
+ rule_depth(n) = 0;
+ } else {
+ rule_width(n) = wd;
+ rule_height(n) = ht;
+ rule_depth(n) = dp;
+ }
+ if (lua_type(L, 5) == LUA_TNUMBER) {
+ rule_data(n) = (halfword) lmt_roundnumber(L, 5);
+ }
+ }
+ return 0;
+}
+
/* node.direct.getlist */
static int nodelib_direct_getlist(lua_State *L)
@@ -6577,21 +6603,21 @@ static int nodelib_common_getfield(lua_State *L, int direct, halfword n)
} else if (lua_key_eq(s, total)) {
lua_pushinteger(L, rule_total(n));
} else if (lua_key_eq(s, xoffset)) {
- lua_pushinteger(L,rule_x_offset(n));
+ lua_pushinteger(L, rule_x_offset(n));
} else if (lua_key_eq(s, yoffset)) {
- lua_pushinteger(L,rule_y_offset(n));
+ lua_pushinteger(L, rule_y_offset(n));
} else if (lua_key_eq(s, left)) {
- lua_pushinteger(L,rule_left(n));
+ lua_pushinteger(L, tex_get_rule_left(n));
} else if (lua_key_eq(s, right)) {
- lua_pushinteger(L,rule_right(n));
+ lua_pushinteger(L, tex_get_rule_right(n));
} else if (lua_key_eq(s, data)) {
- lua_pushinteger(L,rule_data(n));
+ lua_pushinteger(L, rule_data(n));
} else if (lua_key_eq(s, font)) {
lua_pushinteger(L, tex_get_rule_font(n, text_style));
} else if (lua_key_eq(s, fam)) {
lua_pushinteger(L, tex_get_rule_font(n, text_style));
} else if (lua_key_eq(s, char)) {
- lua_pushinteger(L, rule_character(n));
+ lua_pushinteger(L, rule_strut_character(n));
} else {
lua_pushnil(L);
}
@@ -7262,9 +7288,9 @@ static int nodelib_common_setfield(lua_State *L, int direct, halfword n)
} else if (lua_key_eq(s, yoffset)) {
rule_y_offset(n) = (halfword) lmt_roundnumber(L, 3);
} else if (lua_key_eq(s, left)) {
- rule_left(n) = (halfword) lmt_roundnumber(L, 3);
+ tex_set_rule_left(n, (halfword) lmt_roundnumber(L, 3));
} else if (lua_key_eq(s, right)) {
- rule_right(n) = (halfword) lmt_roundnumber(L, 3);
+ tex_set_rule_right(n, (halfword) lmt_roundnumber(L, 3));
} else if (lua_key_eq(s, data)) {
rule_data(n) = lmt_tohalfword(L, 3);
} else if (lua_key_eq(s, font)) {
@@ -7272,7 +7298,7 @@ static int nodelib_common_setfield(lua_State *L, int direct, halfword n)
} else if (lua_key_eq(s, fam)) {
tex_set_rule_family(n, lmt_tohalfword(L, 3));
} else if (lua_key_eq(s, char)) {
- rule_character(n) = lmt_tohalfword(L, 3);
+ rule_strut_character(n) = lmt_tohalfword(L, 3);
} else {
goto CANTSET;
}
@@ -9809,6 +9835,7 @@ static const struct luaL_Reg nodelib_direct_function_list[] = {
{ "getkerndimension", nodelib_direct_getkerndimension },
{ "getlistdimensions", nodelib_direct_getlistdimensions },
{ "getruledimensions", nodelib_direct_getruledimensions },
+ { "setruledimensions", nodelib_direct_setruledimensions },
{ "patchattributes", nodelib_direct_patchattributes },
{ "remove", nodelib_direct_remove },
{ "removefromlist", nodelib_direct_remove_from_list },
diff --git a/source/luametatex/source/lua/lmtstatuslib.c b/source/luametatex/source/lua/lmtstatuslib.c
index ee785e806..2613115da 100644
--- a/source/luametatex/source/lua/lmtstatuslib.c
+++ b/source/luametatex/source/lua/lmtstatuslib.c
@@ -356,6 +356,8 @@ static int statslib_getconstants(lua_State *L)
lua_set_integer_by_key(L, "assumed_math_control", assumed_math_control);
lua_set_integer_by_key(L, "undefined_math_parameter", undefined_math_parameter);
+
+ lua_set_integer_by_key(L, "max_calculated_badness", max_calculated_badness);
return 1;
}
diff --git a/source/luametatex/source/lua/lmttexlib.c b/source/luametatex/source/lua/lmttexlib.c
index 39afd94fb..1bfd2c38c 100644
--- a/source/luametatex/source/lua/lmttexlib.c
+++ b/source/luametatex/source/lua/lmttexlib.c
@@ -2782,6 +2782,7 @@ static int texlib_aux_convert(lua_State *L, int cur_code)
case cs_active_code: /* arg token */
/* case cs_lastname_code: */ /* arg token */
case detokenized_code: /* arg token */
+ case detokened_code: /* arg cs or {} */
case meaning_code: /* arg token */
case to_mathstyle_code:
break;
@@ -5016,7 +5017,7 @@ static int texlib_getglyphoptionvalues(lua_State *L)
static int texlib_getnoadoptionvalues(lua_State *L)
{
- lua_createtable(L, 2, 36);
+ lua_createtable(L, 2, 37);
lua_push_key_at_index(L, axis, noad_option_axis);
lua_push_key_at_index(L, noaxis, noad_option_no_axis);
lua_push_key_at_index(L, exact, noad_option_exact);
@@ -5058,6 +5059,7 @@ static int texlib_getnoadoptionvalues(lua_State *L)
lua_push_key_at_index(L, center, noad_option_center);
lua_push_key_at_index(L, scale, noad_option_scale);
lua_push_key_at_index(L, keepbase, noad_option_keep_base);
+ lua_push_key_at_index(L, single, noad_option_single);
// lua_set_string_by_index(L, noad_option_keep_base, "keepbase");
return 1;
@@ -5158,7 +5160,7 @@ static int texlib_getspecialmathclassvalues(lua_State *L)
static int texlib_getmathclassoptionvalues(lua_State *L)
{
- lua_createtable(L, 2, 19);
+ lua_createtable(L, 2, 20);
lua_set_string_by_index(L, no_pre_slack_class_option, "nopreslack");
lua_set_string_by_index(L, no_post_slack_class_option, "nopostslack");
lua_set_string_by_index(L, left_top_kern_class_option, "lefttopkern");
@@ -5185,6 +5187,7 @@ static int texlib_getmathclassoptionvalues(lua_State *L)
lua_set_string_by_index(L, auto_inject_class_option, "autoinject");
lua_set_string_by_index(L, remove_italic_correction_class_option, "removeitaliccorrection");
lua_set_string_by_index(L, operator_italic_correction_class_option, "operatoritaliccorrection");
+ lua_set_string_by_index(L, short_inline_class_option, "shortinline");
return 1;
}
@@ -5209,6 +5212,7 @@ static int texlib_getnormalizeparvalues(lua_State *L)
lua_createtable(L, 2, 0);
lua_set_string_by_index(L, normalize_par_mode, "normalizepar");
lua_set_string_by_index(L, flatten_v_leaders_mode, "flattenvleaders");
+ lua_set_string_by_index(L, limit_prev_graf_mode, "limitprevgraf");
return 1;
}
@@ -5397,6 +5401,11 @@ static int texlib_getalignmentcontextvalues(lua_State *L)
return lmt_push_info_values(L, lmt_interface.alignment_context_values);
}
+static int texlib_getbreakcontextvalues(lua_State *L)
+{
+ return lmt_push_info_values(L, lmt_interface.break_context_values);
+}
+
static int texlib_getparbeginvalues(lua_State *L)
{
return lmt_push_info_values(L, lmt_interface.par_begin_values);
@@ -5481,6 +5490,18 @@ static int texlib_gettextcontrolvalues(lua_State *L)
return 1;
}
+static int texlib_getfitnessvalues(lua_State *L)
+{
+ lua_createtable(L, 5, 1);
+ lua_set_string_by_index(L, very_loose_fit, "veryloose");
+ lua_set_string_by_index(L, loose_fit, "loose");
+ lua_set_string_by_index(L, semi_loose_fit, "semiloose");
+ lua_set_string_by_index(L, decent_fit, "decent");
+ lua_set_string_by_index(L, semi_tight_fit, "semitight");
+ lua_set_string_by_index(L, tight_fit, "tight");
+ return 1;
+}
+
static int texlib_getfillvalues(lua_State *L)
{
return lmt_push_info_values(L, lmt_interface.node_fill_values);
@@ -5772,12 +5793,14 @@ static const struct luaL_Reg texlib_function_list[] = {
/* {"getmathflattenvalues", texlib_getmathflattenvalues }, */
{ "getmathcontrolvalues", texlib_getmathcontrolvalues },
{ "gettextcontrolvalues", texlib_gettextcontrolvalues },
+ { "getfitnessvalues", texlib_getfitnessvalues },
{ "getpacktypevalues", texlib_getpacktypevalues },
{ "getgroupvalues", texlib_getgroupvalues },
{ "getparcontextvalues", texlib_getparcontextvalues },
{ "getpagecontextvalues", texlib_getpagecontextvalues },
{ "getappendlinecontextvalues", texlib_getappendlinecontextvalues },
{ "getalignmentcontextvalues", texlib_getalignmentcontextvalues },
+ { "getbreakcontextvalues", texlib_getbreakcontextvalues },
{ "getparbeginvalues", texlib_getparbeginvalues },
{ "getparmodevalues", texlib_getparmodevalues },
{ "getautomigrationvalues", texlib_getautomigrationvalues },
diff --git a/source/luametatex/source/lua/lmttokenlib.c b/source/luametatex/source/lua/lmttokenlib.c
index c8f7f9039..fd3b95b0f 100644
--- a/source/luametatex/source/lua/lmttokenlib.c
+++ b/source/luametatex/source/lua/lmttokenlib.c
@@ -213,7 +213,6 @@ void lmt_tokenlib_initialize(void)
lmt_interface.command_names[convert_cmd] = (command_item) { .id = convert_cmd, .lua = lua_key_index(convert), .name = lua_key(convert), .kind = regular_command_item, .min = 0, .max = last_convert_code, .base = 0, .fixedvalue = 0 };
lmt_interface.command_names[the_cmd] = (command_item) { .id = the_cmd, .lua = lua_key_index(the), .name = lua_key(the), .kind = regular_command_item, .min = 0, .max = last_the_code, .base = 0, .fixedvalue = 0 };
lmt_interface.command_names[get_mark_cmd] = (command_item) { .id = get_mark_cmd, .lua = lua_key_index(get_mark), .name = lua_key(get_mark), .kind = regular_command_item, .min = 0, .max = last_get_mark_code, .base = 0, .fixedvalue = 0 };
- /* lmt_interface.command_names[string_cmd] = (command_item) { .id = string_cmd, .lua = lua_key_index(string), .name = lua_key(string), .kind = regular_command_item, .min = ignore_entry, .max = max_integer, .base = 0, .fixedvalue = 0 }; */
lmt_interface.command_names[call_cmd] = (command_item) { .id = call_cmd, .lua = lua_key_index(call), .name = lua_key(call), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
lmt_interface.command_names[protected_call_cmd] = (command_item) { .id = protected_call_cmd, .lua = lua_key_index(protected_call), .name = lua_key(protected_call), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
lmt_interface.command_names[semi_protected_call_cmd] = (command_item) { .id = semi_protected_call_cmd, .lua = lua_key_index(semi_protected_call), .name = lua_key(protected_call), .kind = token_command_item, .min = ignore_entry, .max = ignore_entry, .base = ignore_entry, .fixedvalue = 0 };
@@ -1431,6 +1430,54 @@ static int tokenlib_scan_tokenlist(lua_State *L)
return 1;
}
+static int tokenlib_scan_detokened(lua_State *L)
+{
+ saved_tex_scanner texstate = tokenlib_aux_save_tex_scanner();
+ int expand = lua_toboolean(L, 1);
+ halfword defref = lmt_input_state.def_ref;
+ halfword result = null;
+ int macro = 0;
+ tokenlib_aux_goto_first_candidate(); /*tex We don't expand the next token! */
+ switch (cur_cmd) {
+ case left_brace_cmd:
+ result = expand ? tex_scan_toks_expand(1, NULL, 0) : tex_scan_toks_normal(1, NULL);
+ break;
+ case call_cmd:
+ case protected_call_cmd:
+ case semi_protected_call_cmd:
+ case tolerant_call_cmd:
+ case tolerant_protected_call_cmd:
+ case tolerant_semi_protected_call_cmd:
+ result = cur_chr;
+ macro = 1;
+ break;
+ default:
+ tex_back_input(cur_tok);
+ break;
+ }
+ tokenlib_aux_unsave_tex_scanner(texstate);
+ lmt_input_state.def_ref = defref;
+ if (result) {
+ if (token_link(result)) {
+ tex_detokenize_list(token_link(result));
+ if (lmt_string_pool_state.string_temp && lmt_string_pool_state.string_temp_top) {
+ lua_pushlstring(L, (char *) lmt_string_pool_state.string_temp, lmt_string_pool_state.string_temp_top);
+ } else {
+ lua_pushliteral(L,"");
+ }
+ tex_reset_cur_string();
+ } else {
+ lua_pushliteral(L,"");
+ }
+ if (! macro) {
+ tex_flush_token_list(result);
+ }
+ } else {
+ lua_pushnil(L);
+ }
+ return 1;
+}
+
/* todo: other call_cmd */
static int tokenlib_scan_string(lua_State *L)
@@ -3630,6 +3677,7 @@ static const struct luaL_Reg tokenlib_function_list[] = {
{ "scancsname", tokenlib_scan_csname },
{ "scantoken", tokenlib_scan_token }, /* expands next token if needed */
{ "scanbox", tokenlib_scan_box },
+ { "scandetokened", tokenlib_scan_detokened },
{ "isnextchar", tokenlib_is_next_char },
/* writers */
{ "putnext", tokenlib_put_next },