[Tex/LaTex] How to denote adjacent vertices

graphsinline()math-modestrikeout

Background

I'm trying to write a rapport that relies on some rudimentary graph theory and as
such I'd like to write a section explaining the basics of it.

Trying to do

I've run into a bit of a snag trying to adequately write out pairs of
vertices that have an edge between them. Hopefully someone more knowledgeable
in regards to TeX either knows of the command which I seek or of a way to create it:

I mean to write vertices u and v (in math-mode) with a long line between them,
approximately the distance of an em-dash. This line denotes an edge between the vertices. However I need to be able to also denote the lack of such an edge by
being able to strike over said line (\not). Any and all help would be much
appreciated!

Tested

I've tried

$u \not\textemdash v$

and

$u \not\textrm{---} v$
$u \not\textrm{\textemdash} v$

however neither works. The latter two are close but I'd need to be able to move the
symbol generated by \not to the right by about half an em somehow.

Best Answer

You could use \arrownot from stmaryrd; the normal \not seems too big for a simple bar.

\documentclass{article}
\usepackage{stmaryrd} % for \arrownot
\newcommand{\notedge}{%
  \mathrel{\mkern-2mu}% a small back up
  \arrownot % a short slash
  \mathrel{\mkern2mu}% compensate
  \mathrel{-}% minus as a relation
}

\begin{document}
$u\notedge v$
\end{document}

enter image description here

This exploits two facts: \arrownot has zero width and is classified as a relation symbol (it extends past its bounding box); TeX doesn't add space between consecutive relation symbols (which can also be spaces)

This is how $u\not\mathrel{-}v$ would print:

enter image description here

A possible alternative:

\documentclass{article}
\usepackage{centernot}

\newcommand{\notedge}{\centernot{\mathrel{-}\joinrel\mathrel{-}}}

\begin{document}

$u\notedge v$

\end{document}

enter image description here

Another proposal with longer symbols:

\documentclass{article}

\usepackage{stmaryrd} % for \arrownot

\newcommand{\edge}{%
  \mathrel{-}% minus as a relation
  \joinrel\joinrel % some backup
  \mathrel{-}% minus as a relation
}
\newcommand{\notedge}{%
  \mathrel{\mkern2mu}% a small advancement
  \arrownot % a short slash
  \mathrel{\mkern-2mu}% compensate
  \edge
}

\begin{document}

$u \edge v$

$u\notedge v$

\end{document}

enter image description here

Related Question