mtheme icon indicating copy to clipboard operation
mtheme copied to clipboard

In knitr, can't get metropolis theme to work with \mathbf and greek letters, or with \bm from the bm package

Open lfmcmillan opened this issue 5 years ago • 2 comments

If I try to include \mathbf around greek letters, or try to use the \bm command instead which is actually the better way of producing bold greek letters, I get various errors when trying to compile

Minimal non-working example:


title: Greek symbols, mathbf and bm with Metropolis output: beamer_presentation: theme: "metropolis" latex_engine: xelatex header-includes:

  • \usefonttheme{professionalfonts}
  • \setsansfont[BoldFont={Fira Sans SemiBold}]{Fira Sans Book}
  • \usepackage{bm}

require(knitr)

Greek symbols

This $\mathbf{\theta}$ should be a greek symbol using

\mathbf{\theta}

This should be a greek symbol using

\bm{\theta}

Neither works.

lfmcmillan avatar Aug 03 '20 12:08 lfmcmillan

To clarify, $\bm{x}$ also breaks, but $\mathbf{x}$ is ok, but neither works for greek letters

lfmcmillan avatar Aug 03 '20 12:08 lfmcmillan

@lfmcmillan You should use the package unicode-math together with the mtheme and the font "Fira Math" is especially suited as companion to Fira Sans: https://github.com/firamath/firamath.

With unicode-math you then have to use \symbf{\theta}

Minimal example:

\documentclass[1610]{beamer}

\usefonttheme{professionalfonts}
\usetheme{metropolis}

\usepackage{fontspec}
\setsansfont[BoldFont={Fira Sans SemiBold}]{Fira Sans Book}

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage[
  mathrm=sym,
  math-style=ISO,  % Greek letters also in italics
  bold-style=ISO,  % bold letters also in italics
]{unicode-math}

\setmathfont{Fira Math}
% top is still missing in Fira Math, get it from another font
\setmathfont[range={\top}]{XITS Math}



\begin{document}
  \begin{frame}[t]{Example}
    \begin{align}
      \symbf{\theta} &= (1, 2, 3)^\top \\
    \theta_0 &= 1
    \end{align}
  \end{frame}
\end{document}

There are several other math fonts and you should always set one. Go with "Latin Modern Math" for the "TeX" font.

With Fira Math (and \top from XITS Math):

test

With Latin Modern Math:

test

maxnoe avatar Jan 12 '21 10:01 maxnoe