# How to properly typeset E_{\mathrm{k}} in beamer

Scientific typography makes an important distinction between italic type and roman (upright) type (exemplary source).

The symbol for kinetisch energy is E_k with E printed in italic type, k printed in roman type.

Normally, I would write that as E_{\mathrm{k}}.

However, that does not work with beamer. The package changes normal math to a sans-serif font, but leaves \mathrm a serif-font. The subscript k will be typeset in a serif-font, but it should simply match the default math font, just being upright.

So how do I get the intended behavior in beamer?

\documentclass{beamer}
\begin{document}
\begin{frame}
$E_{\mathrm{k}}$
\end{frame}
\end{document}


(Other packages that switch to sans-serif math fonts also redefine mathrm to be sans-serif and, of course, upright, e.g. cmbright, sfmath and arevmath.)

• Define intended behavior. I'd probably just use mathbf or redefine mathrm to it. Btw probably should not promote users to use the subscript without the outer braces. It is mostly luck that it works here, better to get new users to always use the braces then they don't get confused when not using braces does not work – daleif Apr 29 '18 at 18:02
• @daleif I added the braces. Intended behavior = The subscript "should simply match the default math font, just being upright". mathbf = bold? – mhchem Apr 29 '18 at 18:33
• My bad should have written mathsf. As was mentioned in the comments to another question, it's probably best to use a user defined macro and not hardcode mathrm or similar. Then it is easier to prepare for, for example, beamers oddities – daleif Apr 29 '18 at 18:44

One could use $E_{\mathsf{k}}$, but that is not very portable.

From the beamer manual:

Note: The command \mathrm will always produce upright (not slanted), serif text and the command \mathsf will always produce upright, sans-serif text. The command \mathbf will produce upright, boldface, sans-serif or serif text, depending on whether mathsans or mathserif is used. To produce an upright, sans-serif or serif text, depending on whether mathsans or mathserif is used, you can use for instance the command \operatorname from the amsmath package. Using this command instead of \mathrm or \mathsf directly will automatically adjust upright mathematical text if you switch from sans-serif to serif or back.

So, the beamer way to do things is to define an operator and then use it. But an operator is not quite the same thing.

In my humble opinion, the beamer package is flawed in that respect.

• Probably left over from the fact thst so many users do not mark their operators correctly (I see a lot of people using \text), it definitely do not apply here. Not sure if pinging works here, @JosephWright shouldn't theæis phrase in the beamer manual be changed? – daleif Apr 29 '18 at 20:10

By adding \usefonttheme[onlymath]{serif}, we find the serif font in mathematical formulas.

\documentclass{beamer}
\usefonttheme[onlymath]{serif}
\begin{document}
\begin{frame}
$E_\mathrm{k}$
\end{frame}
\end{document}


Output:

Imho the problem is that at the time the names for the math alphabets were choosen sans serif math wasn't really on the agenda of math typesetters. And while I do understand why you want \mathrm to give a sans serif upright font, I would find it a bit curious if rm leads to a sf font (and that with e.g. arevmath \mathsf gives a slanted sf font).

So with pdflatex I would use (this assumes that amsmath is loaded) \operatorfont:

\documentclass{beamer} %or article
\usepackage{amsmath}
\usepackage{ifluatex}
\ifluatex
\usepackage{unicode-math}
\setmathfont{Cambria Math}
\else
\def\symup{\mathrm}
\fi
\begin{document}
sin

$\sin{x}\quad{\operatorfont sin}{x}\quad\symup{sin}{x}\quad\mathrm{sin}{x}$
\end{document}


## output with article + pdflatex

With unicode math I would probably prefer \symup (I don't quite understand why unicode-math uses a text font for the operators instead of the math font):

## output with article and lualatex:

• So, basically, you say that I should do my own font setup (supporting my notion that beamer's setup is a little bit awkward). // I don't understand your 2nd sentence. Why do you have the notion that rm should have serifs? For me, rm stands for roman = upright letters of the latin script. IUPAP and Wikipedia support my notion. cmbright, sfmath and arevmath see it the same way. – mhchem Apr 30 '18 at 13:35
• Well in latex \rmfamily is normally a serif font (you can find quite lot quotes like "\rmfamily selects a roman (i.e., serifed) font family") and \sffamily is a sans serif font. But things are getting fuzzy here too as more and more document use sans serif as main font (and fontspec quite rightly uses now \setmainfont). – Ulrike Fischer Apr 30 '18 at 13:47
• @UlrikeFischer aren't we just missing a \mathup, aka switch to upright in the current math font. – daleif Apr 30 '18 at 14:36
• @daleif With unicode-math the \mathXX switch to textfonts and so are never "in the current math font". There you should use imho \symup. With pdflatex a \mathup using the operator font could make sense. – Ulrike Fischer Apr 30 '18 at 15:03
• @UlrikeFischer since I hardly ever use the unicode setup (too unstable and confusing interface) accessing the operator font could be ok, but at other times one might want the upright text font (say, you're typesetting an index on a variable and it contains non-ascii letters) – daleif Apr 30 '18 at 15:39