5

I want to use the catchfile package to import the data of nodes from external file ver.dat as following:

\documentclass[tikz]{standalone}
\usepackage{catchfile}

\CatchFileDef{\myver}{ver.dat}{}

\begin{document}
\begin{tikzpicture}
  \foreach [count=\i] \coord in {\myver}{
     \node (p\i) at \coord {\i};
  }
\end{tikzpicture}
\end{document}

where the file ver.dat is (1,0),(0,1).

But the above code doesn't work, what's wrong?

user25607
  • 427
  • 1
    The main problem here is that \myver is not expanded; you can see this by inserting \show\coord inside the \foreach loop to see what \coord looks like. You need to remove the braces around \myver so it's properly expanded, as suggested in TikZ \foreach loop with macro-defined list. – Werner Sep 26 '14 at 05:37
  • @Werner Thanks! Can you write it down as an answer? – user25607 Sep 26 '14 at 05:48
  • 1
    Essentially it's a duplicate. – Werner Sep 26 '14 at 05:51
  • I worked out that the problem was lack of expansion however even with the hint from @Werner I am able to get the MWE to work, so I'd like to see a full solution. My understanding is that Werner is saying that the \foreach line should be: \foreach [count=\i] \coord in \myver {...} but when I do this \coord is still {(1,0), (0,1)}. What am I doing wrong? –  Sep 26 '14 at 06:31
  • @Andrew: That's exactly right. Are you sure ver.dat contains only (1,0), (0,1) (without the braces {...})? – Werner Sep 26 '14 at 13:51
  • @Werner Thanks, you are right: I must have changed it when I was playing with the question. Cheers. –  Sep 27 '14 at 22:23

0 Answers0