Now, this is the exact same question as Is there a way to use different local font files for different font size in fontspec?, but is is left without a solution. @WillRobertson answered in a comment more than two years ago that he would fix this in fontspec, and I assume he has, since this is now addressed in sections 6.6 and 7.6 of the manual. But I still don't understand what I need to do in order to use the different fonts some font families provide for different optical sizes.
EDIT: See this answer to the original question for a solution.
Below is a MWE using EB Garamond. I've tried a dozen or so variants of this, but they all result in errors, the most common of which (as below), is that it can't find a font called EBGaramond.otf.
In this example, I've placed the EB Garamond fonts in a subdirectory called /fonts/.
\documentclass{article}
\usepackage{fontspec}
\setmainfont{EBGaramond}[
Path = ./fonts/,
Extension = .otf,
SizeFeatures =
{
{Size = {10.1-},
UprightFont = *12-Regular,
ItalicFont = *12-Italic},
{Size = {-10.1},
UprightFont = *08-Regular,
ItalicFont = *08-Italic}
},
SmallCapsFeatures = {Letters = SmallCaps},
Ligatures = {Common, TeX},
Numbers = {Proportional, OldStyle}]
\begin{document}
Hello world
\end{document}
Error message:
luaotfload | db : Reload initiated (formats: otf,ttf,ttc,dfont); reason: "File not found: ./fonts/EBGaramond.otf.".
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! fontspec error: "font-not-found"
!
! The font "EBGaramond" cannot be found.
fontspec readmesays forv.2.4that "SizeFeaturescan now be nested insideItalicFeatures(etc.) and behaves correctly. This has been a very long overdue bug!" – Sverre Sep 12 '15 at 17:37SizeFeaturesdidn't work for local files. – Sverre Sep 12 '15 at 17:39