[Tex/LaTex] way to set math mode font non-italic

fontsitalicmath-mode

I read many things about people wanting math mode in sans-serif font and doing crazy things with packages and options to get that, but I did not find anything that would simply make my math mode font non-italic.

Is there an (easy) way to set math mode font to be non-italic?

And is there a way to do that globally for the whole document?

Best Answer

On a case-by-case basis, it is possible to typeset text within math mode using \textrm{...} or \mathrm{...}, the latter being used predominantly for typesetting units or symbols and not pure text (since it gobbles spaces that are not escaped). \mbox{...} is another alternative to \textrm{...}, since it resets its contents to text mode by default. Here are some examples:

enter image description here

\documentclass{article}
\begin{document}
Here is a formula: $x=\exp(\log \mathrm{x})$

Here is another: $\sin^2 t+\cos^2 t = \textrm{famous identity}$
\end{document}​

The above font changes do not work that well in general, since switching to a different font when using sub- and superscripts, say, does not always scale as expected. There are ways around it though. For example, using \text{...} from the amstext package (automatically loaded by amsmath - see the AMS package dependencies), which switches to the appropriate font size via \mathchoice:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
% amsmath loads the amstext package by default
\begin{document}
Here is a formula: $x=y^{abc}$

Here it is again: $x=y^{\mbox{abc}}$

Compare that to: $x=y^{\text{abc}}$
\end{document}​