[Tex/LaTex] Creating a large “such that” symbol

macrossymbols

I'm using the following macro in my LaTeX document:

\newcommand{\suchthat}{\, \mid \,} % nice "such that"

so that set notation like the following looks nice:

\{x_n \suchthat n \in \mathbb{N}}

However, when I use such definitions of sets inside \[...\] and when I need to make the brackets bigger, the \suchthat symbol looks way to small. Try compiling the following MWE as an example:

\documentclass{article}
\usepackage{amssymb}                % for \mathbb font
\newcommand{\suchthat}{\, \mid \,}  % nice "such that"
\begin{document}

\noindent This looks fine:
\[ S = \left\{ x_n \suchthat n \in \mathbb{N} \right\} \]

\noindent But this does not:
\[ S = \left\{ x_n \suchthat \frac{1}{n} \in \mathbb{N} \right\} \]

\end{document}

Is there something I can include in my macro to automatically resize the suchthat symbol as necessary?

Best Answer

Use \middle only if there's a \left before it; we can check this using \currentgrouptype (texdoc etex for more information):

\documentclass{article}
\newcommand{\suchthat}{\;\ifnum\currentgrouptype=16 \middle\fi|\;}

\begin{document}
\[
a \suchthat b\qquad\left\{\frac{a}{b}\suchthat x\right\}
\]
\end{document}

enter image description here