I have a macro to box (parts of) equations with tikz. I want to use mathchoice to remember the style and I want to label the tikz nodes for later reference. However, it does not work.
MWE:
\documentclass{article}
\usepackage[customcolors,shade]{hf-tikz}
\usepackage[]{tikz}
\tikzset{
tbx-base/.style={ fill opacity=0.4, draw ,
color=red, fill=red!80, },
}
\newcommand{\tbx}[3]{
\mathchoice%
{\tikz[remember picture] \node[#1] (#2) {\normalcolor{$\displaystyle#3$}};}
{\tikz[remember picture] \node[#1] (#2) {\normalcolor{$\textstyle#3$}};}
{\tikz[remember picture] \node[#1] (#2) {\normalcolor{$\scriptstyle#3$}};}
{\tikz[remember picture] \node[#1] (#2) {\normalcolor{$\scriptscriptstyle#3$}};}
}
\newcommand{\tbxx}[3]{
{\tikz[remember picture] \node[#1] (#2) {\normalcolor{$\displaystyle#3$}};}
}
\begin{document}
\[
\tbx{tbx-base}{nodeEkin1}{A}
+
\tbxx{tbx-base}{nodeEkin2}{A}
\]
energy \tikz[remember picture,overlay, baseline=-.5ex]\node (nodeEkin01) {}; \\
energy \tikz[remember picture,overlay, baseline=-.5ex]\node (nodeEkin02) {};
\begin{tikzpicture}[remember picture,overlay]
\path[-stealth,draw] (nodeEkin01) edge [out=0, in=-90] (nodeEkin1);
\path[-stealth,draw] (nodeEkin02) edge [out=0, in=-90] (nodeEkin2);
\end{tikzpicture}
\end{document}
The arrow to the box created with \tbxx is correct, but \tbxx does not allow for the correct size (if, e.g. used in fractions or indices). \tbx allows for correct sizing, but not for correct referencing of the tikz nodes.
Is there a possibility to get the advantages of both macros?