# How to redefine the exponent command

I'm preparing a package that defines a special environment, let us call it `myenv`, and within the `myenv` a command, let us call it `\mycom` that stacks its arguments the one above the other. So `\mycom{x}[y]` stacks `x` above the optional `y` (if `y` is not given the command considers `y` to be `{}`).

In `myenv` math makes no sense so I want to simplify the typing by writing `y^x` (or `{y}^{x}`) in textmode to mean `\mycom{x}[y]`.
When the `myenv` closes the meaning of `^` must return to normal.

How can I do this?

• You mean `\mycom{x}[y]` to give `x` above `y` or vice versa? – user156344 Mar 29 at 6:50
• When TeX is in math mode it processes the material twice, first making an abstract representation in terms of atoms and fields attached to them, then delivering the actual formatting in terms of boxes and characters. This is not done in text mode, so when `y` has been scanned, it is out of reach for a following command. But `^{over}[under]` is possible. – egreg Mar 29 at 8:02
• Why don't you try to use the commands from `stackengine`? – Bernard Mar 29 at 9:48