# Generate tex file from lualatex

Consider the following tex file, which compiles fine with lualatex.

\documentclass[preview]{standalone}
\usepackage{luacode}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw (0,0) grid (2,2);
\begin{luacode}
px = 0
py = 0
qx = 2
qy = 2
tex.print("\\draw[ultra thick] (" .. px .. "," .. py .. ") -- (" .. qx .. "," .. qy .. ");" );
\end{luacode}
\end{tikzpicture}
\end{document}


Is there a way to get the file below as an output from a lualatex run which than can be processed with pdflatex? (Of course the luacodepackage is than not needed any more.)

\documentclass[preview]{standalone}
\usepackage{luacode}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw (0,0) grid (2,2);
\draw[ultra thick] (0,0) -- (2,2);
\end{tikzpicture}
\end{document}

• in general no (this is like the common question of getting a file with certain macros expanded) the lua code may depend on things that can't be expressed as a fixed tex expression, however for specific cases such as here then you could do something, eg write to a file rather than to tex then for pdftex define the luacode environment to input the relevant file – David Carlisle Apr 23 '18 at 15:43
• thank you. i just thought it would be nice to check what is produced when the lua code is more complicated and have got for instance if statements and other control statements. – Nik Apr 23 '18 at 15:54
• if it is just for debugging you can use print(.... or texio.write(... in addition to the tex.print(... so you see the generated tex code – David Carlisle Apr 23 '18 at 16:07