# Why does \mathrm{\varphi} work, but \text{\varphi} does not?

This:

\documentclass{article}

\usepackage{amsmath}

\begin{document}
$\mathrm{\varphi}$
\end{document}


Versus:

\documentclass{article}

\usepackage{amsmath}

\begin{document}
$\text{\varphi}$
\end{document}


The first works, the last does not. Why? Especially when defining macros with \text this can lead to problems. Any way around it?

-
There is no reason whatsoever why the second should work: \text is for inserting text in a math formula. The fact that \mathrm{\phi} works is just a coincidence, but the result is in no way different from \phi. – egreg Nov 9 '12 at 17:05

\varphi is a math symbol and requires math mode. Since \mathrm still "provides" math mode, \varphi doesn't complain. On the other hand, \text (from amstext; loaded by amsmath) is a macro that makes the correct choice in font size when switching to text mode - super convenient when typesetting test in exponents/subscripts. However, it still switches to text mode.

If you which to use \varphi in text mode without having to switch to math mode explicitly, use something like

\newcommand{\textphi}{\ensuremath{\varphi}}


which will allow you to use \textphi in either text or math mode. The \ensuremath conditional switches to math mode only when necessary (when you're in text mode, say).

\documentclass{article}
\newcommand{\textphi}{\ensuremath{\varphi}}
\begin{document}
$\varphi^\varphi\ \textphi^\textphi$\ \textphi\textsuperscript{\textphi}
\end{document}

-

Because \varphi is math mode only. As far as I’m concerned, there is no text mode alternative.

The only text mode alternative would be \textphi, but for using it you have to include the package tipa. Also, it’s just a plain normal phi.

-
Does \text{} leave math mode? – Foo Bar Nov 9 '12 at 16:54
@FooBar That’s what text says, isn’t it? ;) – PattaFeuFeu Nov 9 '12 at 16:55
But text is a math mode command, so I'd assume it is fully math mode compatible. ;) – Foo Bar Nov 9 '12 at 16:59
@FooBar Touché. Yet still, text is to use “words or phrases in a display.” (AMSmath documentation). – PattaFeuFeu Nov 9 '12 at 17:01