TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to compile this code (using PDFLaTeX)

\newcommand{\coorpente}[4]{\coordinate(#1) at ($(#2)+({#4/(sqrt((#3*#3)+1))},{#3*#4/(sqrt((#3*#3)+1))})$);}
\newcommand{\inter}[3]{\path [name intersections={of=#2 and #3,by=#1}];}
\newcommand{\linenp}[4]{\path[name path=#1,#4](#2)--(#3);}

\draw[help lines,step=1,line width=1.5pt,black!50] (0,-1) grid (10,6);
\draw[help lines,step=.2] (0,-1) grid (10,6);
\coordinate(ptad1) at (0,0) ;
\coordinate(ptad2) at (10,0) ;
\coordinate(ptg1) at (0.5,-1) ;
\coordinate(ptg2) at (10,5) ;

\linenp{ad}{ptad1}{ptad2}{draw,yellow!80!black,line width=5pt}
\linenp{adb}{ptad1}{ptad2}{draw,line width=1.5pt}
\draw[cyan,line width=4pt,name path=gamma] (ptg1)to [out=90,in=195] (ptg2);
\linenp{adb}{ptad1}{ptad2}{draw,line width=1.5pt}
\draw[line width=1.5pt,name path=gammab] (ptg1)to [out=90,in=195] (ptg2);

\def\pente {3.5}
\coordinate(iterdb1) at (10,3);
\foreach \nuuu/\nddd in{1/2,2/3,3/4,4/5,5/6}

\draw (ptad1)--(ptg1);


I obtain the weird error message:

! Undefined control sequence.
\tikz@intersect@namedpaths ...@path@name@itd\nddd 
                                              \endcsname {\pgfsyssoftpat...
l.165 \draw (ptad1)--(ptg1);

When I remove or comment the line containing \draw (ptad1)--(ptg1);, I don't obtain any error. I think that the error is due to the "foreach" command: when I suppress the \foreach command and I write the command manually (for each step of the foreach command), I don't have any error.

Do you have an idea about the origin of this error?

share|improve this question
Please reduce your code to something more readable, i.e. a MWE. Typically this lets you discover your own mistakes. But the error stems from \foreach not expanding the arguments of the macros, thus it searches for a point named iteru\nuuu and not iteru0, iteru1 etc. There are several similar questions on this site. And welcome! – zeroth Jul 12 '13 at 12:29
possible duplicate of Draw a path between many nodes using foreach – zeroth Jul 12 '13 at 12:31
I get several errors before the Undefined control sequence one; please, fix the code. – egreg Jul 12 '13 at 12:36
@zeroth both points (ptad1) and (ptg1) don't depend of the content of the \foreach command and without the \draw (ptad1) -- (ptg1). So I don't understand why tikz crashes in this case. I will try to simplify my code but currently the easiest solution is to suppress the \foreachcommand. – Guuk Jul 12 '13 at 12:40
@egreg I have fixed one mistake. The code is also available at the following url: writelatex.com/268046xmrpwj – Guuk Jul 12 '13 at 12:48
up vote 3 down vote accepted

Change your macros into

    \noexpand\coordinate(#1) at
    \noexpand\path [name intersections={of=#2 and #3,by=#1}];}\x}
    \noexpand\path[name path=#1,#4](#2)--(#3);}\x}

In this way \nuuu and \nddd will be expanded before the \coordinate and \path commands start their work.

enter image description here

share|improve this answer
Your solution works perfectly. Thank you!! – Guuk Jul 12 '13 at 13:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.