Take the 2-minute tour ×
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.

The built-in commands for text in math mode, such as \sup, are formatted very nicely. How can I define a macro for some short text that is to appear multiple times in math mode (such as "diam"), so that it mimics the formatting of something like \sup?

share|improve this question
add comment

1 Answer

up vote 13 down vote accepted

With the amsmath package loaded:

\DeclareMathOperator{\diam}{diam}

in your preamble. Use it in an equation with \diam. This will give you the upright text that you want, and the proper spacing. See section 5.1 of the amsmath documentation for more details. For single use, instead of defining a macro \operatorname{diam} will have the same effect if you use it directly inside an equation.

For bits of text that are not functions in the mathematical sense, e.g. if you want to put some upright text in a subscript, this package also makes the \text{...} command available. You can use this in a \newcommand as usual. See this question for a demonstration of the \text command.

share|improve this answer
3  
You could also mention \operatorname for cases where an operator is only used once and defining a specific macro is not useful. –  Bruno Le Floch Mar 18 '12 at 6:06
1  
Indeed, although the question specifies multiple use. I will add this. –  qubyte Mar 18 '12 at 9:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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