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? Best regards, Lukas -- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
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
Thank you, Wolfgang, this works better. Actually I need to use '%' in the condition and that fails: --- ... \startrawsetups layer % 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 \startluacode print("N=", n) if n % 2 == 1 then else end \stopluacode \stoprawsetups ... --- with: --- ! LuaTeX error <main ctx instance>:1: 'then' expected near 'else'. --- So like '%' was still treated as TeX comment char. How to enable '%'? Best regards, Lukas NB: Dirty trick: to define a Lua function like 'function isEven(n) return n % 2 == 0 end' and to use this function at the place of 'n % 2 == 1'; but I'd rather avoid this. -- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
Am 25.01.2011 um 09:00 schrieb Procházka Lukáš Ing. - Pontex s. r. o.:
Thank you, Wolfgang, this works better.
Actually I need to use '%' in the condition and that fails:
--- ... \startrawsetups layer % 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
\startluacode print("N=", n)
if n % 2 == 1 then
else
end \stopluacode \stoprawsetups ... ---
with:
--- ! LuaTeX error <main ctx instance>:1: 'then' expected near 'else'. ---
So like '%' was still treated as TeX comment char.
How to enable '%'?
You can’t use % in the luacode environment when you write it inside of another environment because TeX can change the meaning of % but this should works (untested): \startbuffer[lualayer] % … \startluacode … \stopluacode \stopbuffer \doifmode{foo}{\ctxluabuffer[lualayer]} Wolfgang
On 25-1-2011 8:44, Wolfgang Schuster wrote:
\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
\startluasetups layer \stopluasetups \luasetup{...} ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Thanks you, Hans, -
On Tue, 25 Jan 2011 09:33:04 +0100, Hans Hagen
On 25-1-2011 8:44, Wolfgang Schuster wrote:
\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
\startluasetups layer
\stopluasetups
- I guess to be used like: \startluasetups layer \startluacode ... \stopluacode \stopluasetups
\luasetup{...}
To be used how? This way? \setupbackgrounds[page][setups=\luasetup{layer},background={T}] Best regards, Lukas -- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
participants (3)
-
Hans Hagen
-
Procházka Lukáš Ing. - Pontex s. r. o.
-
Wolfgang Schuster