# Extended \Mapsto with text above

\documentclass{standalone}

\usepackage{centernot}
\usepackage{mathtools}
\usepackage{ stmaryrd }

\begin{document}
$\xmapsto{sdfkjhsdf}$ % This is similar to what I want

$\Mapsto$ % however I need this kind of arrow

%$\xMapsto{sdfkjhsdf}$ % does not exist - results in error
\end{document}


Output of the first two:

I want an extensible mapsto with writing on top like the first, but with an arrow like the second. Is there a way to do this from the existing packages?

• Is \Longmapsto enough for you? – Sigur Aug 13 '13 at 12:08
• Should be \longmapsto, it exists. – Yan King Yin Nov 15 '15 at 9:01

The mathtools package provides nearly everything you need to construct this, and stmaryrd has the extra pieces of symbols. Putting these together gives

\documentclass{article}

\usepackage{centernot}
\usepackage{mathtools}
\usepackage{stmaryrd}

\makeatletter
\newcommand{\xMapsto}[2][]{\ext@arrow 0599{\Mapstofill@}{#1}{#2}}
\def\Mapstofill@{\arrowfill@{\Mapstochar\Relbar}\Relbar\Rightarrow}
\makeatother

\begin{document}
\begin{gather*}
\end{gather*}
\end{document}


The parameters 0599 are for the placement of the labels and how much the arrow extends over them. I have use the same numbers as mathtools does for \xmapsto. \Mapstochar is the short bar at the beginning, from the stmaryrd package, \Relbar is the double line which fits with final \Rightarrow. The internal macros names include the @ character, so have to be included in a \makeatletter / \makeatother pair.

It might have been nice to use the extpfeil package for this, but unfortunately it loads stmaryrd with clashing options.

• I was about to post the same answer. ;-) – egreg Aug 13 '13 at 12:50
• why do i get an error saying that mathtools does not exists? MicTex 2.9 X64, Win7 X64. – Chen Stats Yu Oct 18 '14 at 15:12
• @ChenStatsYu That sounds like a completely separate question. May be tex.stackexchange.com/q/187725/15925 helps. – Andrew Swann Oct 18 '14 at 18:01
• when i type \xmapsto{A} then there is a normal rightarrow with a 7 at the start.. – Lillien Sabrina Gluch Jul 7 '18 at 13:21
• @LillienSabrinaGluch I can not reproduce that; it works fine for me. Perhaps you could ask a separate question posting the code you try. – Andrew Swann Jul 10 '18 at 11:00

The fp package is used to calculate the appropriate width of the arrow. The kerns will be important if you change fonts. It's set up to provide an arrow length of a certain minimum width, regardless of the over/underset. THen, as the over/underset grows, the arrow width will grow with it.

\documentclass{article}
\usepackage{stackengine}
\usepackage{scalerel}
\usepackage{fp}
\def\clipeq{\kern -.65pt\mathrm{=}\kern -1pt}
\def\Lla{\rule[-.1ex]{.3pt}{1.3ex}}
\def\Lra{\kern -3.5pt\Longrightarrow}
\newcount\argwidth
\newcount\clipeqwidth
\savestack\tempstack{\stackon{$\clipeq$}{}}%
\clipeqwidth=\wd\tempstackcontent\relax
\newcommand\xMapsto[2]{%
\savestack\tempstack{\stackon{$\scriptstyle#1$}{$\scriptstyle#2$}}%
\argwidth=\wd\tempstackcontent\relax%
\FPdiv\scalefactor{\the\argwidth}{\the\clipeqwidth}%
\FPsub\scalefactor{\scalefactor}{1.5}% <---CAN PLAY WITH THIS VALUE
\FPmax\scalefactor{\scalefactor}{.05}%
\mathrel{%
\stackunder[2pt]{\stackon[3pt]{$\Lla\hstretch{\scalefactor}{\clipeq}\Lra$}%
{$\scriptstyle#1~$}}{$\scriptstyle#2~$}%
}%
}
\parskip 1ex
\begin{document}
$X \xMapsto{ABC}{defghi} Y$

$\xMapsto{}{}$

$\xMapsto{a}{}$

$\xMapsto{ab}{}$

$\xMapsto{abc}{}$

$\xMapsto{abcd}{}$

$\xMapsto{abcde}{}$
\end{document}