答案1
我只是将您引用的两个答案结合起来,使用 David 的技术应用于 Heiko 的代码。功劳归于他们。这是我对 Heiko 代码的补充:
\newcommand\xdashmapsto[2][]{\mathrel{\mapstochar\xdashrightarrow[#1]{#2}}}
唯一的变化是要记住以与 相同的方式使用参数\xdashrightarrow
。
\documentclass{article}
\usepackage{amsfonts}
\usepackage{amsmath}
\newcommand\xdashmapsto[2][]{\mathrel{\mapstochar\xdashrightarrow[#1]{#2}}}
\makeatletter
\newcommand*{\da@rightarrow}{\mathchar"0\hexnumber@\symAMSa 4B }
\newcommand*{\da@leftarrow}{\mathchar"0\hexnumber@\symAMSa 4C }
\newcommand*{\xdashrightarrow}[2][]{%
\mathrel{%
\mathpalette{\da@xarrow{#1}{#2}{}\da@rightarrow{\,}{}}{}%
}%
}
\newcommand{\xdashleftarrow}[2][]{%
\mathrel{%
\mathpalette{\da@xarrow{#1}{#2}\da@leftarrow{}{}{\,}}{}%
}%
}
\newcommand*{\da@xarrow}[7]{%
% #1: below
% #2: above
% #3: arrow left
% #4: arrow right
% #5: space left
% #6: space right
% #7: math style
\sbox0{$\ifx#7\scriptstyle\scriptscriptstyle\else\scriptstyle\fi#5#1#6\m@th$}%
\sbox2{$\ifx#7\scriptstyle\scriptscriptstyle\else\scriptstyle\fi#5#2#6\m@th$}%
\sbox4{$#7\dabar@\m@th$}%
\dimen@=\wd0 %
\ifdim\wd2 >\dimen@
\dimen@=\wd2 %
\fi
\count@=2 %
\def\da@bars{\dabar@\dabar@}%
\@whiledim\count@\wd4<\dimen@\do{%
\advance\count@\@ne
\expandafter\def\expandafter\da@bars\expandafter{%
\da@bars
\dabar@
}%
}%
\mathrel{#3}%
\mathrel{%
\mathop{\da@bars}\limits
\ifx\\#1\\%
\else
_{\copy0}%
\fi
\ifx\\#2\\%
\else
^{\copy2}%
\fi
}%
\mathrel{#4}%
}
\makeatother
\begin{document}
\[ X \xdashmapsto{x} Y \xdashmapsto{\mathrm{longer}} Z
\xdashmapsto[\mathrm{underset}]{\mathrm{longer}} W
\]
\end{document}
如果发现箭头后的间距太大,可以用一个小的负空间重新定义它,如下
\newcommand\xdashmapsto[2][]{\mathrel{\mapstochar\xdashrightarrow[#1]{#2}\!}}