TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
\text{max-color}, assuming you are using \usepackage{amsmath}. – Peter Grill Feb 14 '13 at 4:58
That appears to change the font, I am the variable name no longer looks like other math symbols. – Shamim Hafiz Feb 14 '13 at 5:01
In that case max\text{-}color will put just the dash into text mode. However, I would not recommend that you do that. – Peter Grill 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? – Shamim Hafiz Feb 14 '13 at 5:08
\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
up vote 8 down vote accepted

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

share|improve this answer

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.

share|improve this answer
Just curious... Why not simply \textit the whole thing? – T. Verron Feb 14 '13 at 9:27
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 – Andrew Swann 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. – Andrew Swann 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 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.