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.

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
show 2 more comments

2 Answers

up vote 19 down vote accepted

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.

add comment

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.

@xport: Thanks. If fixed the typo. –  Martin Scharrer May 29 '11 at 9:12
add comment

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .