Before I get to the question and to not receive the answers I do not want, I want to point out that I mainly have 4 usage of equation or math-related boxes in LaTeX (For the question related to the title, skip to usage number 4).
1. For boxing a big list of mathematical properties, in which I use my own custom tcolorbox environment defined using tcolorbox's \newtcolorbox macro.
Example:
% !TEX program = lualatex
\documentclass[preview,border={5mm 5mm 5mm 5mm},varwidth]{standalone}
\usepackage{mathtools}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math}
\setmathfont{Latin Modern Math}
\usepackage{setspace}\setdisplayskipstretch{}
\usepackage{xcolor}
\usepackage{tcolorbox}
\newtcolorbox{mybox}[1][]{colback=black!5!white,colframe=black,boxrule=1pt,arc=0mm,#1}
\begin{document}
\onehalfspacing\small%
\begin{mybox}[before skip=4ex, after skip=5ex, boxsep=0pt,left=0pt,right=15pt,top=-7pt,bottom=10pt]
\begin{alignat}{99}
&\text{(Associative law for addition)} & && a + (b + c) & &&= (a + b) + c. \tag{P1} \
&\text{(Existence of an additive identity)} & && a + 0 & &&= 0 + a = a. \tag{P2} \
&\text{(Existence of additive inverses)} & && a + (-a) & &&= (-a) + a = 0. \tag{P3} \
&\text{(Commutative law for addition)} && & a + b & &&= b + a. \tag{P4} \
&\text{(Associative law for multiplication)} & && a \cdot (b \cdot c) & &&= (a \cdot b) \cdot c. \tag{P5} \
&\text{(Existence of a multiplicative identity)} & && a \cdot 1 & &&= 1 \cdot a = a;\quad 1 \neq 0. \tag{P6}\
&\text{(Existence of multplicative inverses)} & && a \cdot a^{-1} & &&= a^{-1} \cdot a = 1, \text{ for } a \neq 0. \tag{P7} \
&\text{(Commutative law for multiplication)} & && a \cdot b & &&= b \cdot a. \tag{P8} \
&\text{(Distributive law)} & && a \cdot (b + c) & &&= a \cdot b + a \cdot c. \tag{P9}
\end{alignat}
\end{mybox}
\end{document}
2. For highlighting a standalone multiline mathematical definition or equation, in which I use empheq's empheq + align/align* environment + tcolorbox's \tchbhighmath box (a special case of the \tcboxmath macro).
Example:
% !TEX program = lualatex
\documentclass[preview,border={5mm 5mm 5mm 5mm},varwidth]{standalone}
\usepackage{mathtools}
\usepackage{physics}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math}
\setmathfont{Latin Modern Math}
\usepackage{setspace}\setdisplayskipstretch{}
\usepackage{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{empheq}
\tcbset{highlight math style={colback=black!5!white,colframe=black,boxrule=1pt,capture=hbox,arc=0mm,boxsep=0pt,left=4pt,right=4pt}}
\begin{document}
\onehalfspacing\small%
The fact that (-a > 0) if (a < 0) is the basis of a concept which will play an extremely important role in this book. For any number (a), we define the \textbf{absolute value} (\abs{a}) of (a) as follows:
\begin{empheq}[box=\tcbhighmath]{align}
\abs{a} &=
\begin{cases}
\phantom{-}a, & if (a\geq 0), \
-a, & if (a\leq 0).
\end{cases*}
\[3pt]
\abs{a} &= \sqrt{a^2}.
\end{empheq}
\end{document}
3. For highlighting the end result of a mathematical solutions in an align/align* environment, in which I use a custom colored version macro of mathtools' \Aboxed macro taken and modified from this TeX.SX answer
(I switched the optional argument to be the background color instead of the frame color)
Example:
% !TEX program = lualatex
\documentclass[preview,border={-15mm 5mm 10mm 0mm},varwidth]{standalone}
\usepackage{mathtools}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math}
\setmathfont{Latin Modern Math}
\usepackage{setspace}\setdisplayskipstretch{}
\usepackage{xcolor}
% \Acolorboxed (color \Aboxed command) modified from https://tex.stackexchange.com/a/610299/228055
% Basic syntax: \Acolorboxed[<background color>]{<LHS> &<aligned character> <RHS>}
\makeatletter
\newcommand*\Acolorboxed[2][yellow!75]{%
\let\bgroup{\romannumeral-}% \@Acolorboxed{#1}#2&&\ENDDNE } \def\@Acolorboxed#1#2&#3&#4\ENDDNE{% \ifnum0={}\fi
\setbox\z@\hbox{$\displaystyle#2{}\m@th$\kern\fboxsep \kern\fboxrule}%
\edef@tempa{\kern\wd\z@ & \kern-\the\wd\z@ \fboxsep\the\fboxsep \fboxrule\the\fboxrule}%
@tempa
\fcolorbox{black}{#1}{\m@th$\displaystyle#2#3$}%
}
\makeatother
\begin{document}
\onehalfspacing\small%
\begin{align}
x^3 + x^2 - 4x + 2 &= (x - 1)(x^2 + 2x - 2) = 0, \
x_1 &= 1, \
x_2 &= \frac{-2 + \sqrt{2^2 - 4(1)(-2)}}{2(1)} = \frac{2 + 2\sqrt{3}}{2}, \
x_3 &= \frac{-2 - \sqrt{2^2 - 4(1)(-2)}}{2(1)} = \frac{2 - 2\sqrt{3}}{2}, \[1.5ex]
\Acolorboxed{x &\in \left{1 - \sqrt{3}, 1, 1 + \sqrt{3}\right}.}
\end{align}
\end{document}
4. For highlighting with color the multiline end result of a mathematical solutions in an align/align* environment without breaking the alignment from the previous unboxed lines, in which I don't know what to use.
I want a mixture of usage number 3 and usage number 4 but using empheq would not continue the alignment from the previous unboxed lines, and using \Acolorboxed (similar to \Aboxed) would not be possible since the macro cannot handle multiline aligned equations. So I need a new macro.
An example of this macro, let's call it \Acolorboxedmulti[<background color>]{<LHS> &<alignment character> <RHS>}, would be:
\begin{align*}
a &= 1, \\
b &= 2, \\
\Acolorboxedmulti[yellow!75]{%
c &= 3, \\
d &= 4, \\
e &= 5.
}
\end{align*}
Essentially, my question is
How can I define a macro like \Acolorboxed but can handle multiline aligned equations in one box fitted to the width without breaking the alignment from previous lines in align/align*?
Thank you.



align/align*. – Farrel Ahmed Jun 28 '22 at 07:17x_1,x_2andx_3, for example? (Unrelated, the last row there is mathematically wrong.xis not equal to the set.) – mickep Jun 28 '22 at 07:58x \in \left\{1 - \sqrt{3}, 1, 1 + \sqrt{3}\right\}.instead, my bad. I'll fix it soon.) – Farrel Ahmed Jun 28 '22 at 08:05align/align*environment). – Farrel Ahmed Jun 28 '22 at 08:21