[Tex/LaTex] Error with inputenc and UTF-8 non-breaking space

errorsinput-encodingsunicode

This is a follow up to How to make non-breaking spaces (ties) in Org-mode that exports properly to LaTeX. One answer to the question is a solution that uses UTF-8 non-breaking spaces but these cause package errors even though the document compilation finishes.

I have boiled it down to the following. The UTF-8 non-breaking space may not be possible to copy from the example. Therefore, it may have to be manually entered. In Emacs it can be entered with C-x 8 Space.

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

e.g.~ example% non-breaking \240 space between ~ and example

\end{document}

This example gives the following error:

! Package inputenc Error: Unicode char \u8:  not set up for use with
LaTeX.

Note that there is an UTF-8 non-breaking space after the colon in that error message.

How can fix this error?

I use TeX Live 2011 updated (which I updated today).

Best Answer

You can use

\usepackage{newunicodechar}
\newunicodechar{ }{~}

(where in the first argument there's the non-breaking space). This has the advantage that it can be used without any modification also with XeLaTeX and LuaLaTeX, where a non-breaking space would give a space that doesn't stretch or shrink with the other spaces in the same line.

See also Replacing Unicode non-breakable spaces by normal spaces