[NTG-context] upload

Hans Hagen j.hagen at freedom.nl
Thu Jul 7 10:27:29 CEST 2022


On 7/7/2022 3:15 AM, Max Chernoff via ntg-context wrote:
> Hi,
> 
> With the latest upload, "tex.linebreak" doesn't return an "info" table.
> 
> When running this code:
> 
>      \startluacode
>          function test(head)
>              local new_head, info = tex.linebreak(node.copylist(head))
> 
>              print(head, type(head), info, type(info))
> 
>              if info == nil then
>                  print "!!! info is nil !!!"
>              end
> 
>              return head
>          end
> 
>          nodes.tasks.appendaction("processors", "after", "test")
>      \stopluacode
> 
>      \starttext
>          Hello!
>      \stoptext
> 
> with the latest upload I get (also note the small typo in "rigthfill"):
> 
>      luatex warning  > linebreak: no [ leftinit | rightinit | leftfill | 
> rigthfill] expected
>      <node :    nil <=   2265 =>   2353 : par vmodepar>      
> userdata        nil     nil
>      !!! info is nil !!!
>      <node :    nil <=   2475 =>   2299 : glue userskip>     
> userdata        nil     nil
>      !!! info is nil !!!
> 
> but with live.contextgarden.net I get:
> 
>      luatex warning  > tex: left parfill skip is gone
>      Underfull \hbox (badness 10000) in paragraph at lines 20--1
>      <node :    nil <=    936 =>    929 : par vmode_par>    userdata    
> table: 0x39a050f7000    table
>      <node :    nil <=   1529 =>   1561 : glue userskip>    userdata    
> nil    nil
>      !!! info is nil !!!

This is because you need to pass a list that conforms to what the 
builder expects and the callback that you use doesn't do that for you 
(after all, it also gets hbox content).

There is no 'callback sequence handler' for the par builder (currently i 
see no need for it, also given the extra overhead involved) but this 
what what you can do:

\startluacode
     function builders.paragraphs.constructors.methods.preroll_a(head)
         local result, info = tex.linebreak(head)
         tex.prevdepth = info.prevdepth
         tex.prevgraf = info.prevgraf
         return result
     end
     function builders.paragraphs.constructors.methods.preroll_b(head)
         local result, info = tex.linebreak(nodes.nuts.copylist(head))
         inspect(info)
         return true
     end
\stopluacode

\defineparbuilder[preroll_a]
\defineparbuilder[preroll_b]

\starttext
     \setmainparbuilder[default]   \input tufte \par \input tufte \page
     \setmainparbuilder[preroll_a] \input tufte \par \input tufte \page
     \setmainparbuilder[preroll_b] \input tufte \par \input tufte \page
\stoptext

The tex.linebreak function gets the properly prepared paragraph and can 
handle it then. On the to do is a to add a 'prepare' helper that adds 
the mandate nodes (par fillers etc) but even then one has to be careful 
where linebreak hackery is applied.

Hans




-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the ntg-context mailing list