9

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

  • I suggest you to put the commas inside $ $, like if $x, y,$ and $z$ are positive.. – Carlos Viegas Jun 29 '15 at 11:55
  • @CarlosViegas This would work of course, but is not very convenient (especially in text where there is no math symbol in front of the comma). I would prefer a "more proper" solution. – crixstox Jun 29 '15 at 12:00
  • @CarlosViegas -- the commas shown here in math are ordinary roman serif. since the rest of the beamer content is sans serif, changing the commas outside math isn't the right approach. – barbara beeton Jun 29 '15 at 12:50
  • @barbarabeeton Thanks for your clarification. If I understand you correctly, this means, that Beamer uses always serif commas in math, even if I load it with the option [mathsans] ... – crixstox Jun 29 '15 at 13:20
  • since i haven't actually used math in beamer, i can't give a knowledgeable answer. best to pay attention to someone who can. (sorry, i know this is unsatisfying.) – barbara beeton Jun 29 '15 at 13:23
10

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

  • The line \DeclareMathSymbol{,}{\mathpunct}{operators}{"2C} works fine and in addition the beamer class options [mathsans] and [mathserif] are correctly taken into account. – crixstox Jun 29 '15 at 13:23
  • @crixstox Yes. Because it is using whatever is set as the font for maths operators, be that sans or serif. In article, for example, it would get you serif by default. In beamer, it gets you sans. So it tries to work with whatever the active definitions happen to be. – cfr Jun 29 '15 at 13:51
  • @crixstox Also, see edit. You might want to change the full stops to match as well. (Admittedly the difference is less visible but while you are redeclaring one symbol, redeclaring a second seems a relatively painless addition.) – cfr Jul 1 '15 at 1:00

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.