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.

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.

share|improve this question
    
See here tex.stackexchange.com/a/9720 –  Sigur May 15 '13 at 15:12
add comment

1 Answer

up vote 9 down vote accepted

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}}}
share|improve this answer
    
You are a genius! This works like I envisioned. Danke! ;-) –  TyranaSaur May 15 '13 at 15:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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