# Is there a way to set math mode font non-italic?

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?

-

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:

\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:

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

-

The results are not always perfect, but mathastext is what you're looking for, when you want to set globally the math font to upright (or to use another completely different font, check the documentation):

\documentclass{article}
\usepackage[LGRgreek]{mathastext}

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

Here is another: $\sin^2 t+\cos^2 t = 1$

What about Greek? $\alpha+\beta$
\end{document}


Don't tell anybody that I recommended it. :) Indeed I strongly advise not to do evil things like printing all math upright. :)

-
So your advise is typing \mbox{...} before every math line? –  cebe Dec 28 '11 at 23:37
@cebe No, my advise is to use italics for math as typographers have done for centuries. If you really want to use roman letters for math, then mathastext is the right tool. –  egreg Dec 28 '11 at 23:41
Reluctantly I'm casting a vote for this answer:-) The mathastext package lets you cheat on proper math typesetting but sometimes it looks nice. –  Marc van Dongen Dec 28 '11 at 23:52
+1 for the "evil" tag. Bringhurst is weeping. –  Brent.Longborough Dec 29 '11 at 9:54

Probably not what you are looking for, but you could use the Euler math font which is an upright math font (non-italic).

\documentclass{article}
\usepackage[osf,sc]{mathpazo}
\usepackage{eulervm}
\begin{document}
This is some text in Palatino with an inline equation $f(x)=\cos(x^2)$
followed by an equation:
$$\int_{0}^{1}\frac{1}{1 + x^2}\mathrm{d}{x}$$
\end{document}


Just don't use them with Computer Modern. (My example here uses Palatino for the text font.)

-
So far the only asthetic solution for upright maths :-) –  Daniel Sep 25 '13 at 10:48

Also if you're writing the same thing over, like units, I just created a new command and used it every time:

\newcommand{\inch}{\ensuremath{\,\textrm{in.}}}


This returns "in." without italics, and a space after the number. :)

$$\frac{19\inch-2.75\inch}{2} + 0.54 \inch = 8.125\inch + 0.54\inch = 8.665\inch \label{eq:outeredgemodel}$$


becomes:

-

Some packages (MinionPro, mathdesign, fourier, kpfonts) have an option "frenchmath” (the exact name depends on the package), which typesets uppercase roman letters and all greek letters upright, and takes care of the metrics.

-