If I am in Math mode, and I want to name a variable, say max-color, here max and color are treated as two different variables and two spaces are placed around the minus sign. Now, what I really meant was a single variable called max-color. How to achieve this inside Math mode.

  • 3
    \text{max-color}, assuming you are using \usepackage{amsmath}. Feb 14 '13 at 4:58
  • That appears to change the font, I am the variable name no longer looks like other math symbols. Feb 14 '13 at 5:01
  • 1
    In that case max\text{-}color will put just the dash into text mode. However, I would not recommend that you do that. Feb 14 '13 at 5:03
  • Actually, I am trying to type out an algorithm where some variables are named this way. What would be the ideal way to achieve this? Feb 14 '13 at 5:08
  • 1
    \newcommand{\MaxColor}{\textnormal{max-color}} would be more suitable, see the answer to this question : tex.stackexchange.com/questions/98052/umlauts-in-math-mode .
    – T. Verron
    Feb 14 '13 at 6:20

You can take benefit of \operatorname which set things up so that in its argument hyphens give real hyphens and not minus signs:

\usepackage{amsmath} % only amsopn would suffice, actually

The additional pair of braces will keep the object from being considered an operator as far as spacing is concerned. If you want the variable name to appear in italics, change the definition into


In the following minimal example I use \varA for the first realization and \varB for the second one, take your pick.




enter image description here


In order to match the font of the other variables, it is probably best to use \mathit. However, this will still set the dash as a minus. To change that you can use \text, or for better consistency \textnormal around the dash, since \text adopts the font style of the text before the equation. The command \text requires amsmath, whereas \textnormal is a standard LaTeX command but it is improved by the amsmath package, so that it scales appropriately in subscripts, superscripts and fractions. Thus I recommend the following:

Sample output



\( \mathit{max\textnormal{-}color} \)

You can conveniently package this as a command via


EDIT I originally thought an extra level of braces around the definition would be needed to make this directly usable in a sub-/superscripts, but T.Verron pointed out they are not necessary in this case.

  • Just curious... Why not simply \textit the whole thing?
    – T. Verron
    Feb 14 '13 at 9:27
  • 2
    You could use \textnormal{\itshape ...}, but (a) \textit on its own will change in a bold context, (b) there is no guarantee that the text itshape font is the same as the mathit font Feb 14 '13 at 9:39
  • Thank you a lot, that's indeed good reason. On a side note, I just tested it, the extra level of braces you mention in your last command definition seems superfluous. Latex seems to perform smarter command expansion than Tex. :)
    – T. Verron
    Feb 14 '13 at 9:49
  • @T.Verron You are right about the brackets! It seems to be some special property of these font changing commands. Feb 14 '13 at 12:54
  • @AndrewSwann The expansion of \mathit starts, after some work, with \bgroup, followed by the font selection internal command; TeX accepts _\bgroup...\egroup as equivalent to _{...}
    – egreg
    Feb 14 '13 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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