# How to easily use UTF-8 with LaTeX?

It's probably a stupid question, but I cannot find any easy answers online, and the answers are sometimes contradictory.

I am writing a document that uses a few strange alphabets. I want to use some LaTeX variant for typesetting, but nothing works. For example, if I take this document with four example words (one in Russian, one in Czech, one in latin with length indication, one in Vietnamese)

\documentclass[12pt,a4paper]{report}

\usepackage[utf8]{inputenc}
\begin{document}
Днепр kůň dominī Ngữ
\end{document}


and put it through xelatex, which people recommend for Unicode, all I get is this

which is not exactly what I want.

What is the easiest way of putting UTF-8 encoded file on one side and getting actual text on the other side?

edit:

I am using Ubuntu operating system, and I want to use some font appropriate for a bigger thesis (something like Computer Modern is fine, although I personally prefer Palatino-style fonts)

-
With xelatex you don't load inputenc; but you must load fontspec and use a font that has the required glyphs. – egreg Apr 19 '14 at 22:30
....OK, sorry it sounds stupid, but what does it actually mean? What fonts do I need (and how do I get them), and what language should I specify if I use more of them in the same document? – Karel Bílek Apr 19 '14 at 22:31
Instead of saying \usepackage[utf8]{inputenc}, say \usepackage{fontspec}\setmainfont{Arial Unicode}, for example. – Sean Allred Apr 19 '14 at 22:35
I will add that I use ubuntu and apt packages (I will add it to the question) – Karel Bílek Apr 19 '14 at 22:35
The fontspec package provides macros such as \setmainfont, with which you can select the font that should be used in the document. Do familiarize yourself with the user guide of the fontspec package. Just which font family, or families, you should use is hard to tell without more detailed knowledge of your typesetting needs. – Mico Apr 19 '14 at 22:36

You can use XeLaTeX, but inputenc shouldn't be loaded. Instead use fontspec and define a font that has the required glyphs.

Say you have installed the XITS fonts on your system; then you can do

\documentclass[12pt,a4paper]{report}

\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{XITS}

\begin{document}
Днепр kůň dominī Ngữ
\end{document}


If the font is not installed on the system, it's still possible to use it (you need a full TeX Live)

\documentclass[12pt,a4paper]{report}

\usepackage{fontspec}
\setmainfont[
Ligatures=TeX,
Extension=.otf,
UprightFont=*-regular,
ItalicFont=*-italic,
BoldFont=*-bold,
BoldItalicFont=*-bolditalic,
]{xits}

\begin{document}
Днепр kůň dominī Ngữ
\end{document}


Another easy choice is Linux Libertine:

\documentclass[12pt,a4paper]{report}

\begin{document}
Днепр kůň dominī Ngữ
\end{document}


For getting real multilingual support, you still need either Polyglossia or babel.

-
The last thing worked perfectly! Thanks! – Karel Bílek Apr 19 '14 at 22:45
sorry, where could I found fontspec.spe for tex? – Малъ Скрылевъ Jan 27 '15 at 16:46
@МалъСкрылевъ Not sure to understand. – egreg Jan 27 '15 at 17:05
@egreg I meant, in my linux installation the file fontspec.spe is absent. So I have to know where is the file is resided. – Малъ Скрылевъ Jan 27 '15 at 17:11
@МалъСкрылевъ I've never heard about fontspec.spe. – egreg Jan 27 '15 at 17:12

I don't use Ubuntu but Ubuntu should provide a package for Linux Libertine (if it is not installed by default) and that supports all of the languages:

\documentclass[12pt,a4paper]{report}

\usepackage{fontspec}
\setmainfont{Linux Libertine O}

\begin{document}
Днепр kůň dominī Ngữ
\end{document}


To figure out which fonts were installed, I looked in /usr/share/fonts and paid particular attention to the opentype fonts there. I discovered a directory /usr/share/fonts/otf-linux-libertine-ibx/ which contained, for example, /usr/share/fonts/otf-linux-libertine-ibx/LinLibertine_R.otf. Yours will more likely be something like /usr/share/fonts/opentype/LinLibertine-R.otf.

To get basic information about the font, including the name to feed to fontspec:

otfinfo -i /usr/share/fonts/otf-linux-libertine-ibx/LinLibertine_R.otf


which produced:

Family:              Linux Libertine O
Subfamily:           Regular
Full name:           Linux Libertine O
PostScript name:     LinLibertineO
Version:             Version 5.3.0
Unique ID:           FontForge 2.0 : Linux Libertine O : 2-7-2012
Designer:            Philipp H. Poll
Designer URL:        http://www.linuxlibertine.org
Manufacturer:        Philipp H. Poll
Vendor URL:          http://www.linuxlibertine.org
Copyright:           Linux Libertine by Philipp H. Poll,
Open Font under Terms of following Free Software Licenses:
Created with FontForge (http://fontforge.sf.net)
Sept 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,2012
Vendor ID:           PfEd


To check which scripts (alphabets) the font supports:

otfinfo -s /usr/share/fonts/otf-linux-libertine-ibx/LinLibertine_R.otf


which gave me:

DFLT            Default
cyrl            Cyrillic
cyrl.SRB        Cyrillic/Serbian
grek            Greek
hebr            Hebrew
latn            Latin
latn.AZE        Latin/Azeri
latn.CRT        Latin/Crimean Tatar
latn.DEU        Latin/German
latn.MOL        Latin/Moldavian
latn.ROM        Latin/Romanian
latn.TRK        Latin/Turkish
math            Mathematical Alphanumeric Symbols


To typeset the languages correctly, you will want to use either polyglossia or babel. It is probably better to try the former first but not all languages are supported. Read the documentation to figure out how to specify and call the languages you need. This will ensure that things like hyphenation are correctly tuned for each of the languages you use in the document.

# EDIT

For Linux Libertine specifically, you may be best off loading libertine as explained in egreg's answer. But if you would prefer to use a font you've got which doesn't have a TeX package, you can use the above method to figure out if it is likely to work and how to specify it to fontspec.

-
I have marked @egreg's answer, because the libertine package works the best in my case, but thanks for your answer too for all the info, it will be probably helpful too if I (or someone else looking at this question) will get into trouble later. – Karel Bílek Apr 19 '14 at 22:48
Thanks @KarelBílek. I am pretty sure libertine does some other stuff so it is definitely best to use that in this case. My answer would be more useful if you wanted to use a system font for which there is not a (fontspec-aware) LaTeX support package. I really picked Libertine because I figured you'd be sure to either have it or have easy access to it via apt. So it made a good illustration of how to find stuff out and apply it (should you need or wish to do so.) – cfr Apr 19 '14 at 23:12