From 0d725f6894b288e1fbe5fe2fa356e2c429c52172 Mon Sep 17 00:00:00 2001 From: Hironori Kitagawa Date: Wed, 8 Feb 2023 14:52:21 +0900 Subject: [PATCH] unbox: use \expandafter\the... (ticket 47321) --- src/ltj-direction.lua | 38 ++++++++++++++++++++++++++++++++++++-- src/luatexja-core.sty | 28 ++++++++++++++++------------ 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/ltj-direction.lua b/src/ltj-direction.lua index 5321f23..0fbe0c6 100644 --- a/src/ltj-direction.lua +++ b/src/ltj-direction.lua @@ -550,7 +550,41 @@ do local ltj_tempcnta = luatexbase.registernumber 'ltj@tempcnta' local getbox = tex.getbox local dir_backup - function luatexja.direction.unbox_check_dir(is_copy) + function luatexja.direction.unbox_check_dir() + start_time_measure 'box_primitive_hook' + local list_dir = get_dir_count()%dir_math_mod + local b = getbox(getcount(ltj_tempcnta)) + if b and getlist(to_direct(b)) then + local box_dir = get_box_dir(to_direct(b), dir_yoko) + if box_dir%dir_math_mod ~= list_dir then + ltjb.package_error( + 'luatexja', + "Incompatible direction list can't be unboxed", + 'I refuse to unbox a box in differrent direction.') + tex.sprint(cat_lp, '\\@gobbletwo') + else + dir_backup = nil + local bd = to_direct(b) + local hd = getlist(bd) + local nh = hd + while hd do + if getid(hd)==id_whatsit and getsubtype(hd)==sid_user + and getfield(hd, 'user_id')==DIR then + local d = hd + nh, hd = node_remove(nh, hd); node_free(d) + else + hd = node_next(hd) + end + end + setlist(bd, nh) + end + end + if luatexja.global_temp and tex.globaldefs~=luatexja.global_temp then + tex.globaldefs = luatexja.global_temp + end + stop_time_measure 'box_primitive_hook' + end + function luatexja.direction.uncopy_check_dir() start_time_measure 'box_primitive_hook' local list_dir = get_dir_count()%dir_math_mod local b = getbox(getcount(ltj_tempcnta)) @@ -572,7 +606,7 @@ do and getfield(hd, 'user_id')==DIR then local d = hd nh, hd = node_remove(nh, hd) - if is_copy==true and (not dir_backup) then + if not dir_backup then dir_backup = d; setnext(dir_backup, nil) else node_free(d) diff --git a/src/luatexja-core.sty b/src/luatexja-core.sty index 70cec4c..cfe9b79 100644 --- a/src/luatexja-core.sty +++ b/src/luatexja-core.sty @@ -715,30 +715,34 @@ %%%% \unhbox and \unvbox \newluafunction\ltj@@lua@unboxcheckdir@inner +\newluafunction\ltj@@lua@uncopycheckdir@inner +\newluafunction\ltj@@lua@uncopy@restore@whatsit@inner \directlua{ local t = lua.get_functions_table() t[\the\ltj@@lua@unboxcheckdir@inner]=luatexja.direction.unbox_check_dir + t[\the\ltj@@lua@uncopycheckdir@inner]=luatexja.direction.uncopy_check_dir + t[\the\ltj@@lua@uncopy@restore@whatsit@inner]=luatexja.direction.uncopy_restore_whatsit } \luadef\ltj@@lua@unboxcheckdir\ltj@@lua@unboxcheckdir@inner +\luadef\ltj@@lua@uncopycheckdir\ltj@@lua@uncopycheckdir@inner +\luadef\ltj@@lua@uncopy@restore@whatsit\ltj@@lua@uncopy@restore@whatsit@inner \long\def \@gobbletwo #1#2{} \let\ltj@@orig@unhbox\unhbox \let\ltj@@orig@unvbox\unvbox -\protected\def\ltj@@unhbox{\begingroup\ltj@reset@globaldefs\afterassignment\ltj@@unhbox@\ltj@tempcnta} -\protected\def\ltj@@unvbox{\begingroup\ltj@reset@globaldefs\afterassignment\ltj@@unvbox@\ltj@tempcnta} -\protected\def\ltj@@unhbox@{\ltj@@lua@unboxcheckdir\ltj@@orig@unhbox\ltj@tempcnta\endgroup} -\protected\def\ltj@@unvbox@{\ltj@@lua@unboxcheckdir\ltj@@orig@unvbox\ltj@tempcnta\endgroup} +\protected\def\ltj@@unhbox{\ltj@reset@globaldefs\afterassignment\ltj@@unhbox@\ltj@tempcnta} +\protected\def\ltj@@unvbox{\ltj@reset@globaldefs\afterassignment\ltj@@unvbox@\ltj@tempcnta} +\protected\def\ltj@@unhbox@{\ltj@@lua@unboxcheckdir\expandafter\ltj@@orig@unhbox\the\ltj@tempcnta\relax} +\protected\def\ltj@@unvbox@{\ltj@@lua@unboxcheckdir\expandafter\ltj@@orig@unvbox\the\ltj@tempcnta\relax} \let\ltj@@orig@unhcopy\unhcopy \let\ltj@@orig@unvcopy\unvcopy -\protected\def\ltj@@unhcopy{\begingroup\ltj@reset@globaldefs\afterassignment\ltj@@unhcopy@\ltj@tempcnta} -\protected\def\ltj@@unvcopy{\begingroup\ltj@reset@globaldefs\afterassignment\ltj@@unvcopy@\ltj@tempcnta} +\protected\def\ltj@@unhcopy{\ltj@reset@globaldefs\afterassignment\ltj@@unhcopy@\ltj@tempcnta} +\protected\def\ltj@@unvcopy{\ltj@reset@globaldefs\afterassignment\ltj@@unvcopy@\ltj@tempcnta} \protected\def\ltj@@unhcopy@{% - \directlua{luatexja.direction.unbox_check_dir(true)}% - \ltj@@orig@unhcopy\ltj@tempcnta - \directlua{luatexja.direction.uncopy_restore_whatsit()}\endgroup} + \ltj@@lua@uncopycheckdir\expandafter\ltj@@orig@unhcopy\the\ltj@tempcnta\relax + \ltj@@lua@uncopy@restore@whatsit}% \protected\def\ltj@@unvcopy@{% - \directlua{luatexja.direction.unbox_check_dir(true)}% - \ltj@@orig@unvcopy\ltj@tempcnta - \directlua{luatexja.direction.uncopy_restore_whatsit()}\endgroup} + \ltj@@lua@uncopycheckdir\expandafter\ltj@@orig@unvcopy\the\ltj@tempcnta\relax + \ltj@@lua@uncopy@restore@whatsit}% \let\unhbox\ltj@@unhbox %% PRIMITIVE \let\unvbox\ltj@@unvbox %% PRIMITIVE \let\unhcopy\ltj@@unhcopy %% PRIMITIVE -- 2.11.0