# Is it possible to typeset text inside math without amsmath?

Is it possible to typeset text properly inside math without amsmath?

Typically I typeset short text using mathrm, or text (amsmath) within equation:

$M_\mathrm{effective mass}$
$M_\text{effective mass}$


\mathrm works most of the time but is not a real text environment (for example the spaces are ignored as in math mode). On the other hand \text depends on amsmath.

The question is, is possible to create the same result as with text but without using amsmath?

-

To have a functionality similar to amsmath's \text, but without loading any of the AMS-family packages, you can simply copy into your preamble a modification of the code for \text from amstext.sty:

\documentclass{article}

\makeatletter
\DeclareRobustCommand{\text}{%
\ifmmode\expandafter\text@\else\expandafter\mbox\fi}
\let\nfss@text\text
\def\text@#1{{\mathchoice
{\textdef@\displaystyle\f@size{#1}}%
{\textdef@\textstyle\f@size{#1}}%
{\textdef@\textstyle\sf@size{#1}}%
{\textdef@\textstyle \ssf@size{#1}}%
\check@mathfonts
}%
}
\def\textdef@#1#2#3{\hbox{{%
\everymath{#1}%
\let\f@size#2\selectfont
#3}}}
\makeatother

\begin{document}

$\text{effective mass}$

$M_\text{effective mass}$

$A_{M_\text{effective mass}}$

\end{document}


-
While this probably works, there much more in amstext than what appears here; the purpose of \iffirstchoice@, for instance, is avoiding that something important is executed four times. –  egreg May 14 '12 at 6:48
@egreg: Do mean that this solution is inefficient? What is executed four times? –  alfC Jun 1 '12 at 6:07
@alfC This is as efficient as \text; what I wanted to say is that \text takes even some other precaution. In both cases the argument of \text is typeset four times, and this is unavoidable, if you want that the text changes sizes in subscripts or superscripts. –  egreg Jun 1 '12 at 6:21

Edit

Defining a macro \mtext (which can be used like \text from amsmath) as:

\documentclass{article}
\newcommand{\mtext}[1]{%
{\mbox{\tiny #1}}%
}%

\begin{document}
$M_\mtext{effective mass}$ is the effective mass.
\end{document}


First try Use \mbox{}.

\documentclass{article}
\begin{document}
$M_{\mbox{effective mass}}$
\end{document}


Note While using as subscript or superscipt, put \mbox{} inside braces like _{\mbox{...}}.

-
thanks for the answer. two details: 1) it is unfortunate that one needs the extra braces, 2) when using in sub/superscript the resulting text is not smaller but the same as normal text. –  alfC May 14 '12 at 0:31
@alfC: 1. Can't help with extra braces. No alternatives. 2. It is because the content inside is in text mode. You can reduce the size by issuing \footnotesize manually. You can write a macro to automate things. –  Harish Kumar May 14 '12 at 0:44
ok, so I guess this is the reason that \text in amsmath exists, so it can take care of all this automatically. –  alfC May 14 '12 at 0:45
@alfC: See the edit in my answer. –  Harish Kumar May 14 '12 at 0:51