Typesetting multi-letter variable names in math mode
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.
Based on the very useful comments to my question, here's an overview (all credit goes to the people that commented on my question):
A summary of the points that were raised:
Do:
\mathrm
,\mathit
, and\mathsf
take care of the kerning, but leave everything else as is. Choice between them seems to be a matter of taste. Though a possible concern is that\mathit
may lead to confusions because single-letter variables are set in\mathit
.
Don't:
\text
, because it uses whatever is the current text-font, i.e. it changes it's appearance depending on the context.\mathop
, because it increases the spacing after the varname (and used alone does not help with the kerning)\DeclareMathOperator
because (in the same way as\mathop
) it affects spacing between the varname and subsequent things.
The code for the overview above
\documentclass{article}
\usepackage{amsmath}
\usepackage{pgffor}
\def\v{sff}
\DeclareMathOperator{\vO}{\v}
\begin{document}
\foreach \c in {\text,\mathop,\mathrm,\mathit,\mathsf} {
\detokenize\expandafter{\c}:
\(\c{\v}\), %as shown in mathmode
\emph{\(\c{\v}\)}, %what happens if I refer back to it from the text, using \emph{}
\(\frac{\c{\v}}{\c{\v}}\c{\v}x_{\c{\v}}\) %how it integrates with other things in formulas
}
\detokenize{\DeclareMathOperator}:
\(\vO\), %as shown in mathmode
\emph{\(\vO\)}, %what happens if I refer back to it from the text, using \emph{}
\(\frac{\vO}{\vO}\vO x_{\vO}\) %how it integrates with other things in formulas
\end{document}