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