# Connected to paths

Consider the following

\tikzset{
myline/.style={to path={(\tikztostart) -- (\tikztotarget)}}
}


and

\draw (0,0) edge[myline] (1,1) edge[myline] (2,0);


Now, it seems like \tikztostart does not reset on the second edge command, and remains to be (0,0)?

More specifically, at the second "call" to edge, I thought \tikztostart would have the value (1,1) and not (2,0).

Is there e.g. an alternative control sequence to \tikztostart that would make this work?

Feel free to specify and edit the question title

## Runnable example code:

\documentclass[tikz,margin=10pt]{standalone}
\usepackage{tikz}
\tikzset{
myline/.style={to path={(\tikztostart) -- (\tikztotarget)}}
}
\begin{document}
\begin{tikzpicture}
% With edges
\begin{scope}[shift={(0,1)}]
\draw (0,0) edge[myline] (1,1) edge[myline] (2,0);
\node[below] at (1,0){With \texttt{edge}s};
\end{scope}
% With --, which gives "expected" results
\begin{scope}[shift={(0,-1)}]
\draw (0,0) -- (1,1) -- (2,0);
\node[below] at (1,0){With \texttt{--} (expected)};
\end{scope}
\end{tikzpicture}
\end{document}


Result:

• Use to instead of edge and read page 253 of the manual. – Henri Menke May 28 '19 at 11:12
• @HenriMenke that would work, but then having multiple styles for multiple lines breaks: tex.stackexchange.com/questions/103285/let-operation-in-tikz. I'll read the page in the manual! – Andreas Storvik Strauman May 28 '19 at 11:40
• Here you can find a way to get the desired outcome: every edge/.append code = {% \global\let\currenttarget\tikztotarget % save \tikztotarget in a global variable \pgfkeysalso{append after command={(\currenttarget)}}}. However, if you explain what you are really up to, there might be nicer way. (I guess you are looking for show path construction with which you can change the line style during the path.) – user121799 May 28 '19 at 13:18
• @marmot Interesting! Thanks :) Explaining what I am really up to is just too much work -- both for me and the community x) – Andreas Storvik Strauman May 28 '19 at 17:45

This code by Hood Chatman allows you to get the desired result with edges.

\documentclass[tikz,margin=10pt]{standalone}
\usepackage{tikz}
\tikzset{
myline/.style={to path={(\tikztostart) -- (\tikztotarget)}}
}
\begin{document}
\begin{tikzpicture}
% With edges
\begin{scope}[shift={(0,1)},every edge/.append code={%
\global\let\currenttarget\tikztotarget % save \tikztotarget in a global variable
\pgfkeysalso{append after command={(\currenttarget)}}}]
\draw (0,0) edge[myline] (1,1) edge[myline] (2,0);
\node[below] at (1,0){With \texttt{edge}s};
\end{scope}
% With --, which gives "expected" results
\begin{scope}[shift={(0,-1)}]
\draw (0,0) -- (1,1) -- (2,0);
\node[below] at (1,0){With \texttt{--} (expected)};
\end{scope}
\end{tikzpicture}
\end{document}


If you zoom in at the top you will see that it is not quite the same,

simply because split the path in two pieces rather than one.