Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
1  
Possible duplicate: Color box with rounded corners around a fragment of a formula –  Werner Jun 8 '13 at 13:39
    
Are you working with TeX or why do you use $$...$$? –  Marco Daniel Jun 9 '13 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 Jun 9 '13 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 Jun 9 '13 at 17:47

3 Answers 3

up vote 6 down vote accepted

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

\renewcommand{\boxed}[1]{\text{\fboxsep=.2em\fbox{\m@th$\displaystyle#1$}}}

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

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\renewcommand{\boxed}[1]{\text{\fboxsep=.2em\fbox{\m@th$\displaystyle#1$}}}
\makeatother

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

enter image description here

share|improve this answer
    
You're right, \text actually does all the required magic. –  penartur Jun 9 '13 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.

share|improve this answer
    
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 Jun 9 '13 at 17:35
    
@penartur -- for the subscript, _\text{\boxed{i}} should take care of the size problem. marco daniel has addressed that. –  barbara beeton Jun 9 '13 at 20:11

The simplest is probably \fbox{$y$}

share|improve this answer
    
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 Jun 8 '13 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. –  David Carlisle Jun 8 '13 at 14:54

Your Answer

 
discard

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.