[Tex/LaTex] Is it possible to typeset text inside math without amsmath

amsmathmath-modetext-mode

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?

Best Answer

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}

enter image description here