next up previous contents
Next: Setting text superscripts Up: Commands Previous: Font changing: math

Ensuring math mode


\ensuremath {<math commands>}

In LaTeX 2.09, if you wanted a command to work both in math mode and in text mode, the suggested method was to define something like:

   \newcommand{\Gp}{\mbox{$G_p$}}
Unfortunately, the \mbox stops \Gp changing size correctly in (for instance) subscripts or a fraction.

In LaTeX2e you can define it thus:

   \newcommand{\Gp}{\ensuremath{G_p}}
Now \Gp will work correctly in all contexts.

This is because the \ensuremath does nothing, producing simply G_p, when \Gp is used within math mode; but it ensures that math mode is entered (and exited) as required when \Gp is used in text mode.



Rainer Schoepf
Thu Jul 31 16:46:28 MEST 1997