[Tex/LaTex] the “correct” way of embedding text into math mode

math-mode

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"?

Best Answer

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}. \]