I have this piece of code working :
Tex file :
\documentclass{article}
\usepackage{tcolorbox,graphicx,tikz}
\directlua{dofile("placeTextNode.lua")}
\newcommand*{\textNode}{%
\directlua{tex.print(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}
placeTextNode.lua file:
function textNode()
return "\\draw[xshift=50, yshift=50] node[draw, anchor=north west]{AAA};"
end
Now, if I want to take a string and print it in place of AAA, all the various attempts I did in the past 3/4 days have failed.
I took inspiration from :
What I'd like to do is to write instead of \textNode
\textNode{"some
multiline
text"}
and have my text displayed in my tikz node.
One of my multiple attempts, even before trying to go multiline, was the following :
TeX file :
\documentclass{article}
\usepackage{tcolorbox,graphicx,tikz}
\directlua{dofile("placeTextNode.lua")}
\newcommand*{\textNode[1]}{%
\directlua{tex.print(textNode(\luastring{#1}))}%
}
\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{"AAA"}
\end{tikzpicture}
\end{tcolorbox}
\end{document}
placeTextNode.lua :
function textNode(t)
return "\\draw[xshift=50, yshift=50] node[draw, anchor=north west]{" .. t .. "};"
end
I get the following error :
/home/new command.tex:14: Undefined control sequence.
\\textNode ...tlua {tex.print(textNode(\luastring
{#1}))}
l.14 \textNode{
"AAA"}
placeTextNode.lua:2: attempt to concatenate a table value (local 't')
stack traceback:
placeTextNode.lua:2: in function 'textNode'
[\directlua]:1: in main chunk.
\\textNode ...ex.print(textNode(\luastring {#1}))}
l.14 \textNode{
"AAA"}