# Font package in lualatex gives the cm style figure

I want to use the FiraSans font as main text font and the newtx as the math font in my pgfplots figure. Because the data file contains much points I use the lualatex as the compiler for it can dynamically adjust the memory, here is the mwe

\RequirePackage{luatex85}
\documentclass[tikz,12pt]{standalone}
\usepackage{pgfplots}
\usepackage[sfdefault,scaled=.85]{FiraSans}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amsthm}
\usepackage[cmintegrals]{newtxsf}
\begin{document}

test
$a^2+b^2=c^2$
\end{document}


But the font package seems not work well. The text and the figures is still in the cm style. If I use pdflatex all is right. Two warning informations appear when I use lualatex

LaTeX Font Warning: Font shape T1/FiraSans(0)/m/n' undefined(Font)
LaTeX Font Warning: Some font shapes were not available, defaults substituted.


How can I use the font package with the lualatex?

You should load newtxsf before FiraSans and pass no-math to fontspec.

\RequirePackage{luatex85}
\documentclass[tikz,12pt]{standalone}
\usepackage{amsmath,amsthm}

\usepackage[cmintegrals]{newtxsf}
\PassOptionsToPackage{no-math}{fontspec}
\usepackage[sfdefault,scaled=.85]{FiraSans}

\usepackage{pgfplots}

\begin{document}

test $a^2+b^2=c^2$

\end{document}


You don't need \PassOptionsToPackage{no-math}{fontspec} if you add the option as a global one:

\documentclass[tikz,12pt,no-math]{standalone}

• your solution solves the problems, thanks :-) Dec 24, 2016 at 14:43

This answer solves the problem with the font warnings and the text uses font FiraSans instead of Computer Modern. However, it does not solve the problem with the wrong font for the figures in math style.

Font encoding T1 is intended for fonts with at most 256 slots, therefore package fontspec uses a different font encoding. Package FiraSans uses fontspec if it detects a TeX compiler capable of using OpenType fonts (LuaTeX, XeTeX).

As solution, \usepackage[T1]{fontenc} can be wrapped in:

\usepackage{ifluatex, ifxetex}
\newif\ifWithOpenTypeFonts
\ifluatex
\WithOpenTypeFontstrue
\else
\ifxetex
\WithOpenTypeFontstrue
\fi
\fi
\ifWithOpenTypeFonts
% \usepackage{fontspec}
\else
\usepackage[T1]{fontenc}
\fi


Then the document can be compiled with the different TeX compilers.

• thanks for your answer. When I replace the \usepackage[T1]{fontenc} with the code you give, and use the lualatex as the compiler, the error message says that Incomplete \iftrue; all text was ignored after line xx where xx is the location of \else\ifxetex` Dec 24, 2016 at 14:42
• @Ice0cean: There is a \fi missing. Dec 24, 2016 at 14:59