|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- Loaded by:
-- (find-dn5 "tests/testpgf.tex")
print("hello")
pgfshapes = {}
pgfbody = function ()
local outstr = ""
local printf = function (...) outstr = outstr..format(...) end
local mark = function (noden) nodes[noden].used = true end
local gettag = function (node) return node.tag or ":"..node.noden end
for _,ar in ipairs(arrows) do
mark(ar.from)
mark(ar.to)
end
for _,node in ipairs(nodes) do
if node.used then
local tag, TeX = gettag(node), gettag(node)
local px, py = (node.x - 100) / 20, (node.y - 100) / -20
printf(" \\node (%s) at (%s,%s) {%s};\n", tag, px, py, TeX)
end
end
for _,ar in ipairs(arrows) do
local shape = ar.shape
local tagfrom, tagto = gettag(nodes[ar.from]), gettag(nodes[ar.to])
printf(" \\draw [%s] (%s) to node {} (%s);\n", shape, tagfrom, tagto)
end
return outstr
end
pgfdef = function (name, hyperlink)
name = name or diagramname
hyperlink = hyperlink or " % no hyperlink yet"
return format("\\defpgfdiag{%s}{%s\n%s}", name, hyperlink, pgfbody())
end
-- (find-dn5 "diagforth.lua" "enddiagram")
forths["endpgfdiagram"] = function ()
output(pgfdef(getword() or diagramname))
end
output [[
\def\defpgfdiag#1#2{\expandafter\def\csname diag-#1\endcsname
{\begin{tikzpicture}#2\end{tikzpicture}}}
]]