\documentclass{article}
\usepackage{amsopn}

\begin{document}
\title{\LaTeX: Hyphens in Math Mode}
\author{Gernot Salzer, salzer@logic.at}
\date{9 December 2008, updated 1 June 2009}
\maketitle

\begin{abstract}
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.
\end{abstract}

\section*{Bad: typing hyphens directly}

In math mode, the hyphen symbol is typeset as minus sign, which is
too long for an ordinary hyphen. Moreover, the spacing is wrong.
\begin{quote}
\begin{tabular}{ll}
\verb|$\mathit{non-unique}$| & $\mathit{non-unique}$ \\
\verb|$\mathrm{non-unique}$| & $\mathrm{non-unique}$ \\
\verb|$A_{\mathit{non-unique}}$| & $A_{\mathit{non-unique}}$ \\
\verb|\boldmath $A_{\mathit{non-unique}}$| & \boldmath $A_{\mathit{non-unique}}$
\end{tabular}
\end{quote}

\section*{Bad: using mboxes}

Putting the hyphen into an 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.

\begin{quote}
\begin{tabular}{ll}
\verb|$\mathit{non\mbox{-}unique}$| & $\mathit{non\mbox{-}unique}$ \\
\verb|$\mbox{non-unique}$| & $\mbox{non-unique}$ \\
\verb|$\mathrm{non\mbox{-}unique}$| & $\mathrm{non\mbox{-}unique}$ \\
\verb|$A_{\mathit{non\mbox{-}unique}}$| & $A_{\mathit{non\mbox{-}unique}}$ \\
\verb|\boldmath$A_{\mbox{non-unique}}$| & \boldmath$A_{\mbox{non-unique}}$
\end{tabular}
\end{quote}

\section*{Good: defining a mathchar}

To obtain a proper hyphen that changes with the surrounding math
we define a new math character:
\begin{quote}
\mathchardef\mhyphen="2D
\begin{tabular}{ll}
\verb|\mathchardef\mhyphen="2D| &  \\[1ex]
\verb|$\mathit{non\mhyphen unique}$| & $\mathit{non\mhyphen unique}$ \\
\verb|$\mathrm{non\mhyphen unique}$| & $\mathrm{non\mhyphen unique}$ \\
\verb|$A_{\mathit{non\mhyphen unique}}$| & $A_{\mathit{non\mhyphen unique}}$ \\
\verb|\boldmath$A_{\mathit{non\mhyphen unique}}$| & \boldmath$A_{\mathit{non\mhyphen unique}}$
\end{tabular}
\end{quote}

\section*{Good: defining an amsmath operator}

The \verb|amsmath| package provides the command \verb|\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. As a general rule, names denoting
entities with a fixed meaning are typeset in an upright font, whereas
variables are typeset in an italic font.
\begin{quote}
\begin{tabular}{ll}
\verb|\usepackage{amsmath}| &  \\[1ex]
\verb|$\operatorname{non-unique}$| & $\operatorname{non-unique}$ \\
\verb|$A_{\operatorname{non-unique}}}$| & $A_{\operatorname{non-unique}}$ \\
\verb|\boldmath$A_{\operatorname{non-unique}}}$| &
\boldmath$A_{\operatorname{non-unique}}$
\end{tabular}
\end{quote}

\section*{Defining appropriate commands}

No matter which method you choose, it is a good idea to define
commands for your operators. This avoids keying in lengthy character
sequences and achieves consistent typesetting.
\begin{quote}
\mathchardef\mhyphen="2D
\newcommand\nuniq{\mathit{non\mhyphen unique}}
\newcommand\Nuniq{{\operatorname{non-unique}}}
\begin{tabular}{l}
\verb|\mathchardef\mhyphen="2D|  \\
\verb|\newcommand\nuniq{\mathit{non\mhyphen unique}}| \\
\verb|$\nuniq$, \boldmath$A_\nuniq$| \qquad $\nuniq$, \boldmath$A_\nuniq$ \\[2ex]
\verb|\usepackage{amsmath}|   \\
\verb|\newcommand\nuniq{{\operatorname{non-unique}}}| \\
\verb|$\nuniq$, \boldmath$A_\nuniq$| \qquad $\Nuniq$, \boldmath$A_\Nuniq$
\end{tabular}
\end{quote}
Note the use of extra braces around \verb|\operatorname|, which is necessary
to make \verb|\nuniq| work in subscripts and the like.
\end{document}
