I got a weird bug when I want to define and name a list of coordinates

\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> 

The manual expansion of the list works. I can also use foreach with the following syntax which seems to me less natural

      \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.


\usetikzlibrary{scopes, arrows, decorations.markings, calc, intersections}


    \foreach \pos/\name in {{(1,0)}/a, {(0,1)}/b}
      \coordinate (\name) at \pos;
    \draw (a)--(b);

  • 6
    Swap the variables: \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. Sep 17 at 17:07
  • 2
    Please provide complete code to reproduce the error you show. (Generally - I think you have an answer here already.)
    – cfr
    Sep 18 at 5:04
  • 1
    your code works well! Please update your TeX distribution.
    – Black Mild
    Sep 18 at 6:03
  • 1
    Ah, I think I've missed something with my first comment – didn't notice the braces in the first code. But @BlackMild is correct. With an uptodate TikZ, this shouldn't be a problem. Anyway, a workaround might be \coordinate[at/.expanded=\pos](\name);. Sep 18 at 21:10


You must log in to answer this question.

Browse other questions tagged .