25

I am a big lover of the EB-Garamond fonts by Georg Duffner. As of now, he has made two sets of font files, EB-Garamond-8 and EB-Garamond-12, respectively for “design size 8pt” and “design size 12pt”. Is there a way to make fontspec (and possibly unicode-math, too) use EB-Garamond-8 fonts for small sizes e.g. sub/superscripts, footnotes… and EB-Garamond-12 fonts for regular sizes when using local font files¹?

If I use only EBGaramond12, the following code works if I put the EBGaramond12-* .otf files in a fonts/ directory sibling to the .tex²

\setmainfont[
    Path=fonts/,
    Extension=.otf,
    UprightFont=*-Regular,
    ItalicFont=*-Italic,
    BoldFont=*-Bold,
    RawFeature={+clig,+dlig,+cv11},]{EBGaramond12}

but if I try to adapt it to use the SizeFeatures options

\setmainfont[
    Path=fonts/,
    Extension=.otf,
    UprightFont=*-Regular,
    ItalicFont=*-Italic,
    BoldFont=*-Bold,
    RawFeature={+clig,+dlig,+cv11},
    SizeFeatures={
        {Size={-12}, UprightFont=EBGaramond8-Regular, ItalicFont=EBGaramond8-Italic},
        {Size={12-}, UprightFont=EBGaramond12-Regular, ItalicFont=EBGaramond12-Italic, BoldFont=EBGaramond12-Bold}
    }]{EBGaramond12}

Then the document won't compile and I get the following error. Using complete names instead of wildcarded ones changes nothing.

The key 'fontspec/UprightFont' is unknown and is being ignored.

¹ It means that using features that automagically select the right system fonts is not an option.

² the file structure is

.
├── fonts
│   ├── EBGaramond08-Italic.otf
│   ├── EBGaramond08-Regular.otf
│   ├── EBGaramond12-Bold.otf
│   ├── EBGaramond12-Italic.otf
│   └── EBGaramond12-Regular.otf
└── paper.tex
9
  • yes, look into the documentation.
    – user2478
    Commented May 14, 2013 at 13:09
  • @Herbert Actually using local font files instead of system fonts seems to break the SizeFeatures option. Or vice-versa.
    – Evpok
    Commented May 14, 2013 at 14:30
  • There is no need to put the font files into the TeX directory. However, if you are using XeTeX then there will be a problem if you have fonts installed twice, system dir and local tex dir.
    – user2478
    Commented May 15, 2013 at 6:45
  • @Herbert I know, but I need to be able to distribute the project to people who might not have EBGaramond installed or not the same version So I need to use a local fonts/ directory
    – Evpok
    Commented May 15, 2013 at 6:59
  • 2
    From memory this is a (major) oversight in fontspec which I've been meaning to fix for a long time now… I hope that I can free up some cycles soon to look at it! Commented Jul 31, 2013 at 7:45

3 Answers 3

11

Since version 2.4 of fontspec, it has been possible to use different local fonts for different optical sizes, cf. the README.

The trick is to specify the different fonts with a Font option embedded under SizeFeatures, which in turn (and this is the crucial part) must be embedded under the options UprightFeatures, ItalicFeatures, and so on, cf. the fontspec manual under section 6.6.

Here's a minimal example:

\documentclass{article}
\usepackage{fontspec}
    \setmainfont{EBGaramond}[
        Path = ./fonts/,
        Extension = .otf,
        UprightFont = *12-Regular, % set EB Garamond 12 as default upright font
        UprightFeatures = {
            SizeFeatures = {
                {Size = -10.1,
                    Font = *08-Regular}, % use EB Garamond 08 for 10pt size and smaller
                {Size = 10.1-}}}, % use default upright font for larger than 10pt size
        ItalicFont = *12-Italic, % set EB Garamond 12 as default italic font
        ItalicFeatures = {
            SizeFeatures = {
                {Size = -10.1,
                    Font = *08-Italic}, % use EB Garamond 08 for 10pt size and smaller
                {Size = 10.1-}}}, % use default italic font for larger than 10pt size
        SmallCapsFeatures = {Letters = SmallCaps},
        Ligatures = {Common, TeX},
        Numbers = {Proportional, OldStyle}]
\begin{document}

EB Garamond 08: The quick brown fox jumps over the lazy dog 1234567890

\textit{EB Garamond 08: The quick brown fox jumps over the lazy dog 1234567890}

\large
EB Garamond 12: The quick brown fox jumps over the lazy dog 1234567890

\textit{EB Garamond 12: The quick brown fox jumps over the lazy dog 1234567890}

\end{document}

enter image description here

4
  • 2
    Please see this answer for how to use \large and variants correctly. Use {\large ...} instead of \large{...}, as they don't take any arguments; they are switches.
    – sodd
    Commented Sep 13, 2015 at 10:06
  • +1. You can make the example clearer by removing SmallCapsFeatures = {Letters = SmallCaps} (unnecessary with EB Garamond), Ligatures = {Common, TeX} (on by default), and Numbers = {Proportional, OldStyle} (defaults in EB Garamond).
    – Thérèse
    Commented Sep 13, 2015 at 17:54
  • @Thérèse I included them on purpose to demonstrate that features that apply globally to all the EB Garamond fonts don't need to be specified individually under options like UprightFeatures (the manual leads you to believe they do). I can edit my answer and make this explicit.
    – Sverre
    Commented Sep 13, 2015 at 18:15
  • 1
    For purposes of demonstration, a feature that’s not on by default would be better.
    – Thérèse
    Commented Sep 13, 2015 at 18:27
10
+25

If you download the fonts from Georg Duffner’s site, the archive includes a file called README.xelualatex. It tells you to load the font with \setmainfont{EB Garamond} (not your \setmainfont{EBGaramond12}), and explains that the sizes will take care of themselves. It also explains how to turn off optical sizes if you like: \setmainfont[OpticalSize=0]{EB Garamond 12 Regular}.

3
  • 4
    In my case (and in @Evpoks, as evidenced by the comment), I have to include the fonts in the distributed content in case the end-user doesn't have them. This means I have to reference them by filename, so this is not an option.
    – You
    Commented Jul 27, 2013 at 10:08
  • I was just going to suggest using \directlua{fonts.names.scan(".")}, but that’s a neat trick which seems not to work any longer since TeX Live 2013. We need a lua expert to tell us how it goes now.
    – Thérèse
    Commented Jul 27, 2013 at 19:18
  • The question is clearer now with the footnotes, and I see that my answer doesn’t address your situation. However, I’ll leave the answer here anyway, because anyone who downloads EB Garamond from CTAN and not straight from Georg Duffner’s site is likely to be unaware of his explanations (the CTAN package being directed toward users of pdftex).
    – Thérèse
    Commented Jul 31, 2013 at 4:39
-1

I still use the NFSS instead of fontspec. And NFSS has something for font sizes. I never used this feature, therefore can't suggest the exact syntax.

Below is my private NFSS-setup for Univers as an example. It uses the private encoding EUT1, you should change it to probably EU1.

\DeclareFontFamily{EUT1}{univers}{}
\DeclareFontShape{EUT1}{univers}{m}{n}{ <-> "[UniversCom-55Roman.ttf]"}{}
\DeclareFontShape{EUT1}{univers}{m}{it}{ <-> "[UniversCom-55Oblique.ttf]"}{}
\DeclareFontShape{EUT1}{univers}{bx}{n}{ <-> "[UniversCom-65Bold.ttf]"}{}
\DeclareFontShape{EUT1}{univers}{bx}{it}{ <-> "[UniversCom-65Bold.ttf]:slant=0.2"}{}
\DeclareFontShape{EUT1}{univers}{bl}{n}{ <-> "[UniversCom-75Black.ttf]"}{}
\DeclareErrorFont{EUT1}{univers}{m}{n}{10}
\DeclareFontSubstitution{EUT1}{univers}{m}{n}
1
  • 6
    I don't think this answers the question at all.
    – You
    Commented Jul 26, 2013 at 21:02

You must log in to answer this question.

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