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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

It seems to be the de facto standard to use \mathrm for upright letter notation in math mode as opposed to \text. Would it not be better to use \text in general?

One particular problem I am thinking of is when writing in a sans serif-style document (e.g. beamer). In many cases here, your text and math is set in a sans serif font (for screen readability, I guess). Using \mathrm in this case causes the argument to appear in a roman font (with serifs), whereas using \text seems to correctly pick up that the text style in the document is sans serif and display the argument in upright sans serif.

So, would it not be better to generally use \text instead of \mathrm for "upright" notation in math mode?

share|improve this question

marked as duplicate by mafp, Kurt, Thorsten, Paul Gaborit, Werner Feb 13 '13 at 16:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

\text{} returns to the text mode and so it uses the current font. Also, try to type \alpha+\text{A_1}+x. – Sigur Feb 13 '13 at 10:31
Both macros have their own purpose. \mathrm still contains mathematical symbols, whereas \text explicitly marks text and as such returns to text mode (which is different from math mode). In math mode you have different typesetting rules (e.g. spacing) and on top of that by using them interchangeably you don't make use of the semantic mark-up either. Bottomline: I strongly advise aginst this practice! – Count Zero Feb 13 '13 at 10:34
I never use \mathrm. Upright letters only appear in operators for me, so I use \DeclareMathOperator. Otherwise it is text, so I use \text. – mafp Feb 13 '13 at 10:35
@mafp: Not only operators. The upright font must also be chosen in descriptive indices, such as in $\rho_\textrm{Water}$. Descriptive indices aren't variables, as opposed to, e. g., i in $x_i$ which is clearly a variable. – AlexG Feb 13 '13 at 11:21
@mafp: But \rho_{\text{Water}} won't give you upright Water in an italic context, so wouldn't \mathrm be the better choice? (Personally, I use the plain \rm ...) – Hendrik Vogt Feb 13 '13 at 14:20
up vote 15 down vote accepted

As has been said, \text is for text, and will change depending on the surrounding font. But math symbols in a document should always look the same: The meaning of a symbols also depends on the font used. So you should not use \text for mathematical symbols.

If you want an upright math font which adapts to the main document define it by using \familydefault:


\renewcommand\familydefault{\sfdefault} %comment to see the difference
\DeclareMathAlphabet      {\mathup}{OT1}{\familydefault}{m}{n}



$ a=\text{b}=\mathup{b}$

\itshape abc

$ a=\text{b}=\mathup{b}$

\sffamily abc

$ a=\text{b}=\mathup{b}$

share|improve this answer
Nice solution. I guess I had misunderstood \text as more of a "\mathup" solution, but the above definitely seems better. – Thomas Arildsen Feb 13 '13 at 10:50
In this answer to a similar topic you make mention of \textrm. Shouldn't this one be preferred over \text and \mathrm after all? – AlexG Feb 13 '13 at 11:09
@AlexG: None of the commands "should be preferred": It depends on the context: As shown above \text e.g. adjust itself to the current text font (it also adjust size when used e.g. in superscripts. It uses the sans serif family in the last line. \textrm switches always to the roman family. – Ulrike Fischer Feb 13 '13 at 11:34

How complicated does it become if we write the same equation with \text instead of \mathrm?

enter image description here

$\int f(x)\, \mathrm{d_a}x$

$\int f(x)\, \text{d$_\text{a}$}x$
share|improve this answer
Note: please ignore the mathematical aspect of the given expression above. – kiss my armpit Feb 13 '13 at 11:08
The shape of the \text version will change in a say a theorem environment where the surrounding text is italic. – Andrew Swann Feb 13 '13 at 11:21

that depends to your problem. \mathrm{...} uses always Computer Modern and \text{...} the current text font:

%% instead of libertine use the following two lines:

$\mathrm{Foo} \text{Foo}$


enter image description here

share|improve this answer
Unfortunately I don't have the libertine package, I guess. I'm getting this warning No file OT1fxl.fd. on input line 5. – Sigur Feb 13 '13 at 10:44
use another package eg \usepackage{mathpazo} – Herbert Feb 13 '13 at 11:12
@Sigur You have an encoding problem. Your LaTeX found libertine.sty, that's why it is looking for OT1fxl.fd. – mafp Feb 13 '13 at 14:49
\mathrm will use the font that is set to be used as roman math font. It can be changed from Computer Modern!! – rubenvb Nov 30 '15 at 15:30
@rubenvb: That is obvious that it can be changed to another font. – Herbert Nov 30 '15 at 18:30

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