I have a document that takes text from source file via pandoc (that doesn't matter anyway) and inserts it instead of $body$. The source document contains the only one symbol that's shown in hex-editor as "C2 AD". As I discovered, it is a UTF-8 character "U+00AD" — soft hyphen. I have tried to handle it with \DeclareUnicodeCharacter command, just this way:



but Xelatex still returned an error: "! Package inputenc Error: Keyboard character used is undefined (inputenc) in inputencoding `utf8'".

When I tried to use utf8x instead of utf8:



it returned: "! LaTeX Error: Missing \begin{document}".

What I am doing wrong?


2 Answers 2


\usepackage[utf8]{inputenc} or \usepackage[utf8x]{inputenc} are needed for TeX engines that do not support UTF-8. Then TeX sees the two bytes C2 and AD and utf8.def or utf8x.def make C2 active to catch AD to print the symbol or execute \- or whatever.

In XeTeX, the bytes C2 AD become the "big" character AD. "Big" character means that character with character codes >= 256 are possible. Then you can make the character active and give it the meaning you requested:

% XeTeX or LuaTeX

I wouldn't recommend using utf8x; with the package option utf8x to either inputenc or inputenx, but it works also with XeLaTeX and LuaLaTeX, you can use newunicodechar:


%%% Optional part if you want to use multiple engines

\ifx\ifxetex\ifluatex % see http://tex.stackexchange.com/a/140164/

%%% End of optional part

%%% Use just the following line if you only compile with pdflatex

\newunicodechar{­}{\-} % the first argument contains U+00AD
  • I wonder why this isn’t the default behaviour. At least with fontspec or xunicode.
    – bodo
    Feb 20, 2014 at 17:19
  • @canaaerus U+00AD is a character; the concept of soft hyphen is quite different for (Xe|Lua)TeX, where it is a particular node in the horizontal list.
    – egreg
    Feb 20, 2014 at 17:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .