[luatex] Bug in tex.linebreak ?

Hans Hagen pragma at wxs.nl
Thu Mar 10 10:30:11 CET 2016


On 3/10/2016 10:02 AM, Frank Mittelbach wrote:
> Am 10.03.16 um 09:51 schrieb Hans Hagen:
>> On 3/9/2016 8:48 PM, Frank Mittelbach wrote:
>>> I think I found a bug in tex.linebreak.
>>>
>>> Consider the following code
>>>
>>>
>>> function prelinebreak (head, groupnode)  --- for pre_linebreak_filter
>>>                                           --- for example
>>>    local n,t
>>>
>>>    n, t = tex.linebreak(node.copy_list(head), {looseness = -1})
>>>    print("looseness=" .. t.looseness)
>>>    n, t = tex.linebreak(node.copy_list(head), {looseness = 0})
>>>    print("looseness=" .. t.looseness)
>>>
>>>    return true
>>>
>>> end
>>>
>>> and pass it in head a long enough hlist so that looseness -1 actually
>>> works. The second line breaking with looseness=0 reports the previous
>>> looseness ... same happens if you have looseness=+2 or +1 or so
>>>
>>> it seems that tex.linebreak always reports the looseness of the previous
>>> linebreak action in case you pass it a "0"
>>
>> it helps if you also set some more (either explicit or at the tex
>> level), like:
>>
>>    looseness=1,
>>    tolerance=4500,
>>    pretolerance=100,
>>    emergencystretch=655360
>
> not sure I understand Hans, on the TeX they are set (once) -- are you
> saying one needs to set them as part of the params table for
> tex.linebreak as in
>
>    { looseness = 0, tolerance = tex.tolerance ....
>
> just re-providing to tex.linebreak what is already set on the TeX level?
>
> my thoughts without having seen the internal code of tex.linebreak is
> that if looseness = 0 the value that is reported at the end is actually
> never set so retains whatever the last time was put there (which is not
> making a problem while it is always 0 but shows the wrong value once you
> ever set it to non-zero and later back

\setbox0\hbox{\input tufte }
\directlua{
     local n,t,head
     head = tex.box[0].head
     n, t = tex.linebreak(node.copy_list(head), {looseness=1})
     print("1.1",t.looseness)
     n, t = tex.linebreak(node.copy_list(head), {looseness=0})
     print("1.2",t.looseness)
}
\directlua{
     local n,t,head
     head = tex.box[0].head
     n, t = tex.linebreak(node.copy_list(head), {looseness=1, 
tolerance=4500, pretolerance=100, emergencystretch=655360 })
     print("2.1",t.looseness)
     n, t = tex.linebreak(node.copy_list(head), {looseness=0, 
tolerance=4500, pretolerance=100, emergencystretch=655360 })
     print("2.2",t.looseness)
}
\tolerance4500 \pretolerance100 \emergencystretch10pt
\directlua{
     local n,t,head
     head = tex.box[0].head
     n, t = tex.linebreak(node.copy_list(head), {looseness=1})
     print("3.1",t.looseness)
     n, t = tex.linebreak(node.copy_list(head), {looseness=0})
     print("3.2",t.looseness)
}

1.1	0
1.2	0
2.1	1
2.2	1
3.1	1
3.2	1


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


More information about the luatex mailing list