6

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}
\pgfplotsset{compat=newest}
\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. enter image description here 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?

2 Answers 2

6

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}
\pgfplotsset{compat=newest}

\begin{document}

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

\end{document}

enter image description here

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

\documentclass[tikz,12pt,no-math]{standalone}
1
  • your solution solves the problems, thanks :-)
    – Ice0cean
    Dec 24, 2016 at 14:43
4

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.

2
  • 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
    – Ice0cean
    Dec 24, 2016 at 14:42
  • @Ice0cean: There is a \fi missing. Dec 24, 2016 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.