[Tex/LaTex] How to easily use UTF-8 with LaTeX

input-encodingsxetex

Editor's note:

This question addresses a specific case of UTF-8 character not working in LaTeX documents. Refer to Entering Unicode characters in LaTeX for other cases.


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

k domin Ng

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:

To add more information.

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)

Best Answer

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}

\usepackage{libertine} % also loads fontspec

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

enter image description here

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