2

I need to shift document written in pdfLaTeX to XeLaTex and I would like to keep the way it looks intact, however, I can't figure out how to emulate the default pdfLaTeX Computer Modern cyrillic font. As I understand, XeLaTeX only supports CMU, but it looks notably different, as shown by MWEs below, and it really annoys me. Is it just a problem with the counterpart font and there is no workaround?

pdfLaTeX:

\documentclass[oneside,final,14pt]{extreport}

\usepackage{cmap}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english, russian]{babel}

\begin{document}

\chapter{Глава}
\section{Секция}
Текст.

\end{document}

XeLaTeX:

\documentclass[oneside,final,14pt]{extreport}

\usepackage{fontspec}
\usepackage{polyglossia}
  \setdefaultlanguage{russian}
  \setotherlanguage{english}
  
\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}

\begin{document}

\chapter{Глава}
\section{Секция}
Текст.

\end{document}
2
  • 5
    The difference is that with pdflatex you get fonts at a design size of 14.4pt, whereas with xelatex the 10pt font is scaled up, so it appears “bolder”. There is no OpenType version of Cyrillic Computer Modern with optical size, as far as I know. – egreg Aug 3 '20 at 9:41
  • An offtopic suggestion: Try OldStandard, it gives to me a similar vibes as CM Cyrillic. (I'd be getting heavy flak for that, because they are very much different!) – Oleg Lobachev Aug 3 '20 at 12:39
1

Well, not a best solution because there are lot of work around, but maybe someone will find it useful:

(1) In folder texmfs\install\fonts\type1\public\cm-super there are .pfb fonts that are used when you compile with pdfLaTeX.

(2) Convert them in .otf format using FortForge or some other application. (For the best results copy and extract .afm files from texmfs\install\fonts\afm\public\cm-super into same folder where the .pfb files are). For this example I used only upright sfrm*.pfb and bold sfbx*.pfb fonts. Now I have fonts SFRM0500.otf, SFRM0600.otf... etc.

(3) If generated .otf fonts are in the same folder where your .tex file is, use the next code:

\documentclass[oneside,final,14pt]{extreport}

\usepackage{fontspec}
\usepackage{polyglossia}
  \setdefaultlanguage{russian}
  \setotherlanguage{english}
  
\setmainfont[%
Extension = {.otf},
BoldFont = {SFBX1000},
UprightFont = {SFRM1000},
    UprightFeatures={
        SizeFeatures={ 
            {Size={-6.0},Font=SFRM0500},
            {Size={6.0-7.0},Font=SFRM0600},
            {Size={7.0-8.0},Font=SFRM0700},
            {Size={8.0-9.0},Font=SFRM0800},
            {Size={9.0-10.0},Font=SFRM0900},
            {Size={10.0-10.95},Font=SFRM1000},
            {Size={10.95-12.0},Font=SFRM1095},
            {Size={12.0-14.4},Font=SFRM1200},
            {Size={14.4-17.28},Font=SFRM1440},
            {Size={17.28-20.74},Font=SFRM1728},
            {Size={20.74-24.88},Font=SFRM2074},
            {Size={24.88-29.86},Font=SFRM2488},
            {Size={29.86-35.38},Font=SFRM2986},
            {Size={35.83-},Font=SFRM3583},
        },
    },
BoldFeatures={
        SizeFeatures={ 
            {Size={-6.0},Font=SFBX0500},
            {Size={6.0-7.0},Font=SFBX0600},
            {Size={7.0-8.0},Font=SFBX0700},
            {Size={8.0-9.0},Font=SFBX0800},
            {Size={9.0-10.0},Font=SFBX0900},
            {Size={10.0-10.95},Font=SFBX1000},
            {Size={10.95-12.0},Font=SFBX1095},
            {Size={12.0-14.4},Font=SFBX1200},
            {Size={14.4-17.28},Font=SFBX1440},
            {Size={17.28-20.74},Font=SFBX1728},
            {Size={20.74-24.88},Font=SFBX2074},
            {Size={24.88-29.86},Font=SFBX2488},
            {Size={29.86-35.38},Font=SFBX2986},
            {Size={35.83-},Font=SFBX3583},
        },
    }
]
{SFRM1000}

\begin{document}

\chapter{Глава}
\section{Секция}
Текст.

\end{document}

Of course, one will have to create all fonts (italic, smallcaps,...) for the best solution. I've used just upright and bold to show how this can be done. Result: XeLaTeX and pdfLaTeX difference

(4) However, I would not recommend this solution, because it use a lot of resources, plus the generated .otf fonts on this way will miss a lot of features; probably there is an easier way. Maybe someday someone create a font package similar to the Latin Modern that will have a Cyrillic letters in different optical sizes.

1

Nothing useful (yet), so apologies, but I was thinking:

(1) There must be a legacy font file that could be called into play. pdflatex's log listed a stack of metafont files being created, but I couldn't work out the NFSS name. I tried cgr bold (via a Google suggestion), but that got converted to gab10 and then scaled up to 14.4pt.

scaled up

There's a `larm1440' (from the log flood), but then that exposes a second matter.

(2) Encoding. In T2A encoding, Cyrillic small A is in slot 224 (which is Latin à in Unicode):

encoding

so some sort of mapping/wrapping will be needed if T2A encoding and Unicode encoding texts are intertwined together like threads in a tapestry.

mapping

Legacy installations could compile legacy documents, I suppose. A modern installation would need an insulating layer of code (or environment bubbles) to quarantine the encodings, I would expect.

MWE

\documentclass[oneside,final,14pt]{extreport}
\usepackage{cmap}
\usepackage[T2A,OT2]{fontenc}
\usepackage{fontspec}
\usepackage{polyglossia}
  \setdefaultlanguage{russian}
  \setotherlanguage{english}
  
\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}
\newfontfamily\cyrillicfont{Noto Serif}

\usepackage{xcolor}

%=============== font table labels
\newcommand\ftlabel[1]{{\usefont{T1}{lmr}{m}{n}\scriptsize#1}}
%------------------- font table: - 8-bit
\newcommand\displayglyphs[4]{%
{\usefont{#1}{#2}{#3}{#4} %\usefont{T1}{uncl}{m}{n}
\count255 = 0
\loop  
\iffontchar\font\number\count255{%*
\ftlabel{[\number\count255 =}\colorbox{yellow!50}{\textcolor{red!90!blue}{{\large\char\number\count255}}}\ftlabel{]} %need space for line-breaking
}\fi
\ifnum\count255 < 256
\advance\count255 by 1
\repeat
}\ \par\bigskip}

\begin{document}

\chapter{Глава \usefont{OT2}{cgr}{b}{n} Glava}
\section{Секция}
Текст.

xxx


%\usefont{OT2}{cgr}{b}{n}
%OT2 cgr Glava xx Глава
%Секция
%Текст.
%\fontname\font
%\displayglyphs{OT2}{cgr}{b}{n}


\usefont{T2A}{cgr}{b}{n}
T2A cgr Glava xx Глава
Секция
Текст.
\fontname\font 

\char195\char235\char224\char226\char224

\displayglyphs{T2A}{cgr}{b}{n}


%\usefont{OT2}{larm}{bx}{n}
%OT2 larm Glava xx Глава
%Секция
%Текст.
%\fontname\font
%\displayglyphs{OT2}{larm}{bx}{n}

\usefont{T2A}{larm}{bx}{n}
T2A larm Glava xx Глава
Секция
Текст.
\fontname\font

{\usefont{T1}{lmr}{m}{n} In T2A encoding,\\
 \textbackslash char195\textbackslash char235\textbackslash char224\textbackslash char226\textbackslash char224 \\
 produces}\\
\char195\char235\char224\char226\char224

\displayglyphs{T2A}{larm}{bx}{n}

\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.