[Tex/LaTex] Strike out an arrow with a small oblique segment like with \nrightarrow

amsmathmath-modestrikeoutsymbols

I'm looking for a way to strike out an arrow in the same style (or idiscernible) as predefined struck arrows, with short, slightly-oblique segments, like for instance \nrightarrow. Using \not or \cancel unfortunately yields awful results.

Best Answer

New answer (better)

I've come up with a better way to do this. Because the slash created by \not is too long I'm using rotated versions of shorter horizontal lines instead. I'm doing this rather than scaling the slash created by \not to match the thickness of the original line (without spoiling the round caps).

I'm defining four macros below that cross out a relational symbol:

  • \Neg[<shift>]{<symbol>} just uses \not;
  • \sNeg[<shift>]{<symbol>} uses a rotated -;
  • \ssNeg[<shift>]{<symbol>} uses two rotated \dabar@s;
  • \sssNeg[<shift>]{<symbol>} uses one rotated \dabar@;

\Neg matches the slash produced by \not, \sNeg matches that in \nRightarrow, \ssNeg matches that in \nrightarrow and \sssNeg just creates a really short slash. If an optional argument is provided the slash will be shifted to the right by this amount. Note however that <shift> is a length in mu, so it has to be of the form <number>mu (N.B. 18mu is equal to 1em, except it scales in \scriptstyle and \scriptscriptstyle).

(The character produced by \dabar@ is a short horizontal rule (with rounded ends) that is (I think) only used in the definition of \dashrightarrow. I wanted to use \shortmid, but this character isn't vertically centred (which means I would have to manually adjust its vertical position).)

This code produces an (incomplete) list of negated arrows:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amssymb}  %% <- for some of the arrows
\usepackage{graphicx} %% <- for \rotatebox

\makeatletter %% <- make @ usable in command names
\newcommand*\Neg[2][0mu]{\Neginternal{#1}{\negslash}{#2}}
\newcommand*\sNeg[2][0mu]{\Neginternal{#1}{\snegslash}{#2}}
\newcommand*\ssNeg[2][0mu]{\Neginternal{#1}{\ssnegslash}{#2}}
\newcommand*\sssNeg[2][0mu]{\Neginternal{#1}{\sssnegslash}{#2}}
\newcommand*\Neginternal[3]{\mathpalette\Neg@{{#1}{#2}{#3}}}
\newcommand*\Neg@[2]{\Neg@@{#1}#2}
\newcommand*\Neg@@[4]{%
  \mathrel{\ooalign{%
    $\m@th#1#4$\cr
    \hidewidth$\m@th#3{#1}\mkern\muexpr#2*2$\hidewidth\cr
  }}%
}

\newcommand*\negslash[1]{\m@th#1\not\mathrel{\phantom{=}}}
\newcommand*\snegslash[1]{\rotatebox[origin=c]{60}{$\m@th#1-$}}
\newcommand*\ssnegslash[1]{\rotatebox[origin=c]{60}{$\m@th#1{\dabar@}\mkern-7mu{\dabar@}$}}
\newcommand*\sssnegslash[1]{\rotatebox[origin=c]{60}{$\m@th#1\dabar@$}}
\makeatother  %% <- revert @

\begin{document}

\[
    \begin{array}{cccccc}
        \texttt{\tiny\textbackslash not}&
        \texttt{\tiny\textbackslash Neg}&
        \texttt{\tiny\textbackslash sNeg}&
        \texttt{\tiny\textbackslash ssNeg}&
        \texttt{\tiny\textbackslash sssNeg}&
        \texttt{\tiny\textbackslash n<arrow>}
        \\\hline
        \not\rightarrow & \Neg[1mu]{\rightarrow} & \sNeg[1mu]{\rightarrow} & \ssNeg[1mu]{\rightarrow} & \sssNeg[1mu]{\rightarrow} & \nrightarrow
        \\
        \not\leftarrow & \Neg[-1mu]{\leftarrow} & \sNeg[-1mu]{\leftarrow} & \ssNeg[-1mu]{\leftarrow} & \sssNeg[-1mu]{\leftarrow} & \nleftarrow
        \\
        \not\Rightarrow & \Neg[2mu]{\Rightarrow} & \sNeg[2mu]{\Rightarrow} & \ssNeg[2mu]{\Rightarrow} & \sssNeg[2mu]{\Rightarrow} & \nRightarrow
        \\
        \not\leftrightarrow & \Neg{\leftrightarrow} & \sNeg{\leftrightarrow} & \ssNeg{\leftrightarrow} & \sssNeg{\leftrightarrow} & \nleftrightarrow
        \\
        \not\Leftrightarrow & \Neg{\Leftrightarrow} & \sNeg{\Leftrightarrow} & \ssNeg{\Leftrightarrow} & \sssNeg{\Leftrightarrow} & \nLeftrightarrow
        \\
        \not\mapsto & \Neg[1mu]{\mapsto} & \sNeg[1mu]{\mapsto} & \ssNeg[1mu]{\mapsto} & \sssNeg[1mu]{\mapsto}
        \\
        \not\hookrightarrow & \Neg[1mu]{\hookrightarrow} & \sNeg[1mu]{\hookrightarrow} & \ssNeg[1mu]{\hookrightarrow} & \sssNeg[1mu]{\hookrightarrow}
        \\
        \not\leadsto & \Neg[1mu]{\leadsto} & \sNeg[1mu]{\leadsto} & \ssNeg[1mu]{\leadsto} & \sssNeg[1mu]{\leadsto}
        \\
        \not\rightsquigarrow & \Neg[1mu]{\rightsquigarrow} & \sNeg[1mu]{\rightsquigarrow} & \ssNeg[1mu]{\rightsquigarrow} & \sssNeg[1mu]{\rightsquigarrow}
        \\
        \not\rightharpoonup & \Neg[1mu]{\rightharpoonup} & \sNeg[1mu]{\rightharpoonup} & \ssNeg[1mu]{\rightharpoonup} & \sssNeg[1mu]{\rightharpoonup}
        \\
        \not\rightarrowtail & \Neg[1mu]{\rightarrowtail} & \sNeg[1mu]{\rightarrowtail} & \ssNeg[1mu]{\rightarrowtail} & \sssNeg[1mu]{\rightarrowtail}
        \\
        \not\rightrightarrows & \Neg[1mu]{\rightrightarrows} & \sNeg[1mu]{\rightrightarrows} & \ssNeg[1mu]{\rightrightarrows} & \sssNeg[1mu]{\rightrightarrows}
        \\
        \not\longrightarrow & \Neg[1mu]{\longrightarrow} & \sNeg[1mu]{\longrightarrow} & \ssNeg[1mu]{\longrightarrow} & \sssNeg[1mu]{\longrightarrow}
        \\
        \not\xrightarrow{abcdefg} & \Neg[1mu]{\xrightarrow{abcdefg}} & \sNeg[1mu]{\xrightarrow{abcdefg}} & \ssNeg[1mu]{\xrightarrow{abcdefg}} & \sssNeg[1mu]{\xrightarrow{abcdefg}}
    \end{array}
\]

\[
    x \Neg[1mu]{\mapsto} y_{x \Neg[1mu]{\mapsto} y_{x \Neg[1mu]{\mapsto} y}},
    x \sNeg[1mu]{\mapsto} y_{x \sNeg[1mu]{\mapsto} y_{x \sNeg[1mu]{\mapsto} y}},
    x \ssNeg[1mu]{\mapsto} y_{x \ssNeg[1mu]{\mapsto} y_{x \ssNeg[1mu]{\mapsto} y}},
    x \sssNeg[1mu]{\mapsto} y_{x \sssNeg[1mu]{\mapsto} y_{x \sssNeg[1mu]{\mapsto} y}}
\]

\end{document}

output

A few notes

  • I capitalised \Neg because \neg already exists (it produces a "¬").
  • I'm using \mathpalette to ensure that the symbol scales properly in sub-/superscripts etc.
  • I'm using \ooalign (cf. this answer) to superimpose \not\mathrel{\phantom{=}} and these arrows.
  • I'm using \rotatebox from graphicx to rotate horizontal lines by 60º. You can change this number if you want.
  • The \phantom{=} in \negslash is necessary because while \not itself has no width, it is (I believe) designed to match the width of the = character.

(Digression: It's kind of odd that \nrightarrow has a significantly smaller arrowhead than \rightarrow, and the same is true for a couple of the other amssymb arrows. I've personally never really liked the rather wide arrowheads of the Computer Modern maths font, so it would've been nice if they had also included a version of \rightarrow with a smaller head.)

Old answer (obsolete)

In my old answer I superimposed a \scriptstyle or \scriptscriptstyle slash on top of the arrow. The result didn't look as good and didn't work in e.g. sub-/superscripts. It worked the same otherwise.

\newcommand*\negrel[3][0mu]{%
  \mathrel{\ooalign{%
    $#3$\cr
    \hidewidth$\vcenter{\hbox{$#2\not\mathrel{\phantom{=}}$}}\mkern\muexpr#1*2$\hidewidth
    \cr
  }}%
}
\newcommand*\sneg[2][0mu]{\negrel[#1]{\scriptstyle}{#2}}
\newcommand*\ssneg[2][0mu]{\negrel[#1]{\scriptscriptstyle}{#2}}