[Tex/LaTex] Text in a set comprehension

math-mode

What is the proper way to typeset this set comprehension that has a lot of words in it? Is \textrm with manual spaces really the only way?

$$D = (S,
       \{(a,b) \,|\, \exists s,x,y\in S^* \textrm{ and } 
                     i < j \textrm{ such that } 
                     w^i = sax \textrm{ and } w^j = sby\})$$

Best Answer

With that answer, I'm concentrating on the "that has a lot of words in it" part on the question. The solution that is often used is \text{...} with $...$ snippets for the math parts inside of it, just as you would use in normal text mode. You example might then look like this:

\[
D = (S, \{(a,b) \mid \text{$\exists s,x,y\in S^*$ and $i < j$
                            such that $w^i = sax$ and $w^j = sby$}\})
\]