Equivalent of \mathup for upright text in math mode?

To insert text in mathmode, there are a couple of commands:

• \mathrm for Roman script,
• \mathbf for bold weight,
• \mathit for italic shape,
• \mathsf for the sans serif variant,

and so on. Now, sometimes I would like to have some math entities typeset upright (see for example How to best typeset "special" constants (complex unit i, Euler's number e,...)?). I understand that \mathrm sets the text in Roman and upright, but in some cases I do not want serifs (e.g., in presentations). The command \mathup does not seem to exist.

What is recommended way to set upright text in math mode?

• \mathsf? See this. – jubobs Oct 20 '13 at 13:15
• @Jubobs I would not want to have sanf serif script in a serif environment. I really only want to have \upshape. – Nico Schlömer Oct 21 '13 at 13:05
• There is a definition of \mathup: Is \mathrm really preferable to \text? – Qrrbrbirlbel Oct 21 '13 at 13:14
• @Thoge Quoting from tex.stackexchange.com/q/98008: "As has been said, \text is for text, and will change depending on the surrounding font. But math symbols in a document should always look the same: The meaning of a symbols also depends on the font used. So you should not use \text for mathematical symbols.". – Nico Schlömer Oct 23 '13 at 12:44
• What about \newcommand{\mathup}[1]{\text{\textup{#1}}}? This works for me. – Wauzl Aug 7 '14 at 7:35

I guess what you are seeing is the following, when you use \mathrm with a serif font:

\documentclass{beamer}

\usepackage{amsmath}

\begin{document}

\begin{frame}
$$x y \mathrm{x} \text{\textup{x}}$$
\end{frame}

\end{document}


There are two ways to fix this: one fairly drastic option is to put

\renewcommand{\rmdefault}{cmss}


but this may feed through to places you are not expecting. An alternative is to replace the two relevant definitions from beamerbasefont.sty by

\AtBeginDocument{%
\SetMathAlphabet{\mathrm}{normal}{\encodingdefault}{cmss}{\mddefault}{n}
\SetMathAlphabet{\mathrm}{bold}{\encodingdefault}{cmss}{\bfdefault}{n}}


in your preamble. In the beamer style file cmss is \rmdefault.

On the above example, either method gives you:

The package unicode-math for XeLaTeX and LuaLaTeX does the job and offers \mathup.

• It seems that unicode-math turns sans-serif math into serif math (try the beamer example from above). Any way around this? – Nico Schlömer Jul 12 '17 at 17:54
• @NicoSchlömer No, beamer is messing around. – Toscho Jul 12 '17 at 17:58
• @NicoSchlömer Ah, you're right. It's all derived from the fact, that upright and italic in math (may) have different meaning, just as serif and sans serif. You should look into the documentation of unicode-math (if you want to use an OpenMath-font) or mathspec (if you want to use another font). And still, beamer messes around with that. – Toscho Jul 12 '17 at 18:29