[Tex/LaTex] Indices with German Umlaut ä – \mathrm{} or \text{}

amsmathmath-mode

I'm wondering about the correct use of \mathrm{} and/or \text{} (or similar) in formulas. I've read these topics (and some more):

Is there a preference of when to use \text and \mathrm? and

Difference between \textrm{} and \mathrm{} and

Is \mathrm really preferable to \text? [duplicate]

but I'm not fully satisfied with my findings yet. As far as I understood it's best to use \text{} for something like:

$ a = b \text{if, and only if, ...} $ or $ C = \text{const.} $

while \mathrm{} would be used for indices, like

$ \rho_\mathrm{water} $ or $ m_\mathrm{main} $

because \text{} does not necessarily provide upright font (e.g. in an italic context).

My problem with \mathrm{} is that it doesn't accept German umlauts. I want to name a parameter $ m_{äq} $, which is short for for "m äquivalent" (an equivalent mass). When I use m_\mathrm{äq} the "ä" will not be visible, even m_\mathrm{{\"a}q} doesn't work. m_\text{äq} works fine, but it feels like \text{} is not the correct command in this case.

I'm using mathtools (including amsmath) and

\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

if this is of any importance.

Best Answer

You should do use \textup or \textrm as noted in comments.

The reason why it doesn't work is that even if you specify T1 for text math still uses the 7bit OT1 encoding for Roman letters.

You can change that:

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{mathtools}

\DeclareSymbolFont{operators}{T1}{cmr} {m}{n}
\makeatletter
\def\@inmathwarn#1{}
\makeatother

\begin{document}



$A_{\mathrm{Äpfel}}$



\end{document}

which works but try

$\Gamma=\Delta$

and you find that Uppercase greek (and several other commands, notably math accents) are expecting the OT1 encoding. Of course you could assign Greek to another font family and redefine all the commands, but many many packages would then need variant versions of their definitions to match the new setup.


A working version:

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\DeclareSymbolFont{mathrmx}{T1}{cmr} {m}{n}

\DeclareSymbolFontAlphabet\mathrmx{mathrmx}
\usepackage{mathtools}

% make Ä follow the current math alphabet rather than
% use fam0 which os cmr which does not have the character.
\mathcode"C4="71C4


\makeatletter
\def\@inmathwarn#1{}
\makeatother

\begin{document}
\huge

$A_{\mathrmx{Äpfel}}$


$\Gamma=\Delta$

\end{document}