[Tex/LaTex] Hyphenation of Russian text in utf8 encoding

cyrillicdebianhyphenationunicodexetex

All my attempts to make hyphenation work in Debian Linux 6.0 for Russian text encoded in utf8 has failed.

My search on internet indicates that hyphenation should work through babel at least with other encodings (cp855, cp866, cp866av, cp866mav, cp866nav, cp866tat, cp1251, koi8-r, koi8-u, koi8-ru, iso88595, maccyr).

A lot of reading and tries was put forward to resolve this issue but so far no success.

UTF-8 was around for quite awhile and I guess that somebody already stumbled on this problem before.

Is there known solution for hyphenation of utf8 encoded Russian/Cyrillic?

PDF file compiles with command bellow (some warrings "Overfull \hbox", "Underfull \hbox")

work$ xelatex book.tex

Bellow is small snippet of tex code for problem demonstration. First and last paragrhaph in English language show "boundaries" where hyphenation should have happened.

NOTE: ruhyphen is part of texlive-lang-cyrillic which is installed on the system.

\documentclass[a4paper,twoside,titlepage,openright,10pt]{book}
\pagestyle{headings}

\XeTeXinputencoding ”bytes”
\usepackage[T2A,T2B,T2C]{fontenc}
\usepackage{ucs}
\usepackage[utf8]{inputenc}
\usepackage[english,russian]{babel}

\title{УНИКАЛЬНАЯ ЖЕНЩИНА \\ Проницательность и мудрость для достижения полноты жизни}
\author{Эдвин Луис Коул и Нэнси Корбетт Коул}

\begin{document}

\maketitle

"We will implement prudent and responsible macroeconomic policies to ensure mutually reinforcing effect of growth and to maintain economic and financial stability in the region, and prevent negative spillover effect." \\

  Многие женщины начинают поиск истинного <Я> и оказываются обманутыми и разочарованными, пытаясь стать похожими на образец современной женщины. Приспосабливаясь внешне, но сопротивляясь внутренне, они однажды обнаруживают, что глубоко в душе они не являются тем, чем случайно оказались.

  Некоторые женщины научились искать и получать розы, обеды и драгоценности и все же не ощущают стабильности, безопасности, удовлетворения от проявления своей индивидуальности и настоящей любви, чего они в действительности желают.

  Множество женщин вверили свою жизнь мужчинам, желая жить жизнью своих мужей или любовников, но это ведет лишь к тому, что они разочаровываются в мужчинах, а в итоге и в самих себе.

  Многие, очень многие жены отчаянно хотят, чтобы их мужья изменялись, становились зрелыми, брали ответственность на себя и были такими мужчинами, какими они сотворены быть. Они осознают слишком поздно, что подлинно свободна только та замужняя женщина, муж которой <достиг максимума>. \\

"Global growth is too weak, risks remain tilted to the downside, global trade is weakening and the economic outlook suggests growth is likely to be slower and less balanced than desired," the group said in a prepared statement.

\end{document}

System:

Debian GNU/Linux 6.0

work$ xelatex --version
XeTeX 3.1415926-2.2-0.9995.2 (TeX Live 2009/Debian)
kpathsea version 5.0.0
Copyright 2009 SIL International and Jonathan Kew.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the XeTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the XeTeX source.
Primary author of XeTeX: Jonathan Kew.
Compiled with ICU version 3.8.1 [with modifications for XeTeX]
Compiled with zlib version 1.2.3.4; using 1.2.3.4
Compiled with FreeType2 version 2.4.2; using 2.4.2
Compiled with fontconfig version 2.8.0; using 2.8.0
Compiled with libpng version 1.2.44; using 1.2.44
Compiled with poppler version 0.12.4

work$ dpkg -l | grep cyrill
ii  console-cyrillic                     0.9-16                            Better    Cyrillic support for Linux console
ii  t1-cyrillic                          4.13                              A basic set of free PostScript fonts
ii  texlive-lang-cyrillic                2009-3                            TeX Live: Cyrillic
ii  xfonts-cyrillic                      1:1.0.1                           Cyrillic fonts for X

work$ dpkg -l | grep latex
ii  latex-beamer                         3.07-2                            LaTeX class to produce presentations
ii  latex-xcolor                         2.11-1                            Easy driver-independent TeX class for color
ii  preview-latex-style                  11.85-1                           extraction of elements from LaTeX documents as graphics
ii  texlive-latex-base                   2009-11+squeeze1                  TeX Live: Basic LaTeX packages
ii  texlive-latex-base-doc               2009-11+squeeze1                  TeX Live: Documentation files for texlive-latex-base
ii  texlive-latex-extra                  2009-10                           TeX Live: LaTeX supplementary packages
ii  texlive-latex-extra-doc              2009-10                           TeX Live: Documentation files for texlive-latex-extra
ii  texlive-latex-recommended            2009-11+squeeze1                  TeX Live: LaTeX recommended packages
ii  texlive-latex-recommended-doc        2009-11+squeeze1                  TeX Live: Documentation files for texlive-latex-recommended

Best Answer

You shouldn't be using XeLaTeX in that way, since it expects Unicode input. In any case, correct hyphenation does not depend on the input encoding, but rather on the output encoding.

I'll assume your file is UTF-8 encoded, or a bunch of problems would arise. Here's a working version, at least with TeX Live 2013 (the 2009 version shipped with Ubuntu till 12.04 is really outdated). Note that for Russian only T2A should be loaded, but only if pdflatex is used. So I load the ifxetex package to distinguish between the two engines.

You might also put babel in the “non XeLaTeX” code and call polyglossia for XeLaTeX.

\documentclass[a4paper,twoside,titlepage,openright,10pt]{book}

\usepackage{ifxetex}

\ifxetex
  \usepackage{fontspec}
  \defaultfontfeatures{Ligatures=TeX}
  \setmainfont{CMU Serif}
  \setsansfont{CMU Sans Serif}
\else
  \usepackage[T1,T2A]{fontenc}
  \usepackage[utf8]{inputenc}
\fi

\usepackage[english,russian]{babel}

\title{УНИКАЛЬНАЯ ЖЕНЩИНА \\ Проницательность и мудрость для достижения полноты жизни}
\author{Эдвин Луис Коул и Нэнси Корбетт Коул}

\begin{document}

\maketitle

\begin{otherlanguage*}{english}
``We will implement prudent and responsible macroeconomic policies to ensure mutually reinforcing effect of growth and to maintain economic and financial stability in the region, and prevent negative spillover effect.''
\end{otherlanguage*}

Многие женщины начинают поиск истинного <<Я>> и оказываются обманутыми и разочарованными, пытаясь стать похожими на образец современной женщины. Приспосабливаясь внешне, но сопротивляясь внутренне, они однажды обнаруживают, что глубоко в душе они не являются тем, чем случайно оказались.

Некоторые женщины научились искать и получать розы, обеды и драгоценности и все же не ощущают стабильности, безопасности, удовлетворения от проявления своей индивидуальности и настоящей любви, чего они в действительности желают.

Множество женщин вверили свою жизнь мужчинам, желая жить жизнью своих мужей или любовников, но это ведет лишь к тому, что они разочаровываются в мужчинах, а в итоге и в самих себе.

  Многие, очень многие жены отчаянно хотят, чтобы их мужья изменялись, становились зрелыми, брали ответственность на себя и были такими мужчинами, какими они сотворены быть. Они осознают слишком поздно, что подлинно свободна только та замужняя женщина, муж которой <<достиг максимума>>.

\begin{otherlanguage*}{english}
``Global growth is too weak, risks remain tilted to the downside, global trade is weakening and the economic outlook suggests growth is likely to be slower and less balanced than desired," the group said in a prepared statement.''
\end{otherlanguage*}

\end{document}

I can compile this either with pdflatex or xelatex and below I show the results. You can see they are pretty much alike. Note that in order to get English hyphenation you should enclose the text in an otherlanguage* environment.

pdflatex

enter image description here

xelatex

enter image description here

Related Question