[luatex] Verbatim printing of Lua strings

Dirk Laurie dirk.laurie at gmail.com
Sat Mar 14 13:15:10 CET 2015


2015-03-14 14:00 GMT+02:00 Hans Hagen <pragma at wxs.nl>:
> On 3/14/2015 10:57 AM, Dirk Laurie wrote:

>> 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

I messed around a bit with \catcode but since all of Lua is available,
I found it easier to do the line-by-line approach using `gsub`. It's as
easy as this (inside a Lua script file):

    str:gsub("[^\n]+","\\verb$%0$\\\\")

Thanks.

Dirk


More information about the luatex mailing list