This question led to a new package:
(Technically, this question led to a subpackage of the
spath3package provides some foundations on which a TikZ library
knotswas built and the TikZ library is bundled with the
See also the blog post: How can I draw a knot in TeX?
I need to use TikZ to draw some knot/braid diagrams. These will be built from families of curves, which appear to cross over each other in places. At each crossing, it needs to be obvious which line is going over which, and so I'm using the TikZ double functionality, to draw a fat white line underneath the thin black lines representing the curves. That way, if I draw 'on top' line segments after 'on the bottom' line segments, I'll get the correct effect.
But still, drawing these diagrams is a pain. In particular, I might have two continuous curves in one diagram, with the first curve going on top of the second in some places, and beneath it in others. So I can't simply draw the 'lower' curve first: I have to draw different segments of the curves individually.
For ease of programming, I'd really like to have all the code for each curve together. One way I could achieve this is if I could change the layer independently for each segment of a multi-point path command. The idea would be something like this:
\draw (1) to [layer=middlelayer] (2) to [layer=toplayer] (3) to [layer=bottomlayer] (4);
Is this possible? Or is there a better way to achieve the effect I want?
Unfortunately, my diagrams need to be much more freeform than those produced by Andrew Stacey's braid package. They're not of the form of generators of the braid group stacked neatly on top of one another. Here's an example of the sort of thing I need: