David Carlisle d.p.carlisle at gmail.com
Sat Jun 6 23:38:49 CEST 2020

This isn't the right list really especially as your questions are more
latex than luatex related in many ways.
You may prefer to ask on tex.stackexchange.com

On Sat, 6 Jun 2020 at 19:11, Eduardo Ochs <eduardoochs at gmail.com> wrote:

>
>
>
>
> The message about catcodes that I sent yesterday is here:
>
>   https://tug.org/pipermail/luatex/2020-June/007364.html
>
> It contains a simple test that reveals - I mean, to an imaginary
> newbie reading it - that the TeX interpreter and tex.print use two
> different catcode tables.
>

Not really, it's just the standard issue that you can't use  verbatim in
the argument
of another command. You used tex.print but you would see the same from
\def\foo{
\begin{verbatim}
...
\end{verbatim}
}
\foo

without using luatex at all.

As you have the text in a Lua string you don't really need verbatim
environment

You could write out the tokens with \catcodetable at string  as the first
optional catcode table argument. (If I understand your use case)
but you would have to split up the string on \n first and print each
verbatim line separately.

Or you could print using the default catcode table but quote teh special
characters first. I give a small example of this at the end.

> is the LuaTeX reference manual. Let me use a trick from eev to point
> to sections of the manual. The trick is explained here,
> at6.html#hacking <http://angg.twu.net/dednat6.html#hacking>

for the latex interface you could try

texdoc ltluatex
and perhaps
texdoc ctablestack

Here's a small example

verb.Lua defines a multi-line string then makes it safe for the latex
document test.tex

verb.lua

z=[[
aaa  bbb  \gggg
jjj { \zzz
blug
]]
tex.print("\\begin{flushleft}\\ttfamily\\let\\\\=\\textbackslash ")
tex.print(
z:
gsub('\\','\\\\'):
gsub('{','\\{'):
gsub('}','\\}'):
gsub(' ','\\ '):
gsub('\n','\\par ')
.. "")
tex.print("\\end{flushleft}")

test.tex

\documentclass{article}

\begin{document}

\directlua{
require("verb")
}
\end{document}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/luatex/attachments/20200606/f1561b14/attachment.html>