········· > Hello, > > On Wed, 16 Jan 2013 12:47:21 +0100, Philipp Gesang wrote: > > >Lookup the correct string from a table? > > thanks for the idea - > > - in other words, we have to keep running results somewhere; Yes, this is simple because the order of processing doesn’t change -- as long as the data you aggregate fits into your memory, of course! > the algorithm fills a table with texts for each page, and each > \setlayer takes one value back, so we can simplify to: > > \setlayer[beforetext][preset=righttop] > {\framed[width=2in]{\directlua{context(table.remove(userdata.LPr.texts, 1))}}} > context.startTEXpage { background = "foreground,beforetext" } > table.insert(userdata.LPr.texts, "BEF" .. i) > > context.externalfigure({"cow"},{width="30cm"}) > context.stopTEXpage() From my tests calling table.remove() to remove the first element in a list is extremely inefficient compared to accessing an array. (For 10^5 elements it’s 1m41.644s vs. 0m0.030s on my machine.) While we’re at it, table.insert() involves an extra function call that carries another perfomance penalty, albeit a much smaller one. Your code should do the same, though. Regards Philipp