[Tex/LaTex] Define a variable in TikZ

tikz-pgf

I guess this is a very simple question, but I couldn't find the answer… How can I define a variable in TikZ? I want to have something like, for example:

\draw[->] (x1,y1)--(x2,y2);

Such that x1,x2,y1,y2 are defined somewhere else and can be changed in order to adjust the picture.

Should be simple, right?

Best Answer

\begin{tikzpicture} 
\coordinate (A) at (2,3);
\coordinate (B) at (2,5);
\draw[->] (A)--(B) ;
\end{tikzpicture}

You can add

\newcommand\XA{2} etc. and then \coordinate (A) at (\XA,\YA);

Related Question