[Tex/LaTex] Different commas in text and math mode in Beamer

beamerpunctuation

My question is closely related to this one. The difference is, that I would like to make a presentation with beamer and that I use standard fonts. As you can see in the following MWE the commas in math and text mode differ from each other.

What is the best way to fix this?

MWE:

\documentclass{beamer}

\begin{document}

\begin{frame}
    $f(x,y,z) > 0$ if $x$, $y$, and $z$ are positive.
\end{frame}

\end{document}

Output:
different commas in beamer

Best Answer

The commas in maths match commas from the default serif font but are taken from the OML encoding. You can see this if you force the text to use the serif font by changing the frame to

\begin{frame}
  $f(x,y,z) > 0$ if {\rmfamily $x$, $y$,} and $z$ are positive.
\end{frame}

tweaked text commas

However, now the commas are being taken from the serif font while the rest of the text is taken from sans.

It would be better to ensure that the commas are taken from the same font as maths operators, since this is changed to the sans font by beamer, I think. For example:

\documentclass{beamer}
\DeclareMathSymbol{,}{\mathpunct}{operators}{"2C}
\begin{document}

\begin{frame}
  $f(x,y,z) > 0$ if $x$, $y$, and $z$ are positive.
\end{frame}

\end{document}

tweaked maths commas

The nice thing about this is that if you override Beamer's choices and insist it use serif rather than sans, your commas will still match your text:

\documentclass[serif]{beamer}
\DeclareMathSymbol{,}{\mathpunct}{operators}{"2C}
\begin{document}

\begin{frame}
  $f(x,y,z) > 0$ if $x$, $y$, and $z$ are positive.
\end{frame}

\end{document}

serif

Although the redefinition is unnecessary in this case, it is nice that you don't have to worry about removing or disabling it.

EDIT

In light of barbara's comment on the question, I ran a few tests. Although the particular punctuation suggested is unproblematic as it is already taken from operators rather than letters, the full stop is not. Moreover, there is a difference between the serif and sans full stop. In the sans font, it is square; in the serif, round.

Hence, for completeness, you might like to add a line redeclaring this symbol as well:

\documentclass{beamer}
\DeclareMathSymbol{,}{\mathpunct}{operators}{"2C}
\DeclareMathSymbol{.}{\mathpunct}{operators}{"2E}
\begin{document}

\begin{frame}
  $f(x,y,z) > 0$ if $x$, $y$, and $z$ are positive.

  $, . $ , .  {\rmfamily , .}
\end{frame}

\end{document}

Here's the output for commas and full stops in maths and text, after the change, with the serif versions shown on the right for comparison.

fun with full stops