21
\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:

xMapsto

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?

3

2 Answers 2

16

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

Sample output

\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*}
   \mapsto \qquad \xmapsto[A]{sdfkjhsdf} \\
 \Mapsto \qquad \xMapsto[A]{sdfkjhsdf}
\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.

5
  • 1
    I was about to post the same answer. ;-)
    – egreg
    Aug 13, 2013 at 12:50
  • why do i get an error saying that mathtools does not exists? MicTex 2.9 X64, Win7 X64. Oct 18, 2014 at 15:12
  • @ChenStatsYu That sounds like a completely separate question. May be tex.stackexchange.com/q/187725/15925 helps. Oct 18, 2014 at 18:01
  • when i type \xmapsto{A} then there is a normal rightarrow with a 7 at the start.. Jul 7, 2018 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. Jul 10, 2018 at 11:00
3

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}

enter image description here

You must log in to answer this question.

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