[luatex] \latelua

Hans Hagen pragma at wxs.nl
Sun Jul 13 11:52:07 CEST 2014


On 7/13/2014 11:21 AM, David Carlisle wrote:
> On 13 July 2014 10:10, Hans Hagen <pragma at wxs.nl> wrote:
>> On 7/13/2014 10:01 AM, Joseph Wright wrote:
>>>
>>> Hello all,
>>>
>>> I'm trying to understand exactly what \latelua does. I was mainly trying
>>> to follow the expansion behaviour, cf. \directlua, but that at least
>>> seems clear. However, I'm not really sure where the code gets executed.
>>> With the example
>>>
>>>       First
>>>       \directlua{tex.print("direct")}%
>>>       \latelua{tex.print("late")}%
>>>       \par\vfill\penalty-10000 %
>>>       Second
>>>       \directlua{tex.print("direct")}%
>>>       \bye
>>>
>>> the text "late" is inserted into the second page after "Second" but
>>> before "direct", while if I omit the \directlua call on page two "late"
>>> vanishes entirely. The manual does not give a lot away: is there a good
>>> explanation/set of demos somewhere?
>>
>>
>> think of it as \special ... delayed code till shipout (so the latelua gets
>> executes as part of the conversion to pdf or dvi) ... where \directlua
>> happens in the input (no node created unless the lua code does it) a
>> \latelua creates a node
>>
>> in your case, you print, during shipout, something to the input which is why
>> it ends up on the next page (and as there can be left over stuff, it ends up
>> after there)
>>
>> Hans
>
>
>
> Hans, that explains why in Joseph's case the "late" appears after
> "Second" (it's like tokens a that are inserted \aftergroup out of the
> output routine and appear at the point where "Tex exercises the page
> breaker") but it doesn't explain why "late" doesn't appear at all in
>
>     \directlua{tex.print("direct")}%
>      \latelua{tex.print("late")}%
>      \par\vfill\penalty-10000 %
>      Second
> %    \directlua{tex.print("direct")}%
>      \bye
>
> why isn't it inserted into the stream as the first page is shipped
> out, and then appear after "Second"

Because tex.print is disabled in \latelua (we do have pdf.print) the 
printed stuff ends up on the lua 'output stack' and is therefore flushed 
with the next \directlua; one could hook some dummy 
\directlua{tex.print("")} into the output routine to do the flushing. 
It's anyway messy to push stuff back this way (also in macros) so a bit 
of deliberate control doesn't hurt.

This part of luatex is rather old code and a bit complex as there are 
more input states and it will be redone partially as part of the new 
token library that will become available end of year. Then we might also 
get rid of some other ugly bits and pieces like write18 for which one 
could use os.execute, so maybe in the future we could provide some flag 
that influences behaviour.

Hans

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



More information about the luatex mailing list