I got a weird bug when I want to define and name a list of coordinates
\tikz{
\foreach \name/\pos in {{a/(1,0)}, {b/(0,1)}}
\coordinate (\name) at \pos ;
}
The error is
{/usr/local/texlive/2023/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] [2] [3]
Runaway argument?
\pos ;\pgffor@endhook \ifx \pgffor@assign@after@code \pgfutil@empty \ETC.
! Paragraph ended before \tikz@@coordinate@@at was complete.
<to be read again>
\par
l.44
The manual expansion of the list works. I can also use foreach with the following syntax which seems to me less natural
\tikz{
\foreach \name/\pos in {{a/(1,0)}, {b/(0,1)}}
\draw \pos node (\name) {\name};
\draw (a)--(b);
}
A full example with swapped variables does not work either.
\documentclass[tikz,border=5pt]{standalone}
\usepackage[utf8]{inputenc}
\usetikzlibrary{scopes, arrows, decorations.markings, calc, intersections}
\begin{document}
\begin{tikzpicture}
\foreach \pos/\name in {{(1,0)}/a, {(0,1)}/b}
\coordinate (\name) at \pos;
\draw (a)--(b);
\end{tikzpicture}
\end{document}
\pos/\name in {(1,0)/a, …}
. The,
in the coordinate is tripping you up. If the entry starts with(
special parsing is activated. Alternatively, put the coordinate in braces, i.e.a/{(1,0)}
. Your workaround does similar things but on a broader scope.\coordinate[at/.expanded=\pos](\name);
.