# In math mode, when is it appropriate to use ~ as opposed to \,? [closed]

In math mode, a whitespace may be inserted using either a tilde (~) or a comma command (\,).

E.g.:

W=\{x,y~|~x+y=3\}
% or
W=\{x,y\,|\,x+y=3\}


Are either of these frowned upon in general? Is it largely just a stylistic difference? When should I use a tilde as opposed to a comma command?

• Use semantic / symbolic commands. Isn't W = \{ x, y \given x + y = 3 \} better? Or may be with little more effort you have a bit more power W = \set{ x, y \given x + y = 3 }. Then you can define \given in any way you want (this doesn't answer this specific question, but I think it's a good way to go). Sep 29 '16 at 16:20
• I hadn't thought of creating a \given macro, thanks! It helps in this specific case, but I'm interested in a general-case answer; white space exists outside of set notation, after all. Sep 29 '16 at 16:22
• See the mathtools manual for a set defining macro that uses the idea of \given, hint it has build in scaling abilities. Sep 29 '16 at 16:24
• Also space in math is a very special discussion and is very different than outside math. I'd never use ~ in math mode. Sep 29 '16 at 16:26
• Here's my two cent: W = \{\, (x,y) \mid x+y=3 \,\} Sep 29 '16 at 17:08

In the TeXbook, Knuth advocates writing neither \,|\, nor ~|~ for the expression at hand. Given that (pun intended) the | symbol would be read out loud as "given that", it is a relational operator (in TeX jargon) and should therefore be surrounded by "thickspace". (Other objects of mode "mathrel" are =, <, and >.) PlainTeX and LaTeX both provide the macro \mid to meet this particular typesetting purpose.
W=\{ \, x,y \mid x+y=3 \, \}

Observe the thinspace directives inside the opening and closing curly braces -- in addition to \mid.