pgf macro that returns a node

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.

-

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.

\documentclass{article}
\usepackage{tikz}

\begin{document}

\newcommand{\mycoord}[2]{
\pgfcoordinate{#1}{#2}}
\mycoord{a}{\pgfpoint{3cm}{0cm}}

\begin{tikzpicture}
\node[draw] at (a) {good};
\end{tikzpicture}
\end{document}


The next code is interesting only if you want to modify \xand \y

\documentclass{article}
\usepackage{tikz}

\begin{document}

\newcommand{\mycoord}[2]{
\pgfmathsetmacro\x{5} % or what you want
\pgfmathsetmacro\y{-2}}
\begin{tikzpicture}
\node[draw](d){deb};
\path \pgfextra \mycoord{1}{2} \endpgfextra node[draw] (f) at (\x,\y) {end}; %
\draw (d)--(f) ;
\end{tikzpicture}
\end{document}

-
Thank you. Unfortunately I can't quite get it to work. The example I gave is rather simplified. My actual case is more complicated and I need to call mycoord within the tikzpicture environment. Preferably within a path. –  pmav99 Jun 6 '11 at 16:33
@pmav99 perhaps my answer is not clear but you use pgfcoordinate in wrong way. The definition is \pgfcoordinate{⟨name ⟩}{⟨coordinate ⟩}. The first argument must be a name. Then when you use \node at you need to give something that can be parsed like coordinate. I add another example in my answer –  Alain Matthes Jun 6 '11 at 18:48

I think the easiest way to go is simply to have the macro expand to text like "(x,y)" and use e.g. calc or other standard transformations to manipulate that. For example, you can do straightforward things like:

\newcommand{\mycoord}[2]{([xshift=2cm] #1,#2)}


And then embed the macro call in paths just like you'd expect.

\draw (0,0) -- \mycoord{0}{0};


Here's a minimal example that shows using calc. Note that this does something fairly random (I just took an example from the manual and modified it), it is just intended to show how the syntax would work rather than really being useful:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\newcommand{\mycoordB}[3]{(${2*(#3-3)}*(#1,#2)$)}

\begin{tikzpicture}
\fill [black] \mycoordB{0cm}{0cm}{4} circle (2pt);
\fill [blue] \mycoordB{1cm}{2cm}{5} circle (2pt);
\fill [green] \mycoordB{2cm}{2cm}{2} circle (2pt);
\end{tikzpicture}

\end{document}
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9625771641731262, "perplexity": 2569.851385578884}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2015-11/segments/1424936469016.33/warc/CC-MAIN-20150226074109-00190-ip-10-28-5-156.ec2.internal.warc.gz"}