5

When I typeset the same equations using beamer inside a savebox environment, and inside the main document, the font used for the math equations comes out differently.

Here is a MWE showing the difference.

\documentclass{beamer}

\newcommand{\delsq}[2]{
  \frac{\partial^2 {#1}}{\partial {#2}^2}
}
\newcommand{\deldel}[2]{
  \frac{\partial #1}{\partial #2}
}

\newcommand{\waveEqOneD}{\delsq{u}{t} = c^2\delsq{u}{x}}

\newsavebox{\waveEquationTest}
\savebox{\waveEquationTest}{
  $\begin{array}{ll}
    u(0,t)=0 & u(L,t)=0\\
    u(x,0)=f(x) & \deldel{u}{t}(x,0)=g(x)\\
  \end{array}$
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin document           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Boundary conditions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \usebox{\waveEquationTest}
  $\begin{array}{ll}
    u(0,t)=0 & u(L,t)=0\\
    u(x,0)=f(x) & \deldel{u}{t}(x,0)=g(x)\\
  \end{array}$
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The same code is used inside and outside the savebox environment, but the font used to render the code is different.

My question is why do these typeset differently?

Secondly, I actually prefer the look of the italicized font inside the savebox environment. How can I make that the default mathematics font throughout the entire presentation?

6

The beamer class redefines some of the fonts at \begin{document}. This is so it can support font packages you load in the preamble after the \documentclass. If you move the \savebox from the preamble into the document, it will see that beamer changed the math letters to sans-serif italic and use the same fonts as other math.

\documentclass{beamer}

\newcommand{\delsq}[2]{
  \frac{\partial^2 {#1}}{\partial {#2}^2}
}
\newcommand{\deldel}[2]{
  \frac{\partial #1}{\partial #2}
}

\newcommand{\waveEqOneD}{\delsq{u}{t} = c^2\delsq{u}{x}}

\newsavebox{\waveEquationTest}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin document           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\savebox{\waveEquationTest}{
  $\begin{array}{ll}
    u(0,t)=0 & u(L,t)=0\\
    u(x,0)=f(x) & \deldel{u}{t}(x,0)=g(x)\\
  \end{array}$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Boundary conditions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \usebox{\waveEquationTest}
  $\begin{array}{ll}
    u(0,t)=0 & u(L,t)=0\\
    u(x,0)=f(x) & \deldel{u}{t}(x,0)=g(x)\\
  \end{array}$
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The font that will be used inside the \savebox, if you define it in the preamble, is the default serif font (Computer Modern Roman Italic). I would recommend that you set your fonts in beamer by adding the line

\usepackage{unicode-math}

and compiling in LuaLaTeX. If beamer sees unicode-math, it turns its redefinition of the math fonts off and uses the math font you select. If you’re writing a beamer presentation, your publisher is not forcing you to use PDFTeX and legacy fonts. You can then set any OpenType fonts of your choice, such as \usepackage{newcomputermodern} for a slightly-darker clone of the default TeX font.

A PDFTeX-compatible way to do it, though, is to add

\usefonttheme{serif}
1
  • 1
    Thank you, for the well written and comprehensive answer. – Chah Feb 23 at 13:38

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.