Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap node name in \tikz@pp@name when passed to pgf gd #1119

Merged
merged 10 commits into from
Jan 11, 2022
53 changes: 23 additions & 30 deletions testfiles-gd/support/pgfgd-debug.lua
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
local InterfaceToDisplay = pgf.gd.interface.InterfaceToDisplay
local InterfaceToDisplay = assert(pgf.gd.interface.InterfaceToDisplay)

--- Wrap InterfaceToDisplay functions to prepend debugging code
local createVertex = InterfaceToDisplay.createVertex
-- here `...` is a vararg expression,
-- see https://www.lua.org/manual/5.3/manual.html#3.4.11
function InterfaceToDisplay.createVertex(...)
local name = ...
debug("Create vertex '%s'", name)
createVertex(...)
-- helper
local function typeout(...)
texio.write_nl(17, string.format(...))
end

local createEdge = InterfaceToDisplay.createEdge
function InterfaceToDisplay.createEdge(...)
local tail, head, direction = ...
debug("Create edge '%s' from '%s' to '%s'", direction, tail, head)
createEdge(...)
local createVertex = assert(InterfaceToDisplay.createVertex)
function InterfaceToDisplay.createVertex(name, ...)
typeout("Create vertex '%s'", name)
createVertex(name, ...)
end

-- this generates too many debugging lines
-- local createEvent = InterfaceToDisplay.createEvent
-- function InterfaceToDisplay.createEvent(...)
-- local kind = ...
-- debug("Create event '%s'", kind)
-- return createEvent(...)
-- end

local addToVertexOptions = InterfaceToDisplay.addToVertexOptions
function InterfaceToDisplay.addToVertexOptions(...)
local name = ...
debug("Add options to vertex '%s'", name)
addToVertexOptions(...)
local createEdge = assert(InterfaceToDisplay.createEdge)
function InterfaceToDisplay.createEdge(tail, head, direction, ...)
typeout("Create edge '%s' from '%s' to '%s'", direction, tail, head)
createEdge(tail, head, direction, ...)
end

--[[ this generates too many debugging lines
local createEvent = assert(InterfaceToDisplay.createEvent)
function InterfaceToDisplay.createEvent(kind, ...)
typeout("Create event '%s'", kind)
return createEvent(kind, ...)
end
--]]

-- helper
function debug(format_str, ...)
tex.sprint(string.format("\\pgfgdluainfo{" .. format_str .. "}", ...))
local addToVertexOptions = assert(InterfaceToDisplay.addToVertexOptions)
function InterfaceToDisplay.addToVertexOptions(name, ...)
typeout("Add options to vertex '%s'", name)
addToVertexOptions(name, ...)
end
17 changes: 2 additions & 15 deletions testfiles-gd/support/pgfgd-regression-test.tex
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
\input regression-test.tex

\catcode`\@=11 % \makeatletter

% this macro should be used _after_ graphdrawing library is loaded
\def\pgfgdBeforeBeginDocument{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the test fails with

pgfgd-debug.lua:1: attempt to index a nil value (global 'pgf')

because when pgfgd-debug.lua is read in, the whole pgf is not loaded yet. This explains why the \pgfgdBeforeBeginDocument was introduced (and used after package loading and just before \begin{document}). For latex format only, \AtBeginDocument suffices but I more or less want(ed) a portable solution (not a strong opinion).

% redirect error
\def\pgfutil@packageerror#1#2#3{\immediate\write17{Package #1 Error: #2.}}
muzimuzhi marked this conversation as resolved.
Show resolved Hide resolved

% new message type "info"
\def\pgftest@genericinfo#1#2{\immediate\write17{#1 Info: #2.}}
\def\pgfgdluainfo{\pgftest@genericinfo{Gd Lua layer}}

% insert debugging code
\ifdefined\directlua
\directlua{dofile('pgfgd-debug.lua')}
}

\catcode`\@=12 % \makeatother
\fi