we know that, the \xrightarrow can give superscript (over the arrow) and subscript (under the arrow). for example



but, I want to define a command such that it has the following style:

X\xra Y Equals to X\rightarrow{} Y
X\xra^{f}Y Equals to X\xrightarrow{f}Y
X\xra_{g}Y Equals to X\xrightarrow[g]Y

How to solve this?

  • 2
    use the xparse package to spot ^ and _ and then pass it on in the right manner to \xrightarrow – daleif Jan 6 '16 at 14:58
  • @daleif could you give some more detail – jiaopjie Jan 7 '16 at 5:27

Some checks for ^ and _ in either order:


\newcommand{\xra@sup}[2]{% #1 is ^
\newcommand{\xra@sub}[2]{% #1 is _


$A \xra B$

$A\xra^{f} B$

$A\xra^{f}_{g} B$

$A\xra_{g} B$

$A\xra_{g}^{f} B$


enter image description here


Here is one way. Probably not the best

\NewDocumentCommand\xra{ t_ t^  m}{
      \to #3
  X \xra_ t  Y \\
  X \xra^ t  Y \\
  X \xra   Y \\

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.