39

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?

6
  • \mathsf? See this.
    – jub0bs
    Commented Oct 20, 2013 at 13:15
  • 1
    @Jubobs I would not want to have sanf serif script in a serif environment. I really only want to have \upshape. Commented Oct 21, 2013 at 13:05
  • 4
    There is a definition of \mathup: Is \mathrm really preferable to \text? Commented Oct 21, 2013 at 13:14
  • 2
    @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.". Commented Oct 23, 2013 at 12:44
  • 2
    What about \newcommand{\mathup}[1]{\text{\textup{#1}}}? This works for me.
    – Wauzl
    Commented Aug 7, 2014 at 7:35

4 Answers 4

19

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

Sample output

\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}.

Applied to the above example, either method gives you:

Second sample

6

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

5
  • 1
    It seems that unicode-math turns sans-serif math into serif math (try the beamer example from above). Any way around this? Commented Jul 12, 2017 at 17:54
  • @NicoSchlömer No, beamer is messing around.
    – Toscho
    Commented Jul 12, 2017 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
    Commented Jul 12, 2017 at 18:29
  • 1
    If one uses unicode-math is \symup acceptable for math mode text, as in text sub/superscripts? Commented Nov 23, 2020 at 1:12
  • You can load unicode-math with the option mathrm=sym and it will use the correct font.
    – ArTourter
    Commented Jul 22, 2022 at 11:45
0

Your question was: in what cases to use sans serif in math.

In Czech traditional typography (and maybe in the middle Europe too) the vectors and matrices are signed by sans serif bold slanted (or upright) variants. This math alphabet was not preloaded by default in plain TeX (and derived formats), so we are seeing serifs bold in such cases in typical TeX documents, unfortunately.

The Unicode math fonts include many math alphabets including bold sans-serif upright and slanted Latin and Greek, so there is no problem. But there is strong tradition in TeX documents to use serif bold although there is no technical limitations when we are using Unicode math fonts today.

0

If using pandoc with th xelatex-engine to render a PDF \symup was the correct solution for me to have upright units like so \symup{{\mu}m}, for example.

My tex-template is loading unicode-math instead of mathspec despite xelatex is being used. Fortunately I might add, because a not resolved bug in mathspec is preventing it's use together with \siunitx, because it requires \amsmath loaded before and throws this error even if I do so in the template used by pandoc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .