How do I write $\sim$ approximately with the correct spacing?

The \sim symbol is classified as a relation symbol. By the rules of TeX, the combination Rel Ord (relation followed by an ordinary symbol) results in a thick space between them.

The case of binary operations (Bin) is different: they are treated as binary operations only if preceded and followed by math atoms compatible with binary operations, for instance

Ord Bin Ord
Ord Bin Op

and others (Op stands for "operator"). [This is not the full truth, but a good approximation to it.] When a binary operation is "out of place", it's treated as an Ord atom. This is why no space is inserted in $-1$.

Every math symbol can be turned into an ordinary atom by enclosing it in braces. TeX inserts no space between ordinary symbols, so

$\sim 10^{80}$

will result in

~ 1080

while

${\sim}10^{80}$

will give

~1080

I'm afraid that no automatic way exists that allows using only \sim. You can define

\newcommand{\unsim}{\mathord{\sim}}

(the \mathord is just for clarity, the additional braces would do the same) and use \unsim when the "unary" symbol is needed.


I had the same problem, wanting to use \sim for the (unary) logical negation operator. Building on egreg's answer from above, another option is to simply redefine the \sim command so that it produces the tilde without the space:

\let\oldsim\sim 
\renewcommand{\sim}{{\oldsim}}