Text Formattingtextup vs math mode

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Jaraqui
Posts: 26
Joined: Wed Feb 08, 2012 3:54 am

textup vs math mode

Post by Jaraqui »

Hi,

I need to express Q_{-1}, but not in italic.
My attempts were:

Attempt #1
\textup{Q_{-1}}
this sintax showed what I want, generates error ("Missing $ inserted"), but it works.

Attempt #2
$\textup{Q_{-1}}$
this sintax showed nothing (a blank space), generates error ("Missing $ inserted"), and it didn´t work.

Attempt #3
\textup{$Q_{-1}$}
this sintax showed the expression in italic, generated no errors, and it didn´t work (as I need).

Even the attempt #1 is working, I am still looking for how to avoid the error message.

Any ideas?

Regards
Jaraqui
Last edited by cgnieder on Sat Sep 08, 2012 7:29 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

textup vs math mode

Post by cgnieder »

\textup ia text markup command and therefore cannot be used directly in math mode. The most simplest way would be the following:

Code: Select all

\documentclass{article}

\begin{document}

$\mathrm{Q}_{-1}$ $\mathrm{Q_{-1}}$

and to demonstrate \texttt{\textbackslash textup}:
\textit{upright \textup{text} in italic background}

\end{document}
Regards
site moderator & package author
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

textup vs math mode

Post by cgnieder »

For clarification what went wrong in your attempts lets first look at the definition of \textup. The following code:

Code: Select all

\documentclass{article}

\begin{document}

\ttfamily
\meaning\textup

\let\protect\meaning
\textup

\end{document}
generates:

Code: Select all

macro:->\protect \textup
\long macro:#1->\ifmmode \nfss@text {\upshape #1}\else \hmode@bgroup
\text@command {#1}\upshape \check@icl #1\check@icr \expandafter \egroup
\fi
This means that \textup is a protected macro which calls \protect\textup (this \textup is a macro name including a space at its end).
\textup now checks if it is called in math mode (\ifmmode). If the test is true it calls \nfss@text which basically is an \mbox. \mbox can be called anywhere and its argument is in text mode regardless if it is called in math mode or not. If the test is false it does some stuff that is not important to us right now. It boils down to \bgroup\upshape #1\egroup.

Now, what happens in case #1: \textup{Q_{-1}} ?
We're not in math mode so Q_{-1} is simply typeset in upright text in text mode. But since _ is not allowed in text mode you're getting the error “Missing $ inserted”.

Case #2: $\textup{Q_{-1}}$
We're in math mode, so \mbox{Q_{-1}} is called. But since the argument of \mbox is typeset in text mode the same error is raised.

Case #3: \textup{$Q_{-1}$}
This is essentially the same as $Q_{-1}$ (the effect of \upshape vanishes when math mode is entered with the $).

Regards
site moderator & package author
Jaraqui
Posts: 26
Joined: Wed Feb 08, 2012 3:54 am

Re: textup vs math mode

Post by Jaraqui »

perfect!

With your help I found other math types as mathcal, mathbf, mathsf, and others in MITTELBACH(2004, p. 349).

Thank you people!
Jaraqui
Post Reply