[luatex] inserting

Paul Isambert zappathustra at free.fr
Sun Jun 26 07:53:59 CEST 2011

Le 25/06/2011 21:20, Arno Trautmann a écrit :
> Hi all,
> I'm becoming desparate and I guess it's only a small error I'm making. I
> try to (please don't ask why …) to colorize all letters in a document. I
> do so by registering the following function in the post_linebreak_filter:
> local color_push = node.new(WHAT,COL)
> local color_pop = node.new(WHAT,COL)
> color_push.cmd = 1
> color_pop.cmd = 2
> uppercasecolor = function (head)
>    for line in node.traverse_id(HLIST,head) do
>      for letter in node.traverse_id(GLYPH,line.head) do
>          color_push.data = math.random().." .5 .5 rg"
>          node.insert_before(line.head,letter,node.copy(color_push))
>          node.insert_after(line.head,letter,node.copy(color_pop))
>      end
>    end
>    return head
> end
> This works fine /except/ for the first letter of every line except the
> first line. So the first line is fine, but for every following line in a
> paragraph, the first letter is not colored.

As already remarked by Khaled, you have to do:
line.head = node.insert_before...
The thing is the node is inserted, but the head field of the hlist still 
points to the old head, so the new head is ignored.

>   I also get warnings
> LuaTeX warning: pop empty color page stack 0
> so it seems that the color_push does not work in that cases?

It is simply ignored, so the color stack is still empty when the first 
pop occurs.

>   But I don't
> see what I'm doing wrong …
> To understand what mistake I'm making, I tried to use
> letter = node.first_glyph(line) [or line.head?]
> instead of the for loop, but then letter doesn't seem to be a node at all.

That should be node.first_glyph(line.head) (otherwise you browse over 
the list of nodes of which the line is part, not the list of nodes which 
is the contents of the line). But anyway node.first_glyph only finds 
glyph nodes (id 37) with subtype 1 (real glyphs). It's not quite clear 
to me what's the difference between a glyph-character (subtype 0) and a 
glyph-glyph (subtype 1), but the function is concerned with the latter only.


More information about the luatex mailing list