# dealing with thin spaces in XeLaTeX and LuaLaTeX

In the following small example I get unexpected but different results in XeLaTeX and LuaLaTeX:

\documentclass{article}
\usepackage{fontspec}
\setlength\parindent{0pt}
\newcommand*\x{\rule{1cm}{1cm}}

\begin{document}

\x\,\x \par
\x~\x  \par
\x \x  \par  % U202F ('NARROW NO-BREAK SPACE') between
\x \x  \par  % U2009 ('THIN SPACE') between

\end{document}

1. XeLaTeX: The second, third, and fourth squares have the same wide distance.
2. LuaLaTeX: The third and fourth squares have no distance.

I would expect in case three and four the same small distance as in case one with both engines. Are these bugs, or can I correct it by myself?

-
It depends on the used font, specifically, if the font has those glyphs. You use fontspec but do not specify any font. If you do that, I'd wager you'll see the same outcome. –  morbusg Dec 22 '13 at 10:28

If you look at the log file, you'll find

Missing character: There is no <E2><80><AF> in font [lmroman10-regular]:mapping=tex-text!
Missing character: There is no <E2><80><89> in font [lmroman10-regular]:mapping=tex-text!


(I used an ‘ASCII representation’, so the UTF-8 bytes are shown). The UTF-8 sequences correspond to

<E2><80><AF> → U+202F NARROW NO-BREAK SPACE
<E2><80><89> → U+2009 THIN SPACE

If the font has no glyph in those slots, the consequence is either printing a rectangle (old versions of XeTeX), some space or nothing at all.

You can obviate with newunicodechar:

\documentclass{article}
\usepackage{fontspec}
\usepackage{newunicodechar}

\setlength\parindent{0pt}
\newcommand*\x{\rule{1cm}{1cm}}
\newunicodechar{^^^^202f}{~}
\newunicodechar{^^^^2009}{\,}

\begin{document}

\x\,\x \par
\x~\x  \par
\x \x  \par  % U202F ('NARROW NO-BREAK SPACE') between
\x \x  \par  % U2009 ('THIN SPACE') between

\end{document}


Instead of a ^^^^ sequence you can insert the explicit character; but in the case of space characters this is awkward as editors don't distinguish between them; but

\newunicodechar{ }{~}   % U+202F NARROW NO-BREAK SPACE
\newunicodechar{ }{\,}  % U+2009 THIN SPACE


would work as well.

-