# 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.
\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

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.

\documentclass[a4paper]{article} <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