XeTeX + STIX2 Errors: 'Too many symbol fonts declared.'; 'Symbol font Digits:m:n is not defined.'

I've recently been experimenting with typesetting and I stumbled upon an issue, where the following preamble:

\documentclass[12pt,a4paper]{memoir}

\usepackage{stix2}
\usepackage{mathspec}
\defaultfontfeatures{Mapping=tex-text}
\usepackage{fontspec}

\setmainfont[
Extension={.otf},
UprightFont={*-Regular},
BoldFont={*-Bold},
ItalicFont={*-Italic},
BoldItalicFont={*-BoldItalic}
]{StixTwoText}

\setmathfont(Latin,Greek){StixTwoText-Italic.otf}
\setmathfont(Digits){StixTwoText-Regular.otf}
\setmathrm[BoldFont={StixTwoText-Bold.otf}]{StixTwoText-Regular.otf}


Generates errors written in the title. Removing both the \setmathfont and \setmathrm OR \usepackage{stix2} commands fixes the issue, but changes the math fonts.

Can I somehow use the STIX Two Text Italic font in math mode while still having the alternate math symbols defined in stix2?

• Do you need mathspec at all? I believe that unicode-math is better with the fonts you want. Jul 19 at 17:02
• @egreg Perhaps that would be a good idea. I've never used unicode-math. How would I go about implementing the above code with it? Jul 19 at 17:07

You should use unicode-math for this, which supports STIX2 Math.

\documentclass[12pt,a4paper]{memoir}

\usepackage{fontspec}
\usepackage[math-style=ISO]{unicode-math}

\setmainfont[
Extension=.otf,
UprightFont=*-Regular,
BoldFont=*-Bold,
ItalicFont=*-Italic,
BoldItalicFont=*-BoldItalic,
]{STIXTwoText}

\setmathfont[
Extension=.otf,
]{STIXTwoMath-Regular}

\begin{document}

$\alpha+x+\Gamma+\symrm{A}+\symbf{B}+123$

\end{document}


If you remove the math-style=ISO option, you get

Note that STIX should be spelled all capitals; on case-insensitive file systems Stix might find the font, but the document wouldn't be portable.

• Thanks, that seems to work. One more question: is it possible to change the other math fonts in this setup? For example, with mathspec I was able to change the mathfrak font style with \setmathfrak. Can I do something similar in unicode-math? Jul 19 at 18:49
• Ok, I seem to have found an answer to that question here: tex.stackexchange.com/questions/437834/… Thanks again for your help. Jul 19 at 19:28