TeX - LaTeX Asked by MandaloreUltimate on August 28, 2020
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}
Well, not a best solution because there are lot of work around, but maybe someone will find it useful:
(1) In folder texmfsinstallfontstype1publiccm-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 texmfsinstallfontsafmpubliccm-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:
(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.
Correct answer by Урош on August 28, 2020
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.
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):
so some sort of mapping/wrapping will be needed if T2A encoding and Unicode encoding texts are intertwined together like threads in a tapestry.
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}
newfontfamilycyrillicfont{Noto Serif}
usepackage{xcolor}
%=============== font table labels
newcommandftlabel[1]{{usefont{T1}{lmr}{m}{n}scriptsize#1}}
%------------------- font table: - 8-bit
newcommanddisplayglyphs[4]{%
{usefont{#1}{#2}{#3}{#4} %usefont{T1}{uncl}{m}{n}
count255 = 0
loop
iffontcharfontnumbercount255{%*
ftlabel{[numbercount255 =}colorbox{yellow!50}{textcolor{red!90!blue}{{largecharnumbercount255}}}ftlabel{]} %need space for line-breaking
}fi
ifnumcount255 < 256
advancecount255 by 1
repeat
} parbigskip}
begin{document}
chapter{Глава usefont{OT2}{cgr}{b}{n} Glava}
section{Секция}
Текст.
xxx
%usefont{OT2}{cgr}{b}{n}
%OT2 cgr Glava xx Глава
%Секция
%Текст.
%fontnamefont
%displayglyphs{OT2}{cgr}{b}{n}
usefont{T2A}{cgr}{b}{n}
T2A cgr Glava xx Глава
Секция
Текст.
fontnamefont
char195char235char224char226char224
displayglyphs{T2A}{cgr}{b}{n}
%usefont{OT2}{larm}{bx}{n}
%OT2 larm Glava xx Глава
%Секция
%Текст.
%fontnamefont
%displayglyphs{OT2}{larm}{bx}{n}
usefont{T2A}{larm}{bx}{n}
T2A larm Glava xx Глава
Секция
Текст.
fontnamefont
{usefont{T1}{lmr}{m}{n} In T2A encoding,
textbackslash char195textbackslash char235textbackslash char224textbackslash char226textbackslash char224
produces}
char195char235char224char226char224
displayglyphs{T2A}{larm}{bx}{n}
end{document}
Answered by Cicada on August 28, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP