7

I am running XeLaTeX (distributed as part of MikTeX) on Windows 7 Service Pack 1 64-bit. The following test file takes a long time to compile:

\documentclass{article}
\usepackage{fontspec}
\message{Hello}
\setmainfont{AlegreyaSC-Regular}
\message{How are you?}
\begin{document}
Test
\end{document}

Every time I compile it, it takes 45-50 seconds between the "Hello" and "How are you?" messages being printed to the screen. (Alegreya is an opentype font I want to use in a document. I downloaded it from a web site. Alegreya-SC Regular means the small caps non-bold non-italic version of the font.)

I thought that perhaps XeLaTeX or fontspec might be trying to write a font cache somewhere but getting prevented from doing so because it was not running with administrator permissions; so I tried running XeLaTeX as administrator and manually entering the commands in the file. However, compilation remained slow after doing this.

This question appears similar on the face of it, but mentions that the author found that using the -no-pdf argument to xelatex caused it to run more quickly; this made no difference for me when I tried it.

XeLaTeX's greeting:

This is XeTeX, Version 3.14159265-2.6-0.99991 (MiKTeX 2.9 64-bit)

Edit: A part of the log file

(C:\LaTeX\tex\latex\fontspec\fontspec.cfg))) Hello
\g__file_internal_ior=\read1
.................................................
. fontspec info: "no-scripts"
. 
. Font AlegreyaSC-Regular does not contain any OpenType `Script' information.
.................................................
\g__fontspec_family_AlegreyaSC-Regular_int=\count120
.................................................
. fontspec info: "defining-font"
. 
. Font family 'AlegreyaSC-Regular(0)' created for font 'AlegreyaSC-Regular'
. with options [Ligatures=TeX].
. 
. This font family consists of the following shapes:
. 
. * 'normal' with NFSS spec.:
. <->"AlegreyaSC-Regular/OT:mapping=tex-text;"
. 
. * 'small caps' with NFSS spec.:
. 
. and font adjustment code:
. 
. 
. * 'bold' with NFSS spec.:
. <->"AlegreyaSC-Regular/B/OT:mapping=tex-text;"
. 
. * 'bold small caps' with NFSS spec.:
. 
. and font adjustment code:
. 
. 
. * 'italic' with NFSS spec.:
. <->"AlegreyaSC-Regular/I/OT:mapping=tex-text;"
. 
. * 'small caps' with NFSS spec.:
. 
. and font adjustment code:
. 
. 
. * 'bold italic' with NFSS spec.:
. <->"AlegreyaSC-Regular/BI/OT:mapping=tex-text;"
. 
. * 'bold small caps' with NFSS spec.:
. 
. and font adjustment code:
. 
.................................................
 How are you? (test.aux)
Hammerite
  • 3,596
  • Have you tried \usepackage{Alegreya}? Note that the font is included in TeX Live and, I assume, in MikTeX. – cfr Jun 23 '15 at 21:06
  • I was not aware that it was available through the TeX distribution, and yes, it does work fast using the dedicated package. But I still need to know why the "fontspec" method is slow, because I want to use more than one font in my document. – Hammerite Jun 23 '15 at 21:19
  • I really meant to try the package with XeLaTeX - not pdfLaTeX. pdfLaTeX is bound to be faster - XeLaTeX is always much slower for any document. – cfr Jun 23 '15 at 22:16
  • Yes, that is what I did. I commented out the usepackage and setmainfont lines and added a \usepackage{alegreya}, and ran xelatex on the file. It runs much much faster. – Hammerite Jun 23 '15 at 22:20
  • So why can't you use fontspec? I suspect the problem is that it is spending time trying to figure out which fonts correspond to the other shapes it needs to set things up 'normally'. Because you've fibbed and said that the small-caps i actually the main upright font when it isn't, it takes a long time as there is no solution. Whereas the package sets things up 'normally' and it has all the information it needs. But I'm not sure about this. I don't know much about fontspec. – cfr Jun 23 '15 at 22:22
  • I don't understand your question. I am using fontspec. – Hammerite Jun 23 '15 at 22:25
  • So why can't you set up whatever additional font families you want? – cfr Jun 23 '15 at 22:27
  • I can use all of the facilities of fontspec. The issue is not the availability of features, but rather how slow the compile times are. I didn't see your edit to your comment until just now, let me go away and see whether I can get anywhere investigating your theory that it's down to me misleading fontspec as to the nature of the font. – Hammerite Jun 23 '15 at 22:30
  • The only reason I suggested that is because if you are using Alegreya with XeLaTeX then, by default, it is using fontspec to configure the font. So the question is what is different? – cfr Jun 23 '15 at 23:02
  • I don't know why the package redefines \scshape and it does it for the type1 fonts, too - not just the opentype. Odd. – cfr Jun 23 '15 at 23:06
  • Something like this would better reflect the structure of the font family: \setmainfont{Alegreya}[SmallCapsFont={* SC},ItalicFeatures={SmallCapsFont={Alegreya SC Italic}}]. It compiles quickly on my Debian laptop. But I’ve found Alegreya to be odd and difficult to work with in other respects (e.g., https://tex.stackexchange.com/q/162362/7883). – Thérèse Jun 24 '15 at 00:47
  • If your desire to use Alegreya is strong, you may wish to investigate the commercial version; it may be that some of the bugs in the free font have been worked out of the professional font. – Thérèse Jun 24 '15 at 01:19
  • Is the problem actually specific to Alegreya? Because we are all suggesting things which are to do with specifically getting that font to work well since that's what you asked about. But some of your comments suggest that this is not precisely about Alegreya at all - that this is a problem whenever you use system-installed fonts. [I do wish my desktop would stop crashing. Quite disconcerting.] Compiling with XeTeX/LuaTeX is always slow for me, but it always has been whereas it sounds as if that's not so in your case? – cfr Jun 24 '15 at 01:34

1 Answers1

7

The first thing to diagnose for "XeTeX running slowly" problems is to compile the document with xelatex -no-pdf, and then run xdvipdfmx manually on the resulting .xdv file. Timing each one separately will indicate whether it's XeTeX running slowly or xdvipdfmx.

The next step is to figure out if it's XeTeX or fontspec at fault. I would be surprised if it were fontspec that were causing this slowdown. (Not because I have high regard for fontspec's efficiency, but rather that others haven't reported such terrible performance.) Try compiling the following example instead:

\documentclass{article}
\message{Hello}
\font\x="AlegreyaSC-Regular" at 10pt
\message{How are you?}
\begin{document}
{\x Test}
\end{document}

My hypothesis is that this is also slow for you. (If not, maybe it is my fault after all.)

This method for loading the font (by "font name") is presumably using the Windows equivalent of fc-cache, which I know very little about. It's possible that you have many many fonts installed in your system, and this is slowing things down. Or that there's something misconfigured that's forcing some sort of database rebuild every time XeTeX queries for a font.

You might be able to get around this problem by loading the font by filename instead:

\setmainfont[Path=...]{AlegreyaSC-Regular.otf}

This will require you to select the bold/italic shapes manually; e.g., something like:

\setmainfont[Path=...,Extension=.otf,
   UprightFont=*-Regular,
   ItalicFont=*-Italic,...]{AlegreyaSC}
  • 1
    Just to say: if it were fontspec per se, using the Alegreya package wouldn't help, would it? Since that uses fontspec when XeLaTeX is used for compilation? – cfr Jun 24 '15 at 01:24
  • Oh, I didn't check that. It would definitely load the font by file name, so that lends more weight to the issue being font cache related. – Will Robertson Jun 24 '15 at 02:18
  • Loading the font by filename does work. I do not need to set the path, presumably because the fonts directory is one of the places a font is looked for automatically. – Hammerite Jun 25 '15 at 20:29