How to add frame boxes to all equations in a LaTeX file, to make all the equations seems like
which can be obtained by
\[\boxed{a+b}\]
For example, transform this
into this
As far as I know, there are many types of equation environments in LaTeX. Such as
$a+b$,
\[a+b\]
\begin{equation}
a+b
\end{equation}
\begin{equation*}
a+b
\end{equation*}
\begin{eqnarray}
a+b \\
c+d
\end{eqnarray}
\begin{align}
a+b \\
c+d
\end{align}
\begin{equation}
\left(
\begin{matrix}
a &b \\
c &d
\end{matrix}
\right)
\end{equation}
And so on …
So, is there any magic method to add bounding boxes to all these equation environments without change the code of equations? I mean DO NOT modify the code of equations one by one, just like
$\boxed{a+b}$
\[\boxed{a+b}\]
\begin{equation}
\boxed{a+b}
\end{equation}
\begin{equation*}
\boxed{a+b}
\end{equation*}
\begin{eqnarray}
\boxed{a+b} \\
\boxed{c+d}
\end{eqnarray}
\begin{align}
\boxed{a+b} \\
\boxed{c+d}
\end{align}
\begin{equation}
\boxed{
\left(
\begin{matrix}
a &b \\
c &d
\end{matrix}
\right)
}
\end{equation}
Best Answer
(rewrote answer to let it handle multi-line math environments of
amsmath
package)The following solution, which requires LuaLaTeX, handles inline math cases as well as single-line display-math environments such as
equation
,equation*
, anddisplaymath
. It also handles four of the multi-line equation environments ofamsmath
package --align
,alignat
,gather
, andmultline
, plus their "starred" variants -- with the caveat that any equation numbers are suppressed. (The only major standalone multi-line equation environment that's not automatically boxed is theflalign
environment, and its starred cousin.)The code provides two user-level LaTeX macros:
\EqboxOn
and\EqboxOff
. The former turns on automatic boxing, and the latter turns it off. The Lua function that's enabled by\EqboxOn
scans all input lines and inserts\boxed
statements "on the fly", as needed. Note that the definitions of the math environments are not modified.Observe that no code is provided to handle
eqnarray
andeqnarray*
environments. This omission is deliberate: These environments are deprecated and should no longer be used.