[luatex] Turning a string into a list of nodes.

Paul Isambert zappathustra at free.fr
Fri Nov 19 10:51:07 CET 2010

Le 19/11/2010 10:33, Taco Hoekwater a écrit :
>  On 11/18/2010 09:52 PM, Paul Isambert wrote:
>>  Hello all,
>>  I've been trying to devise a Lua function which, when fed a string,
>>  returns a
>>  list of nodes. The application I have in mind is line numbering,
>>  counting lines
>>  in the post_linebreak_filter and adding an \hbox with the number to
>>  lines that
>>  are a multiple of a given number. Everything should be done in Lua,
>>  and thus the
>>  counter must be converted to a list of nodes. I.e. the following
>>  should be
>>  possible:
>>  mylist = string_tolist(tostring(linecounter))
>  This case is fairly straightforward, you could even prepare the 10
>  needed nodes in advance and then use node.copy() to chain them.
>>  And here come the questions: Have I missed a definitely simpler way
>>  to do what I
>>  want?
>  No, there is not. The simple reason for that is that it is an
>  exceedingly tricky function to write in the general case: the
>  luatex main control function has numerous side-effects and global
>  state variables at the moment, making it unsuitable for general use
>  on 'tex input', while on the other hand it seemed a shame to write a
>  'copy' of main control just for this.

So ignore my previous message. I'd thought it might be quite tricky indeed.

>  The 'pure ascii input' is simple enough to do in pure lua, as seen from
>  your own code and Patrick's.
>>     for item in node.traverse(head) do
>>       if item.next then
>>         -- If the second argument isn't there, LuaTeX crashes.
>>         node.kerning(item, item.next)
>>       end
>>     end
>  This is overdoing it, there is no need for a loop here. In fact,
>  the reason for it crashing in the lacking .next case is probably
>  because the list is getting modified inside of the loop.
>  You should be able to simply run
>     node.kerning(head)

Yes, the manual is quite clear, but for some reason I'd understood that
the function applied to its argument only instead of the entire nodelist.


More information about the luatex mailing list