如何使用自定义类将西里尔俄语字符添加到模板中?

如何使用自定义类将西里尔俄语字符添加到模板中?

因此,我一直在尝试将俄语添加到 Overleaf 的模板中。它有一个如下所示的自定义类:

\ProvidesClass{clean_cv}[2021/07/28 v1.0.0 'CleanCV' Class]

\LoadClass[11pt]{article}

\RequirePackage[margin=0.3in]{geometry} % half-inch margins
\RequirePackage{microtype}
\RequirePackage{fancyhdr}
\RequirePackage{titlesec}
\RequirePackage{array}
\RequirePackage{xcolor}
\RequirePackage{xpatch}
\RequirePackage{enumitem}

% Load fonts
\RequirePackage[fixed]{fontawesome5}
\RequirePackage[scaled=.9,osf]{XCharter}
\linespread{0.92}

% Load biber
\RequirePackage[backend=biber,sorting=ydnt,block=none,bibstyle=nature,doi=false,isbn=false,url=false]{biblatex}

\RequirePackage[hidelinks]{hyperref}

\DeclareSourcemap{
    \maps[datatype=bibtex]{
        \map[overwrite]{
            \step[fieldsource=date, match=\regexp{(\d{4})},
                  fieldset=keywords, fieldvalue={YEAR-$1}, append, ]
    }
    \map[overwrite]{
        \step[fieldset=note, null]
    }
}}

% \RequirePackage[T2A]{fontenc}
% \RequirePackage[utf8]{inputenc}
% \RequirePackage[russian]{babel}
\AtBeginBibliography{\vspace*{-2em}}

%-----------------------------------------------------
% Bold one author's name
% https://tex.stackexchange.com/a/73246, CC-BY-SA 3.0
\def\makenamesetup{%
  \def\bibnamedelima{ }%
  \def\bibnamedelimb{ }%
  \def\bibnamedelimc{ }%
  \def\bibnamedelimd{ }%
  \def\bibnamedelimi{ }%
  \def\bibinitperiod{.}%
  \def\bibinitdelim{ }%
  \def\bibinithyphendelim{.-}}    
\newcommand*{\makename}[3]{\begingroup\makenamesetup\xdef#1{#2, #3}\endgroup}

\newbibmacro*{name:bold}[2]{%
  \makename{\currname}{#1}{#2}%
  \makename{\findname}{\lastname}{\firstname}%
  \makename{\findinit}{\lastname}{\firstinit}%
  \ifboolexpr{ test {\ifdefequal{\currname}{\findname}}
            or test {\ifdefequal{\currname}{\findinit}} }{\bfseries}{}}

\newcommand*{\highlightauthorname}[3]{%
  \def\lastname{#3}%
  \def\firstname{#1}%
  \def\firstinit{#2}}

\xpretobibmacro{name:family}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:given-family}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:family-given}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:delim}{\begingroup\normalfont}{}{}

\xapptobibmacro{name:family}{\endgroup}{}{}
\xapptobibmacro{name:given-family}{\endgroup}{}{}
\xapptobibmacro{name:family-given}{\endgroup}{}{}
\xapptobibmacro{name:delim}{\endgroup}{}{}
%------------------------------------------------------
\newcommand{\printbibyear}[1]{\printbibliography[heading=none,keyword=YEAR-#1]\vspace*{-2.5em}\,}


\definecolor{dateline}{gray}{0.5}
\definecolor{datecolor}{gray}{0.4}
\newcolumntype{R}{>{\raggedleft\arraybackslash}p{4em}}
\newcommand{\daterule}{\color{dateline}\vrule width 1pt}
\newcommand{\dateentry}[2]{{\leavevmode\color{datecolor}{#1}} & #2 \\ \noalign{\medskip}}
%\dimexpr(\textwidth - #1)\relax
\newenvironment{datetabular}[1]{%
    \begin{tabular}{@{}>{\raggedleft\arraybackslash}p{#1}!{\daterule}p{\dimexpr(\linewidth - #1 - 1em)\relax}}%
}{%
    \end{tabular}%
}

\newcommand{\faCenter}[1]{\raisebox{-2pt}{\faIcon{#1}}}
\newcommand{\faCenterStyle}[2]{\raisebox{-2pt}{\faIcon[#1]{#2}}}

\titleformat{\section}[display]{\large\bfseries}{}{0pt}{}[\vspace{-10pt}\rule{\linewidth}{1pt}]
\titlespacing*{\section}{0pt}{0em}{0.4em}

\setlength\parindent{0pt}
\setlength\parskip{0pt}

\setlist{noitemsep,topsep=0pt,parsep=0pt,partopsep=0pt}
\newcommand{\eatvspace}{\vspace*{-1.5em}\,}

\newcommand*{\headlineposition}[1]{\def\@headlineposition{#1}}

\let\@author\@empty
\let\@headlineposition\@empty

\renewcommand{\maketitle}{%
\begin{center}
    \ifx\@author\@empty\else{ \Huge \@author} \\\fi \ifx\@headlineposition\@empty\else\vspace{4pt} {\itshape \@headlineposition}\fi
\end{center}%
\vspace{-17.2pt}
\rule{\linewidth}{1pt}
}

\pagestyle{empty}

我按照 Overleaf 教程将俄语添加到乳胶中,并将这些行添加到我的.tex文件中。

\documentclass{clean_cv}
%Russian-specific packages
%--------------------------------------
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
%--------------------------------------
 
%Hyphenation rules
%--------------------------------------
\usepackage{hyphenat}
\hyphenation{ма-те-ма-ти-ка вос-ста-нав-ли-вать}

\author{ASDXCASD ФЫВФЫВ}
\headlineposition{ASDASD ФЫВФЫВ}
\begin{document}

\maketitle

\end{document}

但后来它给了我这些错误:

Font T2A/XCharter-TOsF/m/it/10.95=XCharter1-Italic-tosf-t2a at 9.85492pt not loadable: Metric (TFM) file not found.
<to be read again> 
                   relax 
l.22 \maketitle
               
I wasn't able to read the size data for this font,
so I will ignore the font specification.
[Wizards can fix TFM files using TFtoPL/PLtoTF.]
You might try inserting a different font spec;
e.g., type `I\font<same font id>=<substitute font name>'.

pdfTeX error (font expansion): invalid font identifier.
MT@font ->T2A/XCharter-TOsF/m/it/10.95 
                                       
l.22 \maketitle

我该如何修复此错误?这是向此自定义类添加俄语支持的正确方法吗?

答案1

我认为这是 XCharter 维护者打包时的错误。在我的计算机上,我保留了 2012 年发布的 TeX Live,结果

> locate XCharter1-Italic-tosf-t2a.tfm
/usr/local/texlive/2017/texmf-dist/fonts/tfm/public/xcharter/XCharter1-Italic-tosf-t2a.tfm
/usr/local/texlive/2018/texmf-dist/fonts/tfm/public/xcharter/XCharter1-Italic-tosf-t2a.tfm
/usr/local/texlive/2019/texmf-dist/fonts/tfm/public/xcharter/XCharter1-Italic-tosf-t2a.tfm
/usr/local/texlive/2021/texmf-dist/fonts/tfm/public/xcharter/XCharter1-Italic-tosf-t2a.tfm

> locate XCharter1-Italic-tosf-t2a.vf
/usr/local/texlive/2017/texmf-dist/fonts/vf/public/xcharter/XCharter1-Italic-tosf-t2a.vf
/usr/local/texlive/2018/texmf-dist/fonts/vf/public/xcharter/XCharter1-Italic-tosf-t2a.vf
/usr/local/texlive/2019/texmf-dist/fonts/vf/public/xcharter/XCharter1-Italic-tosf-t2a.vf
/usr/local/texlive/2021/texmf-dist/fonts/vf/public/xcharter/XCharter1-Italic-tosf-t2a.vf

因此您会看到 TeX Live 2020(Overleaf 使用)中缺少字体。现在更新它已经太晚了,因为 TeX Live 2020 已冻结,但您可以使用 TeX Live 2018 进行编译(我相信 Overleaf 可以做到这一点)。

顺便说一句,使用 TeX Live 2019 和 2021 进行编译会失败,原因是

! TeX capacity exceeded, sorry [max level recursion of virtual fonts=10].
\AtBegShi@Output ...ipout \box \AtBeginShipoutBox
                                                  \fi \fi

一种解决方法是删除该osf选项,否则,测试将无法与我拥有的每个支持的 TeX Live 版本XCharter(特别是 TL 2020)兼容。

已向维护人员提交了一份错误报告,但没有机会使其与 TeX Live 2020 一起工作(如果您不做大量工作)。

相关内容