How can I write a macro that returns a coordinate (or a node). The node must be usable within a tikzpicture environment and preferably inside a path declaration.
I need something like the following (it doesn't compile). I am not sure if pgfcoordinate
is the correct way to go…
\documentclass{article}
\usepackage{tikz}
\usepackage{pgf}
\begin{document}
\newcommand{\mycoord}[2]{
\pgfmathsetmacro{\x}{\pgfmathparse{#1} \pgfmathresult} % actually do some calculations
\pgfmathsetmacro{\y}{\pgfmathparse{#2} \pgfmathresult} % actually do some calculations
\pgfcoordinate{\x}{\y}} % I want this node to be returned.
\begin{tikzpicture}
\node at \mycoord{1}{2} {some text}; % I want to use the calculated node
\end{tikzpicture}
\end{document}
the error message is
Package tikz Error: Cannot parse this coordinate.
Best Answer
This a normal error. Tikz waits coordinates something like (3,0) or (a) where a is the name of a node. I think you do not use correctly
\pgfcoordinate
I never use this macro so perhaps I'm wrong but this macro defines quickly a name of a node associates with coordinates. You can define your macro outside the tikzpicture.The next code is interesting only if you want to modify
\x
and\y