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.

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:

\sim gives bad spacing when used as negation compared to \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}
share|improve this question
add comment

3 Answers

up vote 15 down vote accepted

\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).

share|improve this answer
    
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
2  
@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
2  
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
add comment

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}

enter image description here

share|improve this answer
3  
{\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
1  
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
1  
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
show 6 more comments

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: enter image description here

share|improve this answer
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.