3

How can I convert cyrillic letters defined in xecyr (for example, \cyra, \cyrb) to uppercase in XeLaTeX? I've tried \uppercase, \MakeUppercase, \MakeTextUppercase and neither of them worked, the text remains in lowercase.

\documentclass{article}
\usepackage{textcase}
\usepackage{xecyr}
\usepackage{polyglossia}
\setmainlanguage[spelling=modern]{russian}
\newfontfamily{\cyrillicfont}{cmunrm.otf}[
      BoldFont = cmunbx.otf,
      ItalicFont = cmunti.otf,
  BoldItalicFont = cmunbi.otf]

\begin{document}
\uppercase{\cyra\cyrb}

\MakeUppercase{\cyra\cyrb}

\MakeTextUppercase{\cyra\cyrb}
\end{document}

\cyra is defined as \DeclareUTFcharacter[\UTFencname]{x0430}{\cyra}, other letters are defined similarly.

  • 1
    XeLaTeX expects Unicode input. – egreg Apr 5 '17 at 7:41
  • @egreg I know, I should not use these \cyr* in XeLaTeX, it's kind of legacy code that I can't change. – Im ieee Apr 5 '17 at 7:48
1

You will have to add the commands to the list used by \MakeUppercase:

\documentclass{article}
\usepackage{textcase}
\usepackage{xecyr}
\usepackage{polyglossia}
\setmainlanguage[spelling=modern]{russian}
\newfontfamily{\cyrillicfont}{cmunrm.otf}[
      BoldFont = cmunbx.otf,
      ItalicFont = cmunti.otf,
  BoldItalicFont = cmunbi.otf]

\usepackage{etoolbox}
\makeatletter
\appto\@uclclist{\cyra\CYRA\cyrb\CYRB}
\makeatother
\begin{document}

\MakeUppercase{\cyra\cyrb}
\MakeTextUppercase{\cyra\cyrb}

\end{document}

enter image description here

As requested in the comment here a way to redefine \cyra to a simpler command which works in \MakeUppercase. But if could have side-effects, so use it with care. To avoid that it changes all commands defined by xunicode, xunicode is loaded directly:

\documentclass{article}
\usepackage{textcase}

\usepackage{polyglossia}
\setmainlanguage[spelling=modern]{russian}
\newfontfamily{\cyrillicfont}{cmunrm.otf}[
      BoldFont = cmunbx.otf,
      ItalicFont = cmunti.otf,
  BoldItalicFont = cmunbi.otf]

\usepackage{xunicode}
\usepackage{expl3}
\ExplSyntaxOn
\let\OldDeclareUTFcharacter\DeclareUTFcharacter
\renewcommand\DeclareUTFcharacter[3][]{%
 \tl_set:Nx\l_tmpa_tl{\tl_tail:n{#2}}
 \tl_set:Nx #3 {\char_generate:nn{"\l_tmpa_tl}{11}} 
 }
\ExplSyntaxOff 
\usepackage{xecyr} 
\let\DeclareUTFcharacter\OldDeclareUTFcharacter



\begin{document}
\uppercase{\cyra\cyrb}
\MakeUppercase{\cyra\cyrb}
\MakeTextUppercase{\cyra\cyrb}

\end{document}
  • Thank you, but when using your code I have to add a lot of letters manually. I think there is another solution. Is it possible to temporary redefine \DeclareUTFcharacter so that \cyra is mapped to ^^^^0430? The hex digits could be obtained from the first argument (x0430). – Im ieee Apr 5 '17 at 7:21
  • I added an edit. – Ulrike Fischer Apr 5 '17 at 8:38
1

XeLaTeX expects Unicode input, so polyglossia doesn't bother to load a correspondence between upper and lower case for the “old style” LICR specifications. However, I understand that legacy documents might have some problems.

A simple workaround is to load the T2A encoding and then immediately override it:

\documentclass{article}

\usepackage[T2A,TU]{fontenc}
\usepackage{textcase}
\usepackage{xecyr}
\usepackage{polyglossia}

\setmainlanguage[spelling=modern]{russian}

\setmainfont{cmun}[
  Extension      = .otf,
  UprightFont    = *rm,
  BoldFont       = *bx,
  ItalicFont     = *ti,
  BoldItalicFont = *bi
]

\begin{document}

\MakeUppercase{\cyra\cyrb}

\MakeTextUppercase{\cyra\cyrb}

\end{document}

You can redefine the LICR to point to a character, say

\def\cyra{^^^^0430}

This can be done by using the code in t2aenc.dfu, which contains line such as

\DeclareUnicodeCharacter{0410}{\CYRA}

It's easy, with a good editor, to change that file into cyrlicr.tex

\newcommand{\RedefineLICR}[2]{\def#2{#1}}

\RedefineLICR{^^^^0401}{\CYRYO}
\RedefineLICR{^^^^0402}{\CYRDJE}
\RedefineLICR{^^^^0404}{\CYRIE}
\RedefineLICR{^^^^0405}{\CYRDZE}
\RedefineLICR{^^^^0406}{\CYRII}
\RedefineLICR{^^^^0407}{\CYRYI}
\RedefineLICR{^^^^0408}{\CYRJE}
\RedefineLICR{^^^^0409}{\CYRLJE}
\RedefineLICR{^^^^040a}{\CYRNJE}
\RedefineLICR{^^^^040b}{\CYRTSHE}
\RedefineLICR{^^^^040e}{\CYRUSHRT}
\RedefineLICR{^^^^040f}{\CYRDZHE}
\RedefineLICR{^^^^0410}{\CYRA}
\RedefineLICR{^^^^0411}{\CYRB}
\RedefineLICR{^^^^0412}{\CYRV}
\RedefineLICR{^^^^0413}{\CYRG}
\RedefineLICR{^^^^0414}{\CYRD}
\RedefineLICR{^^^^0415}{\CYRE}
\RedefineLICR{^^^^0416}{\CYRZH}
\RedefineLICR{^^^^0417}{\CYRZ}
\RedefineLICR{^^^^0418}{\CYRI}
\RedefineLICR{^^^^0419}{\CYRISHRT}
\RedefineLICR{^^^^041a}{\CYRK}
\RedefineLICR{^^^^041b}{\CYRL}
\RedefineLICR{^^^^041c}{\CYRM}
\RedefineLICR{^^^^041d}{\CYRN}
\RedefineLICR{^^^^041e}{\CYRO}
\RedefineLICR{^^^^041f}{\CYRP}
\RedefineLICR{^^^^0420}{\CYRR}
\RedefineLICR{^^^^0421}{\CYRS}
\RedefineLICR{^^^^0422}{\CYRT}
\RedefineLICR{^^^^0423}{\CYRU}
\RedefineLICR{^^^^0424}{\CYRF}
\RedefineLICR{^^^^0425}{\CYRH}
\RedefineLICR{^^^^0426}{\CYRC}
\RedefineLICR{^^^^0427}{\CYRCH}
\RedefineLICR{^^^^0428}{\CYRSH}
\RedefineLICR{^^^^0429}{\CYRSHCH}
\RedefineLICR{^^^^042a}{\CYRHRDSN}
\RedefineLICR{^^^^042b}{\CYRERY}
\RedefineLICR{^^^^042c}{\CYRSFTSN}
\RedefineLICR{^^^^042d}{\CYREREV}
\RedefineLICR{^^^^042e}{\CYRYU}
\RedefineLICR{^^^^042f}{\CYRYA}
\RedefineLICR{^^^^0430}{\cyra}
\RedefineLICR{^^^^0431}{\cyrb}
\RedefineLICR{^^^^0432}{\cyrv}
\RedefineLICR{^^^^0433}{\cyrg}
\RedefineLICR{^^^^0434}{\cyrd}
\RedefineLICR{^^^^0435}{\cyre}
\RedefineLICR{^^^^0436}{\cyrzh}
\RedefineLICR{^^^^0437}{\cyrz}
\RedefineLICR{^^^^0438}{\cyri}
\RedefineLICR{^^^^0439}{\cyrishrt}
\RedefineLICR{^^^^043a}{\cyrk}
\RedefineLICR{^^^^043b}{\cyrl}
\RedefineLICR{^^^^043c}{\cyrm}
\RedefineLICR{^^^^043d}{\cyrn}
\RedefineLICR{^^^^043e}{\cyro}
\RedefineLICR{^^^^043f}{\cyrp}
\RedefineLICR{^^^^0440}{\cyrr}
\RedefineLICR{^^^^0441}{\cyrs}
\RedefineLICR{^^^^0442}{\cyrt}
\RedefineLICR{^^^^0443}{\cyru}
\RedefineLICR{^^^^0444}{\cyrf}
\RedefineLICR{^^^^0445}{\cyrh}
\RedefineLICR{^^^^0446}{\cyrc}
\RedefineLICR{^^^^0447}{\cyrch}
\RedefineLICR{^^^^0448}{\cyrsh}
\RedefineLICR{^^^^0449}{\cyrshch}
\RedefineLICR{^^^^044a}{\cyrhrdsn}
\RedefineLICR{^^^^044b}{\cyrery}
\RedefineLICR{^^^^044c}{\cyrsftsn}
\RedefineLICR{^^^^044d}{\cyrerev}
\RedefineLICR{^^^^044e}{\cyryu}
\RedefineLICR{^^^^044f}{\cyrya}
\RedefineLICR{^^^^0451}{\cyryo}
\RedefineLICR{^^^^0452}{\cyrdje}
\RedefineLICR{^^^^0454}{\cyrie}
\RedefineLICR{^^^^0455}{\cyrdze}
\RedefineLICR{^^^^0456}{\cyrii}
\RedefineLICR{^^^^0457}{\cyryi}
\RedefineLICR{^^^^0458}{\cyrje}
\RedefineLICR{^^^^0459}{\cyrlje}
\RedefineLICR{^^^^045a}{\cyrnje}
\RedefineLICR{^^^^045b}{\cyrtshe}
\RedefineLICR{^^^^045e}{\cyrushrt}
\RedefineLICR{^^^^045f}{\cyrdzhe}
\RedefineLICR{^^^^0490}{\CYRGUP}
\RedefineLICR{^^^^0491}{\cyrgup}
\RedefineLICR{^^^^0492}{\CYRGHCRS}
\RedefineLICR{^^^^0493}{\cyrghcrs}
\RedefineLICR{^^^^0496}{\CYRZHDSC}
\RedefineLICR{^^^^0497}{\cyrzhdsc}
\RedefineLICR{^^^^0498}{\CYRZDSC}
\RedefineLICR{^^^^0499}{\cyrzdsc}
\RedefineLICR{^^^^049a}{\CYRKDSC}
\RedefineLICR{^^^^049b}{\cyrkdsc}
\RedefineLICR{^^^^049c}{\CYRKVCRS}
\RedefineLICR{^^^^049d}{\cyrkvcrs}
\RedefineLICR{^^^^04a0}{\CYRKBEAK}
\RedefineLICR{^^^^04a1}{\cyrkbeak}
\RedefineLICR{^^^^04a2}{\CYRNDSC}
\RedefineLICR{^^^^04a3}{\cyrndsc}
\RedefineLICR{^^^^04a4}{\CYRNG}
\RedefineLICR{^^^^04a5}{\cyrng}
\RedefineLICR{^^^^04aa}{\CYRSDSC}
\RedefineLICR{^^^^04ab}{\cyrsdsc}
\RedefineLICR{^^^^04ae}{\CYRY}
\RedefineLICR{^^^^04af}{\cyry}
\RedefineLICR{^^^^04b0}{\CYRYHCRS}
\RedefineLICR{^^^^04b1}{\cyryhcrs}
\RedefineLICR{^^^^04b2}{\CYRHDSC}
\RedefineLICR{^^^^04b3}{\cyrhdsc}
\RedefineLICR{^^^^04b6}{\CYRCHRDSC}
\RedefineLICR{^^^^04b7}{\cyrchrdsc}
\RedefineLICR{^^^^04b8}{\CYRCHVCRS}
\RedefineLICR{^^^^04b9}{\cyrchvcrs}
\RedefineLICR{^^^^04ba}{\CYRSHHA}
\RedefineLICR{^^^^04bb}{\cyrshha}
\RedefineLICR{^^^^04c0}{\CYRpalochka}
\RedefineLICR{^^^^04d4}{\CYRAE}
\RedefineLICR{^^^^04d5}{\cyrae}
\RedefineLICR{^^^^04d8}{\CYRSCHWA}
\RedefineLICR{^^^^04d9}{\cyrschwa}
\RedefineLICR{^^^^04e8}{\CYROTLD}
\RedefineLICR{^^^^04e9}{\cyrotld}
\endinput

Note that only the “simple” commands can be used (not the composed ones), and that letters (actually hexadecimal digits) in the first argument must be lowercased. With this file in the working directory, you can do

\documentclass{article}

\usepackage{textcase}
\usepackage{xecyr}
\usepackage{polyglossia}

\setmainlanguage[spelling=modern]{russian}

\setmainfont{cmun}[
  Extension      = .otf,
  UprightFont    = *rm,
  BoldFont       = *bx,
  ItalicFont     = *ti,
  BoldItalicFont = *bi,
]

\input{cyrlicr}

\begin{document}

\MakeUppercase{\cyra\cyrb}

\MakeTextUppercase{\cyra\cyrb}

\end{document}

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.