2

For e.g. take

$G^\times$

here we do not need to write the curly parenthesis, as in

$G^{\times}$

What is it that one has to add to a newly declared command, e.g.

\newcommand{\foo}{\ensuremath \times\ast 2}

so that

$G^\foo$

yields the same as

$G^{\foo}$

thx

arolle
  • 21
  • 1

1 Answers1

4

you can "protect" the string you intend to use in sub- or superscripts by doubling the outer braces; only the outermost pair of braces gets stripped off when a definition is "internalized". thus

\newcommand{\foo}{{\ensuremath \times\ast 2}}

will have the desired effect.

however:

  • you really don't need \ensuremath if you're always going to use this in a sub/superscript.

  • it's not as "informative" when viewed in the input, since it's not obvious that \foo is a compoind object. omitting the braces at the point of use gets one out of the habit of using braces, which can get one into trouble with previously existing definitions that are "unprotected" compounds, such as \neq, defined as \def\neq{\not=} in fontmath.lts (inherited from plain.tex).

edit: a comment from the op states that this doesn't work "when setting <0 or alike as a superscript". that's true, and there's no way around it, except to make a definition, e.g. \newcommand{\lszero}{{<0}}, and use that. (that is what the original question asked for.)

  • 2
    best not to use \ensuremath if you do use it it needs to be {{\ensuremath{\times\ast 2}}} otherwise the ensuremath just takes\times` as its argument. – David Carlisle Jul 30 '13 at 20:26