TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 7 down vote accepted

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

share|improve this answer
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 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.