values for `mode` field in tex.nest
Hi, according to the documentation, the `mode` field in `tex.nest` is explained as
a number representing the main mode at this level: 0 = no mode (this happens during \write), 1 = vertical, 127 = hor- izontal, 253 = display math, -1 = internal vertical, -127 = restricted horizontal, -253 = inline math
This looks as if these values were constant across engine versions, but the real values depend on `max_command_cmd` which changes if new commands are added. Especially the current values are `(-)132` for (restricted) horizontal mode and `(-)263` for (inline) math. So I think the documentation should be either updated to delete these outdated values and instead include a note that you have to query these values yourself or LuaTeX could normalize these values before passing them to Lua. One way to do this could be diff --git a/manual/luatex-tex.tex b/manual/luatex-tex.tex index 7edd561e6..f69906d4c 100644 --- a/manual/luatex-tex.tex +++ b/manual/luatex-tex.tex @@ -943,13 +943,13 @@ The known fields are: \DB key \BC type \BC modes \BC explanation \NC \NR \TB \NC \type{mode} \NC number \NC all \NC a number representing the main mode at this level: - \type {0} = no mode (this happens during \prm {write}), - \type {1} = vertical, - \type {127} = horizontal, - \type {253} = display math, - \type {-1} = internal vertical, - \type {-127} = restricted horizontal, - \type {-253} = inline math \NC \NR + \type {0} = no mode (this happens during \prm {write}), + \type {1} = vertical, + \type {2} = horizontal, + \type {3} = display math, + \type {-1} = internal vertical, + \type {-2} = restricted horizontal, + \type {-3} = inline math \NC \NR \NC \type{modeline} \NC number \NC all \NC source input line where this mode was entered in, negative inside the output routine \NC \NR \NC \type{head} \NC node \NC all \NC the head of the current list \NC \NR diff --git a/source/texk/web2c/luatexdir/lua/ltexlib.c b/source/texk/web2c/luatexdir/lua/ltexlib.c index c3e459b22..c71492644 100644 --- a/source/texk/web2c/luatexdir/lua/ltexlib.c +++ b/source/texk/web2c/luatexdir/lua/ltexlib.c @@ -2355,7 +2355,10 @@ static int lua_nest_getfield(lua_State * L) const char *field = lua_tostring(L, -1); r = *rv; if (lua_key_eq(field,mode)) { - lua_pushinteger(L, r->mode_field); + int mode = r->mode_field; + lua_pushinteger(L, + mode == 0 ? 0 : (mode + max_command_cmd * ((mode > 0) * 2 - 1)) / + (max_command_cmd + 1)); } else if (lua_key_eq(field,head)) { lua_nodelib_push_fast(L, r->head_field); } else if (lua_key_eq(field,tail)) { @@ -2396,7 +2399,8 @@ static int lua_nest_setfield(lua_State * L) r = *rv; if (lua_key_eq(field,mode)) { i = lua_tointeger(L, -1); - r->mode_field = i; + r->mode_field = i == 0 ? 0 : + (max_command_cmd + 1) * i + max_command_cmd * ((i < 0) * 2 - 1); } else if (lua_key_eq(field,head)) { n = check_isnode(L, -1); r->head_field = *n; Best regards Marcel Krüger
participants (1)
-
Marcel Krüger