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 : [email protected] / 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
___________________________________________________________________________________

Reply via email to