Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 ?

share|improve this question

6 Answers 6

up vote 65 down vote accepted

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.

See egreg's answer to this question as well, which outlines how to get extra characters using the [utf8] option of inputenc.

Generally, however, 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.

share|improve this answer
6  
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 '13 at 13:33
1  
@acr I've fixed the broken link. Thanks for pointing it out. –  Alan Munn Jan 18 '13 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.

share|improve this answer
2  
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
9  
@drozzy, the difference is the order of the commands. –  maxschlepzig Jun 24 '12 at 16:08
1  
Could you provide an example of a character unavailable in first case but available in the second case? –  Denis Bitouzé Sep 24 at 13:01
1  
This is just wrong. First, it is just not true that the order affects the available input characters. This is easy to establish. Try the string æ ç ð â. Second, characters available in the input encoding are certainly not restricted to those in the output encoding. If they were, utf8x would not support typesetting ŵ ŷ with the T1 font encoding. (T1 does not include these characters. Yet they are acceptable input with utf8x and they can be typeset to display correctly by combining the accent with the vowel.) –  cfr 18 hours ago

"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}

enter image description here

share|improve this answer
17  
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
1  
@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
1  
@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
6  
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 '13 at 17:30

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

Note: This answer is only relevant to pdfTeX+Babel, not XeTeX+Polyglossia.

share|improve this answer
1  
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
1  
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
    
@kahen: It's true fundamentally, but the package support is still lacking - even more with XeLaTeX+polyglossia than with pdfLaTeX+babel. –  einpoklum Dec 13 '13 at 11:03

Don't use utf8x; with an up-to-date TeX distribution it could show necessary only for its most obscure features (faking characters with images from the Web, for instance).

The problem with Greek, which was probably the main reason for adopting utf8x instead of utf8, have since be solved and

\documentclass{article}

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

\begin{document}

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

\end{document}

will happily print

enter image description here

The occasional missing definitions can be coped with in a simple way. If you're able to input a Unicode character, such as the Welsh letters

Ââ Êê Îî Ôô Ŵŵ Ŷŷ Ïï

or the Latin vowels with prosodic marks

Ăă Ĕĕ Ĭĭ Ŏŏ Ŭŭ Āā Ēē Īī Ōō Ūū Ȳȳ

(y with breve is missing from Unicode, while a with breve is already defined by utf8 because it's a letter in Romanian), you can simply add the unknown ones to the list of known characters:

\documentclass{article}

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

% missing Welsh coverage
\newunicodechar{Ŵ}{\^W}
\newunicodechar{ŵ}{\^w}
\newunicodechar{Ŷ}{\^Y}
\newunicodechar{ŷ}{\^y}

% Latin vowels with prosodic marks    
\newunicodechar{Ĕ}{\u{E}}
\newunicodechar{ĕ}{\u{e}}
\newunicodechar{Ĭ}{\u{I}}
\newunicodechar{ĭ}{\u{\i}}
\newunicodechar{Ŏ}{\u{O}}
\newunicodechar{ŏ}{\u{o}}
\newunicodechar{Ŭ}{\u{U}}
\newunicodechar{ŭ}{\u{u}}
\newunicodechar{Ā}{\=A}
\newunicodechar{ā}{\=a}
\newunicodechar{Ē}{\=E}
\newunicodechar{ē}{\=e}
\newunicodechar{Ī}{\=I}
\newunicodechar{ī}{\={\i}}
\newunicodechar{Ō}{\=O}
\newunicodechar{ō}{\=o}
\newunicodechar{Ū}{\=U}
\newunicodechar{ū}{\=u}
\newunicodechar{Ȳ}{\=Y}
\newunicodechar{ȳ}{\=y}

\begin{document}

Ââ Êê Îî Ôô Ŵŵ Ŷŷ Ïï

Ăă Ĕĕ Ĭĭ Ŏŏ Ŭŭ

Āā Ēē Īī Ōō Ūū Ȳȳ

\end{document}

enter image description here

Note that, for instance, the line

\newunicodechar{Ŵ}{\^W}

can be also input as

\DeclareUnicodeCharacter{0174}{\^W}

without the need of the newunicodechar package, because U+0174 is the code point of LATIN CAPITAL LETTER W WITH CIRCUMFLEX; but \newunicodechar frees from looking up in the Unicode tables.

share|improve this answer

Welsh requires utf8x as the characters ŵ and ŷ are not recognised otherwise:

\documentclass[welsh]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage{babel}
\begin{document}

 Ââ Êê Îî Ôô Ŵŵ Ŷŷ Ïï

\end{document}

Obviously, XeLaTeX is an option although babel is still required as polyglossia doesn't support Welsh.

share|improve this answer
    
\usepackage{newunicodechar}\newunicodechar{ŵ}{\^w} (works with the utf8 option). Of course this breaks hyphenation, but it's the same with utf8x –  egreg Jun 13 at 7:29
    
@egreg Yes, but then you have to add it for every additional accented character you need whereas utf8x is just typing an additional x. It doesn't break hyphenation generally, though - only for cases where words containing those characters would be hyphenated? Is that right? (Those words will not be very common. ^ generally occurs on short words or words which are hyphenated anyway. gwdihŵ would be an example but the most common cases are things like .) –  cfr Jun 13 at 22:14
1  
I wouldn't use a package that's known to be fragile and that breaks easily just in order to avoid a couple of definitions. You should make a feature request to the LaTeX team that they add the Welsh characters to utf8. –  egreg Jun 13 at 22:22
    
@egreg I finally figured out how to do that from David Carlisle. Hence, latex-project.org/cgi-bin/ltxbugs2html?pr=latex/4400. –  cfr 20 hours ago
    
While it may be annoying having to do that for all documents in Welsh, you can see from my answer that all it takes is five lines of code. –  egreg 20 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.