# Fancy \Aboxed without redefining it

I'd like to define a fancy box in align environments while keeping the \Aboxed command as it is defined by default.

What I got so far

\documentclass{article}
\usepackage{mathtools,tcolorbox}

\makeatletter
\patchcmd{\@Aboxed}{\boxed{#1#2}}{\fcolorbox{red}{yellow}{$\displaystyle #1#2$}}{}{}%
\makeatother
\newcommand{\Asol}{\Aboxed}

\begin{document}

\begin{align*}
\Aboxed{n+1 &= 1005} \\
\Asol{n &= 1004}
\end{align*}

\end{document}


How to define a new command \Asol without changing \Aboxed ?

Make copies of both \Aboxed and \@Aboxed. Edit the copied versions.

\documentclass{article}
\usepackage{mathtools,tcolorbox}

\makeatletter
\let\Asol\Aboxed
\let\@Asol\@Aboxed
\patchcmd{\Asol}{\@Aboxed}{\@Asol}{}{}%
\patchcmd{\@Asol}{\boxed{#1#2}}{\fcolorbox{red}{yellow}{$\displaystyle #1#2$}}{}{}%
\makeatother

\begin{document}

\begin{align*}
\Aboxed{n+1 &= 1005} \\
\Asol{n &= 1004}
\end{align*}

\end{document}


• Thank you! Is this the shortest way of doing it or there is another method without using patchcmd? – sound wave Oct 11 '19 at 11:58
• @soundwave This is the shortest. If you wanted to avoid \patchcmd, you would have to make copies of the full macros for \Aboxed and \@Aboxed, renaming them and editing them directly. – Steven B. Segletes Oct 11 '19 at 12:00