[Tex/LaTex] How to automatically resize the vertical bar in a set comprehension


I have a simple command which I use to write set comprehensions so that the braces automatically resize with respect to size of the enclosed arguments, e.g.

\newcommand{\set}[1]{\left\lbrace #1\right\rbrace}

\set{x \in X \mid x > \frac{1}{2}}  
% Produces something like: { x : X | x > 1/2 }

However, the \mid vertical bar wont resize like the braces { .. } do. How can I get the \mid to resize as well?

Best Answer

You can use \middle| instead of \mid like

\[ \left\{ x \in X \middle| x > \frac{1}{2}\right\} \]

or with better spacing

\[ \left\{ x \in X \,\middle|\, x > \frac{1}{2}\right\} \]

(I think this requires a somewhat modern TeX-distribution.)