# How do I make \text{} in math mode fit the math font?

I am having a problem with text in formulas. I am setting tables in sans-serif in order to improve the readability. The math font stays serif for formulas or symbols within the table, when I switch with \sffamiliy directly before \begin{tabular}. I think that's good, because the symbols stay the same over the whole document and are recognizable.

But, when setting indices which are used as abbreviations with _\text{index}, this text of course changes to sans, too. That gives me three different symbols where two different what be easier to understand.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
The mass flow $q_m$ is different from the average heat flow $q_\text{m}$

\sffamily
The mass flow $q_m$ is different from the average heat flow $q_\text{m}$
\end{document}


First of all I wonder how to prevent this behavior and second: What is best practice for this case? How do you type set text indices? Should the math mode follow the text mode and possibly confuse the lector?

An other example are characteristic numbers which should be (Forssmann/Jong) set to circumferential Mach-number $\textit{Ma}_u$ or Reynolds-number over hyd. diameter $\textit{Re}_{D_{\text{h}}}$.

Edit

I am playing around a little with \mathrm and \text. Still not sure, what should be used where. The font is the same for serifs. Using unicode-math or redefining \mathrm however would give different appearances for those outputs. I think that is good, as d for differential should/could look different as d for abbreviation of dynamic. $\frac{\mathrm{d}p_\text{d}}{\mathrm{d}t}$

What I noticed further more:

• \mathrm ignores spaces but not \, etc.
• \mathrm and \text are setting indices in a different distance

This code:

Mach-number, total, mean and mass specific values:

$\textit{Ma}_u$; $\mathit{Ma}_u$

$q_m$; $q_{\text{m\,tot}}$; $q_{\text{m tot}}$; $q_{\text{m,tot}}$; $q_{\text{m, tot}}$

$q_m$; $q_{\mathrm{m\,tot}}$; $q_{\mathrm{m tot}}$; $q_{\mathrm{m,tot}}$; $q_{\mathrm{m, tot}}$

\sffamily
Mach-number, total, mean and mass specific values:

$\textit{Ma}_u$; $\mathit{Ma}_u$

$q_m$; $q_{\text{m\,tot}}$; $q_{\text{m tot}}$; $q_{\text{m,tot}}$; $q_{\text{m, tot}}$

$q_m$; $q_{\mathrm{m\,tot}}$; $q_{\mathrm{m tot}}$; $q_{\mathrm{m,tot}}$; $q_{\mathrm{m, tot}}$


looks like:

• is the above code supposed to work as shown? I copy it, run pdflatex on it, and get an error: ! Undefined control sequence. l.3 ...fferent from the average heat flow $q_\text {m}$ ? I am using TL 2013 on Linux mint Jul 24, 2013 at 8:32
• @Nasser Don't know why, but on my system it runs. However on ShareLaTeX I got the same error like you so I added mathtools to my MWE Jul 24, 2013 at 8:38
• thanks, yes now it compiles on TL2013 with no error. Jul 24, 2013 at 8:40
• Here it is MikTeX 2.9 on Win XP. Lua- and PDFTeX tested. Ahh: My error. I had siunitx loaded which seems to give enough math support as well. Jul 24, 2013 at 8:43
• You are misusing the \text command. It is meant to switch to the (surrounding) text mode, not to give you a roman font. If you want a fix math font, use one of the math alphabets e.g. $q_{\mathrm{m}}$ Jul 24, 2013 at 9:01

When using \text{} you just switch to the family around the mathmode. You could always use \textrm to force the serif family. So I would write

\documentclass{article}
\usepackage{mathtools}
\begin{document}
The mass flow $q_m$ is different from the average heat flow $q_\textrm{m}$

\sffamily
The mass flow $q_m$ is different from the average heat flow $q_\textrm{m}$
\end{document}

• I disagree. \mathrm should be used for symbols not for text (tex.stackexchange.com/a/19503/32245). In future I am going to use unicode-math which brings a different font. For the index that might be OK but for the characteristics I need a text italic. Maybe setting the Mach-number in sans is good typesetting then... I'm really not sure. Jul 24, 2013 at 9:14
• it works for so far, but I have the feeling, that \text, \mathrm and \operatorname still need some discussion. Nobody seems to be quite sure about when to use what. As it works for this particular case, I mark it as an answer. Thank you. Jul 29, 2013 at 12:25