# Put non-italic characters in equation

I am writing an equation, and I want some of the characters to not be italicized. All the other questions similar to this seem to be about globally changing italicizing in equations, but I just have 2 letters I don't want to be italic. The equation isn't in line, so I can't just end the equation and start a new one.

For example, say I'm writing $$f(x) = x^2$$, but I want the f, and only the f, to be non-italicized. How can I do this?

• \mathrm{f} (also if you are using latex don't use $$) – David Carlisle May 19 '18 at 22:55 • @DavidCarlisle This works, thanks. Why shouldn't I use $$? – RothX May 19 '18 at 22:57
• @DavidCarlisle im sorry, but why not \text{} ? – user134500 May 20 '18 at 3:50
• @santimirandarp \text would be wrong, that is for a nested insert of the surrounding text, not for a math variable that needs to be in a specific font. Notably in a theorem, if the surrounding text is italic \text would be italic – David Carlisle May 20 '18 at 7:57

## 2 Answers

As mentioned in the comments, \mathrm{f} will insert a letter from the text font as a math symbol. Here’s an example set in ISO style in legacy NFSS mode. The constants i, e and π are all upright, but the variable x is italic. You’ll notice that the upright letters are the same as from the text font. It would be possible to select another font as \mathrm, for example with isomath.

\documentclass[varwidth, preview]{standalone}

\usepackage[T1]{fontenc}
\usepackage{textcomp, amssymb}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}

\newcommand\upe{\mathord{\mathrm{e}}}
\newcommand\upi{\mathord{\mathrm{i}}}
\newcommand\uppi{\mathord{\mathrm{\pi}}}

\begin{document}
\begin{align*}
\upe^{\upi x} &= \cos{x} + \upi \sin{x} \\
\upe^{\upi \uppi} + 1 &= 0
\end{align*}
\end{document}


The unicode-math package distinguishes between text letters in math mode (\mathrm) and upright math symbols (\symup). However, you need to change the upright math alphabet to notice any difference in appearance. Here is an example that replaces the upright math symbols with CMU Serif Upright Italic, an unslanted version of the Computer Modern italic font. (Except for the digits, because $10$ and 10 should stay the same.) Notice that unicode-math is able to tell the difference between upright math symbols and operator names.

\documentclass[varwidth, preview]{standalone}

\usepackage{mathtools}
\usepackage[math-style=ISO]{unicode-math}

\setmathfont{Latin Modern Math}
\setmathfont[range=up/{Latin,latin,Greek,greek}]{CMU Serif Upright Italic}

\newcommand\upe{\symup{e}}
\newcommand\upi{\symup{i}}

\begin{document}
\begin{align*}
\upe^{\upi x} &= \cos{x} + \upi \sin{x} \\
\upe^{\upi \uppi} + 1 &= 0
\end{align*}
\end{document}


I think the result matches pretty well, but Knuth’s Computer Modern italic font was never intended to be unslanted. (The tail of the e did not originally stick out like that.) So here’s another example, which combines Asana Math with upright math letters from Neo Euler. These are clones of two famous fonts by Hermann Zapf (Palatino and AMS Euler) that complement each other very nicely. The text font (also used for operator names) is another clone of Palatino.

\documentclass[varwidth, preview]{standalone}

\usepackage{mathtools}
\usepackage[math-style=ISO]{unicode-math}

\setmainfont{TeX Gyre Pagella}
\defaultfontfeatures{Scale=MatchLowercase}
\setmathfont{Asana Math}
\setmathfont[range={up/{Latin,latin,Greek,greek},
bfup/{Latin,latin,Greek,greek}},
script-features={}, sscript-features={}
]{Neo Euler}

\newcommand\upe{\symup{e}}
\newcommand\upi{\symup{i}}

\begin{document}
\begin{align*}
\upe^{\upi x} &= \cos{x} + \upi \sin{x} \\
\upe^{\upi \uppi} + 1 &= 0
\end{align*}
\end{document}


Including the relevant text in a {\rm } bracket will fix it. So, using your example,

$$f(x) = x^2$$

would become

$${\rm f}(x) = x^2$$

by simply replacing f with {\rm f}

One thing to note is that the {\rm } does not change the math spacing, so writing some words will just put the characters in roman text rather than italicized, but with no spacing. I think \mathtext{} is the solution there.

• Old-fashioned text commands such as \rm are deprecated. There is a \text command in amsmath that handles size correctly, but it gives the text whatever formatting had been selected before entering math mode, so you would not use it for symbols without specifying the family, weight and series. – Davislor May 20 at 10:55