Although many have attempted to explain the difference among \mathrm
, \textrm
, \textnormal
and \text
(and others?), I found them misleading.
See for example the LaTeX's Wiki \mathrm
explanation
Why is it wrong? Let's try all of them within an article
and a beamer
and you'll see the difference and, therefore, error.
equation.tex
\begin{eqnarray*}
\int_1^9\! \cos{x} \,\mathrm{d}x & & \textrm{this is textrm}\
\sum_1^9 y & & \textsf{this is textsf}\
\prod_1^9 z & & \textnormal{this is textnormal}\
\bigcup_1^9 w & & \text{and this is just text}
\end{eqnarray*}
article.tex
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
\input {equation}
\end{document}
And until here everything looks fine…
beamer.tex
\documentclass{beamer}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
\begin{frame}
\input{equation}
\end{frame}
\end{document}
And here we can clearly see that \mathrm
does not behave as expected, i.e. does not provide a function aspect to the d. Does anyone know what am I supposed to use here instead? Just \text
?? o.O
Moreover, I cannot see any difference between \textnormal
and \text
.
Finally, \textrm
looks useless..
Best Answer
You do not say what you expect
\mathrm
to do however it switches to the roman font font specified by the math version in use, which is what your images show.You will see the difference between
\text
(which switches to the current text font) and\textnormal
(which switches to the document default font) if you test it at a point where the current text font is not the default.\math....
commands are math mode commands which switch the font used for letters but the content is processed in math mode.\text...
commands are text mode commands which process their content in text mode, they are also allowed in math but process the commands in an hbox (by default) or ifamsmath
is loaded they use\text
internally so that they switch to smaller sizes in subscripts etc, however the setting is still in an hbox, so that the content is processed as text rather than math.When defining operators you should really use
\DeclareMathOperator
and not directly use font commands at all, then it works as you wish in beamer, giving sans serif. If you have existing expressions using\mathrm
and you want\mathrm
to behave like\mathsf
in beamer` you can redefine it as shown in the second expression below.