I am using a Beamer template, which uses a bold font for the frame titles. On some slides, I have also math expressions in the title. I would like also the math expressions to be printed in bold. I am using unicode-math
and compiling with lualatex
. In a LaTeX text document, which was compiled with lualatex
, too, I had a similar problem with section titles. There I was able to fix it by using the snippet
\makeatletter
\g@addto@macro\bfseries{\boldmath}
\makeatother
from the internet. This doesn't help in the case of my Beamer presentation with different fonts. Therefore, I tried
\makeatletter
\g@addto@macro\bfseries{\symbfit}
\makeatother
However, in the case of my Beamer presentation, using this version of the snippet results in the error message ! LaTeX Error: \symbfitallowed only in math mode.
So, it seems that adding this snippet to my presentation sources results in Beamer trying to use this math font for all parts of the title, which then causes errors. How can I fix this?
The full MWE is
\documentclass{beamer}
\usetheme{Verona}
\usepackage{amsmath}
\usepackage[mathbf=sym]{unicode-math}
\setmathfont{Fira Math}
\setmathfont[range=up]{Roboto}
\setmathfont[range=\int]{Fira Math}
\setmathfont[range=cal]{Stix Two Math}
\setmathfont[range={\lessapprox}]{Stix Two Math}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the "problematic" code
\makeatletter
\g@addto@macro\bfseries{\symbfit}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{frame}
\frametitle{Test \(f_1(x)\)}
test slide
\[f_1(x)\]
\[\symbfit{f_1(x)}\]
\end{frame}
\end{document}
If I remove the problematic code, the result looks like this:
This illustrates nicely that, in principle, bold math is working.
Note that I don't want to add code in each \frametitle
to make it work manually. I would like a general solution.
I am using TexLive 2019, as it is available from the package sources of Ubuntu 20.04.
Edit on July 5, 23: I corrected the statement about the use of the snippet in the case of the LaTeX text document. I used for that boldmath
and not symbfit
, which was stated falsely in the first version of the question. Thanks to user @samcarter_is_at_topanswers.xyz for questioning my statement, which led to this correction!