# Define optional distances to use with to path of TikZ

I would like in the code below to have the possibility to give optional arguments for the shift distances. What is the best way to do that ?

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{
aczigzag/.style = {
to path = {
([xshift = 0mm] \tikztostart)
|- ([xshift = 3mm, yshift = 5mm] \tikztotarget.north)
-- ([xshift = 3mm] \tikztotarget.north)
}
},
}
\begin{document}

\begin{tikzpicture}
\node
(input) {INPUT};

\node[right] at ($(input) + (2.5,0)$)
(right) {right};

\node[below of = input, node distance = 4cm]
(output) {OUPUT};

\path[draw] (right) to[aczigzag] (output);
\end{tikzpicture}

\end{document}


This is what pgf keys are for. You can store the distances in such keys, and modify them in a path.

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{
aczigzag/.style = {
to path = {
([xshift = 0mm] \tikztostart)
|- ([xshift = \pgfkeysvalueof{/tikz/aczigzag/x}, yshift = \pgfkeysvalueof{/tikz/aczigzag/y}] \tikztotarget.north)
-- ([xshift = \pgfkeysvalueof{/tikz/aczigzag/x}] \tikztotarget.north)
}
},aczigzag/.cd,x/.initial=3mm,y/.initial=5mm}

\begin{document}

\begin{tikzpicture}
\node
(input) {INPUT};

\node[right] at ($(input) + (2.5,0)$)
(right) {right};

\node[below of = input, node distance = 4cm]
(output) {OUPUT};

\path[draw] (right) to[aczigzag] (output);
\end{tikzpicture}

\begin{tikzpicture}
\node
(input) {INPUT};

\node[right] at ($(input) + (2.5,0)$)
(right) {right};

\node[below of = input, node distance = 4cm]
(output) {OUPUT};

\path[draw,aczigzag/x=5mm,aczigzag/y=12mm] (right) to[aczigzag] (output);
\end{tikzpicture}

\end{document}


Here you could equally well use

\path[draw] (right) to[aczigzag,aczigzag/x=5mm,aczigzag/y=12mm] (output);


It might even more convenient to let the argument of the style make these changes. Then

 \path[draw] (right) to[aczigzag={x=5mm,y=12mm}] (output);


will change the horizontal distance to 5mm and the vertical one to 12mm.

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{
aczigzag/.style = {/utils/exec=\tikzset{aczigzag/.cd,#1},
to path = {
([xshift = 0mm] \tikztostart)
|- ([xshift = \pgfkeysvalueof{/tikz/aczigzag/x}, yshift = \pgfkeysvalueof{/tikz/aczigzag/y}] \tikztotarget.north)
-- ([xshift = \pgfkeysvalueof{/tikz/aczigzag/x}] \tikztotarget.north)
}
},aczigzag/.cd,x/.initial=3mm,y/.initial=5mm}

\begin{document}

\begin{tikzpicture}
\node
(input) {INPUT};

\node[right] at ($(input) + (2.5,0)$)
(right) {right};

\node[below of = input, node distance = 4cm]
(output) {OUPUT};

\path[draw] (right) to[aczigzag] (output);
\end{tikzpicture}

\begin{tikzpicture}
\node
(input) {INPUT};

\node[right] at ($(input) + (2.5,0)$)
(right) {right};

\node[below of = input, node distance = 4cm]
(output) {OUPUT};

\path[draw] (right) to[aczigzag={x=5mm,y=12mm}] (output);
\end{tikzpicture}
\end{document}


• @Zarko Did you read the question? (I am not sure if I understand it but according to my understanding the OP only wants the possibility to change the distances on the spot, not add a new syntax.)
– user194703
Oct 22 '19 at 17:45
• i read, but, well, i will delete my comment. Oct 22 '19 at 18:01