Error: Unicode char \u8:φ not set up for use with LaTeX

I have the following LaTeX document:

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
φΔδ汉
\end{document}


But I get the following error:

\$ latex foo
This is pdfTeX, Version 3.1415926-1.40.11 (TeX Live 2010)
restricted \write18 enabled.
[...]
! Package inputenc Error: Unicode char \u8:φ not set up for use with LaTeX.


How can I use these and other UTF-8 characters?

Note: This and this look like duplicates but they are slightly different and don't answer my question.

-

The inputenc package, even with the utf8 option doesn't load all the Unicode tables. It loads only those for which it knows it will have to typeset some glyphs.

You have then to teach the proper environment, because each Unicode block requires a different TeX fonts (they have only 256 characters).

So your example works with pdflatex, but modified into the following code.

\documentclass{article}
\usepackage[LGRx,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[greek,english]{babel}
\usepackage{CJKutf8}
\begin{document}

\foreignlanguage{greek}{φΔδ}\begin{CJK}{UTF8}{gbsn}汉\end{CJK}

\end{document}


This is admittedly largely impractical for extensive usage of characters belonging to different blocks, so it may be advisable to switch to XeLaTeX or LuaLaTeX that can use OpenType fonts.

Important update

After release of Babel version 3.9, the LGRx encoding should not be used any more. Now LaTeX is able to interpret correctly UTF-8 characters for Greek out of the box, provided the Greek language is loaded with babel. So the example above becomes

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[greek,english]{babel}
\usepackage{CJKutf8}
\begin{document}

\foreignlanguage{greek}{φΔδ}\begin{CJK}{UTF8}{gbsn}汉\end{CJK}

\end{document}

-
there are two phis in unicode -- U+03C6 (the curly phi, shown in your answer) and U+03D5 (the straight phi, which is what the input looks like). how can these be distinguished, and, for that matter, which one is actually wanted? – barbara beeton Jan 5 '14 at 21:58
@barbarabeeton U+03C6 is the shape most commonly used this side of the Atlantic. I guess the one in the title is due to a font choice, because it is U+03C6, like the one in the error message. – egreg Jan 5 '14 at 22:12
if the one in the title is identified as U+03C6, then it's wrong. sorry. i've been trying to sort this out for 15 years, and the utc/unicode manual and i are in agreement. where can i find the images for what's in the font used for tex.sx titles? if there's an error, i'd like to get it fixed. – barbara beeton Jan 5 '14 at 23:27
@barbarabeeton I don't know what font is used; something more versed in HTML than I could know; but it's just the glyph the font uses for U+03C6, just try doing an edit and you'll see that the character in the title box is φ (U+03C6). – egreg Jan 5 '14 at 23:34
@barbarabeeton The font is (at least on my machine) Palatino and the glyph corresponding to U+03C6 has the “closed” shape, while the one for U+03D5 has the "open” one. – egreg Jan 5 '14 at 23:46

utf8 for pdflatex has only a limited subset of Unicode. Use xelatex with

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Code2000}
%\setmainfont{Arial Unicode MS}
\begin{document}
φΔδ汉
\end{document}


Code2000 can be replaced by another OpenType or TrueType font which has all that characters, eg. Arial Unicode.

-

This error occurs when the tex editor file encoding and the document file encoding are not the same.

E.g. editor file encoding is ISO-8859-1, and the document has \usepackage[utf8]{inputenc} command. Change the editor file encoding to UTF-8, and restart the editor.

(It is possible that your editor refers to file encoding as font encoding. For details, see the comments.)

-
Welcome to tex.sx! These aren't font encodings, but file encodings you're thinking of. – doncherry Nov 22 '12 at 18:28
Hello! Thank you, precisely so. (My editor refers to it as font encoding.) – NaMarPi Nov 22 '12 at 19:49
Then I would not trust that editor anymore ;). (Which one is it?) The thing is, there is a concept called font encodings in LaTeX, it's what you're dealing with when saying e.g. \usepackage[T1]{fontenc}. – doncherry Nov 22 '12 at 19:53
Texmaker. I am new here, and it is important to me to add correct answers. What is the etiquette here? Can I improve my answers after comments, or leave it as it is? – NaMarPi Nov 22 '12 at 20:07
It's definitely a good idea to edit your answer, possibly with a little note that the edit resulted from comments, but often that's not even necessary. Thanks for caring! (As for Texmaker: That's the editor I use as well. I'll file a bug report later.) – doncherry Nov 22 '12 at 20:23

I'd just like to add my use case, which basically involves a manual install of LGRx:

Essentially, all I want is to be able to type units like μW directly in UTF-8 in the source .tex file (that is, I'd rather not type constructs like \foreignlanguage{greek}{μ}W); and I need to be using pdflatex.

Currently I'm on a machine with texlive 2011, which I cannot upgrade fully at the moment.

On texlive 2011, the combo:

• [utf8x]{inputenc/x} + [LGR, T1]{fontenc} + {textcomp}

generally works fine. Unfortunately, the problem is that additionally I need to be using biblatex, which chokes on the ucs package which utf8x loads.

So, I tried the [LGRx,T1]{fontenc} as recommended in the accepted answer - but it turns out, there is no LGRx encoding in texlive 2011 ...

So, after a bit of digging, this is what I ended up doing in bash:

wget http://milde.users.sourceforge.net/LGR/lgrxenc.def -O /path/to/texlive/2011/texmf-dist/tex/generic/babel/lgrxenc.def
texhash
wget http://milde.users.sourceforge.net/LGR/lgrenc.dfu -O /path/to/texlive/2011/texmf-dist/tex/latex/base/lgrenc.dfu
texhash


Note that you must call texhash (see LaTeX/Installing Extra Packages: 4. Update your index - Wikibooks) otherwise pdflatex will not be able to find the newly downloaded files.

With that, now the combo

• [utf8]{inputenc/x} + [LGRx, T1]{fontenc} + {textcomp}

... works fine, like in this example:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[LGRx, T1]{fontenc}
\usepackage{textcomp}

\usepackage[backend=biber]{biblatex} % just testing - is OK

\begin{document}

μW

\end{document}


Note that

• the lgrxenc.def I've downloaded is v0.6/2012-06-29 , and it contains \DeclareTextSymbol{\textmu}{LGR}{109} - while the latest lgrxenc.def v0.8 2013-05-30 is "backwards compatibility file for new lgrenc.def", and has fewer definitions (and \textmu is not present in it)
• the lgrenc.dfu I've downloaded is v0.2 2012-06-27; the latest is lgrenc.dfu v1.4.1 2013-07-18 and it has now a different location in the tree - but they both contain \DeclareUnicodeCharacter{03BC}{\textmu}
• textcomp.sty is needed, as it defines \DeclareTextSymbolDefault{\textmu}{TS1}

Well, hope this helps someone,
Cheers!

-