Fontspec and EB Garamond: Cannot use EBGaramond12-Italic

ebgaramondfontspecluatexoptical-size

I dowloaded EB Garamond from https://github.com/georgd/EB-Garamond/releases/tag/nightly and copied all fonts, .otf and .ttf to ~/.fonts/e

The typeface contains different font files for the optical sizes 08pt and 12pt:

enter image description here

However, if I create a document which should contain EBGaramond12-Italic and compile it with LuaLaTeX, my PDF reader only shows the following fonts:

enter image description here

%!TEX program = lualatex
\documentclass{article}
\usepackage{fontspec}
% https://tex.stackexchange.com/a/79783/38905
\setmainfont[%
SizeFeatures={%
    {Size={-12},
        Font=*08-Regular,
        ItalicFont=*08-Italic},
    {Size={12-},
        Font=*12-Regular,
        ItalicFont=*12-Italic}
},
]{EB Garamond}

\begin{document}
    \normalsize
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    
    \huge
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    
    \normalsize
    \textit{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
    
    \huge
    \textit{ABCDEFGHIJKLMNOPQRSTUVWXYZ} 
\end{document}

This is how the PDF looks:

enter image description here

This was compiled with

This is LuaHBTeX, Version 1.15.0 (TeX Live 2022/TeX Live for SUSE Linux)
Development id: 7509

Why doesn't this work as expected and how can I work around this issue?

Best Answer

The fontspec manual says about using SizeFeatures with ItalicFeatures:

Interaction with other features For SizeFeatures to work with ItalicFeatures, BoldFeatures, etc., and SmallCapsFeatures, a strict heirarchy(sic) is required:

UprightFeatures =
  {
    SizeFeatures =
      {
        {
          Size = -10,
          Font = ..., % if necessary
          SmallCapsFeatures = {...},
          ... % other features for this size range
        },
        ... % other size ranges
      }
  }

While not explicitly mentioned, the same principle applies to ItalicFont: The font shape (like italic or upright) is applied first, before size processing, so you need to follow specific orders when combining them.

Here you can do this by moving the italic fonts into the SizeFeatures of the ItalicFeatures:

%!TEX program = lualatex
\documentclass{article}
\usepackage{fontspec}
\setmainfont[%
  SizeFeatures={%
    {Size={-12}, Font=*08-Regular},
    {Size={12-}, Font=*12-Regular},
  },
  ItalicFeatures={%
    SizeFeatures={%
      {Size={-12}, Font=*08-Italic},
      {Size={12-}, Font=*12-Italic},
    },
  },
]{EB Garamond}

\begin{document}
    \normalsize
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    
    \huge
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    
    \normalsize
    \textit{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
    
    \huge
    \textit{ABCDEFGHIJKLMNOPQRSTUVWXYZ} 
\end{document}

enter image description here

Related Question