Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Can you explain me what is the difference between \textrm{} and \mathrm{} when they are used in math mode. In what context one is preferred over the other?

share|improve this question
2  
There's a similar question here, relating to \text vs. \mathrm. Is there a preference of when to use \text and \mathrm?. –  Alan Munn Jul 5 '11 at 5:37
    
@Alan Munn: Thanks for the link! –  Marco Jul 5 '11 at 5:56
    
The one is using text fonts and the other one math fonts which can be quite different, right? –  Martin Scharrer Jul 5 '11 at 7:10

1 Answer 1

up vote 27 down vote accepted

\textrm (and the corresponding switch \rmfamily) changes an aspect of the font – in this case the family. If possible other aspects – like the series (bold or not) or the shape (italic) – are preserved. \text...-commands can be nested and their "aspect changes" are combined:

\documentclass{article}
\usepackage[T1]{fontenc}

\begin{document}
\sffamily\bfseries\itshape abc
\textrm{abc}\textrm{\textup{abc}}
\end{document}

\mathrm and the other math alphabets don't change only an aspect of a font. They switch to specific fonts. They make it possible to print symbols in special fonts. It is quite possible to setup things so that e.g. \mathrm use times, \mathbf is a bold palatino, \mathit a slanted Arial etc. You can also confuse everyone by defining \mathbf to be light itshape palatino and \mathit a bold Arial. You can define your own special math fonts e.g. \mathvector or \mathmatrix or \mathfancy. As all these commands switch to dedicated font they can't be nested. The last command (the inner one) always wins:

\documentclass{article}
\usepackage[T1]{fontenc}

\begin{document}

$\mathit{A}
 \mathbf{A}
 \mathit{\mathbf{A}}
 \mathbf{\mathit{A}}$

\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.