[luatex] Passing verbatim text to a function

Sietse Brouwer sbbrouwer at gmail.com
Tue Sep 28 04:54:37 CEST 2010


Hi hi,

On Mon, Sep 27, 2010 at 20:02, Wolfgang Schuster
<schuster.wolfgang at googlemail.com> wrote:
> You need a \unprotect/\protect before and after the definition,

Ah! Yes, no errors now.

> 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

I tested those three with
\one{
    \TeX
        in
    Lua} ,
mutatis mutandis, but none of them preserved linebreaks or spaces,
alas. :-/ I tried inexpertly placing \obeylines and \obeyspaces, but
that did not help.

> You can also write a environment by changing the defintions to
>
> \def\startone#1\stopone{\ctxlua{thirddata.verbatim(...)}}

Where the (...) presumably was one of the above \!!bs...\!!es
stretches. Again (surrounding the definition with \unprotect and
\protect) this threw no errors, but it, too, did not preserve spaces
or newlines.

I also tried to define

\def\doDedent#1
    {\startDedent#1\stopDedent}

using Aditya's named buffer pattern, but that gave 'runaway argument'
errors, so I guess it's not the way to go.

Kind regards,

Sietse



More information about the luatex mailing list