When taking a quotient with respect to a given equivalence relation, make sure to get the correct spacing. That is, S/\sim is not correct because \sim is acting like an operator here. It results in $$S/\sim$$ while the correct result would be $$S/{\sim}$$

This is easily achieved by enclosing the operator in braces, i.e., just write S/{\sim} and all is well. This stuff can be found in the TeXbook of course, but you have to put it in practice.

It is remarkable how nit-picky one can get after using TeX for a while.