Is it possible to capture sub-/superscripts added to a macro by the macro itself? Consider the following example:

\fx{x}   % -> f(x)
\fx{x}^2 % -> f(x)²

Now the question, is it possible to do something like

\fx{x}^2 % -> f²(x)

of course not in this way, but in principle using some hacky TeX stuff?


I find a notation such as "f²(x)" ambiguous; I know that it's traditional for the trigonometric functions, but I believe that


is far less ambiguous, when we agree that "f(x)" has precedence over other algebraic expressions.

However, here it is.



You carry over the argument and test whether the argument is followed by ^; in this case you typeset f^{<exponent>}(<argument of \fx>), otherwise you do the simple thing.

A more general macro might be




which gives

enter image description here

  • Thanks again egreg, I have to admit the example was stupid. I agree that this notion is ambiguous an I don't like it either (except for sin and cos) but that is actually not what I need it for, I thought more of something like f^*(x) or \Psi^\dagger(x) etc.
    – buergi
    Nov 20 '12 at 18:30

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.