Am 25.01.2011 um 08:33 schrieb Procházka Lukáš Ing. - Pontex s. r. o.:
Hello,
I encountered a bit weird thing when I used Lua in \startsetup:
--- \definelayer[T][x=0mm,y=0mm,width=\paperwidth,height=\paperheight]
\directlua{n, m = 1, 11} % Initialization
\startsetups layer % In my real code (= not in this example) % the value of 'n' is used here to set the appropriate background, % = n-th page of a PDF, and also to draw a filled rectangle on % the left or right side (depending on whether n is even or odd)
% The code bellow fails [1]
\startluacode print("N=", n)
if n == 2 then else end \stopluacode \stopsetups
\setupbackgrounds[page][setups=layer,background={T}]
\starttext % The code bellow works well [2]
\startluacode print("M=", m)
if m == 2 then else end \stopluacode
\dorecurse{4}{\page[empty]} \stoptext ---
The problem is that Lua code between \startsetups ... \stopsetups [1] seems to be "parsed" another way than when in [2].
The [1] gives the following error message:
--- ! LuaTeX error <main ctx instance>:1: 'then' expected near 'thenelseend'. ---
So it seems like <space>s and/or <\n>s were "ignored".
If you commented [1], the section [2] would work well.
So how to use make Lua work well even between \startsetups ... \stopsetups?
Use \startrawsetups … \stoprawsetups. Wolfgang