···
Now, I have a code which does much expected, but I'm not able to pass the desired content to setups/layer:
---- \setupbodyfont[30pt]
\starttext A
\definelayer [beforetext][width=\overlaywidth,height=\overlayheight] \defineoverlay[beforetext][{\setups[beforetext]\tightlayer[beforetext]}]
\startsetups[beforetext] \setlayer[beforetext][preset=righttop]{\framed[width=2in]{\directlua{context(userdata.LPr.text)}}} \stopsetups
\startluacode userdata = userdata or {} userdata.LPr = userdata.LPr or {}
for i = 1, 2 do context.startTEXpage{background="foreground,beforetext"} userdata.LPr.text = "BEF" .. i
context.externalfigure({"cow"},{width="30cm"}) context.stopTEXpage() end \stopluacode
Z \stoptext ----
Both images of the cow have "BEF2" in the top right corner, but there should be "BEF1" on the former and "BEF2" on the latter.
I'm trying to pass the text string ("BEF" .. i) via userdata, but it doesn't work.
Afair entire Lua snippet is evaluated first, so any calls to TEX are delayed until after the loop is executed. Thus the layer is drawn only when LPr.text already has the final value. But I’m not entirely sure that’s the correct explanation.
So how to do it?
Lookup the correct string from a table? ······································································· \setupbodyfont[30pt] \starttext A \definelayer [beforetext][width=\overlaywidth,height=\overlayheight] \defineoverlay[beforetext][{\setups[beforetext]\tightlayer[beforetext]}] \startsetups[beforetext] \setlayer[beforetext][preset=righttop] {\framed[width=2in]{\directlua{userdata.LPr.get_label()}}} \stopsetups \startluacode userdata = userdata or { } userdata.LPr = userdata.LPr or { } local labels = { } local current = 0 userdata.LPr.get_label = function ( ) current = current + 1 context(labels[current]) end for i = 1, 2 do context.startTEXpage { background = "foreground,beforetext" } labels[i] = "BEF" .. i context.externalfigure({"cow"},{width="30cm"}) context.stopTEXpage() end \stopluacode Z \stoptext ······································································· Regards Philipp