[luatex] Passing verbatim text to a function

Wolfgang Schuster schuster.wolfgang at googlemail.com
Mon Sep 27 20:02:34 CEST 2010


Am 27.09.2010 um 19:28 schrieb Sietse Brouwer:

>> \def\Dedent#1{\ctxlua{dedent(\!!bs\detokenize{#1}\!!es)}}
>> 
>> or
>> 
>> \def\Dedent#1{\ctxlua{dedent(\!!bs\normalunexpanded{#1}\!!es)}}
> 
> 
> Neither of those works for me; in both cases LuaTeX halts with an
> error. (I added (quotation marks or [[]]) (around the #1 or inside the
> parentheses) to ensure the dedent() function interpreted the argument
> as a string, but that did not change the error.)

You need a \unprotect/\protect before and after the definition, here is a complete example:

\unprotect

\startluacode

	thirddata = thirddata or { }

	function thirddata.verbatim(str)
		print(str)
	end

\stopluacode

\def\one  #1{\ctxlua{thirddata.verbatim(\!!bs\detokenize{#1}\!!es)}}
\def\two  #1{\ctxlua{thirddata.verbatim(\!!bs\luaescapestring{\detokenize{#1}}\!!es)}}
\def\three#1{\ctxlua{thirddata.verbatim(\!!bs\normalunexpanded{#1}\!!es)}}

\protect

\starttext
\one  {\TeX in \Lua}
\two  {\TeX in \Lua}
\three{\TeX in \Lua}
\stoptext

You can also write a environment by changing the defintions to

\def\startone#1\stopone{\ctxlua{thirddata.verbatim(...)}}

Wolfgang




More information about the luatex mailing list