fix: support both variable and static Source Sans fonts

The current font configuration expects separate static font files for
each weight (e.g. "Source Sans 3 Light", "Source Sans 3 Bold"), which
are not found when only variable fonts are installed. Modern package
managers (Homebrew, Google Fonts) ship Source Sans 3 exclusively as
variable fonts, causing build failures on macOS and other platforms.

Use fontspec RawFeature axis syntax to select weights from variable
fonts, and fall back to "Source Sans Pro" (bundled with TeX Live) when
"Source Sans 3" is not installed at all. This supports:
- Variable fonts from Homebrew/Google Fonts
- Static "Source Sans 3" from Adobe or Linux distro packages
- Static "Source Sans Pro" from TeX Live (Overleaf, Docker, etc.)

Fixes #606, fixes #610

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Renaud Guérin 2026-03-20 01:46:25 +00:00
parent 36075ed034
commit a47a7539aa

View file

@ -81,22 +81,41 @@
\defaultfontfeatures{
Renderer=HarfBuzz,
}
\setmainfont{Source Sans 3}[
UprightFont=*,
ItalicFont=* Italic,
BoldFont=* Bold,
BoldItalicFont=* Bold Italic,
FontFace={l}{n}{Font=* Light},
FontFace={l}{it}{Font=* Light Italic},
]
\setsansfont{Source Sans 3}[
UprightFont=*,
ItalicFont=* Italic,
BoldFont=* Bold,
BoldItalicFont=* Bold Italic,
FontFace={l}{n}{Font=* Light},
FontFace={l}{it}{Font=* Light Italic},
]
% Support both "Source Sans 3" (variable or static, from Adobe/Homebrew/distro
% packages) and "Source Sans Pro" (static, bundled with TeX Live).
\IfFontExistsTF{Source Sans 3}{%
\setmainfont{Source Sans 3}[
RawFeature={+axis={wght=400}},
BoldFont={Source Sans 3},
BoldFeatures={RawFeature={+axis={wght=700}}},
ItalicFont={Source Sans 3 Italic},
ItalicFeatures={RawFeature={+axis={wght=400}}},
BoldItalicFont={Source Sans 3 Italic},
BoldItalicFeatures={RawFeature={+axis={wght=700}}},
FontFace={l}{n}{Font=Source Sans 3, RawFeature={+axis={wght=300}}},
FontFace={l}{it}{Font=Source Sans 3 Italic, RawFeature={+axis={wght=300}}},
]
\setsansfont{Source Sans 3}[
RawFeature={+axis={wght=400}},
BoldFont={Source Sans 3},
BoldFeatures={RawFeature={+axis={wght=700}}},
ItalicFont={Source Sans 3 Italic},
ItalicFeatures={RawFeature={+axis={wght=400}}},
BoldItalicFont={Source Sans 3 Italic},
BoldItalicFeatures={RawFeature={+axis={wght=700}}},
FontFace={l}{n}{Font=Source Sans 3, RawFeature={+axis={wght=300}}},
FontFace={l}{it}{Font=Source Sans 3 Italic, RawFeature={+axis={wght=300}}},
]
}{%
\setmainfont{Source Sans Pro}[
FontFace={l}{n}{Font=*-Light},
FontFace={l}{it}{Font=*-LightItalic},
]
\setsansfont{Source Sans Pro}[
FontFace={l}{n}{Font=*-Light},
FontFace={l}{it}{Font=*-LightItalic},
]
}
\newfontfamily\roboto{Roboto}[
UprightFont=*,
ItalicFont=* Italic,