Hi Thomas,

Am 22.10.2011 18:46, schrieb Thomas A. Schmitz:
> Hi all,
> 
> again, I'm playing a bit with processing my xml in lua. I want a simple
> interface for processing tables (I don't need all the power and
> complexity of cals tables and want to learn something in the process).
> And I thought that collecting the setups in lua might be the easiest
> way, but so far, I haven't been successful. Here's an example:
> 
> \startbuffer[test]
> <a>
>   <nattable frame="on">
>     <tr>
>       <td>1</td>
>       <td>2</td>
>       <td>3</td>
>       <td>4</td>
>     </tr>
>     <tr>
>       <td>5</td>
>       <td>6</td>
>       <td>7</td>
>       <td>8</td>
>     </tr>
>   </nattable>
> </a>
> \stopbuffer
> 
> \startxmlsetups xml:testsetups
>     \xmlsetsetup{main}{a|nattable|tr|td|}{xml:*}
> \stopxmlsetups
> 
> \xmlregistersetup{xml:testsetups}
> 
> \startxmlsetups xml:a
>     \xmlflush{#1}
> \stopxmlsetups
> 
> \startxmlsetups xml:nattable
>     \startluacode
>       framestate = lxml.att("#1", "frame")
>       context(framestate)
>       context(true)
>       context.placefigure( { "here" }, "none" , function()
>         context.setupTABLE( { "frame=on" } )
>         context.bTABLE()
>          context.xmlflush("#1")
>         context.eTABLE()
>       end)
>     \stopluacode
> \stopxmlsetups
> 
> \startxmlsetups xml:tr
>     \startluacode
>       context.bTR()
>         context.xmlflush("#1")
>       context.eTR()
>     \stopluacode
> \stopxmlsetups
> 
> \startxmlsetups xml:td
>     \startluacode
>       context.bTD()
>         context.xmlflush("#1")
>       context.eTD()
>     \stopluacode
> \stopxmlsetups
> 
> \starttext
> \xmlprocessbuffer{main}{test}{}
> \stoptext
> 
> question: I have the value "on" in the lua variable "framestate." But
> how can I pass this on to the line
> context.setupTABLE( { "frame=on" } )?
> I tried something like
> context.setupTABLE( { "frame=" .. framestate } )

"frame=" .. tostring(framestate)

seems to work. Anyhow, if you are planning to do some more complex
stuff, you should separate the lua from the tex code.

The advantages are
- no catcode limitations
  Then you can use nice stuff like
  string.format("frame=%s",framestate)
- in case of lua errors you get the real line number
- lua syntax check is possible

Load the lua code at the beginning of your tex file with

\registerctxluafile{filename_without_suffix}{version number or empty}

One last but important tip: if you get lua errors like 'undefined
whatever', check your lua file with 'luatexc -p foo.lua' (lua compiler).
A single syntax error in the lua file and all of its content is ignored!
Can be quite frustrating to find the error cause, if all of your lua
code is undefined right from the beginning.


Best wishes,  Peter


PS: lua programming is most efficient when done in direct moon light,
while drinking a glass of fresh goat milk! Mh, can't find the link to
this interesting statistic right now... so you just have to believe me
and give it a try.. :-)
___________________________________________________________________________________
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
___________________________________________________________________________________

Reply via email to