I am trying to have LuaLatex automate some LaTex.
For example if I write :
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tcolorbox,graphicx,tikz}
\usepackage[paperwidth=120pt, paperheight=120pt, margin=10pt]{geometry}
\begin{document}
\begin{tcolorbox}[boxsep=0pt, left=0pt, right=0pt, top=0pt, bottom=0pt, sharpish corners, opacityframe=0, opacityback=0, boxrule=0pt]
\begin{tikzpicture}[x=1pt, y=1pt]
\draw[line width=0mm, white] (0,0) -- (100,0) -- (100,100) -- (0, 100);
\draw[xshift=50, yshift=50] node[draw, anchor=north west]{AAA};
\end{tikzpicture}
\end{tcolorbox}
\end{document}
my build works.
Now I would like to make Lua write this line :
\draw[xshift=50, yshift=50] node[draw, anchor=north west]{AAA};
If I write :
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tcolorbox,graphicx,tikz}
\directlua{dofile("placeTextNode.lua")}
\newcommand*{\textNode}{%
\directlua{tex.write(textNode())}%
}
\usepackage[paperwidth=120pt, paperheight=120pt, margin=10pt]{geometry}
\begin{document}
\begin{tcolorbox}[boxsep=0pt, left=0pt, right=0pt, top=0pt, bottom=0pt, sharpish corners, opacityframe=0, opacityback=0, boxrule=0pt]
\begin{tikzpicture}[x=1pt, y=1pt]
\draw[line width=0mm, white] (0,0) -- (100,0) -- (100,100) -- (0, 100);
\textNode
\end{tikzpicture}
\end{tcolorbox}
\end{document}
and
function textNode()
return "\draw[xshift=50, yshift=50] node[draw, anchor=north west]{AAA};"
end
I have an error message saying :
invalid escape sequence near '"\d'
If I write :
function textNode()
return "\\draw[xshift=50, yshift=50] node[draw, anchor=north west]{AAA};"
end
having added a \ in front of \draw, I don't have the error anymore, but the node does not appear.
Do you have an idea of what I should write in Lua ?
Thank you.
tex.sprint
.