I have a set of equations summarized in this way:
The code that produces this is the following:
\documentclass[12pt]{article}
\usepackage{empheq}
\usepackage[left=2.5cm,top=2.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage{amsmath}
\begin{document}
\newcommand*\widefbox[1]{\fbox{\hspace{2em}#1\hspace{2em}}}
\begin{subequations}
\begin{empheq}[box=\widefbox]{align}
%
\Aboxed{a = & b + c + d}
\nonumber \\
& d = f + g
\nonumber \\
& \qquad
f = m/4
\nonumber \\
&
d = j + k
\nonumber \\
& \qquad
j = n\cdot3/4
\nonumber \\
& d = l + o
\nonumber \\
\Aboxed{& d = m/4 + q + n\cdot 3/4 + k + l + 0 }
\nonumber \\
\Aboxed{&c = p + q}
\nonumber \\
& \qquad
p = h/2 + h/2
\nonumber \\
\Aboxed{&b = r + s}
\nonumber \\
\Aboxed{&t = u + w}
\nonumber \\ \nonumber\\
\Aboxed{a = & b + c + d}
\nonumber \\ \nonumber\\
\Aboxed{a = & zz + z'}
\nonumber \\ \nonumber\\
\end{empheq}
\end{subequations}
\end{document}
I would like to produce something similar to this:
Is there a way to achieve those arrows, red boxes and circled numbers 1, 2 and 3 ?
Update:
Following @Ignasi's approach, when I try to apply this to the real example, I encounter quite a lot of difficulties, this is the nearest result I could achieve:
where:
1) The circled numbers and the arrows appear in the following page, instead of next to the equations (see image)
2) I could not manage to align the J[p] equations.
3) I could not manage to box the last equation,
4) Is there a way to caption this scheme?
Could you please help me to obtain this result?
This is the code to where I reached so far:
\documentclass[12pt]{article}
\usepackage{empheq}
\usepackage[left=2.5cm,top=2.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark, positioning}
\begin{document}
\newcommand*\widefbox[1]{\fbox{\hspace{2em}#1\hspace{2em}}}
\begin{subequations}
\begin{empheq}[box=\widefbox]{align}
%
%
\tikzmark{1}\Aboxed{
E [\rho ] = & \underbrace{ T[\rho ] + V_{ee}[\rho ] }_{=\,\, F[\rho ]} + V_{ne}[\rho]
}
\nonumber \\
& %
\tikzmark{2}
V_{ne}[\rho ] = \int \rho \left ( \mathbf{r} \right ) v_{\text{ext}} \left ( \mathbf{r} \right ) \mathrm{d}\mathbf {r}
\nonumber \\
& \qquad \qquad
v_{\text{ext}}\left ( \mathbf{r}_{i} \right ) = - \sum_{A=1}^{M} \frac{Z_{A}}{r_{iA}}
\nonumber \\
&
\tikzmark{3}
V_{ne}[\rho ] = \int - \sum_{A=1}^{M} \frac{Z_{A}}{r_{1A}} \rho \left ( \mathbf{r}_{1} \right ) \mathrm{d}\mathbf {r}_{1}
\nonumber \\
& \qquad \qquad
\rho (\mathbf{r}) \equiv \rho_{\text{S}}(\mathbf{r}) = \sum_{i=1}^{N} \left | \varphi_{i} \left ( \mathbf{x} \right ) \right |^{2} = \rho_{0}(\mathbf{r})
\nonumber \\
& %
\tikzmark{4}
V_{ne}[\rho ] = \int - \sum_{A=1}^{M} \frac{Z_{A}}{r_{1A}} \sum_{i=1}^{N} \left | \varphi_{i} \left ( \mathbf{x}_{1} \right ) \right |^{2} \mathrm{d}\mathbf {r}_{1}
\nonumber \\
\tikzmark{5}
\Aboxed{
&V_{ne}[\rho ] = - \sum_{i=1}^{N} \int \sum_{A=1}^{M} \frac{Z_{A}}{r_{1A}} \left | \varphi_{i} \left ( \mathbf{x}_{1} \right ) \right |^{2} \mathrm{d}\mathbf {r}_{1}
}
\nonumber \\
\tikzmark{6}
\Aboxed{
&V_{ee}[\rho ] = J[\rho ] + V_{\text{non-classical}}[\rho ]
}
\nonumber \\
& \qquad \qquad J[\rho] = \frac{1}{2} \int \int \frac{\rho(\mathbf{r}_{1})\rho(\mathbf{r}_{2})}{r_{12}} \mathrm{d}\mathbf {r}_{1} \mathrm{d}\mathbf {r}_{2} \nonumber \\
& \qquad \qquad \qquad \rho (\mathbf{r}) \equiv \rho_{\text{S}}(\mathbf{r}) = \sum_{i=1}^{N} \left | \varphi_{i} \left ( \mathbf{x} \right ) \right |^{2} = \rho_{0}(\mathbf{r}) \nonumber \\
&
\Aboxed{
J[\rho] = \frac{1}{2} \sum_{i=1}^{N} \sum_{j=1}^{N} \int \int \left | \varphi_{i} (\mathbf{r}_{1}) \right |^{2} \frac{1}{r_{12}} \left | \varphi_{j} (\mathbf{r}_{2}) \right |^{2} \mathrm{d}\mathbf {r}_{1} \mathrm{d}\mathbf {r}_{2} }
\nonumber \\
\tikzmark{7}
\Aboxed{
&T[\rho ] = T_{\text{S}}[\rho ] + T_{\text{C}}[\rho ]
}
\nonumber \\
& \qquad \qquad T_{\text{S}}[\rho ] = -\frac{1}{2}\sum_{i=1}^{N} \expval{\nabla^{2}}{\varphi _{i}}
\nonumber \\
\tikzmark{8}
\Aboxed{
E_{\text{XC}} [\rho] &= \left ( T[\rho] - T_{\text{S}}[\rho] \right ) + \left ( E_{ee}[\rho] - J[\rho] \right ) = T_{\text{C}}[\rho] + V_{\text{non-classsical}}[\rho]
}
\nonumber \\
\tikzmark{9}
\Aboxed{
E [\rho ] = & T_{\text{S}}[\rho ] + J[\rho] + V_{ne}[\rho ] + E_{\text{XC}} [\rho]
}
\nonumber \\
%\begin{empheq}[box=\fbox]{align}
%\end{subequations}
%
\tikzmark{10}
E [\rho ] = & -\frac{1}{2}\sum_{i=1}^{N} \expval{\nabla^{2}}{\varphi _{i}} + \frac{1}{2} \sum_{i=1}^{N} \sum_{j=1}^{N} \int \int \left | \varphi_{i} (\mathbf{r}_{1}) \right |^{2} \frac{1}{r_{12}} \left | \varphi_{j} (\mathbf{r}_{2}) \right |^{2} \mathrm{d}\mathbf {r}_{1} \mathrm{d}\mathbf {r}_{2}
\nonumber \\
& + E_{\text{XC}} [\rho] - \sum_{i=1}^{N} \int \sum_{A=1}^{M} \frac{Z_{A}}{r_{1A}} \left | \varphi_{i} \left ( \mathbf{x}_{1} \right ) \right |^{2} \mathrm{d}\mathbf {r}_{1}\\
%}
%\end{empheq}
\end{empheq}
\end{subequations}
\begin{tikzpicture}[remember picture, overlay]
\foreach \i [count=\ni] in {1,9,10}
\node[draw, circle, inner sep=2pt, left=2mm of pic cs:\i, yshift=.5ex] (c\ni) {\ni};
\foreach \i in {2,...,4}
\draw[->] ([shift={(2mm,-4.pt)}]pic cs:1) |- ([shift={(-4pt,.5ex)}]pic cs:\i);
\foreach \i in {5,...,8}
\draw[->] ([shift={(2mm,-4.pt)}]pic cs:1) |- ([yshift=.5ex]pic cs:\i);
\end{tikzpicture}







\Aboxedneeds one and only one&inside. Change\Aboxedby\fbox{$\displaymath.... 3. Same problem with\Aboxed, it's only valid for one line equations. I don't know if a nested boxed empheq will work. 4. Use\captionofcommand to caption non floating environments.