# How to make e in e^x written upright and why \me^x does not work?

I'd like to write e^x in LaTeX math mode where the e is written upright, rather than slanted, to indicate that it is not a variable. Kopka and Daly (4ed) pg. 285 do this with \me^x. When I try this I get the "undefined control sequence" error.

Q: Is \me a deprecated command?

Q: How can I do now what \me used to do?

You have to define yourself that command in your document preamble

\newcommand{\me}{\mathrm{e}}


It's not necessary to declare this symbol as an ordinary symbol because by rule all math characters that are subject to alphabet changes are ordinary.

The construction \mathrm{e} is essentially equivalent to

\begingroup\mathgroup=0 e\endgroup


because the Roman math alphabet corresponds to the math group 0. Each math alphabet (\mathrm, \mathnormal, \mathbf and so on) corresponds to the choice of one among 16 math groups; \mathrm is 0, \mathnormal is 1, the others are from 4 onwards.

Each character has a \mathcode which, for e is "7165 which means

when an e is found in math mode, it should be an ordinary symbol, taken from the font in math group 1 at slot "65; but if \mathgroup is set to a non negative value, use the character at slot "65 from the font in the specified math group (this because of the first digit "7).

Thus calling \mathrm{e} is like asking for a math code "0065 (numbers preceded by " are hexadecimal): the first 0 means "ordinary symbol", the second one is the math group. With \mathbf{e} we would ask for "0465, according to the normal LaTeX setup.

Details about math codes are in the TeXbook or in TeX by Topic. Note that LaTeX calls \mathgroup the primitive \fam.

• wouldn't \DeclareMathOperator{\me}{e} be preferred in this case though? – lowndrul May 30 '11 at 20:32
• @brianjd: Because this creates an atom of operator kind an the “e” should be ordinary, I think … – Tobi May 30 '11 at 20:39
• @brianjd No, as it would create a space in $\me x$ or $x\me$, which is clearly wrong. – egreg May 30 '11 at 20:51
• @brianjd: But e is not an operator, it's a number. – Jeff Jul 12 '13 at 18:48

I do this using the unicode-math package to redefine the alphabet used for e as upright. That way, I can write $$e^{i \pi}$$ and have everything typeset in just the right font shape.

My particular method of doing this is rather complicated (as I mix colours in as well: reals are redish and complex are a shade of purple) but the documentation for unicode-math is fairly straightforward. Here's a simple example

\documentclass{article}
\usepackage{unicode-math}
\setmathfont{xits-math.otf}

\setmathfont[math-style=upright,range={e,i}]{xits-math.otf}

\begin{document}
\Huge
$$e^{i \pi} = -1$$
\end{document}


Result:

Caveats:

1. You have to use xelatex or lualatex for this
2. The above uses the STIX fonts, if you don't have them you'll need to change the example
3. You have to be sneaky if you want to use both e and e in the same document (as bare symbols that is)
4. Of course, \pi should have been upright as well (since it is also a constant) but that's a little more complicated
5. Once you mix colours in, the whole thing can get a little silly!
• It's actually sort of surprising that a mathematician would typeset e and i upright. I've only ever seen physicists do that. But that aside, you can do this without xelatex simply by writing \mathcode"65"65 in the preamble. Similarly for i. – TH. May 30 '11 at 23:44
• @TH. I do this in lectures to quickly distinguish between constants and variables (or local constants). I wouldn't do this in an article. I didn't know about the \mathcode trick, but I suspect it wouldn't work for the full range of what I do in lectures (such as colours). – Loop Space May 31 '11 at 7:08
• @TH. A better way to express your trick would be \mathcodee=e that carries more semantics. – egreg Aug 21 '12 at 9:40
• @LoopSpace If e and i are going to be upright, shouldn't pi be as well? – Alan Sep 21 '16 at 17:49