[Tex/LaTex] Bounding box for each symbol in an equation

boxesmath-mode

Is it possible to make LaTeX put a bounding box around each element in an equation, as in this file? I am aware of this question, but none of the solutions presented there, which does not require LuaTeX, seem to work within equations containing, e.g., commands like \sum.

I have tried to resolve this "manually" by putting a framebox around each symbol within an equation, but neither that seems to work for commands like \sum, even though it do work for simpler symbols such as digits, such as

\fboxrule=.1pt \fboxsep=-\fboxrule
$\framebox[\width]{1}$

Best Answer

This approach is by no means automated, but can be made to manually work. It uses a \boxxed macro for putting things in boxes. However, manual intervention is still needed as follows: \mathop and \mathrel have to be manually introduced for a boxed operator or relation, since the box removes any memory of that.

The \ThisStyle{...\SavedStyle...} syntax of the scalerel package is used to preserve \scriptstyle arguments in their proper style, once inside the box.

The good news is that the kerning is preserved.

\documentclass{article}
\usepackage{amsmath} 
\fboxrule=.1pt
\fboxsep=-.1pt
\usepackage{scalerel}
\newcommand\boxxed[1]{{\ThisStyle{\fbox{$\SavedStyle#1$}}}}
\begin{document} 
\( \mathop{\boxxed{\sum}}_\boxxed{i}^\boxxed{n} \boxxed{A}^\boxxed{2}\)

\( \sum_i^n A^2\)

\( \displaystyle\mathop{\boxxed{\sum}}_\boxxed{i}^\boxxed{n} \boxxed{A}^\boxxed{2}\)

\( \displaystyle\sum_i^n A^2\)
\end{document}

enter image description here

Related Question