The command intended for this purpose is \mathrm
.
The \DeclareMathOperator
and \operatorname
commands are intended for log-like operators such as log
or cos
. The \text
command is intended for short passages of text in math mode, such as “$x$ is even” and “otherwise” next to cases. The \mathop
command does not change the font or its kerning, although you can wrap \mathop{\mathrm #1}}
to get operator-like spacing. The \mathit
command is usually not visually distinct from the default math font, but it could be a valid stylistic choice.
Sans-serif fonts frequently have a different meaning:
Sans-serif upright characters may be used in technical and/or physical texts in order to mark objects that cannot be confused with mathematical symbols, for example for the names of points in the description of geometrical figures, technical objects, experimental setups, and the like. Therefore sans-serif upright letters never appear in a mathematical formula of a physicist or an engineer, while mathematicians use sans-serif fonts to represent certain structures in category theory. As a partial exception, sans-serif sloping uppercase letters are allowed to indicate tensors of the second rank,but this is the only exception mentioned [....]
Since that article appeared in TUGboat more than twenty years ago, things have changed, but most documents that would use sans-serif fonts for full-word variable names also use them as the main font throughout. Therefore, it’s semantically misleading to declare that you want to use the mathematical sans-serif font for this; you really want to use the mathematical upright font. If you copied and pasted the formula into another document, you would want it to be set in that document’s mathematical upright font, to match the rest of the document.
The unicode-math
package defines one other option, \mathup
. If backward-compatibility with legacy 8-bit fonts isn’t a concern, I prefer that over the other alternatives because it means, “The default upright font for mathematics, which might or might not be Roman, and can be distinct from the main text font you get with \text
, the operator font, or the upright individual math symbols you get with \symup
.”
In practice, I would typically declare a \newcomamnd
for \mathop{\mathup{#1}}
or \mathop{\mathrm{#1}}
. Sometimes I’ve declared it as \mathop{\text{\scshape #1}}
to get small caps. That lets me declare the semantics I want, within the body of the document, not a particular appearance that might change between documents. Editing a bunch of \mathrm
commands to \mathsf
or \text
or \operatorname
is tedious and error-prone. Much better to choose a self-explanatory command and define its appearance in the preamble.
\text{name}
in the statement of a theorem.\textit{text $\text{text}$ text}
, what ever solution is used, should not change its apparence if used in say a theorem.\text
the correct way. When you got a hammer, everything looks like a nail.\text{else}
is a textual comment, not a math variable.\text
is only suppose to be used for textual comments\mathrm
would be my choice. The operator-related things are for spacing, as David notes, and anything that has a\text...
in it is for written text (for example, it preserves text spacing, not math spacing; compare\textrm{na me}
tp\mathrm{na me}
). I exclude\mathit
because of the math convention that single-letter variables are set in italic. By process of exclusion, we arrive at\mathrm
which will, by the way, properly set in subscript mode.