When using Lua code inside Latex file, where Lua code sends to Tex Latex code to insert into the document at the location the lua code is made, it will be useful to look at the content of Latex file (internal) after the expansion is made but right before the file is compiled to pdf. This can help in debugging and in many other cases.
Is there an option to do this? A small example will help explain what I mean.
Given this latex file
\documentclass{article}
\usepackage{luacode}
\begin{document}
The following is my table
\begin{luacode}
i=6
j=8
tex.print("\\begin{tabular}{|l|l|}\\hline")
tex.print(i.."&"..j)
tex.print("\\\\ \\hline")
tex.print("\\end{tabular}")
\end{luacode}
\end{document}
Compiling this gives the pdf file:
What I'd like to now see is the Latex file that would resulted after the Lua code expansion, which should be something as follows
\documentclass{article}
\usepackage{luacode}
\begin{document}
The following is my table
\begin{tabular}{|l|l|}\hline
6 & 8 \\\hline
\end{tabular}
\end{document}
I could not find an option to do this so far.
TL 2015
Update
Another example to make clear what is being asked here. I'd like to see not only the latex code that was generated from the lua bits of code, but the full Latex document that would result after all the expansion of all lua code in the original Latex. But this has to be done without modifying the original Latex document itself.
Assuming there is this virtual pipeline:
Latex file -> Lua code expand -> Updated Latex (internal)-> lualatex ->pdf
I'd like to get a copy of the full latex code/file just after all the lua code expanded. Here is another example. Given this Latex file input:
\documentclass{article}
\usepackage{luacode}
\begin{document}
The following is my table
\begin{luacode*}
i=6
j=8
tex.print("\\begin{tabular}{|l|l|}\\hline")
tex.print(i.."&"..j)
tex.print("\\\\ \\hline")
tex.print("\\end{tabular}")
\end{luacode*}
Our annual budget for the company is \luaexec{tex.print(200*15^3)} dollars as
shown in this list of items
\begin{luacode*}
tex.print("\\begin{itemize}")
for i=1,5 do
tex.print("\\item "..i^2)
end
tex.print("\\end{itemize}")
\end{luacode*}
And so on.
\end{document}
The PDF is
I'd like to get a copy of the following latex file, which has all the Lua code expanded and gone and only the Latex code is left in its place. This file can go to a temporary file, or anywhere, as long as it is the complete Latex file as shown and not bits and pieces. This would be very useful in debugging when there is lots of Lua code in different places in the original Latex file.
\documentclass{article}
\usepackage{luacode}
\begin{document}
The following is my table
\begin{tabular}{|l|l|}\hline
6 & 8 \\\hline
\end{tabular}
Our annual budget for the company is 675000 dollars as
shown in this list of items
\begin{itemize}
\item 1
\item 4
\item 9
\item 16
\item 25
\end{itemize}
and so on
\end{document}
I hope now the question is even more clear :)
luacode
with\directlua{...}
. If you could show this is done and how to view the generated Latex that will help. I do not want to have external lua files. I want the lua code to be inside the Latex file itself as shown. I am still learning lua and find all these different environments very confusing so far. Thanks