So far everything I found on the matter of borders only applies to the text mode.

I want to be able to do something like

$x_i = y$

so the result will be like the ordinary "xi = z" formula with the border around "i"?

The common answers seems to be the fbox or boxed commands. Yet they render their argument in the standart mode, unless specified to do otherwise with the specific mode. For example, the following code

\[ x_i, \boxed{x}_i, x_{\boxed{i}}, \boxed{x}_{\boxed{i}} \]

produces two normal xi figures, and another two with an oversized i.

  • 1
    Possible duplicate: Color box with rounded corners around a fragment of a formula
    – Werner
    Commented Jun 8, 2013 at 13:39
  • Are you working with TeX or why do you use $$...$$? Commented Jun 9, 2013 at 17:43
  • @Werner Does not seem to be a duplicate for me. The question you gave link to is for a different problem, and I don't see how the answers could be applied to my problem.
    – penartur
    Commented Jun 9, 2013 at 17:43
  • @MarcoDaniel I guess this depends on the community. For some reason, it seems that $$...$$ is de facto standard in Russia; I only recently learned of \[...\], and the old habits die hard.
    – penartur
    Commented Jun 9, 2013 at 17:47

3 Answers 3


You can combine the advantages of the command \text (also provided by amsmath) and \boxed


With this redefinition and the relativ \fboxsep you get the following:



  \[ x_i, \boxed{x}_i, x_{\boxed{i}}, \boxed{x}_{\boxed{i}} \]

enter image description here

  • You're right, \text actually does all the required magic.
    – penartur
    Commented Jun 9, 2013 at 18:23

if you use amsmath, the command \boxed{...} puts a box around its argument.

to see an example, texdoc testmath. section 9.7 (p.18) deals with boxed formulas. although the entire formula is boxed in that example, the technique works as well with smaller elements.

\boxed is equivalent to \fbox except that its contents are in math mode.

  • It seems that \boxed is just a wrapper for \fbox under the hood, and, as such, faces the same problems (check out the updated question text).
    – penartur
    Commented Jun 9, 2013 at 17:35
  • @penartur -- for the subscript, _\text{\boxed{i}} should take care of the size problem. marco daniel has addressed that. Commented Jun 9, 2013 at 20:11

The simplest is probably \fbox{$y$}

  • This implies switching out of the math mode and then into it again; and, AFAIK, I have to define the formula style in $y$ depending of the specific place I want to use it. Isn't there any more user-friendly approach, that, at least, does not depend on where I use it (as long as it is in the math mode)?
    – penartur
    Commented Jun 8, 2013 at 13:02
  • @penartur yes, the link Werner gives has more exotic and complete versions. Often though boxing is only used at the top level and not in superscripts etc so this simple version is enough. Commented Jun 8, 2013 at 14:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .