[Tex/LaTex] Strange alignment when using tilde as the not operator in logic

logicspacingsymbols

I wish to use ~ which has latex symbol: \sim for the negation sign in logic. \sim and \neg are the two most frequent symbols for negation in logic.

However, I get a strange looking result if I use \sim. The spacing with the variables is odd as the \sim is further from the variable. Compare the alternative using \neg and you will see what I mean.

  1. How can I fix the spacing/alignment?
  2. How can I show the results of my LateX code on SE?

Thanks in advance!

Best Answer

\sim is a relational symbol (like =), the spacing around is quite large (\thickmuskip). In LaTeX it is defined as:

\DeclareMathSymbol{\sim}{\mathrel}{symbols}{"18}

\neg is a \mathord and is defined as:

\DeclareMathSymbol{\neg}{\mathord}{symbols}{"3A}

Thus you can define a \lsim as \mathord:

\DeclareMathSymbol{\lsim}{\mathord}{symbols}{"18}

Or \lsim can be defined using \sim:

\newcommand*{\lsim}{\mathord{\sim}}