Make \mathrm produce upright greek

greekmath-moderoman

I need to distinguish between italic and upright greek letters. I use the alphabeta package for that. This allows me to write e.g. an upright \mu in mathmode by typing $\text\mu$. Can I extend this in such a way that also \mathrm produces the upright \mu?

\documentclass{article}

\usepackage{amsmath}
\usepackage{alphabeta}

\begin{document}

\begin{align}
\text{is italic mu: } & \mu \mathit \mu\\
\text{should be upright mu: } & \text \mu \mathrm \mu
\end{align}

\end{document}

Best Answer

A solution for pdftex. Wildly untested, so there might be issues I haven't thought of. Note that alphabeta cannot be loaded, but its basic functionality is provided.

\documentclass{article}

\usepackage{amsmath}% for \text
\usepackage{bm}
\usepackage{textalpha}

\makeatletter

\def\@tempa#1#2#3{%
   \let#2=#1
   \def#1{\TextOrMath{#3}{\ifnum\fam=0 \text{#3}\else#2\fi}}%
}

\@tempa\alpha\mathalpha\textalpha
\@tempa\beta\mathbeta\textbeta
\@tempa\gamma\mathgamma\textgamma
\@tempa\delta\mathdelta\textdelta
\@tempa\epsilon\mathepsilon\textepsilon
\@tempa\zeta\mathzeta\textzeta
\@tempa\eta\matheta\texteta
\@tempa\theta\maththeta\texttheta
\@tempa\vartheta\mathvartheta\texttheta
\@tempa\iota\mathiota\textiota
\@tempa\kappa\mathkappa\textkappa
\@tempa\lambda\mathlambda\textlambda
\@tempa\mu\mathmu\textmu
\@tempa\mnu\mathmnu\textmnu
\@tempa\xi\mathxi\textxi
\@tempa\rho\mathrho\textrho
\@tempa\varrho\mathvarrho\textrho
\@tempa\sigma\mathsigma\textsigma
\@tempa\tau\mathtau\texttau
\@tempa\upsilon\mathupsilon\textupsilon
\@tempa\phi\mathphi\textphi
\@tempa\chi\mathchi\textchi
\@tempa\psi\mathpsi\textpsi
\@tempa\omega\mathomega\textomega

\makeatother

\begin{document}

See \alpha\beta\gamma, but \theta\vartheta\ or \rho\varrho.\par
Normal: $a\alpha l\lambda r\rho\varrho x_{\mu}$\par
With \verb+\mathrm+: $\mathrm{a\alpha l\lambda r\rho\varrho x_{\mu}}$\par
With \verb+\bm+: $\bm{\alpha}$, but $\bm{\mathrm{\alpha}} $

\end{document}

enter image description here