[Tex/LaTex] Problems with accented characters in xelatex

accentsinput-encodingsxetex

The accented Portuguese characters work well when compiled with pdflatex but not with xelatex giving an inputenc error. Why?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[portuguese]{babel}
\usepackage[T1]{fontenc}
\author{Sérgio}
\title{Há muito açafrão}
\begin{document}
\maketitle
Words/letters with accents: Sérgio áéíóúçãõ.
\end{document}

Best Answer

You shouldn't use inputencwith XeLaTeX : it supposes your document is in utf8 encoding. And you shouldn't use fontenc either, since it manages fonts directly. Also, it is recommended to use polyglossia rather than babel: it is tailored for XeLaTeX.

Here is a code that works:

\documentclass{article}

\usepackage{fontspec}
\setmainfont{Minion Pro}

\usepackage{polyglossia}
\setmainlanguage{portuges}

\author{Sérgio}
\title{Há muito açafrão} 

\begin{document}
\maketitle
Words/letters with accents: Sérgio áéíóúçãõ.
\end{document} 

enter image description here