Exotic spaces: en space, em space, thin space and the rest

A family of spaces of specific widths, from the hair space up to the em quad, plus the medium mathematical space and the ideographic space used in CJK typesetting. Each is a real space of a defined width.

How it works

Unicode defines a family of spaces with fixed widths for typesetting: the en quad and em quad, the en and em spaces, the three-per-em, four-per-em and six-per-em spaces, the figure space sized to a digit, the punctuation space, the thin space, the hair space, the medium mathematical space, and the ideographic space used in CJK text. Each has a defined advance width and its own line-breaking behaviour, and each is a different code point from ASCII 0x20. Layout engines honour the widths, so text using them aligns correctly in the font it was designed for and drifts in another. Everything below layout treats them as ordinary characters that are simply not the space you are looking for: splitting, trimming, tokenising and comparing all fail in the same quiet way. The ideographic space deserves separate mention, because in Japanese and Chinese it is ordinary punctuation rather than an anomaly, and converting it to an ASCII space is a visible change to that text.

What it is legitimately for

Fine typographic control. An em space indents, a thin space separates a number from its unit, and the ideographic space is the ordinary space of Japanese and Chinese text.

What it breaks

  • Splitting on an ASCII space misses them, so parsed columns come out wrong.
  • Text alignment that looks right in one font falls apart in another.
  • Comparison and deduplication fail on strings that look identical.

How to find it yourself

Look for the e2 80 8x range in a hex dump, and e3 80 80 for the ideographic space.

What Clipboard Sanitizer does

Replaced with an ordinary ASCII space, and deleted when part of trailing whitespace.

Questions

What about Japanese and Chinese text?

The ideographic space is ordinary punctuation in those languages, and converting it to an ASCII space is a visible change. If you write in them, turn the whitespace rule off.