XeTeX 编译速度很慢——误用了 \newtoks?

XeTeX 编译速度很慢——误用了 \newtoks?

我正在尝试制作一个用于 XeTeX 的字体切换包。加载此类字体的命令会自动尝试替换缺失的字体(如倾斜字体),并尝试猜测字体类型,并设置 Computer Modern 字体默认定义的所有定义。我曾尝试过,但我清楚地记得,这不会花费太多时间来编译。

现在我正尝试用不同的方法重新制作,因为自己编译它需要太多时间。我不确定 \newtoks 的正确用法,但我用它来存储字体的名称,所以每当我稍微改变字体大小时,我只需重新发出一个应用命令就可以应用它。这样的标记可能最多需要 5-10 秒吗?或者 MikTeX 对 XeTeX 的设置完全错误?

编辑

经过一些调试,我发现较慢的部分是加载 Computer Modern 字体再次有人让我分享代码,但是,现在我知道问题出在哪里了,我只分享了代码的必要部分。(这不是秘密。我分享了代码的链接)慢的部分标有“无论如何,速度都慢得离谱”。

% Define tokens for fontfaces
\newtoks\rmface
\newtoks\itface
\newtoks\slface
\newtoks\bfface
\newtoks\biface  % Bold italic
\newtoks\bsface  % Bold slanted
% Technically impossible to create MORE slanted (slanted) italic font, or
% slanted bold slanted italic.
\newtoks\ttface

% I slightly modified the Typewriter Type, so it can be used, with \rm \it etc.
% Although its still be available with \tt.
\newtoks\ttrmface
\newtoks\ttitface
\newtoks\ttslface
\newtoks\ttbfface
\newtoks\ttbiface
\newtoks\ttbsface

\newtoks\titleface
\newtoks\titleitface
\newtoks\titleslface
\newtoks\titlebfface
\newtoks\titlebiface
\newtoks\titlebsface

\newtoks\mrmface % Math roman (for Ms font set)
\newtoks\mitface % Math italic
\newtoks\msyface % Math symbols
\newtoks\mexface % Math extended
\newtoks\calface % Caligraphic face (Restored to default if empty)
\newtoks\setface % Caligraphic face (Removed/Ignored if empty)
\let\omathbb=\relax % Temporary placement of \mathbb, if defined.

[...]

\rmface={cmr10}
\itface={cmr10}
\slface={cmsl10}
\bfface={cmbx10}
\biface={cmbxti10}
\bsface={cmbxsl10}

\titleface={cmss10}
\titleitface={cmssi10}
\titleslface={cmssi10}
\titlebfface={cmssdc10}
\titlebiface={cmssbx10}
\titlebsface={cmssqi8}

\ttface={cmtt10}
\ttrmface={cmtt10}
\ttitface={cmitt10}
\ttslface={cmsltt10}
\ttbfface={cmtt10}
\ttbiface={cmitt10}
\ttbsface={cmsltt10}

\mrmface={cmr10}
\mitface={cmmi10}
\msyface={cmsy10}
\mexface={cmex10}
\calface={}
\setface={}

\fontsize=10pt
\count\footins=830
\titlesize={3}
\hasize={1.5}
\hbsize={1.17}
\hcsize={1.17}
\hdsize={1}
\hesize={1}
\hfsize={.85}
\hgsize={.85}
\hhsize={.85}
\hisize={.85}

[...]

% Defining main font faces
\font\trm="\the\rmface" at \fontsize%
\ifnum\XeTeXfonttype\trm=0\def\oldstyle{\fam1\tit}\else%
\font\osy="\the\rmface:+onum" at \fontsize%
\def\oldstyle{\fam8\osy}\fi%
\if&\the\itface&%
\font\tit="\the\rmface:slant=.2" at \fontsize%
\font\sit="\the\rmface:slant=.2" at .7\fontsize%
\font\fit="\the\rmface:slant=.2" at .5\fontsize%
\else%
\font\tit="\the\itface" at \fontsize%
\font\sit="\the\itface" at .7\fontsize% Ridiculously slow, no matter what.
\font\fit="\the\itface" at .5\fontsize%
\fi%
\if&\the\slface&%
\font\tsl="\the\rmface:slant=.167" at \fontsize%
\font\ssl="\the\rmface:slant=.167" at .7\fontsize%
\font\fsl="\the\rmface:slant=.167" at .5\fontsize%
\else%
\font\tsl="\the\slface" at \fontsize%
\font\ssl="\the\slface" at .7\fontsize%
\font\fsl="\the\slface" at .5\fontsize%
\fi%
\if&\the\bfface&%
\font\tbf="\the\rmface:embolden=3" at \fontsize%
\font\sbf="\the\rmface:embolden=3" at .7\fontsize%
\font\fbf="\the\rmface:embolden=3" at .5\fontsize%
\else%
\font\tbf="\the\bfface" at \fontsize%
\font\sbf="\the\bfface" at .7\fontsize%
\font\fbf="\the\bfface" at .5\fontsize%
\fi%
\if&\the\biface&\if&\the\itface&\font\tbi="\the\rmface:embolden=3:slant=.2" at \fontsize%
\else\font\tbi="\the\itface:embolden=3" at \fontsize\fi%
\else\font\tbi="\the\biface" at \fontsize\fi%
\if&\the\bsface&\if&\the\bfface&\font\tbs="\the\rmface:embolden=3:slant=.167" at \fontsize%
\else\font\tbs="\the\bfface:slant=.167" at \fontsize\fi%
\else\font\tbs="\the\bsface" at \fontsize\fi%
\if&\the\ttface&%
\else%
\font\ttt="\the\ttface" at \fontsize%
\font\stt="\the\ttface" at .7\fontsize%
\font\ftt="\the\ttface" at .5\fontsize%
\fi%
% Math font face definitions
\if&\the\mrmface&%
\font\mtrm="\the\rmface" at \fontsize%
\font\msrm="\the\rmface" at .7\fontsize%
\font\mfrm="\the\rmface" at .5\fontsize%
\ifnum\XeTeXfonttype\mtrm=0\let\mosy=\relax\else\font\mosy="\the\rmface:+onum" at \fontsize\fi%
\else%
\font\mtrm="\the\mrmface" at \fontsize%
\font\msrm="\the\mrmface" at .7\fontsize%
\font\mfrm="\the\mrmface" at .5\fontsize%
\ifnum\XeTeXfonttype\mtrm=0\let\mosy=\relax\else\font\mosy="\the\mrmface:+onum" at \fontsize\fi%
\fi%
\if&\the\mitface&%
\font\mtit="\the\itface" at \fontsize%
\font\msit="\the\itface" at .7\fontsize%
\font\mfit="\the\itface" at .5\fontsize%
\else%
\font\mtit="\the\mitface" at \fontsize%
\font\msit="\the\mitface" at .7\fontsize%
\font\mfit="\the\mitface" at .5\fontsize%
\fi%
\font\mtsy="\the\msyface" at \fontsize%
\font\mssy="\the\msyface" at .7\fontsize%
\font\mfsy="\the\msyface" at .5\fontsize%
\font\mtex="\the\mexface" at \fontsize%
\font\msex="\the\mexface" at .7\fontsize%
\font\mfex="\the\mexface" at .5\fontsize%
\if&\the\calface&%
\def\cal{\fam2}%
\else%
\font\tcal="\the\calface" at \fontsize%
\font\scal="\the\calface" at .7\fontsize%
\font\fcal="\the\calface" at .5\fontsize%
\textfont9=\tcal\scriptfont9=\scal\scriptscriptfont9=\fcal%
\def\cal{\fam9\tcal}%
\fi%
\if&\the\setface&%
\ifx\omathbb\relax\let\mathbb=\relax\else\let\mathbb=\omathbb\let\omathbb=\relax\fi%
\else%
\font\tset="\the\setface" at \fontsize%
\font\sset="\the\setface" at .7\fontsize%
\font\fset="\the\setface" at .5\fontsize%
\textfont10=\tset\scriptfont10=\sset\scriptscriptfont10=\fset%
\ifx\omathbb\relax\ifx\mathbb\relax\else\let\omathbb=\mathbb\fi\fi%
\def\mathbb####1{{\fam10\tset####1}}%
\fi%
% Family setup
\textfont0=\mtrm\scriptfont0=\msrm\scriptscriptfont0=\mfrm%
\textfont1=\mtit\scriptfont1=\msit\scriptscriptfont1=\mfit%
\textfont2=\mtsy\scriptfont2=\mssy\scriptscriptfont2=\mfsy%
\textfont3=\mtex\scriptfont3=\msex\scriptscriptfont3=\mfex%
\textfont4=\tit\scriptfont4=\sit\scriptscriptfont4=\fit%
\textfont5=\tsl\scriptfont5=\ssl\scriptscriptfont5=\fsl%
\textfont6=\tbf\scriptfont6=\sbf\scriptscriptfont6=\fbf%
\textfont7=\ttt\scriptfont7=\stt\scriptscriptfont7=\ftt%
\ifx\mosy\relax\else\textfont8=\mosy\scriptfont8=\mosy\scriptscriptfont8=\mosy\fi%
%
\rm%
\initrmfam%
\inititfam%
\initsyfam%
\initexfam%

(上面的代码遵循处理顺序,而不是它在文件中的出现顺序)
有趣的是,无论我删除什么,代替它的下一行都会变慢,所以它可能与该行上的内容无关。

答案1

不,从你的描述来看,我怀疑这是使用令牌寄存器的错误。不过你不是每次都调用 \newtoks,对吧?

您是否正在为普通的 xetex 编写软件包?听起来与 fontspec 软件包有相当多的重叠。

相关内容