In TikZ, I would like to build a macro \drawEdges
which for a given list of points produces code that runs through all pairs of two subsequent points, and runs the \drawEdge
macro for them. For example,
\drawEdges{(0, 0), (1, 0), (1, 1), (0, 1)}
should expand to
\drawEdge{(0, 0)}{(1, 0)}
\drawEdge{(1, 0)}{(1, 1)}
\drawEdge{(1, 1)}{(0, 1)}
The purpose is to cut down on the verbosity of repeating the \drawEdge
macro on every pair. How can this be done?
Bonus points if you can also provide a cyclic variant where the expansion includes the pair involving the last and the first point:
\drawEdge{(0, 1)}{(0, 0)}
Edit
In my specific case, the \drawEdge
macro looks something like this:
\newcommand{\drawEdge}[2]{
\draw[edgeStyle, line width = 1pt] #1 -- #2;
\draw[line width = 0.33pt, draw=white] #1 -- #2;
}
Here edgeStyle
includes a decorator to add a custom-styled arrow tip on a position other than the end, and the latter line hollows out the edge. I would also accept a solution which refactors the process into two separate passes
\newcommand{\drawEdgeFirst}[2]{
\draw[edgeStyle, line width = 1pt] #1 -- #2;
}
\newcommand{\drawEdgeSecond}[2]{
\draw[line width = 0.33pt, draw=white] #1 -- #2;
}
with corresponding \drawEdgesFirst
and \drawEdgesSecond
. Then we could do
\newcommand{\drawEdges}[1]{
\drawEdgesFirst{#1}
\drawEdgesSecond{#1}
}
Edit 2
Here's an example of the things I'm drawing. Note that I need exact control of how the hollowing of the edge is done (i.e. its width), so that it connects properly with the arrow tips.
Edit 3
Just realized the hollow edges can be drawn using
\newcommand{\drawEdge}[2] {
\draw[edgeStyle, line width = 0.335pt, double distance = 0.33pt] #1 -- #2;
}
where the hollowing distance can be controlled precisely.