I'm trying to use a few math symbols from my main font as described here: How to set a font everywhere (including math mode) in XeLaTeX? (I'm using lualatex.)
(I don't have to use that method, if there's a better one.)
However, my main font is set up in a complicated way, largely to accommodate regular, italic, bold, etc. fonts that are in different files. There are also different files for different optical sizes. SourceSerif4 comes in 60 .otf files!
Below I've a MWE that just uses 4 of those 60: regular and italic in two optical sizes.
I define "myfont" with \defaultfontfeatures
, and then set that as the main font with \setmainfont{myfont}
, and all works well.
But I cannot do the same with \setmathfont{myfont}
. I get the error:
! Package fontspec Error: The font "myfont" cannot be found.
All this works if I use \setmathfont{SourceSerif4-Regular}
instead of myfont
. But then I would lose the optical size selection.
Sorry I don't know how to reproduce this with a font that comes with Texlive (though SourceSerif4 is free here: https://github.com/adobe-fonts/source-serif)
Is there a way I can get the SourceSerif4 font used in math? I'm not really going to do much math, I mostly want the prime symbol, +, -, and =. (And digits and letters)
MWE:
\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}
\defaultfontfeatures[myfont]{
Path = /Users/ded/Library/Fonts/,
Numbers = {Proportional,OldStyle},
UprightFont = SourceSerif4-Regular ,
UprightFeatures={
SizeFeatures={
{Size={-9.5}, Font=SourceSerif4SmText-Regular},
{Size={9.5-}, Font=SourceSerif4-Regular},
},
},
ItalicFont = SourceSerif4-It ,
ItalicFeatures={
SizeFeatures={
{Size={-9.5}, Font=SourceSerif4SmText-It,
SmallCapsFont=SourceSerif4SmText-Regular},
{Size={9.5-}, Font=SourceSerif4-It,
SmallCapsFont=SourceSerif4-Regular},
},
SmallCapsFeatures={Letters=SmallCaps, FakeSlant=0.2},
},
Ligatures = TeX ,
Extension = .otf
}
\setmainfont{myfont}
\setmathfont[slash-delimiter=frac]{latinmodern-math.otf}
\setmathfont[range={"0000-"FFFF}]{myfont} % error is here
\begin{document}
The quick brown fox jumps over the lazy dog.
$2 + 2 = 4$
\end{document}