\leavevmode together with \everypar{\strut} causes \strutbox to have zero dimensions
By accident I posted the TeX trace when using a patched version of \unhcopy which used \ltj@tempcntb. In truth the real TeX trace ends like this
- \unhcopy ->\ltj@reset@globaldefs \afterassignment \ltj@@unhcopy \ltj@tempcnta
- \ltj@reset@globaldefs ->\luafunction \ltj@reset@globaldefs@inner
- \ltj@@unhcopy ->\directlua {luatexja.direction.unbox_check_dir(true)}\ltj@@orig
- @unhcopy \ltj@tempcnta \directlua {luatexja.direction.uncopy_restore_whatsit()}
i.e. it uses \ltj@tempcnta which originates the issue.
It was bit mind-boggling to me that \ltj@tempcnta value would change between start and end of \unhbox \ltj@tempcnta but this is what happens in the above indeed: \unhcopy reassigns \ltj@tempcnta before it has been used by the \unhbox original TeX primitive...
Thanks for the report. This is mind-boggling to me, too...
a patched version of \unhcopy which used \ltj@tempcntb
I come up with another approach: guarding LuaTeX-ja's \unhcopy by \begingroup...\endgroup (similar guards with \unvcopy, \unhbox, \unvbox).
- \let\ltj@@orig@unhcopy\unhcopy
- \protected\def\ltj@@unhcopy{\begingroup\ltj@reset@globaldefs\afterassignment\ltj@@unhcopy@\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}
This makes an assignment to \ltj@tempcnta by \unhcopy:
- \ltj@@unhbox@ ->\ltj@@lua@unboxcheckdir \ltj@@orig@unhbox \ltj@tempcnta \endgro
- up
- {expandable luacall 51}
- {\unhbox} % <== "\unhbox \voidb@x" (\leavevmode) in vmode
- % ... start a paragraph and re-read this command
- ...
- \strut ->\protect \strut
- ...
- \unhcopy ->\begingroup \ltj@reset@globaldefs \afterassignment \ltj@@unhcopy@ \l
- tj@tempcnta
- {\begingroup}
- {reassigning \nolocalwhatsits=0}
- {reassigning \nolocaldirs=0}
- {luacall 32}
- {reassigning \globaldefs=0}
- {\afterassignment}
- {\count187}
- {changing \count187=10}
- {into \count187=11}
- \ltj@@unhcopy@ ->\directlua {luatexja.direction.unbox_check_dir(true)}\ltj@@ori
- g@unhcopy \ltj@tempcnta \directlua {luatexja.direction.uncopy_restore_whatsit()
- }\endgroup
- {\directlua}
- {\unhcopy}
- {\directlua}
- {\endgroup}
- {restoring \count187=10}
- ...
- {\unhbox} % <== "\unhbox \voidb@x" (\leavevmode) in hmode
Répondre à h7k
Thanks for the report. This is mind-boggling to me, too...
a patched version of \unhcopy which used \ltj@tempcntb
I come up with another approach: guarding LuaTeX-ja's \unhcopy by \begingroup...\endgroup (similar guards with \unvcopy, \unhbox, \unvbox).
I think the scope limiting approach via groups is fine (in theory it has a limitation to 255 levels of nesting if I remember correctly from TeX, I do not know LuaTeX, anyway this is not a truly limiting factor in practice). At any rate, my patch with \ltj@tempcntb was only for me to confirm I had understood the issue, but it is definitely not a robust fix, for example \unhbox can be used in the \everypar too, not only \unhcopy. Your groups if I understand correctly do fix such a situation too of nested usage, that's the whole point.
I had thought of still another approach like this, via some \expandafter.
Other things should probably be modified in this spirit for example
and perhaps similar changes to \unvbox/\unvcopy. After all, \everypar tokens may cause many things to happen.
As I don't know the LuaTeX-ja code base I do not know if the \begingroup/\endgroup may have any side effect but I am quite confident that the above will not have any.
I wanted to show a trace (where I had only patched ltj@unhbox@) but to show what happens I had to replace \ltj@@orig@unhbox with one more layer picking up the digits tokens until \relax to fetch them to the primitive \unhbox
- \leavevmode ->\unhbox \voidb@x
- \unhbox ->\ltj@reset@globaldefs \afterassignment \ltj@@unhbox@ \ltj@tempcnta
- {luacall 32}
- {\afterassignment}
- {\count187}
- \ltj@@unhbox@ ->\ltj@@lua@unboxcheckdir \expandafter \debug@unhbox \the \ltj@te
- mpcnta \relax
- \debug@unhbox #1\relax ->\ltj@@orig@unhbox #1\relax
- #1<-10
- {\unhbox}
(I used
)
Répondre à jfbu
Répondre à h7k
Thanks for the report. This is mind-boggling to me, too...
a patched version of \unhcopy which used \ltj@tempcntb
I come up with another approach: guarding LuaTeX-ja's \unhcopy by \begingroup...\endgroup (similar guards with \unvcopy, \unhbox, \unvbox).
>...
I had thought of still another approach like this, via some \expandafter. {{{ code latex \protected\def\ltj@@unhbox@{\ltj@@lua@unboxcheckdir\expandafter\ltj@@orig@unhbox\the\ltj@tempcnta\relax} }}}
A variant is to insert a space token rather than a \relax I am not sure which is more efficient, but anyhow the \expandafter is probably the costlier bit.
To use a space token as delimiter of the explicit digit tokens one can do:
or alternatively with an \edef and some \unexpanded.
jfbu への返信
I had thought of still another approach like this, via some \expandafter. {{{ code latex \protected\def\ltj@@unhbox@{\ltj@@lua@unboxcheckdir\expandafter\ltj@@orig@unhbox\the\ltj@tempcnta\relax} }}}
A variant is to insert a space token rather than a \relax I am not sure which is more efficient, but anyhow the \expandafter is probably the costlier bit.
Thanks. It seems that your \expandafter...\the\ltj@tempcnta\relax approach is slightly faster than \expandafter...\the\ltj@tempcnta(space token) and \begingroup...\endgroup approaches.
I'll adopt \expandafter...\the\ltj@tempcnta\relax approach to other commands in few days.
This issue is fixed in 20230211.0, so I close this ticket.
Regards, Jean-François B. (jfbu)
Details:
Additional remarks:
File demonstrating the issue