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

share|improve this question
    
One (simple) option is to use XeTeX. See my answers for 'Guttman yad-brush' font and Problems typing in Russian (MiKTeX). These should be able to help you. But you would of course want to use polyglossia instead of babel. –  user2473 Jan 9 '12 at 0:33
    
Nate Glenn: I have the same problem when I copy&paste Vietnamese text containing the capital D with horizontal bar character from the Internet using Chrome. Work around is find & replace that character with the one you type in. (I use unikey) –  Nguyễn Minh Vũ Jul 17 '12 at 12:01
    
One thing to remember is that inputenc's UTF-8 is incomplete and I believe that "Ð" is precisely one of the characters it doesn't understand. You really should use XeTeX or LuaTeX for anything other than fairly common UTF-8. –  PLK Jul 17 '12 at 12:29
    
@PLK There are two characters which are represented graphically by "Ð"; inputenc understands both, but the Vietnamese module doesn't know what to do with the Icelandic "Ð". –  egreg Jul 17 '12 at 23:03

1 Answer 1

up vote 19 down vote accepted

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.

share|improve this answer
    
Almost. When I use the character "Ð" (the lower case one is fine, though), I get this error: ! LaTeX Error: Command \DH unavailable in encoding T5. –  Nate Glenn Jan 9 '12 at 6:57
    
@NateGlenn Would you please update your minimal example? –  egreg Jan 9 '12 at 10:04
    
Done. Got rid of the covington stuff as it wasn't very minimal. –  Nate Glenn Jan 9 '12 at 17:09
    
@NateGlenn You should segregate the non Vietnamese parts in otherlanguage* environments. I'll add an example. –  egreg Jan 9 '12 at 17:17
2  
@NateGlenn I've added a note: you're using the wrong character. –  egreg Jan 9 '12 at 18:15

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.