3

I am trying to use the Fira font within the metropolis presentation theme for the text and the mathpazo font for the math mode. How can I do this?

My MWE is as follows:

\documentclass{beamer}
\usetheme{metropolis} % Use metropolis theme 
\usepackage{FiraSans}
\usefonttheme[onlymath]{serif} 
\usepackage{mathpazo}
\usepackage{mathtools}
\begin{document}
 \begin{frame}{First Frame}
 Hello, world! Here some random math:
 \begin{equation*}
 s_{t}=\begin{cases}
 \bar{s}, & t\in \left\lbrace 0,\dots, T-1\right\rbrace  \\
 \tilde{s}, & t\geq T
 \end{cases}
 \end{equation*} 
\end{frame}
\end{document}

This results in:

enter image description here

The math stuff does not have the shape of the usual mathpazo font.

Thanks in advance!

  • 1
    What engine are you using when compiling the document? You should be using PDFLaTeX! – AboAmmar Dec 31 '18 at 15:54
  • 1
    I compiled with XeLaTeX because it was suggested by metropolis. However, it works with pdfLaTeX! Thanks! – Hazards Dec 31 '18 at 16:30
  • The problem is \usefonttheme[onlymath]{serif}. I'm not exactly sure why it's conflicting, but using \usefonttheme{professionalfonts} will give you basically the same output with pdfLaTeX or XeLaTeX. The latter font theme has slightly different spacing, it seems. Former is more condensed and latter more expanded. – whatisit Dec 31 '18 at 17:07
10

In the Modern Toolchain

I personally recommend you use unicode-math when you can, and legacy fonts when you have to. Not everyone agrees, so I present the alternatives.

With the package unicode-math, you can use any OpenType fonts of your choice, including Fira Sans and its successor FiraGO. Asana Math is a Unicode math font based on mathpazo, but with many more symbols. There is, additionally, an experimental Fira Math font for use with unicode-math, but as of 2019, it is a work in progress.

This example additionally sets all letters and numerals in math mode to Fira Sans. You could change this to FiraGO as well, if you wanted. It supports the mathematical Greek OpenType feature.

\documentclass[10pt]{beamer}

\useinnertheme{metropolis}
\useoutertheme{metropolis}
\usecolortheme{metropolis}
\usefonttheme{professionalfonts}
\usepackage{unicode-math}

\defaultfontfeatures{ Scale = MatchUppercase }
\setmainfont{FiraGO}[Scale = 1.0]
\setsansfont{FiraGO}
\setmonofont{Fira Mono}
\setmathfont{Asana Math}
\setmathfont[range=up]{Fira Sans Regular}
\setmathfont[range=it]{Fira Sans Italic}
\setmathfont[range=bfup]{Fira Sans Bold}
\setmathfont[range=bfit]{Fira Sans Bold Italic}

\begin{document}

\begin{frame}{Math}
  \begin{equation*}
    \symup{e} = \lim_{n\to \infty} \left(1 + \frac{1}{n}\right)^n
  \end{equation*}
\end{frame}

\end{document}

Math Sample

Note that you want to enable \usefonttheme{professionalfonts} for certain math features to work (such as the resized parentheses in this example). Therefore, I overrode all the fonts. The metropolis theme also allows you to select the color theme of your choice.

Mixing OpenType with Legacy Math Fonts

If you want to use a legacy NFSS math package, such as mathpazo, or its successor newpxmath, or the sans-serif modification newtxsf, load the math package and use mathastext.

With XeLaTeX, you have the option to load mathspec and \setmathsfont{Fira Sans} or \setmathsfont{FiraGO}.

Or see @samcarter’s excellent answer.

Using only Legacy Fonts

You do not need to do this if you are using metropolis, but for completeness, you can also do this in PDFLaTeX:

\usepackage[T1]{fontenc}
\usepackage[sfdefault,scaled=.85]{FiraSans}
\usepackage{newtxsf}
5

As long as the metropolis theme is compiled with a suitable engine (e.g. xelatex) it uses fira fonts per default. So simply do not load any other packages or themes and you'll get fira font for text.

% !TeX TS-program = xelatex

\documentclass{beamer}
\usetheme{metropolis} % Use metropolis theme 


\usefonttheme[onlymath]{serif} 
\usepackage{mathpazo}

\begin{document}
 \begin{frame}{First Frame}
 Hello, world! Here some random math:
 \begin{equation*}
 s_{t}=\begin{cases}
 \bar{s}, & t\in \left\lbrace 0,\dots, T-1\right\rbrace  \\
 \tilde{s}, & t\geq T
 \end{cases}
 \end{equation*} 
\end{frame}
\end{document}

enter image description here


A version of the math font which plays nicer with xelatex:

% !TeX TS-program = xelatex

\documentclass{beamer}

\usetheme{metropolis} 
\usefonttheme{professionalfonts}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Pagella Math}

\begin{document}
 \begin{frame}{First Frame}
 Hello, world! Here some random math:
 \begin{equation*}
 s_{t}=\begin{cases}
 \bar{s}, & t\in \left\lbrace 0,\dots, T-1\right\rbrace  \\
 \tilde{s}, & t\geq T
 \end{cases}
 \end{equation*} 
\end{frame}
\end{document}

enter image description here

  • OP said "The math stuff does not have the shape of the usual mathpazo font." and the screenshots looked like Fira was used for non-math mode. I think OP was talking about wanting standard italics when s/he wrote "the shape of the usual mathpazo font". For some reason italics appear with \usefonttheme[onlymath]{serif} with pdfLaTeX but non-italics with XeLaTeX. – whatisit Jan 1 at 0:05
  • 2
    @whatisit In the image of the OP the "math stuff" looked like the computer modern serif font, not mathpazo. \usefonttheme[onlymath]{serif} will result in math italic for both pdflatex and xelatex, just the font is different. – user36296 Jan 1 at 0:15
  • When I compile this with pdfLaTeX, I get italics in math. When I compile it with XeLaTeX, I do not have italics in math (and get the same as in OP's screenshot). Maybe it should be italic in both...but in practice that is not what I am seeing. – whatisit Jan 1 at 0:18
  • 2
    @whatisit The missing math italic is a consequence of the encoding. mathpazo would need T1 or OT1, but this would kind of invalid all the advantages of using xelatex. ... If math italic is a must, I suggest to use \usepackage{unicode-math} \setmathfont{TeX Gyre Pagella Math} instead of mathpazo – user36296 Jan 1 at 1:06
  • 1
    @Davislor Thanks a lot for your comment, I added the professionalfonts theme. Happy new year! – user36296 Jan 1 at 12:56

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.