# Defining commands/abbreviations that contain numbers


-
I think it is important to know what other commands `\H...` you're going to need. Is it as in Jan's answer? Then that one's perfect for you. If not, can you add some explanation to your question? –  Hendrik Vogt Jan 26 '11 at 12:22
Jan's answer works well for many of my use cases; it looks to me like other solutions are cumbersome or have side effects. I often use variables/identifiers with numbers when I compute things, and it is annoying that I cannot reuse these names in LaTeX -- that was my main motivation for asking the question. For the time being I think I'll stick with either not using numbers, or using command parameters as per Jan's suggestion. –  Leo Alekseyev Jan 27 '11 at 5:33
It would be really interesting for me to see other command with numbers that you'd like to use. –  Hendrik Vogt Jan 27 '11 at 10:32
@Hendrik: how about H2O? :) (I am not a chemist, so I actually don't care much about that one.) In truth, almost all my use cases involve subscripts and superscripts -- perhaps used as powers or to indicate matrix elements. So `\newcommand` parameters will work well. –  Leo Alekseyev Jan 27 '11 at 18:26
That's a good one, thanks. One could handle such cases, but it wouldn't be nice. Good that you mostly want sub- und superscripts only! –  Hendrik Vogt Jan 27 '11 at 21:16

Defining commands with parameters would be the way I would deal with this.

``````\newcommand{\H}[1]{H^{(1)}_{#1}}
``````

defines a command with one parameter. You can then do `\H0`, `\H1`, ..., `\H9`. For nore than one digit, you will have to use it as `\H{10}`.

-

In some cases, using Roman rather than Arabic numerals may help: \HI, \HII, \HIII, \HIV. This is also mentioned in Lev Bishop's link and helped in my case.

-

A bad hack (Jan's answer above is much better) `:-)`:

``````\newcommand{\HH}{\afterassignment\HH@aux\count0=}
\newcommand{\HH@aux}{H^{(1)}_{\the\count0}}
``````

between the usual `\makeatletter` and `\makeatother`. If you want to define the commands for various numbers separately, you can do

``````\makeatletter
\newcommand{\GG}{\afterassignment\GG@aux\count0=}
\newcommand{\GG@aux}{\csname GG\the\count0\endcsname}
\makeatother
``````

and define the various `\GG0`, `\GG1`... as

``````\expandafter\newcommand\csname GG0\endcsname{%
Definition of GG0.}
\expandafter\newcommand\csname GG1\endcsname{%
Definition of GG1.}

\GG0 \GG1 \GG2 ...
``````

Note that when we call `\GG` followed by `2`, we don't get any error/warning: it is just ignored. This method could seem good, but it has many drawbacks, failing in unexpected cases. For instance, if `\foo` is say, `123`, then

``````\GG1\foo...
``````

will be seen as `\GG1123`, not the expected behaviour.

-

This faq answer discusses this issue, criticises 4 possible ways of using such a macro and ultimately comes to the conclusion don't do that.

-