Am 29.12.2008 um 13:56 schrieb Ashlock, Tad A:
On 2008-12-28 at 15:33, Wolfgang Schuster wrote:
Am 27.12.2008 um 12:20 schrieb Tad Ashlock:
I'm trying to create a ConTeXt macro (mkiv) that will manipulate the macro argument's text with Lua and then feed it back into ConTeXt with tex.print(). My approach worked correctly until I called the macro with \starttabulate ... \stoptabulate in the macro's argument. So I started reducing the problem down to a minimum example which surprisingly turned out to have nothing to do with the manipulations I was performing. [snip]
\def\testmacro {\bgroup \catcode`\\=12 \dotestmacro}
\def\dotestmacro#1 {\ctxlua{d='\luaescapestring{#1}'}% \egroup}
\starttext
\testmacro{\starttabulate \NC text \NC text \NC\NR \stoptabulate}
%\ctxlua{tex.sprint(d)}
\stoptext
Wolfgang
Thank you Wolfgang! That's certainly a step in the right direction. But what I (and others?) really need is a way of passing any chunk of ConTeXt code into Lua.
Everything you pass to Lua is expanded and this did not work with macros that contain \dosingleempty (or \dodoubleempty etc.). \def\command {\dosingleempty\docommand} \def\docommand[#1]{#1} \def\testmacro#1% {\ctxlua{d='\luaescapestring{#1}'}} \starttext \testmacro{\docommand[text]} % works \testmacro{\command[text]} % fails \stoptext
When I changed '\starttabulate' to '\starttabulate[|l|p|]' in your solution above, it broke.
Try to escape the |, it's a active character in ConTeXt but this could work (untested): \def\testmacro {\bgroup \catcode`\\=12 \catcode`\|=12 \dotestmacro} Wolfgang