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.

Inspired by this question, here's my mathmode spacing bugbear.

I quite often have equations that look like this:

\begin{equation}
  \text{If}\ B_1 \succeq B_2 \ \text{and}\ B_2 \succeq B_3 \ \text{then}\ B_1 \succeq B_3
\end{equation}

Now, you might notice that before and after each bit of \text{...} there is a "normal sized space". I can't imagine why I wouldn't want that space there, but I have to add it manually. Surely this should be the default behaviour of mathmode's text macro?

Why isn't it, and how could I make it so?

share|improve this question
2  
I usually add a space inside the \text (like \text{ and }). Is this wrong? –  Caramdir Dec 31 '10 at 19:07
    
I read somewhere that given that it's wrapped in mathmode, it's preferable to let mathmode do the spacing. Either way, you're adding the space explicitly... –  Seamus Dec 31 '10 at 19:12
add comment

3 Answers

up vote 5 down vote accepted

It's not the default behavior because you don't always want space. For instance, in your example, you don't want space before \text{If}, since that would indent your equation. Or consider

\[ x = \begin{cases}
         1 & \text{if $f(x)$}
         0 & \text{otherwise}
       \end{cases} \]

Again, that shouldn't be spaced out. Also, like in Caramdir's answer, I re-entered math mode within the \text, which often solves the spacing problems as well. You could define an \stext command for spaced out text:

\newcommand*{\stext}[1]{\text{ #1 }}

(Literal spaces inside are the same as outside, I believe.) Another option might be

\newcommand*{\textop}[1]{\mathbin{\text{#1}}}
\newcommand*{\textrel}[1]{\mathrel{\text{#1}}}

Then \textop{foo} would set foo as a binary operator, and \textrel{bar} would set bar as a binary relation. I'm not sure how this spacing would look, though, but it might work for what you want.

share|improve this answer
add comment

It probably doesn't add space because it is harder to remove space than to add space. One possible usage is something like 3-\text{connected graphs}.

Side remark: It is also possible to write your example as

\begin{equation}
  \text{If $B_1 \succeq B_2$ and $B_2 \succeq B_3$ then $B_1 \succeq B_3$.}
\end{equation}
share|improve this answer
    
Maybe even better: replace equation with center and remove the \text. Unless the OP really wants this sentence numbered like an equation. –  Matthew Leingang Dec 31 '10 at 19:49
    
I do, it's a property of a relation that I want to refer back to by a \tag –  Seamus Jan 1 '11 at 15:27
add comment

If you want to introduce automatic spacing before or after \text, your best option is probably to make \text behave like an operator (\mathop), which is the closest thing to text inside math mode. The spacing introduced will be slightly smaller than normal text, but should still be acceptable. Here's the code (making sure that \text still works in text mode):

\newcommand{\textop}[1]{\relax\ifmmode\mathop{\text{#1}}\else\text{#1}\fi}

If you compare this to the respective commands \textbin and \textrel which are of type \mathbin and \mathrel (suggested in Antal's answer), you see that it works quite well in these typical uses of \text, even if the spacing is tight:

alt text

These commands also all fail at the begining of an {align} (e.g. \begin{align} & \text{...}):

alt text

(The order of each command is the same as above.)

share|improve this answer
add comment

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.