4

I am trying to use the chosen solution shown here, for being able to use numbers in the alias I need for \newcommand. (That one is not able to use numbers in the alias directly strikes me as ... well, let me remain polite).

Anyway, even if I implement the top solution there, I get an error and the code cannot compile. My usage:

\newcommand{\H}[1]{H^{(1)}_{#1}}
And so \H1 is now equal to foo.

Perhaps there is something small I am missing, (I am a tex noob), and so any help would be appreciated.

9

Your first problem is that \H is already defined. (Indeed, if you look at your compilation log, you'll see it says "LaTeX Error: Command \H already defined.") So you should change it to a different name, say, \Hankel. (Alternatively, you can overwrite the previous definition by using \renewcommand in place of \newcommand. But if you do, use caution, because some parts of your document might be relying on the old definition without you realising it.)

Your second problem is that superscripts (^) and subscripts (_) only work in math mode. You can toggle math mode using the $ character. So try replacing \Hankel1 with $\Hankel1$. Alternatively, you can make the macro work both inside and outside math mode, by using \ensuremath like so:

\newcommand{\Hankel}[1]{\ensuremath{H^{(1)}_{#1}}}
  • You are a genius! This works like I envisioned. Danke! ;-) – Spacey May 15 '13 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.