[luatex] reverse node lists

Arno Trautmann Arno.Trautmann at gmx.de
Tue Nov 1 10:03:10 CET 2011

Hi Patrick,

thanks for your answer!

Patrick Gundlach wrote:
>> this is again a rather simple question and I am sorry for taking your time for this …
>> In short, I want to reverse all glyph nodes in a line, and/or all lines in a paragraph. I tried something like the following (with the idea to store all lines in a list, then replace the lines with the list in reversed order):
>> function reverse(head)
>> newlines = {}
>> i = 1
>>   for line in node.traverse_id(node.id"hhead",head) do
>>     newlines[i] = line
> a lua idiom is newlines[#newlines + 1] = ... - easer to read to the average Lua hackr.

Oh, of course … I fear I'll never get used to this Lua style …

>>     i = i+1
>>   end
>> j = #newlines
>>   for line in node.traverse_id(node.id"hhead",head) do
>>     node.insert_before(head,line,newlines[j])
>>     j = j-1
>>   end
>>   return head
>> end
> I have to admit that I don't understand exactly what is going on here.

Me neither ;)

> I never use the node.insert_* functions as they are some black magic to me, I always change next/prev pointsers manually, so I have the feeling of what I have to do.

But shouldn't the node.insert_* just do the same?

> Therefore my brain just blocks when I try to analyze your code. Sorry. If you want a manual solution, see the following code.

I'm happy with anything that works and that I understand. However, 
that's a lot of code for such a (seemingly) simple task … I'll try to 
understand your code and do an implementation on my own to learn it. 
(Also, I want to separate the line reversing and glyph-per-line-reversing)

Thank you very much,


p.s.: as I'm already writing about silly manipulations, I have two more 
“useless” questions:
• I want to rotate a page after it has been completed. Could anyone give 
me a hint where to start for this? (callbacks, how to rotate a box? …)
• I'd like to rotate single glyphs by an arbitrary angle. Is this 
possible with Lua code, after line breaking? Or would I have to create a 
new font for that?

More information about the luatex mailing list