2

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: screenshot of a slide showing that math expressions in the title are not printed in bold, whereas the main part shows that the \symbfit command is working

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!

1

1 Answer 1

3

Depending on which versions are contained in your font, a simple \boldmath can be added to the frametitle font:

% !TeX TS-program = lualatex

\documentclass{beamer}
\usetheme{Verona}

\usepackage{amsmath}

\usepackage[mathbf=sym]{unicode-math}
\setmathfont{XITS Math}
\setbeamerfont{frametitle}{series=\bfseries\boldmath}

\begin{document}

\begin{frame}
    \frametitle{Test \(f_1(x)\)}
    test slide
    \[f_1(x)\]
    \[\symbfit{ f_1(x)}\]
\end{frame}

\end{document}

enter image description here

If your font does not support this, you can fake it:

% !TeX TS-program = lualatex

\documentclass{beamer}
\usetheme{Verona}

\usepackage{amsmath}

\usepackage[mathbf=sym]{unicode-math}
\setmathfont{Fira Math}

\setmathfont[version=bold,FakeBold=3]{Fira Math}

\setmathfont[range=up]{Roboto}
\setmathfont[range=\int]{Fira Math}
\setmathfont[range=cal]{Stix Two Math}
\setmathfont[range={\lessapprox}]{Stix Two Math}

\setbeamerfont{frametitle}{series=\bfseries\boldmath}

\begin{document}

\begin{frame}
    \frametitle{Test \(f_1(x)\)}
    test slide
    \[f_1(x)\]
    \[\symbfit{ f_1(x)}\]
\end{frame}

\end{document}

enter image description here

3
  • Thanks for the answer. The workaround \setmathfont[version=bold,FakeBold=3]{Fira Math} from your second example is quite nice. However, it appears to me that \setbeamerfont{frametitle}{series=\bfseries\boldmath} is more or less (in terms of the effects) equivalent to \makeatletter \g@addto@macro\bfseries{\boldmath} \makeatother, which works equally well if the FakeBold workaround is active. Nevertheless, I would be interested in understanding why \makeatletter \g@addto@macro\bfseries{\symbfit} \makeatother causes an error in Beamer, while it works in text documents. Jul 5 at 14:14
  • 1
    @user5415068 \g@addto@macro\bfseries{\symbfit} will throw an error in other classes as well. You are mixing a macro which is only for text mode and a macro which is only for math mode - this can't end well. Jul 5 at 14:18
  • You are right, in my text document I used \makeatletter \g@addto@macro\bfseries{\boldmath} \makeatother and not the version of this code with \symbfit! I corrected my question accordingly and added at the end an explanation of the changes. Thank you very much for pointing this out! Jul 5 at 14:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .