# Russian language within figure captions in unicode-aware systems [duplicate]

When I try to compile the following document caption package seem to convert caption text to \cyr.. sequences and fontspec don't understand them. Is it possible do somehow get around that without getting back to 8-byte internal encodings?

\documentclass[11pt]{article}
\usepackage{fontspec}
\usepackage[english,russian]{babel}
\setmainfont{Arial} %anything will do

\begin{document}
Надпись на русском.
\begin{figure}
\caption{Это надпись} %if you comment this document compiles
\end{figure}
\end{document}


Here's the error string

! Undefined control sequence.
\figurename ->{\cyr \CYRR
\cyri \cyrs .}
l.9 \caption{Это надпись}
%if you comment this document compiles


Update: this is the same as \tableofcontents encoding issue with lualatex

-

## marked as duplicate by egreg, lockstep, mafp, Martin Schröder, Claudio FiandrinoApr 22 '13 at 12:26

The problem not in your text: xetex takes wrong \figurename. Redefine it before using: \def\figurename{Рис. } –  Eddy_Em Apr 22 '13 at 10:18
I can't answer my own question in 8 hours, but this helps. tex.stackexchange.com/questions/9175/… Problem is with \cyr sequences, changing the order of babel languages makes figure names to become english, but any cyrillic characters in captions cause the same error. –  eiennohito Apr 22 '13 at 10:18
Thinking some more about it -- you are right about \figurename, but the second workaround would be more compatible with other packages, I think. –  eiennohito Apr 22 '13 at 10:33
@eiennohito I've voted to close this as a duplicate; there's good news: the new version of Babel will support Unicode, so you won't have this problem any more (the new version is already available on CTAN, but it hasn't still be included in distributions, it will be soon). –  egreg Apr 22 '13 at 10:47

It seems that the babel russian files are not expecting xetex native utf8.

Possibly the simplest thing is to read the OT2 encoding file backwards to define the \cyr... commands in terms of Unicode code points rather than the other way round. This produces the following. Sorry I can not read the script so I have no idea if this is correct (If not, I'll fix or delete this answer)

\documentclass[11pt]{article}
\usepackage{fontspec}
\usepackage[english,russian]{babel}
\setmainfont{Arial} %anything will do
\begingroup
\def\DeclareUnicodeCharacter#1#2{\setunicode{#1}#2!!}%
\def\setunicode#1#2#3!!{%
\ifx\undefined#2%
\gdef#2{\char"#1 }%
\fi}
\input{ot2enc.dfu}
\endgroup

\begin{document}
Надпись на русском.
\begin{figure}
\caption{Это надпись} %if you comment this document compiles
\end{figure}
\end{document}

-
Output is right, thank you! Very nice idea. I like it. But @egreg said that this issue is already fixed in babel. –  eiennohito Apr 22 '13 at 11:14
@eiennohito egreg is probably right (he is sometimes:-) –  David Carlisle Apr 22 '13 at 11:19