gucci-on-fleek / lua-widow-control

(Lua)TeX package to automatically remove widows and orphans from any document
15 stars 1 forks source link

ConTeXt crashes when description is used in the document #45

Closed hason closed 1 month ago

hason commented 6 months ago

Issue

lua-widow-control cannot work properly with a ConTeXt document that contains description - https://wiki.contextgarden.net/Description.

Expected Behavior

Reproduction

\usemodule[lua-widow-control]

\setuppapersize[A6]

\definedescription[concept]

\startdocument
\input knuth

\startconcept{Concept}
  \input knuth
\stopconcept
\stopdocument

Log File

resolvers       | formats | executing runner 'run luametatex format': /usr/share/tex/texmf-linuxmusl/bin/luametatex --jobname="./test.tex" --socket --shell-escape --fmt=/usr/share/tex/texmf-cache/luametatex-cache/context/5fe67e0bfe781ce0dde776fb1556f32e/formats/luametatex/cont-en.fmt --lua=/usr/share/tex/texmf-cache/luametatex-cache/context/5fe67e0bfe781ce0dde776fb1556f32e/formats/luametatex/cont-en.lui  --c:currentrun=1 --c:fulljobname="./test.tex" --c:input="./test.tex" --c:kindofrun=1 --c:maxnofruns=9 --c:texmfbinpath="/usr/share/tex/texmf/bin"
system          > 
system          > ConTeXt  ver: 2023.09.26 18:19 LMTX  fmt: 2023.12.18  int: english/english
system          > 
system          > 'cont-new.mkxl' loaded
open source     > level 1, order 1, name '/usr/share/tex/texmf-context/tex/context/base/mkxl/cont-new.mkxl'
system          > beware: some patches loaded from cont-new.mkiv
close source    > level 1, order 1, name '/usr/share/tex/texmf-context/tex/context/base/mkxl/cont-new.mkxl'
system          > files > jobname './test', input './test.tex', result './test'
fonts           > latin modern fonts are not preloaded
languages       > language 'en' is active
open source     > level 1, order 2, name './test.tex'
modules         > 'lua-widow-control' is loaded
open source     > level 2, order 3, name '/usr/share/tex/texmf-modules/tex/context/third/lua-widow-control/t-lua-widow-control.mkxl'
system          > callbacks > not registering frozen 'pre_output_filter'
resolvers       > lua > loading file '/usr/share/tex/texmf-modules/tex/luatex/lua-widow-control/lua-widow-control.lua' succeeded
close source    > level 2, order 3, name '/usr/share/tex/texmf-modules/tex/context/third/lua-widow-control/t-lua-widow-control.mkxl'
fonts           > preloading latin modern fonts (second stage)
fonts           > 'fallback modern rm 12pt' is loaded
open source     > level 2, order 4, name 'knuth.tex'
system          > callbacks > not registering frozen 'hpack_quality'
pack quality    > underfull hbox at line 1 - 5 in file 'knuth.tex': the designer of a new system must (badness 1521)
pack quality    > underfull hbox at line 1 - 5 in file 'knuth.tex': not only be the implementer and (badness 5490)
pack quality    > underfull hbox at line 1 - 5 in file 'knuth.tex': first large[[--]]scale user; the designer (badness 5022)
pack quality    > underfull hbox at line 1 - 5 in file 'knuth.tex': ual.  (badness 3138)
system          > callbacks > not registering frozen 'hpack_quality'
system          > callbacks > not registering frozen 'hpack_quality'
pack quality    > overfull hbox at line 6 - 11 in file 'knuth.tex': ponents would have hurt T[E]X significantly. (1.90387pt)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': The separation of any of these four (badness 1057)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': components would have hurt T[E]X (badness 7168)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': significantly. If I had not partic- (badness 2478)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': ipated fully in all these activities, (badness 4303)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': literally hundreds of improvements (badness 10000)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': would never have been made, be- (badness 4156)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': cause I would never have thought (badness 4254)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': The separation of any of these four (badness 1057)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': components would have hurt T[E]X (badness 7168)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': significantly. If I had not partic- (badness 2478)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': ipated fully in all these activities, (badness 4303)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': literally hundreds of improvements (badness 10000)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': would never have been made, be- (badness 4156)
pack quality    > underfull hbox at line 6 - 11 in file 'knuth.tex': cause I would never have thought (badness 4254)
system          > callbacks > not registering frozen 'hpack_quality'
pack quality    > overfull hbox at line 6 - 11 in file 'knuth.tex': ponents would have hurt T[E]X significantly. (1.90387pt)
close source    > level 2, order 4, name 'knuth.tex'
system          > callbacks > not registering frozen 'hpack_quality'
pack quality    > underfull hbox at line 9 in file './test.tex': But a system cannot be success- (badness 6910)
pack quality    > underfull hbox at line 9 in file './test.tex': ful if it is too strongly influenced (badness 3209)
pack quality    > underfull hbox at line 9 in file './test.tex': by a single person. Once the ini- (badness 1490)
pack quality    > underfull hbox at line 9 in file './test.tex': tial design is complete and fairly (badness 6173)
pack quality    > underfull hbox at line 9 in file './test.tex': robust, the real test begins as (badness 10000)
pack quality    > underfull hbox at line 9 in file './test.tex': people with many different view- (badness 10000)
pack quality    > underfull hbox at line 9 in file './test.tex': points undertake their own experi- (badness 4739)
pack quality    > underfull hbox at line 9 in file './test.tex': begins as people with many differ- (badness 2818)
pack quality    > underfull hbox at line 9 in file './test.tex': ent viewpoints undertake their own (badness 3029)
system          > callbacks > not registering frozen 'hpack_quality'
system          > callbacks > not registering frozen 'hpack_quality'
luatex warning  > linebreak: [ leftinit | rightinit | leftfill | rigthfill ] expected
luatex warning  > linebreak: [ leftinit | rightinit | leftfill | rigthfill ] expected
lua error       > lua error on line 10 in file ./test.tex:

callback error: ...dules/tex/luatex/lua-widow-control/lua-widow-control.lua:570: attempt to index a nil value (global 'long_info')
stack traceback:
        ...dules/tex/luatex/lua-widow-control/lua-widow-control.lua:570: in upvalue 'lwc_save_paragraphs'
        [string "local tonut  = nodes.tonut..."]:27: in function <[string "local tonut  = nodes.tonut..."]:12>
        (...tail calls...)
 1     \usemodule[lua-widow-control]
 2     
 3     \setuppapersize[A6]
 4     
 5     \definedescription[concept]
 6     
 7     \startdocument
 8     \input knuth
 9     
10 >>  \startconcept{Concept}
11       \input knuth
12     \stopconcept
13     \stopdocument
mtx-context     | fatal error: return code: 1

Format

ConTeXt MKXL

Distribution

ConTeXt

Distribution Version

ConTeXt ver: 2023.09.26 18:19 LMTX fmt: 2023.12.18 int: english/english

Lua-widow-control Version

3.0.0

Other Relevant Packages and Versions

No response

Other

No response

conradolandia commented 3 months ago

I also report a similar result when the document contains makeup. Using LWC 3.0.1 in ConTeXt LMTX 2024.03.05 11:26

callback error: ...texmf/tex/luatex/lua-widow-control/lua-widow-control.lua:160: attempt to call a nil value (upvalue 'copy')
stack traceback:
        ...texmf/tex/luatex/lua-widow-control/lua-widow-control.lua:160: in upvalue 'lwc_save_paragraphs'
        [string "local tonut  = nodes.tonut..."]:30: in function <[string "local tonut  = nodes.tonut..."]:13>
        (...tail calls...)
 1     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PORTADILLA
 2     \startmakeup[antetitulo]
 3       \start\bf\raggedleft\dontleavehmode\switchtobodyfont[14pt]\getvariable{document}{titulouno}\space\getvariable{document}{titulodos}\stop
 4 >>  \stopmakeup
gucci-on-fleek commented 3 months ago

(sorry for the delay in replying)

Lua-widow-control has unfortunately been completely broken with LMTX since mid-June. So even if you don't use descriptions/makeup and ConTeXt doesn't crash, lua-widow-control isn't actually doing anything.

Fixing this is pretty high on my todo list since the the manual requires LMTX to compile: https://github.com/gucci-on-fleek/lua-widow-control/blob/49fb91b634338af0b5842cff11129dff5bc4340c/docs/manual/lwc-manual.tex#L6-L9 (that's why version 3.0.1 still contains the 3.0.0 manual)

When I wrote the first version of lua-widow-control, LuaMetaTeX was still closed-source, so I had to guess at lots of the interfaces. But the engine is now open source, and it looks like there are some new hooks, so I'm hoping that this is relatively easy to fix.

conradolandia commented 3 months ago

I remembered something I did read a little while ago about a new mechanism (vz, analog to hz): https://mailman.ntg.nl/archives/list/ntg-context@ntg.nl/message/RYEL5O2KSNWJQXTCMHLFSFF6F5YUVAMS/

Maybe worth it checking it out...

gucci-on-fleek commented 1 month ago

(Sorry for the delay, again)

The issue here was that ConTeXt combines the hpack_filter and pre_linebreak_filter callbacks, so to distinguish between being triggered by an \hbox or by a paragraph, lua-widow-control checks to see if the first node is a “paragraph” node. However, ConTeXt LMTX uses the new “localboxes” mechanism to typeset the description title, but for whatever reason, localboxes are internally encoded as paragraph nodes, so lua-widow-control thought that it was given a paragraph and got confused.

The manual hints at this exact issue:

Local boxes are stored in an initial par node with an adequate subtype but users won't notice this (unless they mess around in Lua).

and the fix was pretty simple:

https://github.com/gucci-on-fleek/lua-widow-control/blob/783905600561e88b65297802516929fb293f6a31/source/lua-widow-control.lua#L567-L570

The other issue was that ConTeXt registered+froze some of the callbacks that lua-widow-control used, so when lua-widow-control tried hook into them, it was unable to, rendering the entire package non-functional. The fix for this was pretty short (73445ca0), but figuring out the correct details was a little tricky.

Anyways, everything should hopefully be fixed now. The builder that generates the .tds.zip and CTAN files is currently broken, so if you want to test this, you'll need to manually copy both source/lua-widow-control.lua and source/t-lua-widow-control.mkxl to either the same folder as your .tex document, or somewhere convenient in one of your texmf trees.

Let me know if you find any other issues, and thanks for the bug report!