The code


\usetikzlibrary{hobby, knots}


  \begin{tikzpicture}[rotate=90,scale=3]% remove 'scale=3' to get the error
    \begin{knot}[flip crossing=1,consider self intersections=true,
      ignore endpoint intersections=false]
      \strand (0,1) to[out=-90,in=90](0,0.5) to [out=270, in=270]
        (0.3,0.5)to [out=90, in=90]
        (0,0.5)to[out=-90,in=90] (0,0);


uses the knots package to produce:

enter image description here

(It's rotated only to take up less space.) This is what I want, except that it is too large. Unfortunately, removing the scale=3 from the tikzpicture environment gives the error:

! Undefined control sequence. \LaTeX3 error: Erroneous variable \knotnextfilament6 used! l.14 \end{knot}x

Does anyone have any idea why this error occurs and how to fix it to get a smaller twist? (Of course, I could just rescale the image using \scalebox but this hack does not really solve the problem.)

In some sense the error is caused by the ignore endpoint intersections=false because without this the code compiles producing:

enter image description here

This does not solve my problem, however, as the crossing has been replaced by in intersection

The post Crossings in tikz knots package shows several ways to draw the twist using the knots package, so I can draw the diagram that I want, however, I still do not understand why the code above does not work when scale=3 is removed.

  • 1
    Not an answer but a workaround: moving the control points slightly away from each other and using an edge for the stretch that is in the foreground anyway avoids the error: \strand (0,1) to[out=-90,in=90](0,0.55) to [out=-90, in=-90] (0.3,0.5)to [out=90, in=90] (0,0.45)edge(0,0);
    – user255043
    Commented Oct 24, 2021 at 1:00
  • Thanks! Perhaps this is the answer: I just need to use slightly different points. This might explain why the error goes away if I remove the ignore endpoint intersections=false. Commented Oct 24, 2021 at 1:12
  • The source of the problem is that the crossing is exactly where one segment ends and another begins. I suspect it is miscounting the number of crossings, I'll investigate to see what's going on. In the meantime, there are various possible solutions. How exact is your picture? Must the path follow exactly what you have specified, or can it vary slightly? Commented Oct 24, 2021 at 8:44
  • @AndrewStacey Thanks Andrew. The picture can vary slightly -- I'm just drawing Reidemeister moves as, as mentioned above, your post tex.stackexchange.com/questions/570111/… gives ways of doing this. Btw, I'm growing to love your knots and spytj3 packages as I get more used to using them. Commented Oct 25, 2021 at 9:13
  • 1
    I'm not sure I have a clear picture and I wrote all three of those! The main two are knots and spath3; the hobby package is for designing the curves in the first place and the others are for rendering the intersections as knots. They work in different ways, knots overdraws while spath3 cuts. I'd say that neither is superior, but sometimes one is more appropriate than the other. If you want to illustrate 3-colouring, for example, then spath3 is better. If your paths are decorated, often the overdrawing method is better. Commented Oct 26, 2021 at 9:28

1 Answer 1


Let me sum up the comments into an "answer".

There were really two issues with the code. The first is that there was a bug in the package, which is now squished in the version on github.

The second is that the crossing point is actually where several segments of the strand start or end. This leads to it being found more times than is warranted. In short, when consider self intersections is set then the path is split up into segments (which themselves might be further split as bézier curves can self-intersect) to find the self-intersection points. In this case, even without the further split then the crossing point is found four times: between segments 1 and 3, 1 and 4, 2 and 3, 2 and 4 (the package does recognise that the intersection between, say, segments 1 and 2 is spurious).

The simplest fix for this is to adjust the end points of the segments so that the crossing does not occur at such an end point. Experimenting shows that adjusting them to (0,0.501) and (0,0.499) is sufficient.

The reason why the scale affects things is because by the time the knots library gets to work then all coordinates have been converted into dimensions so the tolerances and tests are all in terms of pt.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .