18
\documentclass[11pt,a4paper]{article}
\title{Title}
\author{Author}
\begin{document}
\maketitle
$\{ n \mid n\ \mbox{is\ even} \}$

\end{document}

Since it is a relatively rare occasion for me to display upright letters in math mode, I kind of ignored this problem for a long time. But recently, when I prepared my tutoring notes, I found manually creating space is annoying. I thus wonder if there is any way out?

I would also like to know if it is possible to display upright letters without commands such as "\mbox" or "\textup" in math mode?

8
  • 2
    Just put the space inside the \mbox, and there's no need for control space (\ ) inside. Better yet, do that but use \text from amsmath or \textrm, etc., instead of \mbox. May 13, 2015 at 2:19
  • Thanks. But how to prevent the space stolen by putting $n$ and $\mbox{is even}$ side by side?
    – Yes
    May 13, 2015 at 2:21
  • As I said, put the space inside: $\{ n \mid n \textrm{ is even} \}$. May 13, 2015 at 2:22
  • Is "\text" better or is "\textrm" better? According to my trials, they behave equally well. @PaulGessler
    – Yes
    May 13, 2015 at 2:25
  • It depends what you're after: \text will match the local text font, so if you want it to match the surrounding text, use that. The specific commands (\textrm, \textit, \textbf) are "absolute", so this might be used if you were setting up a specific notation that should be independent of the surrounding text. May 13, 2015 at 2:27

1 Answer 1

24

You have several options. A comment up front: \mathrm isn't among your options, as you'd have to manually insert interword space markers. (Aside: I would also insert thinspace directives after the opening curly brace and before the closing curly brace.)

  • "Basic LaTeX": \mbox

    $\{\, n \mid n \mbox{ is even} \,\}$
    
  • With the amsmath package loaded: \text

    $\{\, n \mid \text{$n$ is even} \,\}$
    

    Observe that the second n is part of the argument of \text because the phrase "n is even" is a syntactic unit. The fact that "n" should be rendered in math italics is subordinate to the syntactic concern.

  • Additional considerations. The \mbox and \text macros render their arguments in the font style that's in effect for the "surrounding" text material. Usually, the "surrounding" style will be ordinary or upright lettering mode. However, if the expression ${\, n \mid \text{$n$ is even} \,}$ occurs in a theorem-like environment, which generally renders ordinary text in italics, the argument of \mbox and \text will be set in italics as well. If that's not what you want, you should write either

    $\{\, n \mid \textnormal{$n$ is even} \,\}$
    

or

    $\{\, n \mid \textup{$n$ is even} \,\}$
  • The following examples examine the output that's generated by \mbox, \text, \textrm, \textnormal, and \textup to encase the clause $n$ is even. Note that, depending on the font style that's in effect for the material that surrounds the math stuff, the five macros may and will generate differing outcomes.

    The only fail-safe way to "guarantee" that the clause will always be typeset with upright serif ("roman") characters is to use the composite command \textrm{\textup{...}}. However, depending on the font settings that are in effect for your document, using the composite command need not be optimal. For instance, in a beamer document that uses sans-serif fonts for text and math material, it wouln't be correct to use the composite command.

enter image description here

\documentclass{article}
\usepackage{amsmath,array}
\setlength\parindent{0pt} % just for this example
\newcommand{\myexample}{\par
   $\begin{array}{@{}l >{$\upshape}l<{$}}
   \{\, n \mid n \mbox{ is even} \,\}        & {\ttfamily \string\mbox}\\
   \{\, n \mid \text{$n$ is even} \,\}       & {\ttfamily \string\text}\\
   \{\, n \mid \textrm{$n$ is even} \,\}     & {\ttfamily \string\textrm}\\
   \{\, n \mid \textnormal{$n$ is even} \,\} & {\ttfamily \string\textnormal}\\
   \{\, n \mid \textup{$n$ is even} \,\}     & {\ttfamily \string\textup}\\
   \{\, n \mid \textup{\textrm{$n$ is even}} \,\}     & {\ttfamily \string\textup/\string\textrm\ combined}\\
   \end{array}$}

\begin{document}

Surrounding text mode: ``normal,'' i.e., upright/serif
\myexample

\bigskip
{\itshape Surrounding text mode italics \myexample}

\bigskip
{\sffamily Surrounding text mode sans-serif/upright\myexample}

\bigskip
{\renewcommand\familydefault\sfdefault 
Surrounding text mode: ``normal text mode'' reset to sans-serif, but current text mode is serif\slash upright 
\myexample}

\bigskip
{\renewcommand\familydefault\sfdefault 
\sffamily\itshape
Surrounding text mode: ``normal text mode'' reset to sans-serif, current text mode is sans-serif\slash italic
\myexample}

\end{document}
2
  • 3
    Very good illustration.
    – user11232
    May 13, 2015 at 8:10
  • 1
    I removed some comments which were opinions, I hope that's ok.
    – Stefan Kottwitz
    Sep 21, 2021 at 6:42

You must log in to answer this question.

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