0

I've found this example of using lua node. To output Va they've:

\documentclass{minimal}
\begin{document}
\directlua{
        local g1 = node.new("glyph")
        g1.font = font.current()
        g1.lang = tex.language
        g1.char = 86

        local g2 = node.new("glyph")
        g2.font = font.current()
        g2.lang = tex.language
        g2.char = 97

        g1.next = g2
        g2.prev = g1

        local hbox = node.hpack(g1)
        local vbox = node.vpack(hbox)
        node.write(vbox)
}
\end{document}

Can we draw tikz node like this:

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
    \tikz[node distance = 3cm]{
        \node (a) at (0,0) [draw, circle] {A};
        \node (b) [below of = a, draw, circle] {B};
        \draw [<->] (a) to (b);
    }
\end{document}

to produce this:

enter image description here

using lua node?

1
  • 7
    despite the similarity in name there is no connection between nodes in lua and in tikz. It would be a lot (thousands of lines I guess) of work to recreate the tikz logic in lua, so you are almost certainly going to just want to print the tex string from lua and interpret it as tex. Commented Jun 5, 2019 at 12:46

1 Answer 1

1

Like this?

\documentclass{minimal}
\usepackage{tikz}
\usepackage{luacode}

\begin{document}
\luaexec{
tp=tex.print
tp("\\begin{tikzpicture}")
tp("\\node (a) at (0,0) [draw, circle] {A};")
tp("\\node (b) [below of = a, draw, circle,node distance=3cm] {B};")
tp("\\draw [<->] (a) to (b);")
tp("\\end{tikzpicture}")
}

\end{document}

enter image description here

1
  • I think those tex.print and tex.sprint are for formatting plaint text, tables, etc.. These works really well for those purposes BUT for tikz node I think lua node is a good candidate.
    – user189833
    Commented Jun 5, 2019 at 12:08

You must log in to answer this question.