In this answer I saw that we can use [<new pgf key>/.code={...}, <new pgf key>]
to smuggle in some code into the construction of a TikZ path. This approach works if all coordinates have a label because the standard arrays are comma-separated. I was thinking that the listofitems
package could be used to process lists of coordinates without labels by changing the separator. However, the below code throws an error during path construction and I don't quite understand why.
The polyline simply serves as a means of illustration in an MWE. I am trying to understand more generally how to iterate over lists from the listofitems
package in a Tikz environment.
\documentclass{standalone}
\usepackage{tikz, listofitems}
\usetikzlibrary{calc}
\newcommand{\polyline}[2][,]{
\setsepchar{#1}
\readlist*\inputlist{#2}
[create coords/.code={
\foreach \i in {1, ..., \inputlistlen} {
\coordinate (coord\i) at (\inputlist[\i]);
}
}, create coords]
(coord1)
\foreach \i in {2, ..., \inputlistlen} {
-- (coord\i)
}
}
\begin{document}
\begin{tikzpicture}
\draw \polyline[:]{0,0: 1,0};
\end{tikzpicture}
\end{document}