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.

This is what I want to achieve:

{ 2 \pow -(n+4) } --> {2^{-(n+4)}}

This is what I know how to do:

\def\pow#1#2{{{#1}^{#2}}}

This is what I don't like about it:

\pow{2}{-(n+4)} is ugly to me.

Now, I know that plain TeX can do things like this due to:

\over, \choose, \above

However:

\show\over

"shows that such commands are internals."

I have dug into the TeX book (chapter 20), but do not see examples of how arguments can be to the left, i.e. I want something like:

\def #1\pow #2 {{#1}^{#2}}

Then, I tried things like:

\def \pow #1 \} {^{#1}\}}

However, neither of these work. Is it possible to define pow s.t.

{ 2 \pow -(n+4) } --> {2^{-(n+4)}}
share|improve this question
3  
\over is a primitive, and therefore does not implement the syntax in macros. Alexey's solution may work for you, but in TeX arguments have to come after the macro processing them (so in your case more complex 'before' parts may go wrong). –  Joseph Wright Aug 18 '11 at 10:18

1 Answer 1

\newtoks \powtoks
\def \pow {\afterassignment\powhelp \powtoks=\bgroup }
\def \powhelp{^{\the\powtoks} \egroup }
share|improve this answer

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.