Why is the font not always Fira Sans using XeLaTeX

fontsxetex

I'd like to use Fira Sans as the main font because it has awesome math support, but I'd like to use other fonts as well, which is why I'd like to use XeLaTeX with the fontspec package. However, it appears to change the font here and there and I don't know why.

Here's a MWE:

\documentclass[]{article}

\usepackage[T1]{fontenc}
\usepackage[sfdefault]{FiraSans}
\usepackage{newtxsf}

\begin{document}

Writing numbers 12345 in line and in $12345$ math mode using the font Fira Sans.\\

Some math:
\begin{align*}
\lim_{n \to \infty} \sum_{k=0}^4 a_0 q^k
\end{align*}

\end{document}

Using LaTeX:
enter image description here

Using XeLaTeX:
enter image description here

Best Answer

On XeTeX, the Firasans package loads fontspec, which sets up the \mathrm font in a way that breaks with sfdefault. This is a bug in the FiraSans package.

One solution is to use modern OpenType fonts with fontsetup (which loads Fira Math in unicode-math):

\documentclass[]{article}

\usepackage[fira]{fontsetup}

\begin{document}

Writing numbers 12345 in line and in $12345$ math mode using the font Fira Sans.\\

Some math:
\begin{align*}
\lim_{n \to \infty} \sum_{k=0}^4 a_0 q^k
\end{align*}

\end{document}

Fira Math sample

I recommend you use OpenType fonts when you can, and legacy 8-bit packages when you have to.

If you want to use your legacy math font with Fira Sans, you can turn off the redefinition of \mathrm, which is used as the operator font for \lim, in fontspec before you load FiraSans:

\documentclass[]{article}

\PassOptionsToPackage{no-math}{fontspec}
\usepackage[sfdefault]{FiraSans}
\usepackage{newtxsf}

\begin{document}

Writing numbers 12345 in line and in $12345$ math mode using the font Fira Sans.\\

Some math:
\begin{align*}
\lim_{n \to \infty} \sum_{k=0}^4 a_0 q^k
\end{align*}

\end{document}

Fira Sans + newtxsf sample

You could also fix \mathrm afterwards with \setmathrm, as \usepackage[sfdefault]{FiraSans] should have done.

\documentclass[]{article}

\usepackage[sfdefault]{FiraSans}
\setmathrm{Fira Sans}
\usepackage{newtxsf}

\begin{document}

Writing numbers 12345 in line and in $12345$ math mode using the font Fira Sans.\\

Some math:
\begin{align*}
\lim_{n \to \infty} \sum_{k=0}^4 a_0 q^k
\end{align*}

\end{document}

Fira Sans + newtxsf sample