I am using the rmarkdown
package to produce PDF slides with the Metropolis theme. Recently, I noticed that the equations started to appear differently - they use a different font.
Minimal example of *.Rmd
file:
---
output:
beamer_presentation:
theme: "metropolis"
latex_engine: xelatex
keep_tex: true
---
## Problem with font
$$f(x_i\mid\mu,\sigma^2) = \exp\left\{-\frac{(x_i-\mu)^2}{2\sigma^2}\right\}$$
which, when knitted in RStudio, produces:
This looks different from what is obtained when compiling the same slide directly in LaTeX with xelatex:
\documentclass{beamer}
\usetheme{metropolis}
\begin{document}
\begin{frame}{Problem with font}
\[f(x_i\mid\mu,\sigma^2) = \exp\left\{-\frac{(x_i-\mu)^2}{2\sigma^2}\right\}\]
\end{frame}
\end{document}
This does not look like a big difference, but in other equations some special characters are missing, and the font size is slightly different, affecting the whole layout of my slides.
After some investigation, it turns out that commenting out those two lines in the tex file produced by rmarkdown
makes it better:
%\usepackage{unicode-math}
%\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
Is the unicode-math
package the (only) culprit here? How to solve this problem and make sure that Metropolis uses the right fonts without manually changing the tex files?
Thanks in advance for your help!
System configuration:
- RStudio 1.2.1335
- rmarkdown 1.15
- pandoc 2.3.1 (through RStudio)
- Metropolis theme 1.2
- Fira Sans font 4.3
- XeTeX 3.14159265-2.6-0.999991 (TeX Live 2019)
mathspec
variable for some reason? Try unsetting it. I searched the default template (pandoc -D latex
) forunicode-math
and that came up... see pandoc.org/MANUAL.html#templates – mb21