3

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.

2
  • 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
    Commented Sep 27, 2012 at 19:36
  • Add \usepackage[T1]{fontenc} after including babel. This should fix your font encoding problem.
    – szantaii
    Commented Oct 26, 2012 at 8:46

3 Answers 3

6

enter image description here

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}
4
  • 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
    Commented Sep 27, 2012 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) Commented Sep 27, 2012 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
    Commented Sep 27, 2012 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.... Commented Sep 27, 2012 at 20:27
2

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.

1
  • 2
    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. Commented Nov 10, 2013 at 16:03
-1

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

3
  • 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
    Commented Sep 20, 2016 at 22:02
  • Sorry. Of course : \chapter{\protect{Énigmes mathématiques}} Commented Sep 24, 2016 at 13:37
  • That \protect does nothing at all
    – egreg
    Commented Sep 24, 2016 at 14:21

You must log in to answer this question.

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