3

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}

enter image description here

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

4

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}

enter image description here

| improve this answer | |
  • 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
  • 1
    @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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.