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.

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

Lets say I have something like:

\[ Let x = number of cats \]

(This is a contrived example, but pretend we are actually inside a long align environment block...) "Let" and "number of cats" need to be written like normal text, while x= needs to be math type text.

I've seen this:

\[ \mbox{Let } x = \mbox{ number of cats} \]

and this:

\[ \textrm{Let } x = \textrm{ number of cats} \]

They seem to produce equivalent output, but I'm not sure which is the "correct" one. Also, they are not ideal in that the extra space needs to be placed inside the text mode block, otherwise it is ignored as math mode and butts the text right up against the math.

Ideally there would be some command which allowed embedding text into an equation, which correctly inserted leading and trailing space around the block as required without adding space inside the text block.

How does one do that "correctly"?

share|improve this question
up vote 86 down vote accepted

Another option is to use the \text{} command provided by the amsmath package.

Having said that, I doubt that it's possible to have a single format that is "correct" for all possible requirements of leading and trailing spaces. For instance, I think you'll find that your example looks better without the space before "number" but with the space after "Let."

If there's some reason that you really want to not have the space inside whatever text environment you choose, you can force a space in math mode using a single backslash followed by a space (i.e. \<space>). For example,

\[ \text{Let}\ x=\text{number of cats}. \]
share|improve this answer
Note, however, that the option with \ is not exactly the same: ,\ in math mode produces a larger space than \text{, } since the comma behaves differently in math mode. (I prefer the ,\ version.) – Hendrik Vogt Sep 23 '10 at 19:02
\text is almost identical to \mbox. The only difference I'm aware of (besides the more semantic name) is that \text will produce subscript-size text if you use it inside a subscript. – Mark Meckes Sep 23 '10 at 20:03
Yes, it's impossible to do the right spacing thing in all cases, but putting the space there might not look the best, but it will never be wrong. Not having any space there, however, results in output that is wrong no matter how one looks at it. – Billy ONeal Sep 24 '10 at 15:11
I've just noticed that \text produces crashes used with knitr while \textrm and \mathrm don't (the second one allows for subscripts when used like this x_\mathrm{ – clemlaflemme Sep 2 '15 at 10:24

I'd agree that the AMS text command is the way to go, but don't be afraid to re-enter,

  \text{Let $x=\text{number of cats}$} 

so that the spacing is handled correctly.

share|improve this answer

Which command is best is subject to an open discussion. See for example the FAQ, but also this thread. Concerning the space, I think the manual solution that you posted is indeed the best one; after all, the normal case is to enter spaces manually, and every attempt to introduce some automatic behavior would break the strict separation concerning space handling in text and math mode.

share|improve this answer
But there is a space -- it's between the ending } and the next math character. :/ – Billy ONeal Sep 24 '10 at 12:45
At that place math mode is active, so spaces are ignored. If the space after the } were significant, the treatment of spaces in math mode would be inconsistent. – Philipp Sep 24 '10 at 15:10

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.