Use \operatorname for operators, \mathrm for ordinary text.
The command \operatorname treats text like a function name, adding the correct spacing and handling punctuation, while \mathrm treats text as an ordinary letter. Using the wrong one leads to awkward spacing and incorrect formatting in your equations.
The short answer: use \operatorname (or \DeclareMathOperator) for operators like sin or custom functions. Use \mathrm only when you need a piece of text to appear in upright roman font without any special operator spacing.
Why it matters
In LaTeX, math mode treats characters as variables by default, which is why they appear in italics. Commands like \mathrm and \operatorname force upright roman type, but they do it differently.
\operatorname is designed for math operators. It adds thin spaces around the text so it doesn't crowd the surrounding variables, and it handles punctuation correctly. \mathrm is a simple font switch. It changes the font to roman but keeps the text as an ordinary math atom, meaning it ignores the spacing rules that govern operators.
See the difference
Best practices
| Case | Recommended Command |
|---|---|
| Standard operators (sin, log, etc.) | Use built-in macros |
| Custom operators used multiple times | \DeclareMathOperator{\name}{name} |
| Custom operators used once | \operatorname{name} |
| Ordinary text inside math |
Handling limits
| Command | Behavior |
|---|---|
| \operatorname{name} | Subscripts appear to the side |
| \operatorname*{name} | Subscripts appear below |
| \DeclareMathOperator{\name}{name} | Standard operator definition |
| \DeclareMathOperator*{\name}{name} | Operator with limits |
Some operators, like \lim or \max, place subscripts below the text in display mode. You can replicate this behavior for your own custom operators using the starred version of the command.
Questions
What does 'rm' stand for in \mathrm?
It stands for 'roman'. In typography, roman refers to the upright, non-italicized font style that is standard for text.
Why does my hyphen look like a minus sign?
\mathrm treats the hyphen as a mathematical minus operator. \operatorname correctly recognizes it as a punctuation mark.
Should I use \text instead of \mathrm?
\text is useful for actual words inside math mode because it respects the surrounding text font and size. \mathrm is strictly for upright roman characters in math mode.
Try your own paper in Texeno.
Start free, upload a project as a .zip and press Recompile. Upgrade when you need longer compiles.
Start writing