# Correct spacing when using \sim as negation

When using \sim as a symbol for negation it gives incorrect spacing and this is clear if the spacing is compared to the spacing of \lnot:

How can the spacing be corrected?

\documentclass{article}

\begin{document}

$$p \leftrightarrow \lnot \lnot p$$

$$p \leftrightarrow \sim \sim p$$

$$\lnot (p \land q) \leftrightarrow (\lnot p \lor \lnot q)$$

$$\sim (p \land q) \leftrightarrow (\sim p \lor \sim q)$$

\end{document}

-

\sim qualifies as a relation symbol, hence the "bizarre" spacing you get. Writing

\renewcommand{\lnot}{\mathord{\sim}}


allows you to later change your mind and to ensure symbol coherence, as you'd always write \lnot. If you prefer, use a different name:

\newcommand{\varlnot}{\mathord{\sim}}


The \mathord function is not strictly necessary, as \newcommand{\varlnot}{{\sim}} (note the extra pair of braces) would be sufficient to change \sim into an ordinary symbol, but being specific is never a bad idea (as barbara correctly remarks).

-
I want to use both in the same document (they are sometimes used to symbolize different sorts of negation). How can I redefine \sim so that it gets the same spacing properties as \lnot? –  N.N. Oct 27 '11 at 8:14
@N.N.: As @egreg suggests, use a different name. For example, \newcommand{\simnot}{{\sim}}. Note the double braces. –  Werner Oct 27 '11 at 8:18
as noted in comments to another question, the class of \lnot is ultimately \mathord, which is equivalent to what you've got here. but it's never a bad idea to be excruciatingly specific: \newcommand{\varlnot}{\mathord{\sim}} –  barbara beeton Oct 27 '11 at 13:43

As mentioned in other answers, \sim is defined as a relational symbol, to use it as \lnot you have to turn it into ordinary symbol using \mathord macro; \mathord{\sim} (this might give the same result as {\sim}, but it is always better to be more explicit), you can even wrap it in a new macro if you use it frequently:

\documentclass{article}

\newcommand{\simnot}{\mathord{\sim}}

\begin{document}

$$p \leftrightarrow \lnot \lnot p$$

$$p \leftrightarrow \simnot \simnot p$$

$$\lnot (p \land q) \leftrightarrow (\lnot p \lor \lnot q)$$

$$\simnot (p \land q) \leftrightarrow (\simnot p \lor \simnot q)$$

\end{document}


-
{\sim} is the same thing as \mathord{\sim}, not as \mathbin{\sim} which gives wrong spacing here. –  Philippe Goutet Oct 27 '11 at 10:17
You can see in the second line that \mathbin{\sim} gives wrong spacing; a \mathbin becomes a \mathord when it can't be interpreted as an operation symbol, such as in (-1): the second formula becomes "Ord Rel Ord Bin Ord", that's incorrect. –  egreg Oct 27 '11 at 12:14
Since \lnot (which he was comparing to) is defined as a binaray operator, I think \mathbin not \mathord is what is desired here; \simnot \simnot is doing exactly as \lnot \lnot (I don't "read" math, so I can't tell what this double negation is supposed to mean and to tell if the spacing is right or not). –  Khaled Hosny Oct 27 '11 at 12:26
The definition of \lnot in fontmath.ltx is \DeclareMathSymbol{\neg}{\mathord}{symbols}{"3A} and then \let\lnot=\neg. \simnot\simnot is not spaced at all as \lnot\lnot as you can see by comparing the first and second lines of your image (there should be no space between the two \sim symbols). –  Philippe Goutet Oct 27 '11 at 13:36
I did not check the latex code, but \show\lnot gives me \lnot=\mathchar"23A, so that is class 2 (binary operator), or so I think. –  Khaled Hosny Oct 27 '11 at 14:56

For my part, I find that \sim it too wavy. I prefer to define \simnot thus:

\newcommand*{\simnot}{\mathord{\raisebox{-4pt}{\textasciitilde}}}


The value used with \raisebox is determined empirically, however, depeding on the chosen font.

So this code:

\documentclass{minimal}
\newcommand*{\simnot}{\mathord{\raisebox{-4pt}{\textasciitilde}}}
\begin{document}
$$\simnot\cdot$$ \quad (height comparison with \texttt{\textbackslash cdot})
$$p \leftrightarrow \lnot \lnot p$$
$$p \leftrightarrow \simnot \simnot p$$
$$\lnot (p \land q) \leftrightarrow (\lnot p \lor \lnot q)$$
$$\simnot (p \land q) \leftrightarrow (\simnot p \lor \simnot q)$$
\end{document}


gets rendered thus:

-