Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need a dotted or dashed arrow with text like \xrightarrow.

I am aware of the MnSymbol package, but \dashedrightarrow does not allow me to write text on the arrow. Is there a package to accomplish what I want to do?

share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted

The following example uses \dashrightarrow and \dashleftarrow from AMS fonts (package amsfonts):

\documentclass{article}
\usepackage{amsfonts}
\usepackage{amsmath}

\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 \xrightarrow{} Y \xrightarrow[\text{below}]{\text{above}} Z \]

\[ X \xdashrightarrow{} Y \xdashrightarrow[\text{below}]{\text{above}} Z \]

\[ X \xleftarrow{} Y \xleftarrow[\text{below}]{\text{above}} Z \]

\[ X \xdashleftarrow{} Y \xdashleftarrow[\text{below}]{\text{above}} Z \]

\end{document}

Result

Remarks:

  • \dashrightarrow and \dashleftarrow are internally composed of the dash \dabar@ and the arrow. This is used to extend the dashes as needed.
  • \mathpalette is needed for size adaptation according to the current math style.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.