To insert a set \({A | B}\) (using set builder notation), type "\setdef{A \suchthat B}". The heights of the braces and center bar will adjust automatically to the height of the contents.

Definition
\newcommand*{\setdef}[1]{\left\{#1 \right\}} 
\newcommand{\suchthat}{\mathrel{}\ifnum\currentgrouptype=16 \middle\fi|\mathrel{}}

Examples

Code Output
\setdef{A \suchthat B}
$$\left\{A \mid B\right\} $$
\setdef{x \suchthat \frac{1}{1+x} = 0}
$$\left\{x \mathrel{}\middle|\mathrel{} \frac{1}{1+x} = 0\right\} $$
\setdef{A, B, C}
$$\left\{A, B, C\right\} $$

Updated: