# [luatex] Creating a token list

Henri Menke henrimenke at gmail.com
Thu Mar 7 04:47:20 CET 2019


On 7/03/19 3:22 AM, Javier Bezos wrote:
>> I have no idea what you mean.  Your description is very unclear.
>
> 1) What I want is to create a whatsit node with
> subtype write. The code to be written is, say,
> \string\doit{\the\lastypos}. This subtype has a
> field named data, with a table representing the
> token list to be written. So, I write:
>
> local n = node.new(8, 1)
> n.stream = 1
> n.data =       -- ???
>
> My original question was how to generate in lua
> the token list to feed the data field (ie, ???)

Still not sure whether I understand the question...

local n = node.new(8, 1)
n.stream = 1
tex.scantoks(0, 0, "\the\lastxpos")
n.data = tex.toks[0]

>
> 2) I've managed to do it by the procedure I explained
> in my second message, like this:
>
> \setbox0\hbox{\write1{\the\lastxpos}}
>
> \directlua{
>
>    for _,d in ipairs(tex.box[0].head.data) do
>      texio.write(' ** ' .. d[1] .. '/' .. d[2] .. '/' .. d[3])
>    end
>
> }
>
> Well, instead of printing it I pass it to n.data and
> primitives work as expected (user defined macros fail,
> but this is a minor problem because adding them as a
> list of chars when the data table is built is easy).
>
> But this looks much like a hack.
>
> Javier
>
>