The minimal code below demonstrates the problem. The code as it is does not give the desired output. I assume the \x-\y
is not being correctly handled. I have tried including braces, brackets, but to no avail.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\connection}[4][]{\draw[{#1}] (#2#3)--([yshift={#4cm}]#2#3) --([yshift={#4cm}]#2#3-|#3#2)--(#2#3-|#3#2)}
\begin{document}
\begin{tikzpicture}
% create the coordinates
\foreach \Lletter/\l in {A/0,B/1,C/2}
{\foreach \Rletter/\r in {A/0,B/1,C/2}
{\coordinate (\Lletter\Rletter) at ({\l+\r/10},0);}
}
% create the paths
\foreach \L/\x in {A/5}
{\foreach \R/\y in {A/0,B/1,C/2}
{\connection{\L}{\R}{\x-\y};}
}
% this is the desired result
% \connection{A}{A}{5};
% \connection{A}{B}{4};
% \connection{A}{C}{3};
\end{tikzpicture}
\end{document}
\foreach \L/\x in {A/5} {\foreach \R/\y in {A/0,B/1,C/2} {\pgfmathsetmacro\result{\x-\y} \connection{\L}{\R}{\result};} }
tikzpicture
spaces and empty lines usually don't matter (exception before the environment's optional argument, see Q41567). A nullfont is installed.#4
gets replaced by\x-\y
and thus:\x-\y cm
becomes\x pt - \y cm
. Use either(#4)*1cm
or, staying in the local coordinate system:shift=(up:{#4})
.