I would like to define a phrase once that contains both math and text, and be able to use usable in both math and text mode. For example:
\newcommand{\Constraint}{\ensuremath{x \neq 0} \text{ and } \ensuremath{x \neq -1}}
This works fine in math mode, but leaves too much space in text mode. Of course:
\newcommand{\Constraint}{\ensuremath{x \neq 0} \text{and} \ensuremath{x \neq -1}}
works fine in text mode, but not in math mode.
Well that led me to:
\newcommand{\Space}{\ifmmode{ }\else{}\fi}%
\newcommand{\Constraint}{\ensuremath{x \neq 0} \text{\Space and\Space} \ensuremath{x \neq -1}}
which of course is a brilliant solution, except for the fact that it only yields correct results in text mode!! I attempted to replace the { } with various math spacing (\;, and \hspace{1ex}) and they had no effect in math mode.
The one case that does yield correct spacing in both is using an \mbox as in:
\newcommand{\Constraint}{\mbox{\ensuremath{x \neq 0} and \ensuremath{x \neq -1}}}
but then the text can not be split across line boundaries so is not good enough.
Below are my various failed attempts commented out. The code as below yields:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xspace}
\usepackage{showframe}
%%%% Math Mode: Works fine
%%%% Text Mode: Too much space before and after "and"
%\newcommand{\Constraint}{\ensuremath{x \neq 0} \text{ and } \ensuremath{x \neq -1}}
%%%% Math Mode: No space before and after "and"
%%%% Text Mode: Works fine
%\newcommand{\Constraint}{\ensuremath{x \neq 0} \text{and} \ensuremath{x \neq -1}}
%%%% Math Mode: Works fine
%%%% Text Mode: Too much space before and after "and"
%\newcommand{\Constraint}{\ensuremath{x \neq 0} \text{~and~} \ensuremath{x \neq -1}}
%%%% Math Mode: missing space after "and"
%%%% Text Mode: Too much space before and after "and"
%\newcommand{\Constraint}{\ensuremath{x \neq 0} \text{~and\xspace} \ensuremath{x \neq -1}}
%%%% Math Mode: missing spaces before and after
%%%% Text Mode: Works fine.
\newcommand{\Space}{\ifmmode{ }\else{}\fi}%
\newcommand{\Constraint}{\ensuremath{x \neq 0} \text{\Space and\Space} \ensuremath{x \neq -1}}
\begin{document}
\begin{align*}
\frac{2x}{x+1} &= \frac {2x-1}{x}\\
\implies 2x (x) &= (x+1) (2x-1) \qquad\Constraint
\end{align*}
%
In a short sentence note the constraint: \Constraint.
In a long sentence note the above the constraint must be satisfied: $\Constraint$.
\end{document}


\text{\Constraint}? Or perhaps this isn't robust enough... – cmhughes Mar 27 '12 at 2:30\text{}around it still yields too much space in\textmode. – Peter Grill Mar 27 '12 at 3:52