6

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}$
  • 1
    Framebox holds it argument i text-mode no matter where it It is used. You might want to have a look at the \boxed command from amsmath – daleif Dec 26 '13 at 20:22
  • @daleif this does not work either, as it makes a separate math environment for each symbol, making it impossible to have say the subscripts of an integral in a separate box, as writing $\boxed{\sum}_ {1 \leq i \leq j \leq k \leq n}$ places the subscripts incorrectly and $\boxed{\sum}_\boxed{1 \leq i \leq j \leq k \leq n}$ does not work at all. – malin Dec 26 '13 at 21:10
  • @malin There's no way to do it in pure TeX, unless you're ready to reimplement math mode with boxes and glue after reading appendix G of the TeXbook. – egreg Dec 27 '13 at 0:35
6

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

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.