4

When I compile the following snippet

\documentclass[tikz,border=0pt]{standalone}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usetikzlibrary{shapes.misc}
\usegdlibrary{trees}

\begin{document}
\begin{tikzpicture}
  \graph [tree layout]
  {
    A -- { 
      B[draw,cross out]
    } 
  };
\end{tikzpicture}
\end{document}

I get the following error:

ERROR: LuaTeX error ...graphdrawing/lua/pgf/gd/interface/InterfaceToDisplay.lua:213: 

--- TeX said ---
...9/tex/generic/pgf/graphdrawing/lua/pgf/gd/model/Path.lua:704: memoization tab
le filled incorrectly
stack traceback:
    [C]: in function 'assert'
    ...graphdrawing/lua/pgf/gd/interface/InterfaceToDisplay.lua:213: in function 'r
esumeGraphDrawingCoroutine'
    ...graphdrawing/lua/pgf/gd/interface/InterfaceToDisplay.lua:182: in function 'r
unGraphDrawingAlgorithm'
    [string "\directlua "]:1: in main chunk.
\pgfgdendscope ...lay.runGraphDrawingAlgorithm() }
                                                   \endgroup \directlua {pgf...
l.14   }

However, when I leave out the tree laylout argument, it's fine. It seems that I can have either cross out or tree layout, but not both.

Am I doing something wrong here or is this a bug? Is there another way to cross out a node?

1 Answers1

2

According to the SourceForge bug tracker for pgf, this appears to be a bug that was claimed to be fixed at the end of 2015. At the end of 2018, I still have this behavior in MiKTeX... plus another issue, which seems to be another bug (introduce after the OP?). There are two edits you can make to work around these problems, but they aren't exactly pretty.

Issue #1:

Using \usegdlibrary{trees} results in the following error for me on MiKTeX (up-to-date as of 2018-12-13):

! Package pgf Error: Graph drawing library 'trees' not found.

To fix this, this answer from @henri-menke (for TexLive 2018 and posted in Sep 2018) helped me also on MiKTex. Before loading \usegdlibrary{trees}, you basically need to load this Lua code:

\usepackage{luacode}
\begin{luacode}
  function pgf_lookup_and_require(name)
    local sep = '/'
    if string.find(os.getenv('PATH'),';') then
      sep = '\string\\'
    end
    local function lookup(name)
      local sub = name:gsub('%.',sep)
      local find_func = function (name, suffix)
        if resolvers then
          local n = resolvers.findfile (name.."."..suffix, suffix) -- changed
          return (not (n == '')) and n or nil
        else
          return kpse.find_file(name,suffix)
        end
      end
      if find_func(sub, 'lua') then
        require(name)
      elseif find_func(sub, 'clua') then
        collectgarbage('stop')
        require(name)
        collectgarbage('restart')
      else
        return false
      end
      return true
    end
    return
      lookup('pgf.gd.' .. name .. '.library') or
      lookup('pgf.gd.' .. name) or
      lookup(name .. '.library') or
      lookup(name)
  end
\end{luacode}

Issue #2:

Unfortunately, this only allowed me to reach the point of getting the same error as your OP inquired about. To address this, I turn back to the SourceForge bug tracker. There is a post on 2015-08-17 by JP-Ellis who has a workaround which requires you manually changing a file within the pgf package.

That fix involves adding these lines of code to the beginning of the InterfaceToDisplay.createVertex function of the InterfaceToDisplay.lua file:

  -- The path should never be empty, so we create a trivial path in the provided
  -- path is empty.  This occurs with the `coordinate` shape for example.
  if #path == 0 then
    path:appendMoveto(0, 0)
    path:appendClosepath()
  end

Because this can be difficult for those with little or no experience. Let me explain the steps to add this chunk of code.

  1. Locate [YOUR TEX INSTALLATION]/tex/generic/pgf/graphdrawing/lua/pgf/gd/interface folder
  2. Copy and backup the InterfaceToDisplay.lua file
  3. Open InterfaceToDisplay.lua
  4. Locate function InterfaceToDisplay.createVertex(name, shape, path, height, binding_infos, anchors) in the file
  5. Immediately below that line (and above -- Setup) add

    -- The path should never be empty, so we create a trivial path in the provided

    -- path is empty. This occurs with the ``coordinate`` shape for example.

    if #path == 0 then

    path:appendMoveto(0, 0)

    path:appendClosepath()

    end

  6. Save the file (you may need admin rights, depending on the installation)

Result after fixing issues #1 and #2:

Now your updated file from OP will look like this:

\documentclass[tikz,border=0pt]{standalone}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usetikzlibrary{shapes.misc}

%%% ADDED TO FIX ISSUE #1, (NOT ABLE TO FILE TREE GRAPH DRAWING LIBRARY)
\usepackage{luacode}
\begin{luacode}
  function pgf_lookup_and_require(name)
    local sep = '/'
    if string.find(os.getenv('PATH'),';') then
      sep = '\string\\'
    end
    local function lookup(name)
      local sub = name:gsub('%.',sep)
      local find_func = function (name, suffix)
        if resolvers then
          local n = resolvers.findfile (name.."."..suffix, suffix) -- changed
          return (not (n == '')) and n or nil
        else
          return kpse.find_file(name,suffix)
        end
      end
      if find_func(sub, 'lua') then
        require(name)
      elseif find_func(sub, 'clua') then
        collectgarbage('stop')
        require(name)
        collectgarbage('restart')
      else
        return false
      end
      return true
    end
    return
      lookup('pgf.gd.' .. name .. '.library') or
      lookup('pgf.gd.' .. name) or
      lookup(name .. '.library') or
      lookup(name)
  end
\end{luacode}

\usegdlibrary{trees}

\begin{document}
\begin{tikzpicture}
  \graph [tree layout]
  {
    A -- { 
      B[draw,cross out]
    } 
  };
\end{tikzpicture}
\end{document}

And the resulting image looks like this:

Correct cross out inside \graph using tree layout

whatisit
  • 1,870