Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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).

share|improve this question
add comment

2 Answers 2

up vote 6 down vote accepted

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

share|improve this answer
    
Just wanted to add: it seems that this method does not work with texlive package as supplied by Debian/Ubuntu. Probably the newunicodechar package is missing from the distribution. (It could be added manually in /usr/local/share/texmf.) –  snap Feb 18 '12 at 11:07
    
@snap The TeX Live/Debian distribution is based on the October 2009 snapshot of TeX Live and is largely outdated. –  egreg Feb 18 '12 at 11:15
add comment

Write in the preamble

\DeclareUnicodeCharacter{00A0}{~}

Explanation:

The macro DeclareUnicodeCharacter is defined in the file utf8.def (the file used by inputenc to define the utf8 mapping) to define the meaning of Unicode characters. The first argument is the hexadecimal code for the character, and the second is the replacement LaTeX code.

The non breaking space is U+00A0, therefore the first argument is 00A0.

In LaTeX, a non-breaking space is generated with a tilde, therefore the second argument is a single tilde.

You can more clearly see what happens if you change the command to

\DeclareUnicodeCharacter{00A0}{\emph{-- non-breaking space --}}

Now in place of the non-breaking space, the text "‒ non-braking space ‒" is inserted.

share|improve this answer
    
That works. Could you please include an explanation of what that bit of code does in your answer? –  N.N. Feb 16 '12 at 20:06
    
I came across this problem and was lucky to find it answered just yesterday. I wanted to add that this method works perfectly with Ubuntu/Debian texlive installation. –  snap Feb 18 '12 at 11:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.