# encoding problem

I'm trying to write a program in Python that exports data into PDF. Unfortunately, the well known reportlab module is not available on Python 3. (What a shame.) So I have decided to generate TEX files from the program and compile them with TeX.

I know that my operating system have True Type fonts that can handle all of the characters that I need. So all I need is to use such a font for any UTF8 character in the document. I also need to create some tables and figures. It is that simple.

I was trying to do it with pdfLaTex and also with XeLaTex. I'm not sure what is the difference between them. Here is an example generated file for pdfLaTex:

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[hungarian]{babel}
\author{Nagy László}
\title{Elemzés}
\begin{document}
\maketitle
\tableofcontents

\section{Esetleírás}

\subsection{A vizsgálat tárgya}

\begin{itemize}
\item árvíztűrő tükörfórógép
\item ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP
\item  80g/m²
\end{itemize}
\end{document}


This throws the error:

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


Another guy told me to use XeLaTex instead, because it has better unicode support. I don't understand the details, but I have tried that too. With XeLaTex, I got this error:

Runaway argument?
! Paragraph ended before \UTFviii@three@octets was complete.
<to be read again>
\par
l.7 \maketitle


All right, I have no idea what it means, but somebody told me that I should try putting

%%!TEX encoding = UTF-8 Unicode


at the beginning of the file. I'm not sure what this means, because I could not find anything about a special %% macro (???) in the "not too short introduction into latex2e" documentation. It did not help anyway. So I removed \maketitle and now I got this:

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


Can somebody help me where to start? I don't understand the error message, and I don't know how to fix it.

• UPDATE Here are some more that are not working: 10C° This is the degree in celsius. 5€ This is the euro sign. All right, I know that the euro sign and the "superscript 2" have their escape sequences. But this does not explain why they don't work when I give them as plain UTF8 characters. Possibly I could write my own escaper function in Python, and replace such occurences with special TeX sequences. But come on, isn't that what UTF8 is for? (Or maybe the error message is not related at all?) – nagylzs Sep 27 '12 at 19:36
• Add \usepackage[T1]{fontenc} after including babel. This should fix your font encoding problem. – szantaii Oct 26 '12 at 8:46

## 3 Answers

With xelatex you do not want to use inputenc which is for input encodings for the 8-bit tex and pdftex systems, load fontspec then you can access system fonts as shown below using Arial.

\documentclass[a4paper,11pt]{article}
\usepackage{fontspec}
\setmainfont{Arial}
\usepackage[hungarian]{babel}
\author{Nagy László}
\title{Elemzés}
\begin{document}
\maketitle
\tableofcontents

\section{Esetleírás}

\subsection{A vizsgálat tárgya}

\begin{itemize}
\item árvíztűrő tükörfórógép
\item ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP
\item  80g/m²
\end{itemize}
\end{document}

• Using your code, I get this error: ! Undefined control sequence. <argument> \numberline {1.}Esetle\IeC {\'\i }r\IeC {\'a}s l.2 ...line {1.}Esetle\IeC {\'\i }r\IeC {\'a}s}{1} – nagylzs Sep 27 '12 at 20:16
• Delete the .aux and .toc file generated by pdflatex and then use xelatex and all should be OK (you will need to run xelatex twice to generate the table of contents) – David Carlisle Sep 27 '12 at 20:19
• Yes, that worked! So I guess I will have to delete these files from my program too. Can you please point me to a documentation that explains why do I have to delete these files manually? – nagylzs Sep 27 '12 at 20:22
• You don't normally have to delete them manually but they store information in internal forms and if you change tex engine between pdflatex and xetex the internal forms are different and it goes wrong.... – David Carlisle Sep 27 '12 at 20:27

I had the same error, but with \maketitle.

My header was:

\documentclass[a4paper]{article} <br>
\usepackage[left=3cm,right=3cm,top=2.5cm,bottom=2.5cm]{geometry} <br>
**\usepackage[utf8]{inputenc}** <br>
\usepackage[portuguese]{babel} <br>
\usepackage[T1]{fontenc} <br>


The problem was with \usepackage[utf8]{inputenc}. The encoding is wrong. Delete it from the header and put the encoding in Western European > ISO 8859-1 It will solve the problem, I hope.

• inputenc is only relevant if using pdflatex - in which case the specified encoding should match that of the file. If using xelatex, then inputenc should not be used, and the source file should be utf8 encoded. – Andrew Swann Nov 10 '13 at 16:03

I had the same problem, in a \chapter command. I just put the title of my chapter in a \protect command, and it just solve the problem...

• Welcome to TeX.SX! As it stands, your answer is not really good, because at least you should explain where precisely the \protect command should go. – egreg Sep 20 '16 at 22:02
• Sorry. Of course : \chapter{\protect{Énigmes mathématiques}} – Nicolas FRANCOIS Sep 24 '16 at 13:37
• That \protect does nothing at all – egreg Sep 24 '16 at 14:21