<div dir="ltr"><div>This isn't the right list really especially as your questions are more latex than luatex related in many ways.</div><div>You may prefer to ask on <a href="http://tex.stackexchange.com" target="_blank">tex.stackexchange.com</a><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 6 Jun 2020 at 19:11, Eduardo Ochs <<a href="mailto:eduardoochs@gmail.com" target="_blank">eduardoochs@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
<br>
<br>
The message about catcodes that I sent yesterday is here:<br>
<br>
  <a href="https://tug.org/pipermail/luatex/2020-June/007364.html" rel="noreferrer" target="_blank">https://tug.org/pipermail/luatex/2020-June/007364.html</a><br>
<br>
It contains a simple test that reveals - I mean, to an imaginary<br>
newbie reading it - that the TeX interpreter and tex.print use two<br>
different catcode tables.<br></blockquote><div><br></div><div><br></div><div>Not really, it's just the standard issue that you can't use  verbatim in the argument</div><div>of another command. You used tex.print but you would see the same from</div><div>\def\foo{</div><div>\begin{verbatim}</div><div>...</div><div>\end{verbatim}</div><div>}</div><div>\foo</div><div><br></div><div>without using luatex at all.</div><div><br></div><div>As you have the text in a Lua string you don't really need verbatim environment</div><div><br></div><div>You could write out the tokens with \catcodetable@string  as the first optional catcode table argument. (If I understand your use case) <br></div><div>but you would have to split up the string on \n first and print each verbatim line separately.</div><div><br></div><div>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.<br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
One obvious place to learn more about these different catcode tables<br>
is the LuaTeX reference manual. Let me use a trick from eev to point<br>
to sections of the manual. The trick is explained here,<br>
<a href="http://angg.twu.net/dednat6.html#hacking" rel="noreferrer" target="_blank">at6.html#hacking</a></blockquote><div><br></div><div><br></div><div>for the latex interface you could try</div><div><br></div><div>texdoc ltluatex <br></div><div>and perhaps</div><div>texdoc ctablestack</div><div><br></div><div><br></div><div>Here's a small example</div><div><br></div><div>verb.Lua defines a multi-line string then makes it safe for the latex document test.tex<br></div><div><br></div><div><br></div><div>verb.lua</div><div><br></div><div>z=[[<br>aaa  bbb  \gggg<br>     jjj { \zzz<br>    blug<br>]]<br>tex.print("\\begin{flushleft}\\ttfamily\\let\\\\=\\textbackslash ")<br>tex.print(<br>z:<br>gsub('\\','\\\\'):<br>gsub('{','\\{'):<br>gsub('}','\\}'):<br>gsub(' ','\\ '):<br>gsub('\n','\\par ')<br>.. "")<br>tex.print("\\end{flushleft}")</div><div><br></div><div><br></div><div><br></div><div>test.tex</div><div><br></div><div>\documentclass{article}<br><br>\begin{document}<br><br>\directlua{<br>require("verb")<br>}<br>\end{document}<br></div></div></div>