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)
13
  • Have you tried \usepackage{Alegreya}? Note that the font is included in TeX Live and, I assume, in MikTeX.
    – cfr
    Commented Jun 23, 2015 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
    Commented Jun 23, 2015 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
    Commented Jun 23, 2015 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
    Commented Jun 23, 2015 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
    Commented Jun 23, 2015 at 22:22

1 Answer 1

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}
3
  • 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
    Commented Jun 24, 2015 at 1: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. Commented Jun 24, 2015 at 2: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
    Commented Jun 25, 2015 at 20:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .