6

I have next setup:

% !TeX program = lualatex

\documentclass[11pt]{report}
\usepackage{polyglossia}

\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}


\setmainlanguage{Ukrainian}
\setotherlanguages{english, russian}

\usepackage[demo]{graphicx}

\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}
    \begin{figure}[tbp]
        \centering
        \includegraphics{file}
        \caption{caption}
        \label{fig:tag}
    \end{figure}
        
    На \cref{fig:tag} зображено чорний квадрат.
\end{document}

It produces next errors:

polycref.tex|27 error| Undefined control sequence.
polycref.tex|27 error| Undefined control sequence.
polycref.tex|27 error| Undefined control sequence.

If I set main language to English it works as intended. How to fix it? I tried to find answer on texdoc but it didn't help.

1

1 Answer 1

7

It's best to load packages first and then do setup.

Unfortunately, though, cleveref for Ukrainian doesn't work directly with Unicode, because it relies on LICR commands such as \cyra, \CYRA and so on. However, we can do the conversion exploiting the t2aenc.dfu file, but in reverse. I only define the simple characters.

\documentclass[11pt]{report}
\usepackage{polyglossia}
\usepackage{hyperref}
\usepackage[ukrainian]{cleveref}

\setmainlanguage{ukrainian}
\setotherlanguages{english, russian}

\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}

% convert \cyr... and \CYR... to Unicode
\ExplSyntaxOn
\group_begin:
\cs_set:Npn \DeclareUnicodeCharacter #1 #2
 {
  \bool_lazy_or:nnT
   { \str_if_eq_p:ee { cyr } { \str_range:nnn { #2 } { 2 } { 4 } } }% \cyr...
   { \str_if_eq_p:ee { CYR } { \str_range:nnn { #2 } { 2 } { 4 } } }% \CYR...
   { \cs_gset:Npe #2 { \char_generate:nn { "#1 } { 11 } } }
 }
\file_input:n { t2aenc.dfu }
\group_end:
\ExplSyntaxOff


\begin{document}

\begin{figure}[tbp]
\centering

\fbox{This is a figure}

\caption{caption}
\label{fig:tag}

\end{figure}
        
На \cref{fig:tag} зображено чорний квадрат.

\end{document}

A typical line in t2aenc.dfu has the form

\DeclareUnicodeCharacter{0401}{\CYRYO}

so I define \CYRYO to be the character at position U+0401, courtesy of \char_generate:nn. Lines such as

\DeclareUnicodeCharacter{0400}{\@tabacckludge`\CYRE}

are ignored: only those where the second argument is either \cyr... or \CYR... are considered.

enter image description here

1
  • It's sad that this won't work out-of-the-box but anyway your solution works. Thank You a lot! Jan 1 at 23:20

You must log in to answer this question.

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