12

I have a LaTeX document, that can be compiled without any problems, but after copying some text into the document, I'm getting a huge amount of errors that say:

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

I know that this kind of error is quite common, but in my case it is not caused by a single character, but the whole text (which is very long).

The text has been written in Abi Word and saved as UTF-8 encoded text file. The Texmaker Editor uses also UTF-8 encoding. I don't know what could be wrong with that copied text.

9
  • 2
    Welcome to TeX.SX! Can you add the whole line with the error?
    – egreg
    Jun 13, 2013 at 21:46
  • 1
    There are many, many lines with the same error: ! Package inputenc Error: Unicode char \u8:‭ not set up for use with LaTeX.See the inputenc package documentation for explanation.Type H <return> for immediate help Jun 13, 2013 at 21:51
  • I understand it. But if you faithfully copy and paste one of those lines from the log file, it's maybe possible to know which character is triggering the error. Add the line to your question rather than in a comment, please.
    – egreg
    Jun 13, 2013 at 21:58
  • 1
    Try also adding before \begin{document} the instruction \DeclareUnicodeCharacter{00A0}{ }
    – egreg
    Jun 13, 2013 at 22:00
  • I have tried this command already, which I have found in another thread, but it didn't work. The evildoer seems to be a ":", but I don't know why that happens. Jun 13, 2013 at 22:13

1 Answer 1

21

Unhappily utf8.def does not show the numerical representation for the missing Unicode character. The missing character <char> is shown directly in macro \u8:<char>. The following example adds the numerical information in the error message:

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

\makeatletter
\renewcommand*{\UTFviii@defined}[1]{%
  \ifx#1\relax
    \begingroup
      % Remove prefix "\u8:"
      \def\x##1:{}%
      % Extract Unicode char from command name
      % (utf8.def does not support surrogates)
      \edef\x{\expandafter\x\string#1}%
      \StringEncodingConvert\x\x{utf8}{utf16be}% convert to UTF-16BE
      % Hexadecimal representation
      \EdefEscapeHex\x\x
      % Enhanced error message
      \PackageError{inputenc}{Unicode\space char\space \string#1\space
                              (U+\x)\MessageBreak
                              not\space set\space up\space
                              for\space use\space with\space LaTeX}\@eha
    \endgroup
  \else\expandafter
    #1%
  \fi
}
\makeatother

\begin{document}
^^c2^^a0 % 7-bit input for U+00A0
\end{document}

Result:

! Package inputenc Error: Unicode char \u8:  (U+00A0)
(inputenc)                not set up for use with LaTeX.
7
  • 2
    That's a neat feature! Is there a sensible place for it in some of your packages? Jun 14, 2013 at 8:02
  • Thanks for that nice macro :-) It reveals the following characters: \u8:‭ (U+202D) and \u8:‬ (U+202C). I have already found a solution by trial and error: I just copied the text from AbiWord to OpenOffice, saved it and then copied it to the Latex document. The document then compiled without any problems - for whatever reason. However, I would like to know what exactly caused that problem. Jun 14, 2013 at 8:08
  • Perhaps you could also add some meaningful message if no sensible utf8 char is recognized (when people use \usepackage[utf8]{inputenc} in a 8-bit document). Currently e.g. äü gives: Unicode char \u8:äü (U+) not set up for use with LaTeX. Jun 14, 2013 at 8:13
  • 1
    @user1812379: These characters are U+202D LEFT-TO-RIGHT OVERRIDE and U+202C POP DIRECTIONAL FORMATTING. I assume your text always has left-to-right writing direction, then you can disable these Unicode characters by \DeclareUnicodeCharacter{202D}{} and \DeclareUnicodeCharacter{202C}{}. Jun 14, 2013 at 9:11
  • 1
    @UlrikeFischer: Yes, my intention is to make a package and thanks for the hint that there might be malformed Unicode sequences. Jun 14, 2013 at 9:13

You must log in to answer this question.

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