# Typesetting multi-letter variable names in math mode

In many applications variable names in formulas have more than one letter. In order not to mess up kerning, one cannot simply write $nameff=123$. People seem to use different approaches: \DeclareMathOperator, \text, \mathop, \mathit, \mathrm.

Some of them seem---by name---to be intended for operators, rather than variable names, which makes me worried that there could be unintended effects in some context that I might not foresee now, when using it for variable names.

Hence my question: What is the correct way to typeset multi-letter variable names, i.e., which command is intended for this use.

• Try \text{name} in the statement of a theorem. Apr 2, 2019 at 10:10
• (1) it uses the text font not the math font (depending on your document, they may look differently), (2) \textit{text $\text{text}$ text}, what ever solution is used, should not change its apparence if used in say a theorem. Apr 2, 2019 at 10:10
• Nowadays there are so many users who does nor know how to use \text the correct way. When you got a hammer, everything looks like a nail. Apr 2, 2019 at 10:12
• Remember \text{else} is a textual comment, not a math variable. \text is only suppose to be used for textual comments Apr 2, 2019 at 10:13
• \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. Apr 2, 2019 at 11:02

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}

• Still no \text should never be used to typeset math variables, please alter that. If a pseudo variable (like yearly income) is used like this, it is better to use \textup or \textnormal for it as they should always be upright (and remember \text is italic in italic contexts). Apr 3, 2019 at 8:58