Thursday, July 23, 2009

Typesetting tilde or backslash

Typesetting a tilde in Latex or Xetex is not so easy. It's a reserved character (non breakable fixed width space) and \~ produces a diacritic. Typing this diacritic alone, i.e. \~{} still produces a tilde which is small and high above the base line. When you follow most of the recommendations in Latex books, you probably write tilde by $\sim$ or any other more complicated variant thereof to work in both text and math environment. This produces a tilde nice and big, not too high above the baseline. What you also see is the recommendation to write tilde in the verbatim mode. For me these two are still not acceptable because they usually switch the font and you really see that the font of it looks alien to the surrounding text. Why should I switch the font when I want to write a tilde in the text mode? I want to get a nice tilde in the normal font which is not a diacritic. Font designers strived to match the appearance of the tilde glyph to the rest of the font so why shouldn't I use it?

Fortunately, there is a macro for typing the kind of tilde I need: \textasciitilde{}. It is just not generally known. This produces a tilde in the text mode which uses the tilde glyph from the font just as the font designers shaped it. It's similar to the command \textbackslash{} which is more widely known for typsetting backslash in text mode.

When you are in text mode, use these commands and spread the word.