TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone have any suggestions for recreating the \boxed{...} function from LaTeX in plain TeX? I'm pretty sure it's part of the amsmath package for LaTeX.

share|improve this question
From amsmath.dtx: \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}; and you can extract the definition of \fbox (and friends) from latex.ltx. – Werner Jan 31 '13 at 3:22
up vote 12 down vote accepted

You can recycle the definition of \cstok that you can find in manmac.tex:

\def\boxed#1{% from \cstok in manmac.tex

a = \boxed{1\over2} = {2\over 4} = \boxed{\root3\of{8^{-1}}}


Adjust the spacing to suit your taste.

enter image description here

share|improve this answer
Interesting to see how the TeX math routines put the -1 in a visibly too low position. – jfbu Jan 31 '13 at 9:01
@jfbu The argument to \radical is typeset in cramped text style (in this case). You can force "non cramped" with an explicit \textstyle or \displaystyle declaration. – egreg Jan 31 '13 at 9:02
surprising though that with an overall displaystyle, TeX decides that stuff within a \root3\of should be in cramped style, as if this was destined for an inline equation. – jfbu Jan 31 '13 at 9:06
another interesting aspect is that removing the braces around the #1 would be a very bad idea, as the \displaystyle scope is ended by the \over in \boxed{1\over2} for example. – jfbu Jan 31 '13 at 9:10
@jfbu In my first attempt I missed those braces. ;-) But I immediately realized the mistake because I used 1\over2. – egreg Jan 31 '13 at 9:11

I have done Werner's exercise. With the additional braces for use with \over as in egreg's answer.

Edit for my first ever non zero use of \mathsurround. But sub-formulas (in \hboxes) then should be aware and set their own, as is systematic I think in LaTeX/amsmath.

\newdimen\fboxsep  \fboxsep3pt
\newdimen\fboxrule \fboxrule.4pt

\long\def\boxed #1{\leavevmode
  \setbox \boxedbox = 
  %%\hbox{\kern\fboxsep {\mathsurround0pt $\displaystyle {#1}$}\kern\fboxsep}%
  \hbox{{\mathsurround\fboxsep $\displaystyle {#1}$}}%
  \hbox{\lower \dimen0
           \hbox {%
            \vbox {\hrule height \fboxrule 
             \hbox {\vrule width \fboxrule 
              \vbox {\vskip \fboxsep \box \boxedbox \vskip \fboxsep }%
                    \vrule width \fboxrule }%
                   \hrule height \fboxrule }}}}

a = \boxed{1\over2} = {2\over 4} = \boxed{\root3\of{8^{-1}}}


boxed formulas boxedams

The second being the output of



a = \boxed{{1\over2}} = {2\over 4} = \boxed{\root3\of{8^{-1}}}

share|improve this answer
in passing I removed the \color@begingroup and \color@endgroup, not having checked if package color could be used with plain TeX. – jfbu Jan 31 '13 at 15:11
actually, \hbox{{\mathsurround\fboxsep $\displaystyle {#1}$}} would give the first ever actual use of mathsurround I would have ever done. In LaTeX2e they use \m@th for \mathsurround0pt but here \mathsurround\fboxsep would spare some tokens... – jfbu Jan 31 '13 at 15:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.