[Tex/LaTex] Highlight and use arrows in an equation In a robust manner

arrowsequationshighlightingtikz-arrowstikz-pgf

I am trying to give a very simple analogy to what I am trying to do with LaTeX. I simply want to write two vectors, one below or next the other, and then, use nodes to link the last two elements of the first vector and the last element from the second vector.
Here is the code I am using

\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows}% For nice arrow tips
% One style for all TikZ pictures for working with overlays:
\tikzset{every picture/.style=remember picture}
% Define a TikZ node for math content:
\newcommand{\mathnode}[1]{%
  \mathord{\tikz[baseline=(#1.base), inner sep = 0pt]{\node (#1) {$#1$};}}}



\begin{document}

$\begin{bmatrix}
     1 \\ \mathnode{2\rho \pi \\ 3}
\end{bmatrix}$
\\
$\begin{bmatrix}
     1 \\ 2\rho \pi \\ \mathnode{3}
\end{bmatrix}$

% Now we draw connections between defined nodes:
\begin{tikzpicture}[overlay]
  \path [>=stealth, <->, shorten <= 3pt, shorten >=3 pt]
    (N1) edge [bend left=60] (N2);
\end{tikzpicture}


\end{document}

How can I modify the mathnode declaration, to give a name to the node, and to be able to fill each node separately ?

Please, any suggestions?

Thanks.

Best Answer

I don't quite understand the output you have in mind, but I definitely would go through the tikz matrix way, by putting two matrices of nodes in the same tikzpicture, without using remember picture nor overlay.

For example:

\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows,matrix,positioning}% For nice arrow tips
\begin{document}

\tikzset{
    !/.style = {
        fill=yellow!30,
    },
    mymatrix/.style = {
        matrix of math nodes,
        left delimiter  = (,
        right delimiter = ),
        nodes={minimum width=6ex},
    }
}

\begin{tikzpicture}
    \matrix[mymatrix, name=M1]{
                1 \\
        |[!]|   2\rho\pi \\
        |[!]|   3\\
    };
    \matrix[mymatrix, name=M2, below=of M1] {
                 1 \\
                 2\rho\pi\\
        |[!]|    3\\
    };
   \draw [red, >=stealth, <->, shorten <= 3pt, shorten >=3 pt]
     (M1-2-1.south east) to[bend left=60] (M2-3-1.east);
\end{tikzpicture}

\end{document}

Produces:

Result