Dynamic coordinate name

The following works fine:

\documentclass[a4paper]{memoir}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\coordinate (fs-1-2-ne) at (7,8);
\node at (fs-1-2-ne) {Hello};

\end{tikzpicture}
\end{document}


But, this one does not (it said "Package pgf Error: No shape named fs-1-2 is known"):

\documentclass[a4paper]{memoir}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\coordinate (fs-1-2-ne) at (7,8);

\pgfmathsetmacro{\prevcoordinate}{3-1};

\node at (fs-1-\prevcoordinate-ne) {Hello};

\end{tikzpicture}
\end{document}


My use-case is to get another existing coordinate by name, and the name is obtained from a mathematical expression.

-
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  Harish Kumar Mar 29 at 7:46

You can use \pgfmathparse and then assign \pgfmathresult to a macro.

\documentclass[a4paper]{memoir}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\pgfmathparse{int(3-1)}
\let\prevcoordinate\pgfmathresult
\coordinate (fs-1-2-ne) at (7,8);

\node at (fs-1-\prevcoordinate-ne) {Hello};

\end{tikzpicture}
\end{document}


As noted by percusse, you can use \pgfmathtruncatemacro (like \pgfmathtruncatemacro{\prevcoordinate}{3-1};)to make your approach work. This will ensure that the output is an integer.

-
Use \pgfmathtruncatemacro to make it work!! :) –  percusse Mar 29 at 9:37
@percusse Thanks, and I added a note in the answer. :) –  Harish Kumar Mar 29 at 10:00