[luatex] Verbatim printing of Lua strings

Hans Hagen pragma at wxs.nl
Sat Mar 14 13:00:53 CET 2015


On 3/14/2015 10:57 AM, Dirk Laurie wrote:
> I have a Lua script that produces a Lua string like this:
>
>      str = [[
> 1. First line.
> 2. Second line.
> ]]
>
> I wish to achieve the effect that
>
> \begin{verbatim}
> 1. First line.
> 2. Second line.
> \end{verbatim}
>
> would have produced. My attempt has been to make the module
> produce
>
>      vstr = [[
> \begin{verbatim}
> 1. First line.
> 2. Second line.
> \end{verbatim}
> ]]
>
> and code `\directlua{tex.print(vstr)}`. But the end-of-line is not respected.
>
> I can't find the string `verbatim` in the LuaTeX manual. Under what word
> should I search for a trick that can achieve what I need?

this is because by default a newline becomes a space

you need to change the catcode of the newline character (and probably 
more if you want verbatim but that is macro package dependent so not 
relevant here) or alternatively print line by line and add a \par at the 
end of each line

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the luatex mailing list