ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* luacode inside xmlsetups
@ 2010-03-30 16:09 Hans van der Meer
  2010-03-30 17:56 ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Hans van der Meer @ 2010-03-30 16:09 UTC (permalink / raw)
  To: NTG ConTeXt


[-- Attachment #1.1: Type: text/plain, Size: 1039 bytes --]

The following works outside xmlsetups but not inside it.
It seems to bolt on the % with:
! LuaTeX error <main ctx instance>:1: ')' expected near '<eof>'.
<inserted text> ....pitex.print("pi = " .. (x - x}

This in spite of the wiki telling me:
To circumvent this problem, ConTeXt defines a environment called  
\startluacode ... \stopluacode. This sets the catcodes to what one  
would expect in lua. Basically only \ has its usual TeX meaning, the  
catcode of everything else is set to other. So, for all practical  
purposes, we can forget about catcodes inside \startluacode ...  
\stopluacode.

The code is:

\startxmlsetups xml:mycommand
\startluacode
local x = math.pi
tex.print("pi = " .. (x - x\%0.01))
\stopluacode
\stopxmlsetups

When I try to escape the % with \% the result is no better:
! LuaTeX error <main ctx instance>:1: ')' expected near '\'.
<inserted text> ...rint("pi = " .. (x - x\%0.01))}

Is it not possible to directly use Lua inside these setups? If do, why  
the nonconforming behaviour?

Hans van der Meer





[-- Attachment #1.2: Type: text/html, Size: 6604 bytes --]

[-- Attachment #2: 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] 4+ messages in thread

* Re: luacode inside xmlsetups
  2010-03-30 16:09 luacode inside xmlsetups Hans van der Meer
@ 2010-03-30 17:56 ` Hans Hagen
  2010-03-30 18:05   ` Hans van der Meer
  0 siblings, 1 reply; 4+ messages in thread
From: Hans Hagen @ 2010-03-30 17:56 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 30-3-2010 18:09, Hans van der Meer wrote:
> The following works outside xmlsetups but not inside it.
> It seems to bolt on the % with:
> ! LuaTeX error <main ctx instance>:1: ')' expected near '<eof>'.
> <inserted text> ....pitex.print("pi = " .. (x - x}
>
> This in spite of the wiki telling me:
> To circumvent this problem, ConTeXt defines a environment called
> \startluacode ... \stopluacode. This sets the catcodes to what one would
> expect in lua. Basically only \ has its usual TeX meaning, the catcode
> of everything else is set to other. So, for all practical purposes, we
> can forget about catcodes inside \startluacode ... \stopluacode.
>
> The code is:
>
> \startxmlsetups xml:mycommand
> \startluacode
> local x = math.pi
> tex.print("pi = " .. (x - x\%0.01))
> \stopluacode
> \stopxmlsetups
>
> When I try to escape the % with \% the result is no better:
> ! LuaTeX error <main ctx instance>:1: ')' expected near '\'.
> <inserted text> ...rint("pi = " .. (x - x\%0.01))}
>
> Is it not possible to directly use Lua inside these setups? If do, why
> the nonconforming behaviour?

use \letterpercent

or beter, define a nice function outside the setups and call that one 
inside the setup

\startluacode
function document.MyPiStuff()
   local x = math.pi
   tex.print("pi = " .. (x - x%0.01))
end
\stopluacode


\startxmlsetups xml:mycommand
   \ctxlua{document.MyPiStuff()}
\stopxmlsetups

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 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] 4+ messages in thread

* Re: luacode inside xmlsetups
  2010-03-30 17:56 ` Hans Hagen
@ 2010-03-30 18:05   ` Hans van der Meer
  2010-03-30 18:13     ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Hans van der Meer @ 2010-03-30 18:05 UTC (permalink / raw)
  To: NTG ConTeXt

I see.
What is the scope of that function you suggest? Can I make it a local  
function or has it to exist in a more global scope?
I see in your example document.MyPiStuff. Is that because you suppose  
the lua code enclosed in a module "document"?
For but a handful of functions I would rather keep them together with  
the TeX-code.

Hans van der Meer




On 30 mrt 2010, at 19:56, Hans Hagen wrote:

> On 30-3-2010 18:09, Hans van der Meer wrote:
>> The following works outside xmlsetups but not inside it.
>> It seems to bolt on the % with:
>> ! LuaTeX error <main ctx instance>:1: ')' expected near '<eof>'.
>> <inserted text> ....pitex.print("pi = " .. (x - x}
>>
>> This in spite of the wiki telling me:
>> To circumvent this problem, ConTeXt defines a environment called
>> \startluacode ... \stopluacode. This sets the catcodes to what one  
>> would
>> expect in lua. Basically only \ has its usual TeX meaning, the  
>> catcode
>> of everything else is set to other. So, for all practical purposes,  
>> we
>> can forget about catcodes inside \startluacode ... \stopluacode.
>>
>> The code is:
>>
>> \startxmlsetups xml:mycommand
>> \startluacode
>> local x = math.pi
>> tex.print("pi = " .. (x - x\%0.01))
>> \stopluacode
>> \stopxmlsetups
>>
>> When I try to escape the % with \% the result is no better:
>> ! LuaTeX error <main ctx instance>:1: ')' expected near '\'.
>> <inserted text> ...rint("pi = " .. (x - x\%0.01))}
>>
>> Is it not possible to directly use Lua inside these setups? If do,  
>> why
>> the nonconforming behaviour?
>
> use \letterpercent
>
> or beter, define a nice function outside the setups and call that  
> one inside the setup
>
> \startluacode
> function document.MyPiStuff()
>  local x = math.pi
>  tex.print("pi = " .. (x - x%0.01))
> end
> \stopluacode
>
>
> \startxmlsetups xml:mycommand
>  \ctxlua{document.MyPiStuff()}
> \stopxmlsetups
>
> Hans
>
>
> -----------------------------------------------------------------
>                                          Hans Hagen | PRAGMA ADE
>              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>     tel: 038 477 53 69 | fax: 038 477 53 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] 4+ messages in thread

* Re: luacode inside xmlsetups
  2010-03-30 18:05   ` Hans van der Meer
@ 2010-03-30 18:13     ` Hans Hagen
  0 siblings, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2010-03-30 18:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 30-3-2010 20:05, Hans van der Meer wrote:
> I see.
> What is the scope of that function you suggest? Can I make it a local
> function or has it to exist in a more global scope?
> I see in your example document.MyPiStuff. Is that because you suppose
> the lua code enclosed in a module "document"?
> For but a handful of functions I would rather keep them together with
> the TeX-code.

all definitions are (as usual) global although the direct lua call 
happens in a closure so you can use local to prevent bleeding

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 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] 4+ messages in thread

end of thread, other threads:[~2010-03-30 18:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-30 16:09 luacode inside xmlsetups Hans van der Meer
2010-03-30 17:56 ` Hans Hagen
2010-03-30 18:05   ` Hans van der Meer
2010-03-30 18:13     ` Hans Hagen

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).