If you are using LaTeX (LuaLaTeX), I'd strongly advice against using \directlua{} for more than a simple call to execute another Lua file. \directlua{} is in no way safe. For example:
- if you use a Lua comment (
--), your code gets Q="!%"§I. This is because in \directlua{} everything is read on one line.
- If you try to use a literal
% sign, for example in tex.print() you... well, try yourself . Good luck.
- If you try to use an active character such as
~ surprising results are guaranteed.
- When you want to use
tex.print() with a macro, such as \par, you have do crazy stuff to not let TeX see the macro before Lua sees the macro.
- And good luck inserting strings like "\n" for a new line character.
Now what to do? Use the environment luacode* from the luacode package:
\begin{luacode*}
for i=1,3,1 do
tex.print("FOO\\par")
end
\end{luacode*}
If you can't use the luacode package (for example when you use plain TeX), use dofile() or require() to load a package and put your code there. TeX can't find and interpret the code there, only Lua. And then you can write
for i=1,3,1 do
tex.print("FOO\\par")
end
without trouble.
tex.print("Foo", "\par")– Marco Apr 23 '12 at 21:22\parbut something else, which I don't know at the moment. – topskip Apr 24 '12 at 06:29