Quantcast
Channel: Combination of arrows with and without label - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 3

Combination of arrows with and without label

$
0
0

Suppose that an arrow can be

  1. With one head (o), two heads (t), or "squiggly" (g),
  2. Single-lined (s) or double-lined (d),
  3. With (w) or without (o) a label (i.e., text above)

Some of those arrows are defined by "standard" packages, like \xrightarrow{abc}, which corresponds to osw, some of them needs more "exotic" packages, like \xLongrightarrow (tdw), defined by extarrows.

Some needs to be drawn with Tikz, like \xtwoheadrightarrow (tsw), cf. https://tex.stackexchange.com/a/60219/34551

I tried to have a macro allowing me to define all those combinations at once, and to display them with a uniform appearance. I tried to use xparse and l3regex, which seemed to be a good combination to handle it (shout-out to https://tex.stackexchange.com/a/188593/34551).

I think I managed to define a macro that define them all at once, but they look terrible, i.e., really not uniform, and the hack I used for tdw is simply awful.

Should I give up my idea of taking an arrow there and another there, and just draw them all in tiKz? How to make sure, in this case, that they do behave like mathematical operators?

Here's what I managed to get:

enter image description here

Using the following code:

\documentclass{article}\usepackage{xparse,l3regex}\usepackage{amssymb}\usepackage{amsmath}\usepackage{extarrows} % For \xLongrightarrow\usepackage{mathtools}\usepackage{tikz}\usetikzlibrary{calc,decorations.pathmorphing,shapes,arrows}\newcommand\xRightsquigarrow[1]{% https://tex.stackexchange.com/a/83086  \mathrel{%    \begin{tikzpicture}[baseline= {( $ (current bounding box.south) + (0,-0.5ex) $ )}]      \node[inner sep=.5ex] (a) {$\scriptstyle #1$};      \path[draw,implies-,double distance between line centers=1.5pt,decorate,      decoration={zigzag,amplitude=0.7pt,segment length=1.2mm,pre=lineto,    pre   length=4pt}]       (a.south east) -- (a.south west);    \end{tikzpicture}}%}\newcommand\Rightsquigarrow{%  \mathrel{%    \begin{tikzpicture}[baseline= {( $ (current bounding box.south) + (0,-0.5ex) $ )}]      \node[inner sep=.5ex] (a) {\hspace*{1em}};      \path[draw,implies- ,double distance between line centers=1.5pt,decorate,      decoration={zigzag,amplitude=0.7pt,segment length=1.2mm,pre=lineto,    pre   length=4pt}]       (a.south east) -- (a.south west);    \end{tikzpicture}}%}\makeatletter % https://tex.stackexchange.com/a/114242/34551\providecommand*{\twoheadrightarrowfill@}{%  \arrowfill@\relbar\relbar\twoheadrightarrow}\providecommand*{\xtwoheadrightarrow}[2][]{%  \ext@arrow 0579\twoheadrightarrowfill@{#1}{#2}%}\makeatother\ExplSyntaxOn\NewDocumentCommand{\ar}{ m o }{  \IfNoValueTF{#2}  {% there is no trailing optional argument, set the boolean to false    \bool_set_false:N \l_label_bool  }  {% there is a trailing optional argument, set the boolean to true    \bool_set_true:N \l_label_bool    % and store the argument for later usage    \tl_set:Nn \l_label_tl { #2 }  }  \ar_short:n { #1 }}% First byte: o, t, g     (one head, two heads, squiggly)% Second byte: s, d       (single or double)% Third byte:             (label to write on it)\bool_new:N \l_label_bool\tl_new:N \l_label_tl\cs_new_protected:Npn \ar_short:n #1{% separate the two characters  \ar_short_aux:NN #1}\cs_new_protected:Npn \ar_short_aux:NN #1 #2{  \str_case:nn { #1 }  {    {o}% One head    {      \str_case:nn { #2 }      {{s}{% Single      \xtwoheadrightarrow[]{  \bool_if:NT \l_label_bool { \l_label_tl }}    }{d}{% Double      \xRightarrow{  \bool_if:NT \l_label_bool { \l_label_tl }}\!\!\!\!\Rightarrow}      }    }    {t}% Two heads    {\str_case:nn { #2 }      {{s}{% Single      \xrightarrow{  \bool_if:NT \l_label_bool { \l_label_tl }}    }{d}{% Double      \xLongrightarrow{  \bool_if:NT \l_label_bool { \l_label_tl }}    }      }    }    {g}% Squiggly    {\str_case:nn { #2 }      {{s}{% Single      \bool_if:NTF \l_label_bool {\overset{\l_label_tl}{\rightsquigarrow}}{\rightsquigarrow}    }    {d}{% Double      \bool_if:NTF \l_label_bool {\xRightsquigarrow{\l_label_tl}}{\Rightsquigarrow}}      }    }  }}\ExplSyntaxOff\begin{document}  $a \ar{os} b$  $a \ar{od} b$  $a \ar{ts} b$  $a \ar{td} b$  $a \ar{gs} b$  $a \ar{gd} b$  $a \ar{os}[i_2 : \alpha, 34] b$  $a \ar{od}[i_2 : \alpha, 34] b$  $a \ar{ts}[i_2 : \alpha, 34] b$  $a \ar{td}[i_2 : \alpha, 34] b$  $a \ar{gs}[i_2 : \alpha, 34] b$  $a \ar{gd}[i_2 : \alpha, 34] b$\end{document}

The difference of spacing between them, and the fact that one of them (gsw) is not extensible, are what bug me the most.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images