10

How can I get roman font by default in math mode?

lockstep
  • 250,273
Vin
  • 163
  • 7
    This is almost certainly a bad idea if you are actually typesetting math. If you want stretches of text in roman you should use the \text command from the amsmath package. – Alan Munn Apr 05 '11 at 18:19
  • 1
    @Alan I totally agree but in some countries roman font is actually used for math symbols (French does this, IIRC). – Konrad Rudolph Apr 05 '11 at 18:59
  • 2
    @Konrad: yes, but only for capital letters and for greek. Font packages like fourier or kpfonts have options for this as does unicode-math. – Philippe Goutet Apr 05 '11 at 20:05

6 Answers6

12

Add the following code to the preamble, basically what it does is changing the default symbol font for letters to the Roman font.

\DeclareSymbolFont{letters}{OT1}{cmr}{m}{n}

Shuhao Cao
  • 3,131
  • 3
  • 29
  • 33
6

If you’re using unicode-math (which I recommend), \DeclareSymbolFont doesn’t seem to work, but

\usepackage[math-style=upright]{unicode-math}

does, per http://mirror.ctan.org/macros/latex/contrib/unicode-math/unicode-math.pdf.

Flash Sheridan
  • 269
  • 3
  • 7
6

Thanks again for those who have answered. I'm glad to see the LaTeX community is so helpful (it's my first post). The solution I'm using at present is the mathastext package, which gives good results in most cases without any strange parameters.

Martin Scharrer
  • 262,582
Vin
  • 163
2

\everymath={\fam0}

\everymath is a token list that gets read before any math-material. With it you can set up special conventions that you wish to apply to all formulas.

Note that with the above, accents doesn't work correctly with amsmath!

morbusg
  • 25,490
  • 4
  • 81
  • 162
  • 3
    @morbusg: this applies \mathrm only to the first token in the formula. Try with $a+b$: "a" will be upright, but "b" will be in italics. – egreg May 14 '11 at 09:09
  • @egreg: to be honest, I only tried it with plain-tex: \let\mathrm=\rm \everymath={\mathrm} $a + b$ \bye works as advertised. I'll change it to the answer. – morbusg May 14 '11 at 09:22
  • @morbusg: Maybe it's better to state in the answer that this is a Plain TeX only solution. – egreg May 14 '11 at 09:53
  • @egreg: why would I do that when it's not? \documentclass{article} \everymath={\rm} \begin{document} $a+b$ \end{document} – morbusg May 14 '11 at 09:58
  • 1
    @morbusg: try it with the memoir class; \rm is an obsolete command that should not be used in LaTeX any more. – egreg May 14 '11 at 10:04
  • @egreg: So LaTeX doesn't have an equivalent of \rm? ie. one that, instead of taking an argument, changes the family from there on? – morbusg May 14 '11 at 10:11
  • @morbusg: no, it hasn't. – egreg May 14 '11 at 10:22
  • 1
    @egreg, @morbusg: it's in text mode that \rm is obsolete and should not be used, as it can't stack properly. In math mode, that's not a problem as the command is more or less just \fam0. So by replacing \rm by \fam0 (or \mathgroup0), you'll have something which works with all classes. – Philippe Goutet May 14 '11 at 21:59
  • @egreg: Hmm, but what about \upshape? – Andrey Vihrov May 15 '11 at 06:38
  • @Andrey: Command \upshape invalid in math mode. What Philippe says is right, but it's not a "LaTeX equivalent", it's just primitive TeX. – egreg May 15 '11 at 08:15
  • @egreg: I don't see anyone claiming it'd be "LaTeX equivalent". – morbusg May 15 '11 at 09:35
  • @morbusg: a major problem with this solution is that it's incompatible with the amsmath package as it will mess with accents. E.g. \documentclass{article}\usepackage{amsmath}\begin{document}\everymath={\fam0} $\vec{E}$\end{document} will produce a tilde instead of an arrow (same phenomenon as in http://tex.stackexchange.com/q/69526). – Philippe Goutet Aug 31 '12 at 07:26
2

As mentioned in the comments on the question, you can achieve this with certain fonts that have this as an option.

For example the following makes the greek alphabet and the uppercase Roman letters upright (as is apparently the style in France):

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[upright]{kpfonts}
\begin{document}
Here is an equation $e^{i\pi}+1=0$. 
Note the slanted e$e$.

Note the upright N$N$.
\end{document}

Upright uppercase Roman letters

Seamus
  • 73,242
  • 1
    With kpfont's code, it's almost trivial to obtain French style math letters: it's just a long list of \re@DeclareMathSymbol. For the main question there's also the mathastext package, as mentioned by Martin. – egreg May 16 '11 at 13:57
  • 1
    @egreg It was actually Vin who mentioned mathastext as far as I can tell... Also, I didn't mention mathastext (which would be my preferred solution) because it's already in a different answer. I only added this because it was mentioned in the comments, but not made clear exactly how to do it. – Seamus May 16 '11 at 14:40
1

If I have to add some comment to some kind of equation I use \textrm. Hope that's what you need.

Martin Scharrer
  • 262,582
dingo_d
  • 2,976