# Is it worth defining \ensuretext ?

We already have \ensuremath to make sure the argument get enclosed in math mode. Is it worth defining \ensuretext ?

-
\def\ensuretext#1{\ensuremath{$#1$}} –  Seamus May 28 '11 at 17:55
@Seamus: \ensuremath must not enclose a pair of \$s. –  xport May 28 '11 at 17:56
Would \ensuremath{\)#1$$} work? – Seamus May 28 '11 at 17:59 @Seamus: I cannot down vote your comments :) – xport May 28 '11 at 18:00 Ugh. I just tried x^2$$ which compiles fine... (Though it breaks emacs syntax highlighting...) –  Seamus May 28 '11 at 18:02

I think amsmath's \text is just OK.

Quoted from document of amstext:

The \text macro is a sophisticated command which allows the user to insert “normal text” into math formulas without worrying about correct sizes in sub- or superscripts. It can also be used in ordinary text; there it produces an unbreakable unit similar to \mbox.

-
AFAIK there is no \ensuretext because a simple \hbox or \mbox is enforcing text mode already. However, if you need automatic scaling for subscripts etc. then use Leo's answer which handles this.
BTW there is the \ifmmode switch to test if you are in mathmode. It is used by e.g. \text.