3

Сondition to change language of the month on titlepage doesn't work.

How to write condition to activate russian or english date depending on the choice?

XeLaTeX is used.

My code doesn't work. MWE:

\documentclass[10pt, oneside, a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{polyglossia}

\setotherlanguage{russian}
\foreignlanguage{russian}

\usepackage{datetime}

\ifthenelse{\umruslang>0}
{ %rus
\newcommand{\rus}[1]{\foreignlanguage{russian}{#1}}
\newdateformat{docdatef}{\rus{\monthname\ \THEYEAR}}
}
{%eng
\newdateformat{docdatef}{\monthname\ \THEYEAR}
}
1

The language definition file dt-russian.def (provided by datetime) uses commands like \cyrya in the month names, which aren't provided with XeLaTeX. However, datetime has been replaced by datetime2 and the corresponding datetime2-russian module (which needs to be installed separately) provides UTF-8 support.

MWE:

\documentclass{article}

\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{russian}

\setmainfont{Liberation Serif}
\newfontfamily\cyrillicfont{Liberation Serif}

\usepackage[en-GB,russian]{datetime2}

\DTMlangsetup[en-GB,russian]{showdayofmonth=false}

\begin{document}
\today

\selectlanguage{russian}

\today

\end{document}

January 2018 января 2018 г.

0

I agree that datetime2 is better, but you can also do it with datetime, provided you translate the calls of \cyr? and \CYR? into their Unicode counterparts, which can be done with the help of t2aenc.dfu.

\documentclass[10pt, oneside, a4paper]{report}
\usepackage{polyglossia}

\setmainfont{Old Standard} % supports Cyrillic

\setmainlanguage{english}
\setotherlanguage{russian}

\usepackage{datetime}
\usepackage{expl3}

\newcommand{\rus}[1]{\foreignlanguage{russian}{#1}}
\newdateformat{docdatef}{\rus{\monthname\ \THEYEAR}}

%% convert \cyr? and \CYR? to unicode
\ExplSyntaxOn
\prg_generate_conditional_variant:Nnn \str_if_in:nn {xn} { T }
\group_begin:
\cs_set:Npn \DeclareUnicodeCharacter #1 #2
 {
  \tl_if_single:nT { #2 }
   {
    \str_if_in:xnT { \str_upper_case:f { \tl_to_str:n { #2 } } } { CYR }
     {
      \cs_gset:Npn #2 { \symbol{"#1} }
     }
   }
 }
\file_input:n { t2aenc.dfu }
\group_end:
\ExplSyntaxOff

\begin{document}

\today

{\docdatef\today}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.