0

Often I want to define a math symbol with a subscript or a superscript that is a word. Typically I use \text for this purpose, e.g. X_\text{word}, because (as I understand it) \text will use text spacing whereas \mathrm will typeset it as if it was w times o times r times d, and that might lead to different spacing.

However, I've noticed that in italic text (such as in theorem environment) \text will typeset "word" in italic, not roman. I don't think that's what I want it to do, because although 'word' is a word, in this case it's part of a math symbol, and I don't think the symbol should look different in a theorem environment from normal text.

Surprisingly, \textrm behaves the same as \text, setting the word in italic when used in a theorem environment. (This is true regardless of whether amsmath is loaded, but if amsmath is not loaded then it will also be the wrong size.)

So then the question is, what's the right command for this use case?

In the MWE below, the \mathrm version looks identical to the \text version in normal text - it doesn't have the weird spacing between letters that I was expecting. (I tried a few other words besides "word" but didn't find one where it looked different.) So part of this question is, am I just wrong about the behaviour of \mathrm - can I rely on it producing correct spacing for a word? If not, is there a command that does produce the correct spacing for a word, but always typesets it in roman?

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}

\newcommand{\xwordi}{{X_\text{word}}}
\newcommand{\xwordii}{{X_\textrm{word}}}
\newcommand{\xwordiii}{{X_\mathrm{word}}}
\newcommand{\xwordiv}{{X_{\operatorname{word}}}}

\begin{document}

Here is $\xwordi$ (i) in a text environment. And in a superscript: $e^\xwordi$.

\begin{theorem}
    Here is $\xwordi$ (i) in a theorem environment. 
\end{theorem}

Here is $\xwordii$ (ii) in a text environment. And in a superscript: $e^\xwordii$.

\begin{theorem}
    Here is $\xwordii$ (ii) in a theorem environment.
\end{theorem}

Here is $\xwordiii$ (iii) in a text environment. And in a superscript: $e^\xwordiii$.

\begin{theorem}
    Here is $\xwordiii$ (iii) in a theorem environment.
\end{theorem}

Here is $\xwordiv$ (iv) in a text environment. And in a superscript: $e^\xwordiv$.

\begin{theorem}
    Here is $\xwordiv$ (iv) in a theorem environment.
\end{theorem}

\end{document}

enter image description here

3
  • 2
    Give \textnormal{…} or \textup{…} a try. (I’m pretty sure this is a dupe.)
    – Mico
    May 30, 2023 at 5:42
  • 1
    @Mico thanks, both seem to work. I'd be surprised if someone hasn't asked this before, but I did search for duplicates before asking and wasn't able to find one.
    – N. Virgo
    May 30, 2023 at 5:53
  • 1
    This one is fairly close to a duplicate. (I only found it when searching for "textnormal vs textup". tex.stackexchange.com/questions/98406/…. Additionally this one has a nice answer by @Mico explaining the differences in behaviour between the various options. (Again found by searching for textnormal and textup.) tex.stackexchange.com/questions/244657/…. (In summary it looks like \textnomal is the best option.)
    – N. Virgo
    May 30, 2023 at 6:02

1 Answer 1

2

If you literally mean, always in Roman, you probably want \text{\rmfamily\upshape #1} from amsmath (or more precisely, amstext). You can use any text-mode commands inside \text, including selecting any font family you please. If you use this in a math expression, and want spacing like the log or cos operators, use \mathop{\text{\rmfamily\upshape #1}}\nolimits.

For math symbols that should be typeset as individual letters and not as words, use \mathrm, or \symup if you are using unicode-math.

Note that the reason I don’t just use \textnormal is to inherit the font weight of the surrounding text. This allows me to add \boldmath\bfseries to the formatting of my section headers, and get matching bold text and math. If you use medium-weight math even in bold headers, you would prefer \textnormal.

You also don’t want to use only \textrm, as that would give you italics if you happen to use it in an italic block (such as a theorem statement from amsthm).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .