[luatex] Three questions about tex.print("a\nb\n\nc")
Eduardo Ochs
eduardoochs at gmail.com
Tue Sep 10 02:33:15 CEST 2024
Hi list,
consider the following code:
--snip--snip--
rm -Rfv /tmp/test/
mkdir /tmp/test/
cd /tmp/test/
cat > abc.lua <<'%%%'
tex.print("a\nb\n\nc")
%%%
cat > test.tex <<'%%%'
\par a
b
c % a b \par c
\par \directlua{dofile "abc.lua"} % aObOOc
\par \catcode`\^^J=10 \directlua{dofile "abc.lua"} % a b c
\par \catcode`\^^J=14 \directlua{dofile "abc.lua"} % a
\par \catcode`\^^J=5 \directlua{dofile "abc.lua"} % a
\bye
%%%
luatex test.tex
xpdf test.pdf
--snip--snip--
When I started using "tex.print" years ago I expected that in
tex.print("a\nb\n\nc")
the first "\n" would be translated to a space and the "\n\n" between
"b" and "c" would be translated to a \par. I wasn't so, but I tried
this:
\catcode`\^^J=10
and I thought that that would fix everything. But I just discovered
that the "\n\n" gets translated to a space, and I checked on p.37 of
the TeXBook and category 10 is "space" (duh!!!), and that's why the
result of the
\par \catcode`\^^J=10 \directlua{dofile "abc.lua"} % a b c
in the .tex file above is "a b c" in a single line. The obvious fix
would be to use \catcode`\^^J=5 - category 5 is "end of line" - but
the output of these two lines in my .tex file
\par \catcode`\^^J=14 \directlua{dofile "abc.lua"} % a
\par \catcode`\^^J=5 \directlua{dofile "abc.lua"} % a
is the same... just an "a", and the rest disappears. So apparently
\catcode`\^^J=5 is behaving just like \catcode`\^^J=14, where category
14 is "comment character". So...
Question 1: how do I make "\n"s in tex.print behave like "return"s?
Question 2: how do I get the catecode of "\n" from Lua?
Question 3: how do I set the catecode of "\n" from Lua?
Thanks in advance...
Eduardo Ochs
http://anggtwu.net/dednat6.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/luatex/attachments/20240909/8c0c0d23/attachment.htm>
More information about the luatex
mailing list.