# How to show the current coordinates for mark=text?

In the following example I'm using the library plotmarks to set a text on the given path. Now I am interested in showing the current coordinates of the marker instead of p.

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\begin{document}
\begin{tikzpicture}

\draw[thick,mark=text,
%      text mark=(CURRENT COORDINATE)
] plot [smooth,] coordinates{
(-0.5,0)(-0.7,-0.75) (1.3,1)
(-1.6,0.8) (-1,0)
};
\end{tikzpicture}
\end{document}


Now I'm using the provided solution expanded by a precision:

\documentclass[12pt]{article}
\usepackage{tikz}

\usetikzlibrary{plotmarks}
\begin{document}
\begin{tikzpicture}
\draw[thick,mark=text,
text mark={%
\pgfgetlastxy{\x}{\y}%
(\pgfmathparse{\x/28.45274}\pgfmathprintnumber[fixed,precision=0]{\pgfmathresult},% Convert to cm.
\pgfmathparse{\y/28.45274}\pgfmathprintnumber[fixed,precision=0]{\pgfmathresult})% Convert to cm.
}%
] plot [smooth,] coordinates{
(-0.5,0)(-0.7,-0.75) (1.3,1)
(-1.6,0.8) (-1,0)
};
\end{tikzpicture}
\end{document}


-

A possible "quite lucky" solution is to check if the last used coordinate is available in the pgfgetlastxy command (it is.)

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\begin{document}
\begin{tikzpicture}

\draw[thick,mark=text,
text mark={%
\pgfgetlastxy{\x}{\y}%
(\pgfmathparse{\x/28.45274}\pgfmathresult cm,% Convert to cm.
\pgfmathparse{\y/28.45274}\pgfmathresult cm)% Convert to cm.
}%
] plot [smooth,] coordinates{
(-0.5,0)(-0.7,-0.75) (1.3,1)
(-1.6,0.8) (-1,0)
};
\end{tikzpicture}
\end{document}


But suffers from numerical errors for the display which can further be trimmed. But I don't have any elegant solution for that yet.

-

You can get the coordinates by using \pgfgetlastxy. This will give you the coordinates in points, so if you want to use them for display purposes you will need to perform some further calculations to get values that will display nicely.

You can simply use it like this:

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\begin{document}
\begin{tikzpicture}

\draw[thick,mark=text,
text mark={\pgfgetlastxy{\myx}{\myy}(\myx,\myy)}
] plot [smooth,] coordinates{
(-0.5,0)(-0.7,-0.75) (1.3,1)
(-1.6,0.8) (-1,0)
};
\end{tikzpicture}
\end{document}


It looks like this (very bad due to the dimensions being in points and thus very long).

-
+1 I accept the answer of percusse because he has an additional converting ;-) –  Marco Daniel Dec 30 '11 at 12:30

Here is a different approach by saving the actual input in a macro and accessing it later. As the plotsmarks are placed after the actual path and not when the point is used in the path. We need to define a few macros (for each coordinate one macro).

Still, this doesn’t show the real coordinates (e.g. not (1.5cm, 0cm) but (2-0.5,0)) but if you know the type of input you can also process it again (splitting at the ,, appending cm, …).

## Code

\documentclass[tikz]{standalone}
\usepackage{etoolbox}
\usetikzlibrary{plotmarks}
\makeatletter
\newcount\tikz@plot@coordinate
\tikzset{text mark/.append code=\tikz@plot@coordinate\z@}
\pretocmd{\tikz@@scan@@no@calculator}{%
\expandafter\def\csname tikz@plot@coordinate@\the\tikz@plot@coordinate\endcsname{#2}%
}{}{\errmessage{!}}
\preto\tikz@@@plot{\tikz@plot@coordinate\z@}
\pgfdeclareplotmark{text*}
{
\pgfkeysgetvalue{/pgf/text mark style}\pgfmarktext@style
\pgfkeysgetvalue{/pgf/text mark}\pgfmarktext@
\expandafter\pgfutil@in@\expandafter*\expandafter{\pgfmarktext@}
\ifpgfutil@in@
\expandafter\def\expandafter\pgfmarktext@\expandafter{\expandafter\qrr@tikz@plot@replace\pgfmarktext@\@qrr@tikz@plot@replace
{\csname tikz@plot@coordinate@\the\tikz@plot@coordinate\endcsname}}
\fi
\ifpgfmarktext@usetikznode
\expandafter\node\expandafter[\pgfmarktext@style]{\pgfmarktext@};
\else
\expandafter\pgftext\expandafter[\pgfmarktext@style]{\pgfmarktext@}
\fi
}
\def\qrr@tikz@plot@replace#1*#2\@qrr@tikz@plot@replace#3{#1#3#2}
\makeatother

\begin{document}
\begin{tikzpicture}

\draw[
thick,
mark=text*,
/pgf/text mark=$(*)$,
text mark as node,
text mark style={fill=white,fill opacity=.5,text opacity=1,inner sep=+0pt}
] plot [smooth] coordinates{
(2-0.5,0) (-0.7,-0.75) (1.3,1in)
(-1.6,0.8) (-1,0)
};
\end{tikzpicture}
\end{document}


-