What effect does the tilde character ~
have in math mode? Is it the same non-breaking space that it is in text mode? Is it bad style to use ~
in math mode? I've seen it used in some examples but have not seen it explained in any of the usual LaTeX references.
[Tex/LaTex] What does the tilde character (~) do in math mode
math-modespacingtilde
Related Question
- [Tex/LaTex] Adding Non-breaking space after single character in text mode
- [Tex/LaTex] How come the tilde ~ sometimes does not behave like non-breaking space
- [Tex/LaTex] The correct way to type tilde
- [Tex/LaTex] \widetilde{} alternative for formula over the tilde
- [Tex/LaTex] How to properly handle non-breaking spaces in math mode
- Is there difference between using ‘~’ and Unicode non-breaking space
Best Answer
Using
~
or\⍽
(control space, just in order to make it clear) in math mode is not equivalent, as the following example shows:This produces
Why is that? Because the definition of
~
is(line numbers are those in
latex.ltx
). Thus~
also adds a{}
group that's significant in math mode and explains the difference in output: in the first line we have (Ord stands for an atom of class “ordinary”, Rel for an atom of class “binary relation”)and TeX ignores explicit skips when deciding what math spacing to insert. So by rule it inserts a thick space between Ord and Rel and between Rel and Ord, but no space between Rel and Rel. The
<skip>
due to\⍽
is inserted back when converting the math list to a horizontal box.In the second case we have
because in math mode
{}
counts as an Ord atom. Thick spaces will be inserted at either side of the empty Ord atom.Thus it's better to use
\⍽
instead of~
, in order to avoid surprises. However, the usage should be limited to separating parts of a formula that need to be considered as words, typically in displays. There's no difference betweenand
Just a question of personal preference, because either will use the interword space relative to the current font outside of math, without stretching or shrinking. For spacing math symbols the best is to use
\mkern
or\mskip
(possibly the latter, for whichamsmath
provides the\mspace
interface, analog to\hspace
).Note that in inline math mode
\⍽\text{and}\⍽
and\text{⍽and⍽}
are different, as the former inserts spaces that may participate to stretching and shrinking, whereas the latter inserts “frozen” spaces. However, something likeis more properly written as
so as to give TeX more chances to properly break the line.