How to extract coordinates in the current scope (before the coordinate transformation matrix is applied)

Numbers get slightly distorted due to internal transformation inersion.

\documentclass[margin=0.5cm]{standalone}
\usepackage{tikz}
\makeatletter
\newcommand{\myDraw}[2]{%
\begin{minipage}[t]{6cm}
  \centering #1,#2\\
  \begin{tikzpicture}[#1,#2]
    \draw[->] (0,0) -- (3,0);
    \draw[->] (0,0) -- (0,3);
    \coordinate (A) at (1,3);
    \draw[blue] (A) node {$+$} node[above right] {\footnotesize A(2,3)};
    \pgfpointanchor{A}{center} %<----
    \edef\xa{\the\pgf@x}
    \edef\ya{\the\pgf@y}       %<----
    \draw[red] (canvas cs:x=\xa,y=\ya)
               node {$+$} node[red,below right] {\parbox{2.5cm}{\footnotesize%
               \textbackslash xA = \xa\\\textbackslash yA = \ya}};

  \end{tikzpicture}
\end{minipage}}
\makeatother
\begin{document}
  \myDraw{scale=1}{rotate=0}
  \myDraw{scale=0.5}{rotate=0}
  \myDraw{scale=1}{rotate=-20}
\end{document}

enter image description here

The marked code can be replaced with a higher level TikZ syntax

\path (A); \pgfgetlastxy{\xA}{\yA}; % Extract the coordinates of A
\begin{scope}
\pgftransforminvert
\coordinate (B) at (\xA,\yA);\path (B); \pgfgetlastxy{\xB}{\yB};    
\xdef\xorigA{\xB}
\xdef\yorigA{\yB}
\end{scope}

which does more or less the same thing.


Here a solution, without the low level macro \pgfgetlastxy, via a let operation:

enter image description here

\documentclass[margin=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\myDraw}[2]{%
\begin{minipage}[t]{6cm}
  \centering #1,#2\\
  \begin{tikzpicture}[#1,#2]
    \draw[->] (0,0) -- (3,0);
    \draw[->] (0,0) -- (0,3);
    \coordinate (A) at (1,3);
    \draw[blue] (A) node {$+$} node[above right] {\footnotesize A(2,3)};

    \path [green!50!black]
    let \p1=(A) in
    (\x1,\y1)  node {$+$}
    node[below right,align=left,font=\footnotesize]{
      \textbackslash xA = \x1\\
      \textbackslash yA = \y1
    };

  \end{tikzpicture}
\end{minipage}}

\begin{document}
  \myDraw{scale=1}{rotate=0}
  \myDraw{scale=0.5}{rotate=0}
  \myDraw{scale=1}{rotate=-20}
\end{document}

If you need these macro definitions after the path and its let operation, you may:

  • use \xdef:

\path let \p1=(A) in
  \pgfextra{
    \xdef\xA{\x1}
    \xdef\yA{\y1}
  };
  • use \AfterGroup (from etextools package):

\usepackage{etextools}
...
\path let \p1=(A) in
  \pgfextra{
    \AfterGroup*{
      \noexpand\def\noexpand\xA{\x1}
      \noexpand\def\noexpand\yA{\y1}
    }
  };