# Set builder notation command, adjusting mid bar

I would like to create a command which prints its arguments in a set builder notation. The problem

\documentclass{article}
\newcommand{\set}[2]{\left\{\  #1  \ \left| \ #2 \ \right. \right\}  }

\begin{document}

$\set{A}{ (B) }$

\bigskip

$\set{A}{\Bigg(B\Bigg)}$

\bigskip

% but:

$\set{\Bigg(A\Bigg)}{B}$

\end{document}


is that my attempt to make the height of the middle bar automatically adjusted to the contents of the set, only works wih respect to the content of the right hand side of it. I know I could use the colon instead, but I just don't like the way it looks.

Is there any simple work around?

• Look for \middle – egreg Apr 10 '18 at 21:25

Here is a solution, adapted from a code in the documentation of mathtools, with a natural syntax: it uses two arguments in one, separated by a semi-colon. If the second argument does not exist, it also works, letting you define a set as a list of its elements.

The \set command has a starred version, adding a pair of implicit \left \right. It also can take an optional argument: \big,\Big, \bigg, \Bigg which adds a pair of implicit \bigl \bigr or one of its siblings.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{xparse}
%
\DeclarePairedDelimiterX{\set}[1]{\{}{\}}{\setargs{#1}}
\NewDocumentCommand{\setargs}{>{\SplitArgument{1}{;}}m}
{\setargsaux#1}
\NewDocumentCommand{\setargsaux}{mm}
{\IfNoValueTF{#2}{#1} {#1\nonscript\:\delimsize\vert\allowbreak\nonscript\:\mathopen{}#2}}%
\def\Set{\set*}%

\begin{document}

\begin{align*}
& \set*{\frac{A}{B}; A, B\in K[X]} \\
& \set[\Big]{A; A = \sqrt{B},\:B\in K[X]} \\
& A\set[big]{2,3, 5,7,11,\dots}
\end{align*}

\end{document}


• Very excellent. Is correct in English language :-)? – Sebastiano Apr 10 '18 at 21:46
• What is correct in English language? – Bernard Apr 10 '18 at 21:49
• Very excellent are words that are they used? – Sebastiano Apr 10 '18 at 21:51
• I think excellent is already a form of superlative. However you mean ‘molto eccellente’? Anyway it's very exaggerated ;o) – Bernard Apr 10 '18 at 21:57
• In Sicily all it is possible. ahhaha. For example when we talk to someone we always double the consonants. – Sebastiano Apr 10 '18 at 22:00