[Tex/LaTex] Is \mathrm really preferable to \text?

beamermath-modesans-serif

It seems to be the de facto standard to use \mathrm for upright letter notation in math mode as opposed to \text. Would it not be better to use \text in general?

One particular problem I am thinking of is when writing in a sans serif-style document (e.g. beamer). In many cases here, your text and math is set in a sans serif font (for screen readability, I guess). Using \mathrm in this case causes the argument to appear in a roman font (with serifs), whereas using \text seems to correctly pick up that the text style in the document is sans serif and display the argument in upright sans serif.

So, would it not be better to generally use \text instead of \mathrm for "upright" notation in math mode?

Best Answer

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.

If you want an upright math font which adapts to the main document define it by using \familydefault:

\documentclass[12pt]{article}
\usepackage{amsmath}

\renewcommand\familydefault{\sfdefault} %comment to see the difference
\DeclareMathAlphabet      {\mathup}{OT1}{\familydefault}{m}{n}

\begin{document}

abc

$ a=\text{b}=\mathup{b}$

\itshape abc

$ a=\text{b}=\mathup{b}$


\sffamily abc

$ a=\text{b}=\mathup{b}$

\end{document}