Replaces ~ by ' ' in TeXs (thanks to @larsrh for reporting this).

Adds unit tests for this.