9

I use $\xrightarrow{f}$ a lot and I found myself in need of the corresponding commands \xmapsto and \xhookrightarrow quite a few times and I was wondering if there is anything like it. I'd like to produce

(i) a labeled hookrightarrow

(ii) a labeled mapsto

Thanks in advance for any help.

1
  • 1
    A tip: you can highlight commands and small portions of code by enclosing it between two backticks `` Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Jun 27, 2014 at 10:41

2 Answers 2

16

I am not sure, whether you mean those commands with labels, but I think they could provide the relevant symbols:

\xmapsto{label}, \xhookrightarrow, all from mathtools package.

\documentclass[12pt]{article}
\usepackage{mathtools}

\begin{document}


\begin{align*}
\xmapsto{\text{Look here}} &&  x\\
\xrightarrow{\text{Something}} && y \\
\xhookrightarrow{\text{Something completely different}} && z 
\end{align*}

\end{document}

enter image description here

Please have also a look on http://mirrors.ctan.org/info/symbols/comprehensive/symbols-a4.pdf, which provides a (perhaps not complete, but near to it) overview of symbols in LaTeX

5
  • Ooh! mathtools was exactly what I needed! : ) Thank you very much for this helpful answer. It does make one wonder though why xrightarrowdoes not need the same package included as the other two commands.
    – Matt N.
    Jun 27, 2014 at 11:08
  • 2
    @MattN. \xrightarrow is a command already available by ususal amsmath and perhaps redefined/improved in mathtools (I did not check for it now), but not \xmapsto and \xhookrightarrow (as far as I know). To make it work. If you include both amsmath and mathtools, amsmath must come before the other one.
    – user31729
    Jun 27, 2014 at 11:11
  • 1
    mathtools does not touch \xrightarrow, we only provide the extra ones.
    – daleif
    Jun 27, 2014 at 11:16
  • @daleif: Ok, I already guessed that, therefore I wrote perhaps. Thank you.
    – user31729
    Jun 27, 2014 at 11:17
  • @ChristianHupfer Thank you for pointing that out to me.
    – Matt N.
    Jun 27, 2014 at 12:09
5

A minimal implementation if you do not wish to import mathtools

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\providecommand*{\xmapstofill@}{%
  \arrowfill@{\mapstochar\relbar}\relbar\rightarrow
}
\providecommand*{\xmapsto}[2][]{%
  \ext@arrow 0395\xmapstofill@{#1}{#2}%
}

\providecommand*{\xhookrightfill@}{%
  \arrowfill@{\lhook\joinrel\relbar}\relbar\rightarrow
}
\providecommand*{\xhookrightarrow}[2][]{%
  \ext@arrow 0395\xhookrightfill@{#1}{#2}%
}
\makeatother

\begin{document}
\[ A \xmapsto[under]{over} B \]
and
\[ A \xhookrightarrow[under]{over} B \]
\end{document}

AMSmath's \ext@arrow is the command that generates the extensible arrow composed of the chars defined in its fifth argument, in this case \xmapstofill@; in turn this defines the arrow to start with \mapstochar\relbar (|-) then repeat \relbar (-) as many times as needed to fit the label, then end with \rightarrow (->).

2
  • What about the same for \hookrightarrow?
    – Sigur
    Jul 2, 2015 at 8:41
  • 1
    @Sigur there you go!
    – Bordaigorl
    Jul 2, 2015 at 10:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .