* Problem calling Lua during \startsetups
@ 2011-01-25 7:33 Procházka Lukáš Ing. - Pontex s. r. o.
2011-01-25 7:44 ` Wolfgang Schuster
0 siblings, 1 reply; 6+ messages in thread
From: Procházka Lukáš Ing. - Pontex s. r. o. @ 2011-01-25 7:33 UTC (permalink / raw)
To: ConTeXt
[-- Attachment #1: Type: text/plain, Size: 1556 bytes --]
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
[-- Attachment #2: t-Bkg.log --]
[-- Type: application/octet-stream, Size: 8183 bytes --]
(C:/Lukas/ConTeXt/Samples/t-Bkg.mkiv
jobcontrol > resuming randomizer with 0.77956480605487
ConTeXt ver: 2011.01.12 10:20 MKIV fmt: 2011.1.13 int: english/english
system : cont-new loaded
(c:/ConTeXt/tex/texmf-context/tex/context/base/cont-new.tex
systems : beware: some patches loaded from cont-new.tex
(c:/ConTeXt/tex/texmf-context/tex/context/base/cont-new.mkiv))
system : cont-fil.mkiv loaded
(c:/ConTeXt/tex/texmf-context/tex/context/base/cont-fil.mkiv
loading : ConTeXt File Synonyms
)
system : cont-sys.rme loaded
(c:/ConTeXt/tex/texmf-context/tex/context/user/cont-sys.rme (c:/ConTeXt/tex/texmf-context/tex/context/base/type-def.mkiv) (c:/ConTeXt/tex/texmf-context/tex/context/base/type-lua.mkiv) (c:/ConTeXt/tex/texmf-context/tex/context/base/type-siz.mkiv) (c:/ConTeXt/tex/texmf-context/tex/context/base/type-otf.mkiv))
system : cont-err loaded
(c:/ConTeXt/tex/texmf-context/tex/context/base/cont-err.tex
systems : no file 'cont-sys.tex', using 'cont-sys.rme' instead
)
system : t-Bkg.top loaded
%
% begin of optionfile
%
% % runtime options files (command line driven)
% \unprotect
% % feedback and basic job control
% \nonstopmode
% % handy for special styles
% \startluacode
% document = document or { }
% document.arguments={
% ["FILE"]="t-Bkg.mkiv",
% ["halt-on-error"]=true,
% ["nonstopmode"]=true,
% }
% document.files={
% "C:/Lukas/ConTeXt/Samples/t-Bkg.mkiv",
% }
% \stopluacode
% % process info
% \setupsystem[inputfile=C:/Lukas/ConTeXt/Samples/t-Bkg.mkiv]
% \setupsystem[\c!n=1,\c!m=1]
% % modes
% % options (not that important)
% \startsetups *runtime:options
% \setupoutput[pdftex]
% \stopsetups
% % styles and modules
% \startsetups *runtime:modules
% \stopsetups
% % done
% \protect \endinput
%
% end of optionfile
%
(t-Bkg.top
){c:/ConTeXt/tex/texmf/fonts/map/dvips/lm/lm-math.map}{c:/ConTeXt/tex/texmf/fonts/map/dvips/lm/lm-rm.map}{c:/ConTeXt/tex/texmf-context/fonts/map/pdftex/context/mkiv-base.map}
bodyfont : 12pt rm is loaded
fonts : preloading latin modern fonts (first stage)
language : language en is active
publications : loading formatting style from bxml-apa
(c:/ConTeXt/tex/texmf-context/tex/context/base/bxml-apa.mkiv)
systems : begin file C:/Lukas/ConTeXt/Samples/t-Bkg.mkiv at line 17
! LuaTeX error <main ctx instance>:1: 'then' expected near 'thenelseend'.
<inserted text> ...("N=", n)if n == 2 thenelseend}
\dodostartluacode ...d \directlua \zerocount {#1}}
\next2 #1,->\dosetups {#1}
\doprocesscommaitem
\doprocesscommalist ...item \gobbleoneargument #1,
]\relax \global \advance \...
\doprocesslocalsetups ... \dodoprocesslocalsetups
\fi
\addsomebackground ...?ma #1\c!setups \endcsname }
\fi \localbackgroundframed...
...
l.26 \dorecurse{4}{\page[empty]}
The lua interpreter ran into a problem, so the
remainder of this lua chunk will be ignored.
backends > using xmp file 'c:/ConTeXt/tex/texmf-context/tex/context/base/lpdf-pdx.xml'
pages > flushing realpage 1, userpage 1, subpage 1
! LuaTeX error <main ctx instance>:1: 'then' expected near 'thenelseend'.
<inserted text> ...("N=", n)if n == 2 thenelseend}
\dodostartluacode ...d \directlua \zerocount {#1}}
\next2 #1,->\dosetups {#1}
\doprocesscommaitem
\doprocesscommalist ...item \gobbleoneargument #1,
]\relax \global \advance \...
\doprocesslocalsetups ... \dodoprocesslocalsetups
\fi
\addsomebackground ...?ma #1\c!setups \endcsname }
\fi \localbackgroundframed...
...
l.26 \dorecurse{4}{\page[empty]}
The lua interpreter ran into a problem, so the
remainder of this lua chunk will be ignored.
pages > flushing realpage 2, userpage 2
! LuaTeX error <main ctx instance>:1: 'then' expected near 'thenelseend'.
<inserted text> ...("N=", n)if n == 2 thenelseend}
\dodostartluacode ...d \directlua \zerocount {#1}}
\next2 #1,->\dosetups {#1}
\doprocesscommaitem
\doprocesscommalist ...item \gobbleoneargument #1,
]\relax \global \advance \...
\doprocesslocalsetups ... \dodoprocesslocalsetups
\fi
\addsomebackground ...?ma #1\c!setups \endcsname }
\fi \localbackgroundframed...
...
l.26 \dorecurse{4}{\page[empty]}
The lua interpreter ran into a problem, so the
remainder of this lua chunk will be ignored.
pages > flushing realpage 3, userpage 3
! LuaTeX error <main ctx instance>:1: 'then' expected near 'thenelseend'.
<inserted text> ...("N=", n)if n == 2 thenelseend}
\dodostartluacode ...d \directlua \zerocount {#1}}
\next2 #1,->\dosetups {#1}
\doprocesscommaitem
\doprocesscommalist ...item \gobbleoneargument #1,
]\relax \global \advance \...
\doprocesslocalsetups ... \dodoprocesslocalsetups
\fi
\addsomebackground ...?ma #1\c!setups \endcsname }
\fi \localbackgroundframed...
...
l.26 \dorecurse{4}{\page[empty]}
The lua interpreter ran into a problem, so the
remainder of this lua chunk will be ignored.
pages > flushing realpage 4, userpage 4
systems : end file C:/Lukas/ConTeXt/Samples/t-Bkg.mkiv at line 27
)
mkiv lua stats : used config file - c:/ConTeXt/tex/texmf/web2c/texmfcnf.lua
mkiv lua stats : used cache path - c:/ConTeXt/tex/texmf-cache/luatex-cache/context/f53042fa2e1c106bc7e3383ec8c3a00c
mkiv lua stats : input load time - 0.016 seconds
mkiv lua stats : stored bytecode data - 261 modules, 55 tables, 316 chunks
mkiv lua stats : cleaned up reserved nodes - 32 nodes, 10 lists of 412
mkiv lua stats : node memory usage - 18 glue_spec
mkiv lua stats : node list callback tasks - 6 unique task lists, 5 instances (re)created, 469 calls
mkiv lua stats : used backend - pdf (backend for directly generating pdf output)
mkiv lua stats : loaded patterns - en::2
mkiv lua stats : callbacks - direct: 766, indirect: 4520, total: 5286
mkiv lua stats : lxml preparation time - 0.000 seconds, 0 nodes, 15 lpath calls, 0 cached calls
mkiv lua stats : result saved in file - t-Bkg.pdf
mkiv lua stats : loaded fonts - 33 files: stmary10.afm lmmono12-regular.otf lmmono8-regular.otf lmmono9-regular.otf lmroman12-bold.otf lmroman12-regular.otf lmroman7-bold.otf lmroman7-regular.otf lmroman9-bold.otf lmroman9-regular.otf lmsans12-regular.otf lmsans8-regular.otf lmsans9-regular.otf eufb10.tfm eufb7.tfm eufm10.tfm eufm7.tfm msam10.tfm msam7.tfm msbm10.tfm msbm7.tfm lmex10.tfm lmmi12.tfm lmmi7.tfm lmmi9.tfm lmmib10.tfm lmmib7.tfm lmsy10.tfm lmsy7.tfm lmsy9.tfm rm-lmr12.tfm rm-lmr7.tfm rm-lmr9.tfm
mkiv lua stats : fonts load time - 0.266 seconds
mkiv lua stats : luatex banner - this is luatex, version beta-0.65.0-2010121421 (web2c 2010) (rev 4034)
mkiv lua stats : control sequences - 29986 of 165536
mkiv lua stats : current memory usage - 32 MB (ctx: 32 MB)
mkiv lua stats : runtime - 0.719 seconds, 3 processed pages, 4 shipped pages, 5.563 pages/second
[-- Attachment #3: t-Bkg.mkiv --]
[-- Type: application/octet-stream, Size: 704 bytes --]
\definelayer[T][x=000mm,y=0mm,width=\paperwidth,height=\paperheight]
\directlua{n, m = 1, 11}
\startsetups 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 then
else
end
\stopluacode
\stopsetups
\setupbackgrounds[page][setups=layer,background={T}]
\starttext
% The code bellow works well
\startluacode
print("M=", m)
if m == 2 then
else
end
\stopluacode
\dorecurse{4}{\page[empty]}
\stoptext
[-- Attachment #4: Type: text/plain, Size: 486 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem calling Lua during \startsetups
2011-01-25 7:33 Problem calling Lua during \startsetups Procházka Lukáš Ing. - Pontex s. r. o.
@ 2011-01-25 7:44 ` Wolfgang Schuster
2011-01-25 8:00 ` Procházka Lukáš Ing. - Pontex s. r. o.
2011-01-25 8:33 ` Hans Hagen
0 siblings, 2 replies; 6+ messages in thread
From: Wolfgang Schuster @ 2011-01-25 7:44 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem calling Lua during \startsetups
2011-01-25 7:44 ` Wolfgang Schuster
@ 2011-01-25 8:00 ` Procházka Lukáš Ing. - Pontex s. r. o.
2011-01-25 8:34 ` Wolfgang Schuster
2011-01-25 8:33 ` Hans Hagen
1 sibling, 1 reply; 6+ messages in thread
From: Procházka Lukáš Ing. - Pontex s. r. o. @ 2011-01-25 8:00 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem calling Lua during \startsetups
2011-01-25 7:44 ` Wolfgang Schuster
2011-01-25 8:00 ` Procházka Lukáš Ing. - Pontex s. r. o.
@ 2011-01-25 8:33 ` Hans Hagen
2011-01-25 13:01 ` Procházka Lukáš Ing. - Pontex s. r. o.
1 sibling, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2011-01-25 8:33 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem calling Lua during \startsetups
2011-01-25 8:00 ` Procházka Lukáš Ing. - Pontex s. r. o.
@ 2011-01-25 8:34 ` Wolfgang Schuster
0 siblings, 0 replies; 6+ messages in thread
From: Wolfgang Schuster @ 2011-01-25 8:34 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem calling Lua during \startsetups
2011-01-25 8:33 ` Hans Hagen
@ 2011-01-25 13:01 ` Procházka Lukáš Ing. - Pontex s. r. o.
0 siblings, 0 replies; 6+ messages in thread
From: Procházka Lukáš Ing. - Pontex s. r. o. @ 2011-01-25 13:01 UTC (permalink / raw)
To: mailing list for ConTeXt users
Thanks you, Hans, -
On Tue, 25 Jan 2011 09:33:04 +0100, Hans Hagen <pragma@wxs.nl> wrote:
> 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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-01-25 13:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-25 7:33 Problem calling Lua during \startsetups Procházka Lukáš Ing. - Pontex s. r. o.
2011-01-25 7:44 ` Wolfgang Schuster
2011-01-25 8:00 ` Procházka Lukáš Ing. - Pontex s. r. o.
2011-01-25 8:34 ` Wolfgang Schuster
2011-01-25 8:33 ` Hans Hagen
2011-01-25 13:01 ` Procházka Lukáš Ing. - Pontex s. r. o.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).