# Inject LaTeX code 1:1 with LuaLaTeX

I would like to automate the creation of some beamer slides using LuaLaTeX. These are my first steps with LuaLaTeX so please excuse my ignorance.

\documentclass{beamer}

\begin{document}

\directlua{
for i=0, 5 do
tex.print("\unexpanded{\\begin{frame}}")
tex.print("Math: $x_{" .. i .. "}$")
tex.print("\unexpanded{\\end{frame}}")
end
}

\end{document}


The example compiles and gives the expected result; 6 frames with x_0,1,2,3,5 on it.

I'm a bit unhappy about the additional \unexpands and \s before \begin and \end.

Is there a dedicated LuaTeX command that just inserts latex code 1:1 to the document?

-
You might find Which Lua environment should I use with LuaTeX (LuaLaTeX)? useful. – Joseph Wright Sep 9 '12 at 12:50

a short \frame{..} is possible

\documentclass{beamer}

\begin{document}

\directlua{
for i=0, 5 do
tex.print("\string\\frame{")
tex.print("Math: $x_{" .. i .. "}$")
tex.print("}")
end
}

\end{document}

-