# Define pretty sets in LaTeX; esp., how to do the condition-separator?

E.g., I have this set:

\{ \alpha \in \Sigma^\omega | \exists^\omega n : \alpha [0,n] \notin \Sigma^* a_1 \Sigma^* a_2 \dotsb a_n \Sigma^* \}


Here, I use | as the separator for the condition part. But LaTeX doesn't add any spaces around it, thus it looks a bit strange/wrong. I could manually add some space here but I wondered if there is some more "correct" way. E.g. also to make it behave similar as : (which I actually want to behave different here; in this case, : adds too much space in front of it for my taste).

-
I had an additional question regarding this topic, which you may find here if you are interested. –  aulste Aug 10 '11 at 18:27

I sometimes do something a little more evil

\documentclass[a4paper]{memoir}
\usepackage{mathtools}
\DeclarePairedDelimiterX\Set[2]{\lbrace}{\rbrace}%
{ #1 \,\delimsize|\,\mathopen{} #2 }
\begin{document}
$\Set*{ x }{ x>0 }$
\end{document}


and thus hide the symbol inside the construction. Both a starred and non-starred \Set is created with \Set* autoscaling braces and vertical line is used.

Update August 2014: I no longer recommend a two argument solution, but rather this as I feel it gives an interface much closer to the mathematical meaning

\documentclass[a4paper]{memoir}
\usepackage{mathtools}
\providecommand\given{} % so it exists
\newcommand\SetSymbol[1][]{
\nonscript\,#1\vert\nonscript\,\mathopen{}\allowbreak}
\DeclarePairedDelimiterX\Set[1]{\lbrace}{\rbrace}%
{ \renewcommand\given{\SetSymbol[\delimsize] #1 }
\begin{document}
$\Set*{ x \given x>0 }$
\end{document}


BTW: notice the added \mathopen{} withput it \Set{ X \given -a < x < a} would give us the wrong -a (a subtraction minus, not a sign minus)

-
Hehe, yea, I actually use some similar construct now. Whereby I used \newcommand. Is there any advantage with \DeclarePairedDelimiterX? –  Albert Mar 16 '11 at 15:20
Test the document, it defines more than one command, try \Set[\big]{...}{...} –  daleif Mar 16 '11 at 15:23
Hm, it seems something is wrong there. I get the error Runaway argument? ./texdefs.tex:33: Paragraph ended before \DeclarePairedDelimiterX was complete. <to be read again> \par l.33 ?  –  Albert Mar 16 '11 at 15:25
@Albert: @daleif 's code works OK in my system. The error message suggests that you forgot a closing brace. If that's not the case, we'll need to see the problematic code to detect the problem. –  Gonzalo Medina Mar 16 '11 at 15:35
My code: \DeclarePairedDelimiterX\SetC[2]{\lbrace}{\rbrace}{ #1 \,\delimsize|\, #2 } –  Albert Mar 16 '11 at 15:37

The braket package contains a \set command which does what you want :

\set{\alpha \in \Sigma^\omega | \exists^\omega n : \alpha [0,n] \notin \Sigma^* a_1 \Sigma^* a_2 \dotsb a_n \Sigma^*}


It also defines \Set, where the first | is expandable, which allows to properly typeset sets like

\Set{x| x\in\mathbb R, |x|<\frac12 }

-

You should use \mid instead of |. And use \colon instead of : after the existential quantifier (although I would just put a thinspace).

-
I started to use \bigl\{ and \bigr\} now. What about \bigm| instead of \mid? Is there a difference except that it is slightly bigger? –  Albert Mar 16 '11 at 15:19
I would think : might be correct there whereas \colon is more for F\colon A\to B –  daleif Mar 16 '11 at 15:23
The problem with \mid is that it is not a fence, thus not scalable –  daleif Mar 16 '11 at 15:24
If you use big braces, you should indeed use \bigm| instead of \mid since \mid is not defined as a delimiter and thus cannot be used with \bigm. –  Michael Ummels Mar 16 '11 at 15:24