# Indices with German Umlaut ä - \mathrm{} or \text{}?

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 \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.

• How about \mathrm{\text{Äpfel}} ? ;-) – user31729 Jun 12 '15 at 11:14
• logically it would be \mathrm as it would be for an english abreviation, but sadly the world we live in isn't always logical. \textrm (which I'd use rather than \text) has the advantage of working. – David Carlisle Jun 12 '15 at 11:15
• @DavidCarlisle Isn't \textup better, as not to force the font into the rm variant? – daleif Jun 12 '15 at 11:28
• @daleif normally in math you want to force the font, just as \log uses a fixed font. – David Carlisle Jun 12 '15 at 11:32
• so you'd say that \mathrm{} should be correct, but it simply doesn't work with Ä Ö Ü? – zaddo Jun 12 '15 at 11:36

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}

• Do you know why it works when you change the default operators font to T1, but not if you declare a new symbolfont e.g. newoperators? – Ulrike Fischer Jun 12 '15 at 13:39
• @UlrikeFischer I noticed that:-) I'd need to step through the NFSS code there but I think basically multiple encodings aren't supported (because otherwise commands defined by \mathcode would fail in weird ways) but the declaration syntax sort of implies it should, Something to look at one weekend.... – David Carlisle Jun 12 '15 at 14:17
• But there are already multiple encodings see the letters and symbols fonts. It looks as if latex falls back to the default operator font for all chars above 128. I could output an ä in a new font with \mathrmx{\char228} after the commands \DeclareSymbolFont{myoperators}{T1}{phv} {m}{n} \DeclareMathSymbol{^^e4} {\mathalpha}{myoperators}{228} \DeclareSymbolFontAlphabet{\mathrmx} {myoperators} – Ulrike Fischer Jun 12 '15 at 14:52
• @UlrikeFischer yes but symbols fonts are only (sensibly) accessed through \mathchardef tokens, it is the mathalphabet and mathsymbolalphabet that need to map the encodings more explicitly to map input characters, but can't look at that during the day:-) – David Carlisle Jun 12 '15 at 14:55
• What I meant is that multiple encoding are imho not at the core of the question (e.g. \DeclareSymbolFont{myoperators}{LGR}{cmr} {m}{n} or \DeclareMathAlphabet{\mathgreek}{LGR}{cmr}{m}{n} work fine. The problem is the non-ASCII-range (and perhaps some other chars). – Ulrike Fischer Jun 12 '15 at 15:36

Just use \textrm{äq} for the subscript.

\documentclass{article}

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

\usepackage{mathtools}

\begin{document}

$A_{\textrm{Äpfel}}$

\end{document}


• I'd say \textup would be a better solution, \textrm switches to the current rm font. \textup use the current non-italic text font. It becomes a factor if the text is in sans-serif (and it is not the rm font) – daleif Jun 12 '15 at 11:27
• And I would personally use \textnormal. – Manuel Jun 12 '15 at 12:15
• @Manuel: Anybody uses a different style ;-) Even as a German I would not use Umlauts in subscripts... – user31729 Jun 12 '15 at 12:16
• @ChristianHupfer Yep, I posted it more or less to show that there's no clear way of doing it (at least there's no “official” way). – Manuel Jun 12 '15 at 12:17
• @henry have you tried \textit{test $A_{\text{test}}$ test}? – daleif Jun 12 '15 at 13:08

If you have a few textual subscripts and no special characters in them, use \mathrm; otherwise use \textnormal

The second method, however, has a drawback: it doesn't honor \mathversion{bold}, as seen from the following example.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\begin{document}

$A_{\mathrm{apple}}$

{\mathversion{bold}$A_{\mathrm{apple}}$}

$A_{\textnormal{Äpfel}}$

{\mathversion{bold}$A_{\textnormal{Äpfel}}$}

\end{document}


In the case of just a few of these subscripts, you can probably get away by adding \bfseries where needed; or, if you don't use bold math, there's nothing to worry about, probably. However, some classes (the Springer ones, for instance) add \mathversion{bold} (or the alias \boldmath) to the code for section titles.

Thus a personal command seems best:

\DeclareRobustCommand{\tsb}[1]{% textual subscript
\textnormal{\setupforversion#1}%
}

\makeatletter
\newcommand{\setupforversion}{%
\csname setupfor\math@version\endcsname
}
\makeatother

\newcommand{\setupfornormal}{}
\newcommand{\setupforbold}{\bfseries}
% set up also for possible other math versions you use


Full example

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\DeclareRobustCommand{\tsb}[1]{% textual subscript
\textnormal{\setupforversion#1}%
}

\makeatletter % some syntactic sugar
\newcommand{\setupforversion}{%
\csname setupfor\math@version\endcsname
}
\makeatother

% the commands to execute for the various versions
\newcommand{\setupfornormal}{}
\newcommand{\setupforbold}{\bfseries}

\begin{document}

$A_{\mathrm{apple}}$

{\mathversion{bold}$A_{\mathrm{apple}}$}

$A_{\tsb{Äpfel}}$

{\mathversion{bold}$A_{\tsb{Äpfel}}$}

\end{document}


Since I've been in doubt myself a few times (and not only with this), I think the best is to create an universal way of doing it so, in case one needs to change it, you just need to go back to the preamble.

With the code I post here the following syntax works: A_|whatever| (one could choose another like A_[foo] or A_(bar), but I prefer those for other things).

Basically we make _ active, and, if it's followed by a | then the argument is delimited by two |..| rather than {..}, and it's put in whatever font we choose.

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}

\makeatletter
\def\sbtext|#1|{\sb{\textnormal{#1}}}
\begingroup\lccode\~=\_\lowercase{\endgroup\def~}{\@ifnextchar|\sbtext\sb}
\makeatother

\AtBeginDocument{\catcode\_=12 \mathcode\_="8000 }

\begin{document}

$A_{\mathrm{apple}}$

$A_|apple|$

$A_|Äpfel|$

$A_{\textnormal{Äpfel}}$

\end{document}