# utf8x vs. utf8 (inputenc)

I normally use \usepackage[utf8]{inputenc} for my latex document but on this site i saw a lot of code with \usepackage[utf8x]{inputenc}.

What are the differences between the 2 options ?

Is there one of the option obsolete and which one should I use ?

-

The simple answer is that utf8x is to be avoided if possible. It loads the ucs package, which for a long time was unmaintained (although there is now a new maintainer) and breaks various other things.

The best way to deal with unicode source (especially with non-latin scripts) is really XeLaTeX or LuaLaTeX.

There's an extended discussion of this here: Encoding remarks. See especially the comments by Philipp Lehman and Philipp Stephani.

-
In some case utf8 breaks some things too when utf8x is fine. I work only with utf8 and utf8x and I don't remember why but after working with utf8 and some problems, now I work with utf8x. I agree with you about XeLaTeX or LuaLaTeX but some users need to work again with pdflatex. –  Alain Matthes Mar 9 '11 at 18:39
usually I use LuaLaTeX, but for some stuff I don't have choice to use pdfLaTeX –  Matsaya Mar 9 '11 at 19:58
The link to "encoding remarks" above seems to be broken, and I can't seem to find the right object. Does anyone know how to relocate this (apparently important) discussion? –  acr Jan 18 at 13:33
@acr I've fixed the broken link. Thanks for pointing it out. –  Alan Munn Jan 18 at 17:18

In fact, utf8 may not be as restrictive as it seems: it only loads characters that can be displayed by the font encoding.

When typing

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}


the font encoding is still OT1 when loading inputenc, which has very few characters. By using

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


you will allow all displayable utf8 characters to be available as input.

-
I think I am blind but I see no difference between those two lines... Except for what seems to be a typo in "userpackage" –  drozzy Mar 4 '12 at 22:01
@drozzy, the difference is the order of the commands. –  maxschlepzig Jun 24 '12 at 16:08

"The simple answer is that utf8x is to be avoided if possible." Yes and No. No it's not so simple utf8x is sometimes necessary when you need to write greek or some special symbols. Yes utf8x is for a long time was unmaintained but we can use it. Try to compile the next code with utf8

\documentclass{article}

\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[polutonikogreek,english]{babel}

\renewcommand*{\textgreek}[1]{%
\foreignlanguage{greek}{#1}%
}

\begin{document}

This is english
\textgreek{Τηις ις γρεεκ}
This is english again.

\end{document}


-
utfx is not necessary for greek. utf8 is extensible: You need a lgrenc.dfu to get the definition for greek then utf8 will work fine. lgrenc.dfu can be found on the net (e.g. in the latex bug database if I remember it correctly). –  Ulrike Fischer Mar 9 '11 at 18:50
@Ulrike: Thanks Ulrike, I don't know 'lgrenc.dfu' ! Is it recent ? Josselin Noirel writes something about "mem.sty" but I think this package disappears. \usepackage[charset=utf8,greek,english]{mem} –  Alain Matthes Mar 9 '11 at 19:06
@Ulrike: Why lgrenc.dfu is not in TeXLive ? and I read : Based on a babel patch by Werner Lemberg, with input from the ucs package (ucsencs.def) by Dominique Unruh and CB.enc by Apostolos Syropoulos. So there is a part from ucs ! –  Alain Matthes Mar 9 '11 at 19:56
I have no idea why it never found its way to CTAN. But it is not part of ucs, it only reused some (or a lot) definitions from it (writing all this long list which maps a input char to a command is a lot work). lgrenc.dfu is quite similar to standard lists like t1enc.dfu and utf8enc.def which are part of basic latex/inputenc+utf8. –  Ulrike Fischer Mar 9 '11 at 20:31
In TeX Live 2012 one can say \usepackage[LGRx,T1]{fontenc} and then \usepackage[utf8]{inputenc} will enable direct usage of Greek characters. –  egreg Jan 18 at 17:30
show 1 more comment

I've had the experience of not being able to compile Hebrew with utf8, only with utf8x, using pdflatex in MikTeX (e.g. 2.9). Many guides on writing Hebrew LaTeX suggest using utf8x:

This is not to contradict what the learned sages say above, it's just an example of a case in which it seems to be impossible to avoid (unless someone suggests a way like Ulrike's suggesting regarding Greek).

-
Frankly, if you are working with Hebrew, you should really be using XeLaTeX and the bidi package. –  Alan Munn Sep 23 '11 at 13:25
Well, I was talking in the past tense... although, frankly, I haven't made the switch yet. Still find it important to mention it here, as people looking up the difference between the two options will probably hit this question. –  einpoklum Sep 29 '11 at 15:03
XeLaTeX must have been a great improvement for people writing in Hebrew. I don't think the incompatibility between babel with the hebrew option and amsthm was ever fixed (I don't write Hebrew myself, so I never bothered to check) –  kahen Nov 8 '11 at 1:29