# LaTeX: Hyphens in Math Mode

Hyphens are sometimes necessary in LaTeX's math mode to structure long variable or function names. We present four ways to typeset them, two bad ones and two good ones. This discussion seems to be necessary since the knowledge about how to do it right is not wide-spread. See the example LaTeX code below for technical details.

In math mode, the hyphen symbol is typeset as minus sign, which is too long for an ordinary hyphen. Moreover, the spacing is wrong.

Putting the hyphen into an mbox (\mbox{-}) improves the situation: the length of the hyphen as well as the spacing is correct. However, size and font don't change with the surrounding math.

## Good: defining a mathchar

Define a new math character: \mathchardef\mhyphen="2D. The hyphen generated by \mhyphen has the correct length and spacing, and it changes size and font depending on the current settings in math mode.

## Good: defining an amsmath operator

The amsmath package provides the command \operatorname, which typesets hyphens correctly and also changes their size and font. The only restriction is that you are bound to the current operator font, usually upright.

## Example

See the following document for details:

Gernot Salzer, 2009-06-01