1

For fonts in math mode, I am using package stix2 like

\usepackage[notext]{stix2}

As expected, this changes the default (sans-serif) font for \mathsf. But I would like to use \mathsf with the font from the sans-serif Computer Modern typeface that LaTeX uses by default (that is, the font for \mathsf if there were no \usepackage[notext]{stix2} at all), while keeping with the rest of stix2 fonts in math mode. How can I do this?

I've been looking here through previous questions on TeX Stack Exchange and I have found nothing related.

1
  • 1
    Are you willing and able to use LuaLaTeX? Then, running \usepackage{unicode-math} \setmathfont{Stix Two Math} will change the serif math font but not the sans-serif math font face.
    – Mico
    Jun 17, 2021 at 17:56

2 Answers 2

4

The \mathsf alphabet from sansmathfonts is the cmssm family, using NFSS. It’s in the OML encoding, which supports both Latin and Greek. You can select it through the isomath package:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[notext]{stix2}
\usepackage[OMLmathsfit,sfdefault=cmssm]{isomath}

\begin{document}
\[ \mathsfit{y} = \mathsfit{\alpha x} + \mathsfit{\beta} \]
\end{document}

sansmathfonts + stix2 sample

If you want to use both an upright \mathsf and an italic \mathsfit in the same document, you can define them with \DeclareMathAlphabet. In that case, you would want the OT1 or T1 version of the xcmss family as your upright font. There is no upright font in sansmathfonts with lowercase Greek letters.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[notext]{stix2}

\DeclareMathAlphabet{\mathsf}{OT1}{xcmss}{m}{n}
\SetMathAlphabet{\mathsf}{bold}{OT1}{xcmss}{b}{n}
\DeclareMathAlphabet{\mathsfit}{OML}{cmssm}{m}{it}
\SetMathAlphabet{\mathsfit}{bold}{OML}{cmssm}{b}{it}

\begin{document}
\[ \mathsfit{y} = \mathsfit{\alpha x} + \mathsfit{\beta} + \mathsf{\Phi x_0} \]
\end{document}

sansmathfonts + stix2 sample

In LuaLaTeX or XeLaTeX, you can load OpenType fonts through unicode-math. Unicode does not support sans-serif Greek. For example:

\documentclass{article}
\usepackage{unicode-math}

\defaultfontfeatures{ Scale=MatchLowercase }
\setmathfont{STIX Two Math}
\setmathfont{NewCMSans10-Book}[
  range=sfup,
  script-font={NewCMSans08-Book},
  script-features={}, % Suppress a harmless warning.
  sscript-font={NewCMSans08-Book},
  sscript-features={},
  Extension=.otf]
\setmathfont{NewCMSans10-BookOblique}[
  range=sfit,
  script-font={NewCMSans08-BookOblique},
  script-features={},
  sscript-font={NewCMSans08-BookOblique},
  sscript-features={},
  Extension=.otf]

\begin{document}
\[ \symsfit{y} = \symsfit{\alpha x} + \symsfit{\beta} + \symsfup{\Phi x_0} \]
\end{document}

New Computer Modern Sans/STIX Two Math sample

Or perhaps:

\documentclass{article}
\usepackage{unicode-math}

\defaultfontfeatures{ Scale=MatchLowercase }
\setmathfont{STIX Two Math}
\setmathfont{NewCMMath-Book}[
  range={sfup,sfit,bfsfup,bfsfit}]

\begin{document}
\[ \symsfit{y} = \symsfit{\alpha x} + \symsfit{\beta} + \symsfup{\Phi x_0} \]
\end{document}

New Computer Modern Math/STIX Two Math sample

It is possible to define a sans-serif Greek alphabet in unicode-math with \setmathsf or \setmathfontface, for example:

\documentclass{article}
\usepackage{unicode-math}

\defaultfontfeatures{ Scale=MatchLowercase }
\setmathfont{STIX Two Math}
\setmathfont{NewCMMath-Book}[
  range={sfup,sfit,bfsfup,bfsfit}]

\setmathfontface\varsfup{NewCMSans10-Regular.otf} % Can define SizeFeatures for subscripts.
\setmathfontface\varsfit{NewCMSans10-Oblique.otf}

\begin{document}
\[ \symsfit{y} = \varsfit{\mupalpha} \symsfit{x} + \varsfit{\mupbeta} + \varsfup{\mupPhi} \symsfup{x_0} \]
\end{document}

NewCMMath + NewCMSans + STIX Two Math sample

If you use \mathsf extensively in your document, you might want to load unicode-math with the [sf=sym] package option, for backward compatibility. This means that, if you ever have code like \mathsf{cosine} in your document, you should change it to \textsf, or change your operator font with \setoperatorfont.

2

I'd never use the notext option to stix2: you get a very strange mix of fonts.

Anyway, here's how you can solve your problem.

\documentclass{article}
\usepackage{fix-cm}
\usepackage{amsmath}
\usepackage[notext]{stix2}

\DeclareMathAlphabet{\mathsf}{OT1}{cmss}{m}{n}

\begin{document}

This is text and we have math
$a+b=\mathsf{C}$ {\fontfamily{cmss}\selectfont C}

\end{document}

enter image description here

Just as a check, here's the output if I comment out the loading of stix2.

enter image description here

You must log in to answer this question.

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