0

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}

1 Answer 1

3

You don’t say what isn’t working, but [range={"0000-"FFFF} is wrong. This will overwrite the entire Basic Multilingual Plane with a font that has no OpenType math table.

You almost certainly want to use \setmathfont{My Font italic}[range=it] for italic math variables, or [range=up] for upright, bfup for bold upright, and bfit for bold italic. (To use an upright font by default in math mode, load unicode-math with the [math-style=upright] option.)

You might need to add the font options for the Italic face, such as optical sizes. Either add them as options along with range, or use \defaultfontfeatures{My Font Italic}.

Update

Based on your comment, you want something like (untested)

\setmathfont{SourceSerif4-It}[
  range=it,
  SizeFeatures={
    {Size={-9.5}, Font=SourceSerif4SmText-It},
    {Size={9.5-}, Font=SourceSerif4-It}
  },
  Extension=.otf]

The other options are irrelevant to math mode. The default font for math variables is \symit, not upright. If you also want to use \symup or \usepackage[math-style=upright]{unicode-math}, you would declare a corresponding command for range=up. If you are using bold for vectors, you might want to set a command for range=bfit or range=bfup as well.

5
  • What doesn't work is specifying myfont in the \setmathfont command. If I use SourceSerif4-Regular instead, it works. But then I would lose the automatic font selection based on point size (optical sizes in SourceSerif4 are in separate .otf files).
    – dedded
    Jan 18, 2022 at 3:46
  • OK, thanks. This works, with a modification. I first set the font to SourceSerif4-Regular, etc., using the range range={"0000-"FFFF}. I don't know how else to get the symbols. Then I set the math font to SourceSerif4-It, etc., for range=it.
    – dedded
    Jan 18, 2022 at 22:20
  • @dedded I have no idea which symbols you want, but range={"0000-"FFFF} is certainly an error.
    – Davislor
    Jan 18, 2022 at 23:07
  • Mostly the prime tick mark and =, +, -
    – dedded
    Jan 18, 2022 at 23:30
  • @dedded Use their ASCII values with a double quote, {"2B,"2D,"3D,"60}, or "00-"FF to overwrite only Basic Latin. Prime should be \prime.
    – Davislor
    Jan 18, 2022 at 23:47

You must log in to answer this question.

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