[Tex/LaTex] How to put a character inside a square

math-modesymbols

In a math formula, is there a way to put a number inside a square, as a decoration? I.e., instead of $\bar{1}$ or $\widehat{1}$ I would like to write something like $\insquare{1}$ and have the “1” inside a small square. Is this possible?

Best Answer

There are three simple options. One is \fbox{}, the content of which is typeset in text mode, but can handle math mode as well. Loading the amsmath package provides \boxed{}, the content of which is typeset in math mode. Both of these can be used in text or math mode (i.e., you don't need to enter math mode first). Loading the mathtools package provides \Aboxed{}, which is for placing part of an align environment in a box.

\documentclass{article}
\usepackage{amsmath} % for \boxed{}
\usepackage{mathtools} % also loads amsmath
\begin{document}
\fbox{foo}
\(\fbox{$\delta$}\)

\boxed{foo}
\(\boxed{\delta}\)

\begin{align}
y&=x\\
\Aboxed{y&=x^2}
\end{align}
\end{document}

enter image description here