10

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

crixstox
  • 1,784
  • 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
  • @barbarabeeton Is my answer horrible? I'm not sure what side-effects taking the comma from operators rather than OML might have? – cfr Jun 29 '15 at 22:20
  • @cfr -- answer not horrible; in fact, very nice. (thanks for asking.) wonder what the likelihood is for semicolons in math, and maybe worth looking at the ! (for factorial). – barbara beeton Jun 30 '15 at 12:38
  • @barbarabeeton I just made a quick test for the semicolons (I just replaced all commas in my MWE with semicolons). Curiously they behave quite well, i.e. in math and text they are the same. The same seems to hold for !. – crixstox Jun 30 '15 at 15:58
  • @crixstox -- thanks for the update. nice to know that apparently only the comma is affected. – barbara beeton Jun 30 '15 at 16:07
  • @barbarabeeton Thanks! I didn't exactly understand your comment concerning semicolons and factorials. These are not normally taken from the OML encoded font, are they? For example, fontmath.ltx defines the semicolon with \DeclareMathSymbol{;}{\mathpunct}{operators}{"3B} and the factorial with \DeclareMathSymbol{!}{\mathclose}{operators}{"21}. So those are already taken from operators which I think is automatically set to sans or serif by Beamer according to the requested package options. The only problem is punctuation taken from e.g. letters because letters is configured for... – cfr Jul 01 '15 at 00:46
  • ... the OML encoded font and that is sensitive to sans/serif selection because the only font available is serif. At least, that was my understanding of what was going on. But I could easily be mistaken? – cfr Jul 01 '15 at 00:47
  • @cfr -- i didn't check before commenting. it just seemed that semicolons and the exclamation mark are (logically) in the same class as commas, and if commas weren't switching, it wouldn't be a bad idea to check the others. you've done so, and found that they'd already been taken care of. good. – barbara beeton Jul 01 '15 at 12:10
  • @barbarabeeton Oh, I see. OK. Thanks. LaTeX is not logical about this. (Although I think it is just mirroring what TeX does, isn't it. So maybe my complaint should be with TeX?) – cfr Jul 01 '15 at 12:14
  • since tex (rather plain tex) doesn't do anything for math with fonts other than computer modern roman, i'm not sure where to put the complaint. anyhow, you gave an answer that does the job, and that's what counts. – barbara beeton Jul 01 '15 at 12:20

1 Answers1

13

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

cfr
  • 198,882
  • 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 01 '15 at 01:00