[Tex/LaTex] Typesetting any language, Vietnamese for example

languages

I have this document which contains Vietnamese characters, and it doesn't compile correctly:

\documentclass[letterpaper]{article}
\usepackage[vietnam]{babel}
\begin{document}
        Ðàn con chung một trái tim
\end{document}

The characters come out as gobbledygook. I don't know how to give Latex the ability to display characters in any language. It's rather frustrating because I'm used to just typing anything I want in UTF-8.

What are the steps to enabling a language in a Latex document? For the answer, you can use my Vietnamese example.

Best Answer

I copied the start of the Hanoi entry in the vietnamese Wikipedia:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[vietnam]{babel}

\begin{document}

Hà Nội là thủ đô, đồng thời là thành phố đứng đầu Việt Nam về diện
tích tự nhiên và đứng thứ hai về diện tích đô thị sau thành phố Hồ Chí
Minh, nó cũng đứng thứ hai về dân số với 6.913.161 người.

\end{document}

The trick is to enable the utf8 encoding for the package inputenc.

Note The proper Unicode character for the capital "đê" (or "đờ") character is Đ (U+0110 LATIN CAPITAL LETTER D WITH STROKE) and not the one you're using, that is Ð (U+00D0 LATIN CAPITAL LETTER ETH). They are pretty similar, but distinct. The former is used in Croatian and Vietnamese, the latter in Icelandic (and its lowercase form is ð).


enter image description here


In case different languages must be used, they should be declared to babel:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english,vietnam]{babel}

\begin{document}

Hà Nội là thủ đô, đồng thời là thành phố đứng đầu Việt Nam về diện
tích tự nhiên và đứng thứ hai về diện tích đô thị sau thành phố Hồ Chí
Minh, nó cũng đứng thứ hai về dân số với 6.913.161 người.

\begin{otherlanguage*}{english}
Hanoi is the capital of Vietnam and the country's second largest city.
Its population in 2009 was estimated at 2.6 million for urban
districts, 6.5 million for the metropolitan jurisdiction.
\end{otherlanguage*}

\end{document}

For short inserts in English, \foreignlanguage{english}{some text in English} can be used. One can also define a personal abbreviation, such as

\newcommand{\EN}{\foreignlanguage{english}}

so to be allowed to write \EN{some text in english}. You can also abbreviate the environment form with

\newenvironment{english}
  {\begin{otherlanguage}{english}}
  {\end{otherlanguage}}
\newenvironment{english*}
  {\begin{otherlanguage*}{english}}
  {\end{otherlanguage*}}

See the babel manual for the difference between otherlanguage and otherlanguage*.


Alternatively, you can use XeLaTeX:

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\usepackage{polyglossia}
\setmainlanguage{vietnamese}

\begin{document}

Hà Nội là thủ đô, đồng thời là thành phố đứng đầu Việt Nam về diện
tích tự nhiên và đứng thứ hai về diện tích đô thị sau thành phố Hồ Chí
Minh, nó cũng đứng thứ hai về dân số với 6.913.161 người.

\end{document}

which gives a correct result:


enter image description here


Polyglossia issues a warning about missing hyphenation patterns for Vietnamese, which should not be a problem.

For declaring other languages to Polyglossia, one should use, for instance,

\setotherlanguage{english}

Note that the same commands as in babel can be used with Polyglossia, but in this case the english environment would already be defined, so only english* might need to be.

Related Question