7

Consider the following file:

\documentclass{article}

\usepackage{fontspec}

\setmainfont[Numbers={Lining,Proportional},Ligatures=Common]{EB Garamond}
\newfontface\garamondoldstylenumbers[Numbers={OldStyle,Proportional},Ligatures=Common]{EB Garamond}

\begin{document}

EB Garamond 123

\typeout{1st use of \addfontfeatures}
{\addfontfeatures{Numbers={OldStyle,Proportional}}EB Garamond 123\par}
\typeout{2nd use of \addfontfeatures}
{\addfontfeatures{Numbers={OldStyle,Proportional}}EB Garamond 123\par}

\typeout{1st use of \garamondoldstylenumbers}
{\garamondoldstylenumbers EB Garamond 123\par}
\typeout{2nd use of \garamondoldstylenumbers}
{\garamondoldstylenumbers EB Garamond 123\par}

\end{document}

If this is compiled under either XeLaTeX or LuaLaTeX, examining the log file shows messages along the lines of

.................................................
. Font family 'EBGaramond(2)' created for font 'EB Garamond' with options
. [Numbers={Lining,Proportional},Ligatures=Common,Numbers={OldStyle,Proportional}].
. 
. This font family consists of the following shapes:
. 

etc. after both uses of \addfontfeatures, but not after using \garamondoldstylenumbers. (Naturally, similar messages occurs in when \setmainfont and \newfontface are processed in the preamble.)

There will be some performance hit from parsing the options to \addfontfeatures. But is there a performance hit beyond this, because fontspec seems to be defining the font anew each time?

The only relevant thing I can find in the fontspec manual says "For cases when a specific font with a specific feature set is going to be re-used many times in a document, it is inefficient to keep calling \fontspec for every use. While the \fontspec command does not define a new font instance after the first call, the feature options must still be parsed and processed." I would assume that \addfontfeatures uses the \fontspec command, but I don't know the details of the implementation.

(I will be typesetting a long document that will require frequent use of both the italic and swashed italic of a commercial font: I have used old style numbers and EB Garamond in the example because it is freely available. Naturally, I would normally define a macro for \addfontfeatures{...}.)

7

My development version of fontspec might be out of sync with the current TeX Live version on this matter — I know I recently fixed an issue that involved \addfontfeatures incorrectly creating new font families.

In my development version, the 2nd use of \addfontfeatures line in the log file doesn't lead into the ‘Font Family (…) created’ message. However, I did notice when browsing the code that there could be some significant improvements in how early the pre-existence of a font family is checked.

The short answer is: if fontspec is behaving correctly then \addfontfeatures should be somewhat but not ‘much’ less efficient than \newfontface. But external benchmarking is recommended :)

  • Thank you for the authoritative answer. I just updated TeX Live, and the fix you mentioned is now in effect and I am no longer seeing the extra "Font Family ... created" messages. Thank you for the reassurance in the last paragraph. – Senex Aug 23 '14 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.