1

I was reading this article on drawing with lua and tikz. On page 45 of the article, the author's given an example code demonstrating the way to do so. Here's his lua code:

-- File SimpleDemo.lua
local MyAlgorithmClass = {}
function MyAlgorithmClass:run()
    local g = self.digraph
    local alpha = (2 * math.pi) / #g.vertices
    local radius = g.options.radius
    for i,vertex in ipairs(g.vertices) do
        vertex.pos.x = radius * math.cos(i * alpha)
        vertex.pos.y = radius * math.sin(i * alpha)
    end
end

-- "Publish" the algorithm
local graph_drawing_framework = require "pgf.gd.interface.InterfaceToAlgorithms"
graph_drawing_framework.declare{
    key = "simple demo layout",
    algorithm = MyAlgorithmClass,
    preconditions = { connected = true }
}

and on the following pages he's added four tikz{…} code to show the output. 3rd example gives me the following error:

! Package pgfkeys Error: I do not know the key '/tikz/stub' and I am going to ignore it. Perhaps you misspelled it.

Here's my tex document with the 3rd example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs, graphdrawing, mindmap}
\usegdlibrary{SimpleDemo}

\begin{document}
    \tikz \graph [ simple demo layout, radius=1cm]{
        a --[orient=right] b -- c -- a;
        d -- e;
        f -- g -- h -- d --[stub,red] f;
        e --[stub, red] g;
    };
\end{document}

graphs, graphdrawing, mindmap libraries resolved issues for other 3 examples. Which one do I have to add to resolve the issue of 3rd example?

  • 1
    Does the problem also occur when you put the extension in the require, i.e., \directlua{require("SimpleDemo.lua")}? – Marijn Jun 3 at 11:04
  • 1
    Could be a custom style I suppose. If you add a placeholder like \tikzset{stub/.style={{}} does it work as expected? – Torbjørn T. Jun 3 at 15:51
  • 1
    Sorry, brace error. Remove one opening brace after style. Or just remove stub from the code, that’s just as easy for testing. – Torbjørn T. Jun 3 at 15:58
  • 1
    Was just opening it. (It's not an article, but a set of slides for a presentation.) You're sort of asking the wrong question though. You've done the Lua part, which does the positioning of the nodes, that works, and isn't really relevant for the problem, I think. What you want to know is how to define a TikZ style stub which changes how a path between two nodes is drawn in a specific manner. Looks like the middle part of the path is cut out. – Torbjørn T. Jun 3 at 16:11
4

Below is one possible definition of a stub style which does something similar to what is seen in the slides you refer to. I used one of the built-in positioning algorithms, but that shouldn't matter for the line style. Slide 46 indicates how you can change the style of the nodes.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs, graphdrawing, calc} % <-- added the calc library
\usegdlibrary{circular}
\tikzset{stub/.style={
  to path={%
      (\tikztostart) -- ($(\tikztostart)!0.3!(\tikztotarget)$)
      ($(\tikztostart)!0.7!(\tikztotarget)$) -- (\tikztotarget)
      }
}}
\begin{document}
    \tikz \graph [ simple necklace layout, radius=1cm, nodes={circle,draw=blue!80,fill=blue!10}]{
        d -- e;
        f -- g -- h -- d --[stub,red] f;
        e --[stub, red] g;
    };
\end{document}
  • That's what I've done when I was experimenting flowcharts. I've seen one doing like those /.style … on YouTube! Can we set these styles in lua? – Emon Haque Jun 3 at 16:31
  • @EmonHaque Why do you want that? Such a style contains TikZ-options, using TikZ syntax. – Torbjørn T. Jun 3 at 16:34
  • Someone wrote that there are other libraries like kpse, node, etc. besides tex e.g. tex.print. I thought there are something like node.draw, node.shape, etc. to help us avoid those tex syntax. Are there any actually? – Emon Haque Jun 3 at 16:39
  • 1
    @EmonHaque No idea. – Torbjørn T. Jun 3 at 16:40
  • I've found an example of using lua node and posted this question – Emon Haque Jun 5 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.