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.

Recently I asked this question: Dashed left arrow over symbol

I needed to know how to put an dashed left arrow over a symbol. I received two answers, one of them used Tikz for this, other use pure LaTeX solution. I had problems with the Tikz-created arrow, so I went with the LaTeX solution. Solution worked great.

However, now I need to create the same arrow, only directing to the right.

I tried to modify (by trial and error) the code that I was provided by user mapf. But because I do not have good grip on what the commands mean, I am getting wierd results.

I managed to: 1) import dashed right arrow symbol from MnSymbol (symbol \dashedrightarrow, 96) 2) Define command \dashedrightarrowtip

I failed to: 1) Define command \odrafill.

I tried different ways, but the arrows were not aligned and the dashes did not appear correctly.

I added a picture that shows my "testing". I added text to the pictures to describe what are my expectations.

Test 1![][1]

Here is the code I am using:

\documentclass[12pt,a4paper,draft]{article}
\pagestyle{plain}
\usepackage[estonian]{babel}
\usepackage[a4paper]{geometry}
\usepackage{hyphenat}
\usepackage{enumerate}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{indentfirst}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{verbatim}
\usepackage{color}
\usepackage{tikz} 

% =============================================
%Import symbol "\dashedleftarrow" from font MnSymbol without importing the whole package
% =============================================

\DeclareFontFamily{U} {MnSymbolA}{}

\DeclareFontShape{U}{MnSymbolA}{m}{n}{
  <-6> MnSymbolA5
  <6-7> MnSymbolA6
  <7-8> MnSymbolA7
  <8-9> MnSymbolA8
  <9-10> MnSymbolA9
  <10-12> MnSymbolA10
  <12-> MnSymbolA12}{}
\DeclareFontShape{U}{MnSymbolA}{b}{n}{
  <-6> MnSymbolA-Bold5
  <6-7> MnSymbolA-Bold6
  <7-8> MnSymbolA-Bold7
  <8-9> MnSymbolA-Bold8
  <9-10> MnSymbolA-Bold9
  <10-12> MnSymbolA-Bold10
  <12-> MnSymbolA-Bold12}{}

\DeclareSymbolFont{MnSyA} {U} {MnSymbolA}{m}{n}

\DeclareMathSymbol{\dashedleftarrow}{\mathrel}{MnSyA}{98}
\DeclareMathSymbol{\dashedrightarrow}{\mathrel}{MnSyA}{96}

\def\Gg{{\mathbf{G}}}
\def\gc{{\mathbf{g}}}

\newcommand{\toright}[1]{\overrightarrow{#1}}
\newcommand{\toleft}[1]{\overleftarrow{#1}}

\newcommand{\torightleft}[1]{\toleft{\toright{#1}}}
\newcommand{\toprerightleft}[1]{\toleft{\topreright{#1}}}    
\newcommand{\torightpreleft}[1]{\topreleft{\toright{#1}}}    
\newcommand{\toprerightpreleft}[1]{\topreleft{\topreright{#1}}}

\newcommand{\toleftright}[1]{\toright{\toleft{#1}}}
\newcommand{\topreleftright}[1]{\toright{\topreleft{#1}}}
\newcommand{\toleftpreright}[1]{\topreright{\toleft{#1}}}
\newcommand{\topreleftpreright}[1]{\topreright{\topreleft{#1}}}

% =============================================
% How to make dashed left arrow over symbol:
% http://tex.stackexchange.com/questions/114501/dashed-left-arrow-over-symbol
% =============================================
\makeatletter
\newcommand{\topreleft}[1]{%
  \vbox {\m@th\ialign{##\crcr
  \odlafill \crcr
  \noalign{\kern-\p@\nointerlineskip}
  $\hfil\displaystyle{#1}\hfil$\crcr}}}

\newcommand{\topreright}[1]{%
  \vbox {\m@th\ialign{##\crcr
  \odrafill \crcr
  \noalign{\kern-\p@\nointerlineskip}
  $\hfil\displaystyle{#1}\hfil$\crcr}}}

%% fill with (short) minus signs
\def\odlafill{%
$\m@th\dashedleftarrowtip\mkern-5mu\cleaders\hbox{$\mkern4mu\shortbar\mkern-3mu$}\hfill\mkern-0.5mu$}
%  $\m@th\mkern0mu\dashedleftarrowtip\cleaders\hbox{$\mkern4mu\shortbar\mkern-3mu$}\hfill$}

%% fill with find (short) minus signs
\def\odrafill{%
$\m@th\mkern-5mu\cleaders\hbox{$\mkern-3mu\shortbar\mkern4mu$}\hfill\mkern-0.5mu\dashedrightarrowtip$}

%Test 1
%$\m@th\mkern-0.5mu\cleaders\hbox{$\mkern4mu\shortbar\mkern-3mu$}\hfill\mkern-5mu\dashedrightarrowtip$}

%Test 2
%$\m@th\dashedrightarrowtip\mkern-5mu\cleaders\hbox{$\mkern4mu\shortbar\mkern-3mu$}\hfill\mkern-0.5mu$}

%Test 3
%$\m@th\mkern0mu\dashedrightarrowtip\cleaders\hbox{$\mkern4mu\shortbar\mkern-3mu$}\hfill$}

%% put 5pt space above and 1pt below the tip
\def\dashedleftarrowtip{%
  \raisebox{\z@}[5pt][1pt]{$\mathord{\dashedleftarrow}$}}

%% put 5pt space above and 1pt below the tip
\def\dashedrightarrowtip{%
  \raisebox{\z@}[5pt][1pt]{$\mathord{\dashedrightarrow}$}}

%% make the minus shorter to fit \dashedleftarrow
\def\shortbar{%
%  \smash{\scalebox{1}[1.0]{$-$}}}
\smash{\scalebox{0.4}[1.0]{$-$}}}
\makeatother

% =============================================


\begin{document}
Arrow over G should fit nicely into the brackets:

$\left[\toleft{\Gg}\right] = \left[ \topreleft{\Gg} \right].$

Dashed right arrow and left arrow should be of the same length:

$\toprerightleft{\gc}$

Left and right arrow are misaligned:

$\toprerightpreleft{\gc}$

Just for comparison:

$\torightleft{[\gc]}$

Both dashed arrows should be of the same length and align:

$\topreright{\topreleft{\Gg}}$

\end{document}
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

OK, this is far from being perfect, but in some sense there is no perfectness on the route my answer you linked to. The problem is this: when we use the dashed arrow from MnSymbol as the arrow tip of an extensible dashed arrow, this symbol defines the length of the dash as well as the gap between dashes. If you also want the extensible dashed arrow to have exactly the same length as one of the standard extensible arrows like \overrightarrow, we have to compromise somewhere as not always an integral multiple of the (fixed) dashed pattern will match. So we will have uneven spaces somewhere.

\documentclass{article}

\usepackage{graphicx}

\DeclareFontFamily{U}{MnSymbolA}{}
\DeclareSymbolFont{MnSyA}{U}{MnSymbolA}{m}{n}
\DeclareFontShape{U}{MnSymbolA}{m}{n}{
    <-6>  MnSymbolA5
   <6-7>  MnSymbolA6
   <7-8>  MnSymbolA7
   <8-9>  MnSymbolA8
   <9-10> MnSymbolA9
  <10-12> MnSymbolA10
  <12->   MnSymbolA12}{}
\DeclareMathSymbol{\dashedleftarrow}{\mathrel}{MnSyA}{98}
\DeclareMathSymbol{\dashedrightarrow}{\mathrel}{MnSyA}{96}

\def\Gg{{\mathbf{G}}}
\def\gc{{\mathbf{g}}}

\newcommand{\toright}[1]{\overrightarrow{#1}}
\newcommand{\toleft}[1]{\overleftarrow{#1}}

\newcommand{\torightleft}[1]{\toleft{\toright{#1}}}
\newcommand{\toprerightleft}[1]{\toleft{\topreright{#1}}}
\newcommand{\torightpreleft}[1]{\topreleft{\toright{#1}}}
\newcommand{\toprerightpreleft}[1]{\topreleft{\topreright{#1}}}

\newcommand{\toleftright}[1]{\toright{\toleft{#1}}}
\newcommand{\topreleftright}[1]{\toright{\topreleft{#1}}}
\newcommand{\toleftpreright}[1]{\topreright{\toleft{#1}}}
\newcommand{\topreleftpreright}[1]{\topreright{\topreleft{#1}}}

\makeatletter
\newcommand{\topreleft}[1]{%
  \vbox {\m@th\ialign{##\crcr
  \topreleftfill \crcr
  \noalign{\kern-\p@\nointerlineskip}
  $\hfil\displaystyle{#1}\hfil$\crcr}}}

\newcommand{\topreright}[1]{%
  \vbox {\m@th\ialign{##\crcr
  \toprerightfill \crcr
  \noalign{\kern-\p@\nointerlineskip}
  $\hfil\displaystyle{#1}\hfil$\crcr}}}

%% fill with (short) minus signs
\def\topreleftfill{%
  $\m@th%
  \dashedleftarrowtip%
  \mkern-1mu%
  \xleaders\hbox{$\mkern2mu\shortbar\mkern-1mu$}\hfill%
  \mkern1mu%
  \shortbar%
  \mkern0.5mu%
$}

\def\toprerightfill{%
  $\m@th%
  \mkern.5mu%
  \shortbar%
  \mkern-1mu%
  \xleaders\hbox{$\mkern2mu\shortbar\mkern-1mu$}\hfill%
  \mkern1mu%
  ‌​\dashedrightarrowtip%
$}

%% put 4.0pt space above and 0.0pt below the tip
\def\dashedleftarrowtip{%
  \raisebox{\z@}[4.0pt][0.0pt]{$\mathord{\dashedleftarrow}$}}

\def\dashedrightarrowtip{%
  \raisebox{\z@}[4.0pt][0.0pt]{$\mathord{\dashedrightarrow}$}}

%% make the minus shorter to fit \dashedleftarrow
\def\shortbar{%
  \smash{\scalebox{0.4}[1.0]{$-$}}}
\makeatother

\begin{document}
Arrow over G should fit nicely into the brackets:
\[%
  \left[\toleft{\Gg}\right] = \left[ \topreleft{\Gg} \right]
  = \left[\toright{\Gg}\right] = \left[ \topreright{\Gg} \right].
\]

Dashed right arrow and left arrow should be of the same length and align:
\[%
  \toprerightleft{\gc} = \topreleftright{\gc} = \torightpreleft{\gc} = \toleftpreright{\gc} = \toprerightpreleft{\gc} = \topreleftpreright{\gc} = \torightleft{\gc} = \torightleft{[\gc]}
\]

Left and right arrow should align and have the same length:
\[%
  \toprerightpreleft{\gc} = \toprerightpreleft{\Gg}
\]

\bigskip

\[%
  \topreright{\topreleft{x}} \quad \topreright{\topreleft{ab}} \quad \topreright{\topreleft{abc}} \quad \topreright{\topreleft{abcd}} \quad \topreright{\topreleft{abcde}}
\]

\[%
  \topreleft{\topreright{x}} \quad \topreleft{\topreright{ab}} \quad \topreleft{\topreright{abc}} \quad \topreleft{\topreright{abcd}} \quad \topreleft{\topreright{abcde}}
\]
\end{document}

sample output

So there is still some perfectness to be desired. Since you wanted to know how to tweak the parameters, here is how it works. The vertical layout is determined by the arrow tips. The definition

\def\dashedleftarrowtip{%
  \raisebox{\z@}[4.0pt][0.0pt]{$\mathord{\dashedleftarrow}$}}

says that thre is no space (0.0pt) below the arrow tip, and 4.0pt above. That way you can position the arrows and determine their distance when they are stacked. This also influences the size of the \left[...\right] braces, as those encompass also the white space above the arrow.

The horizontal pattern is determined by

\def\topreleftfill{%
  $\m@th%
  \dashedleftarrowtip%
  \mkern-1mu%
  \xleaders\hbox{$\mkern2mu\shortbar\mkern-1mu$}\hfill%
  \mkern1mu%
  \shortbar%
  \mkern0.5mu%
$}

Here, \mkern1mu is a horizontal kerning space of length 1mu=1/18\quad. The \xleaders command fills as much space as possible (\hfill) with the pattern \hbox{$\mkern2mu\shortbar\mkern-1mu$}, where the remaining space that can not be filled with another box is evenly distributed before, after and in between the repeated boxes.

share|improve this answer
    
Strangely, when I compile, I get an error about non-Unicode character. You didn't happen to write the code in Linux, did You? I suppose an line-ending character confuses LaTeX. By trial and error I found that the problem is in definition of \toprerightfill. I re-wrote the definition of \toprerightfill and copied over Your definition and now it works, although it looks 100% the same. Wierd :) Error I got was the following: ! Package inputenc Error: Unicode char \u8:​ not set up for use with LaTeX. –  Rauni Jun 3 '13 at 10:11
    
@Rauni The code is written on Linux. I just copied it from the answer again and it worked fine. So it may also have to do with the browser, the clipboard, and other things. –  mafp Jun 3 '13 at 10:37
    
Yes, You are right. I proof-read my thesis and checked the symbols. It is beautiful now! Thank You! :) –  Rauni Jun 3 '13 at 10:45
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.