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. Here is the working example (without \starttabulate): \long\def\testmacro#1{\directlua0{d='\luaescapestring{#1}'}} \starttext Hello, world! \testmacro{% testing} \stoptext Here is the broken example: \long\def\testmacro#1{\directlua0{d='\luaescapestring{#1}'}} \starttext Hello, world! \testmacro{% testing \starttabulate \NC 0 \NC testing tabulate. \NC \NR \stoptabulate} \stoptext Here's the output: ===================================== MtxRun | loading configuration for C:/context/tex/texmf/web2c from C:/context/tex/texmf-cache/luatex-cache/context/2fea56f92e5267d7cc9662e4d5f52e1e/trees/53ad5f8b88994bdd02baa17501789699 MtxRun | run 1: luatex --fmt="C:/context/tex/texmf-cache/luatex-cache/context/2fea56f92e5267d7cc9662e4d5f52e1e/formats/cont-en" --lua="C:/context/tex/texmf-cache/luatex-cache/context/2fea56f92e5267d7cc9662e4d5f52e1e/formats/cont-en.lua" "./test.tex" (test.tex ConTeXt ver: 2008.10.31 13:58 MKIV fmt: 2008.12.24 int: english/english language : language en is active 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) (C:/context/tex/texmf-context/tex/context/base/cont-mtx.tex)) system : cont-fil loaded (C:/context/tex/texmf-context/tex/context/base/cont-fil.tex 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-tmf.tex) (C:/context/tex/texmf-context/tex/context/base/type-siz.tex) (C:/context/tex/texmf-context/tex/context/base/type-otf.tex)) bodyfont : 12pt rm is loaded specials : pdftex loaded system : test.top loaded (test.top) (test.tuo) (test.tuo) systems : begin file test at line 2 ! Argument of \dodoubletestempty has an extra }. <inserted text> \par <to be read again> } \doifnextcharelse ...token =#1\def \!!stringa {#2} \def \!!stringb {#3}\futur... <argument> testing \starttabulate \NC 0 \NC testing tabulate. \NC \NR \stopt... \testmacro ...\directlua 0{d='\luaescapestring {#1 }'} l.8 \stoptabulate} ? ===================================== I've tried all sorts of variations on the above example including using \ctxlua, \startlua, \startluacode, etc. I tried using '[[...]]' and '[===[...]===]' instead of \luaescapestring. I tried \def with and without \long. I tried other \start* ... \stop* commands (different errors, but still broken). Plus many more variations. At this point I'm convinced that there's something fundamental that I'm not understanding. What is the general method for taking any chunk of ConTeXt code and passing it into Lua so that it can be written back out with tex.print()? Info: running on Windows XP, SP3 -- ConTeXt: 2008.10.31 -- LuaTeX, Version snapshot-0.31.2-2008121200, build 1659 (The older versions of ConTeXt and LuaTeX are necessary because of the problem the latest Windows versions are having. See the "Serious Bug?" thread.) Thank you, Tad Ashlock