6

I've loaded babel in my .sty file like this:

\RequirePackage[ukrainian,russian,english]{babel}

Then at .tex or at the same .sty file I am trying to:

\selectlanguage(X)
\languagename
\iflanguage{english}{eng}{}
\iflanguage{russian}{rus}{}
\iflanguage{ukrainian}{ukr}{}

And the result is:

X=>output
russian => rus (\languagename says russian)  OK!
ukrainian => rus (!!!) (languagename says ukrainian) WRONG!
english => eng (\languagename says english) OK!

What a magic it is? Note: everything else like word "Content", "Chapter" and so on are correctly translates to specified language.

1

1 Answer 1

8

This is a bug in babel, which appears when two cyrillic languages are chosen. I wrote about it in an article published in number 9 of ArsTeXnica, the journal of GuIT, the Italian TeX users group.

You can get around the bug by correcting the behaviour of babel:

\documentclass{article}
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ukrainian,russian,english]{babel}

\makeatletter
\newcommand{\@cyrillictext}{% 
  \fontencoding\cyrillicencoding 
  \selectfont 
  \let\encodingdefault\cyrillicencoding 
} 
\DeclareRobustCommand{\cyrillictext}{%
  \@cyrillictext} 
\let\cyr\cyrillictext 
\DeclareRobustCommand{\Bulgarian}{% 
  \@cyrillictext 
  \foreign@language{bulgarian}} 
\let\Bul\Bulgarian \let\Bg\Bulgarian 
\DeclareRobustCommand{\Russian}{% 
  \@cyrillictext 
  \foreign@language{russian}} 
\let\Rus\Russian 
\DeclareRobustCommand{\Ukrainian}{% 
  \@cyrillictext 
  \foreign@language{ukrainian}} 
\let\Ukr\Ukrainian 
\AtBeginDocument{ 
  \@ifundefined{defaultcyrlanguage} 
    {\let\defaultcyrlanguage\bbl@main@language}
    {}
}
\renewcommand{\textcyrillic}[2][\defaultcyrlanguage]{%
  \expandafter\foreignlanguage\expandafter{#1}{#2}}
\makeatother

\begin{document}
\selectlanguage{english}
\languagename --\the\language --%
\iflanguage{english}{eng}{}%
\iflanguage{russian}{rus}{}%
\iflanguage{ukrainian}{ukr}{}

\selectlanguage{ukrainian}
\languagename --\the\language --%
\iflanguage{english}{eng}{}%
\iflanguage{russian}{rus}{}%
\iflanguage{ukrainian}{ukr}{}%

\selectlanguage{russian}
\languagename --\the\language --%
\iflanguage{english}{eng}{}%
\iflanguage{russian}{rus}{}%
\iflanguage{ukrainian}{ukr}{}%

\end{document}

enter image description here

With this code the declaration \Russian and \Ukrainian don't change the fixed words (they behave like the otherlanguage* environment); if you prefer to have the (IMO wrong) behavior of babel, change the occurrences of \foreign@language into \select@language.


The problem is that at loading time, each language defines \cyrillictext to use that language; so the last language loaded wins. When \selectlanguage or a similar command to select a cyrillic language is issued, \cyrillictext is executed as part of \extras<language>; so the language name is set correctly, but the language number is set instead to the cyrillic language last loaded in with babel, in the example case to Russian.

2
  • 1
    Great article. If you I have found more bugs, please report them for them to get fixed. Nov 1, 2012 at 7:41
  • @JavierBezos I've sent a bug report at LaTeX Project
    – egreg
    Nov 1, 2012 at 19:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .