The packages braket and mathtools provide two different command to typeset set with dynamically sized braces.

For example with braket:

$\displaystyle \set{ \frac{x}{2} | x > 5 }$
$\displaystyle \Set{ \frac{x}{2} | x > 5 }$  

And the example with mathtools:

\DeclarePairedDelimiterX\setc[2]{\{}{\}}{\,#1 \;\delimsize\vert\; #2\,}
$\displaystyle \setc{ \frac{x}{2} }{ x > 5 }$
$\displaystyle \setc*{ \frac{x}{2} }{ x > 5 }$
$\displaystyle \setc[\bigg]{ \frac{x}{2} }{ x > 5 }$

(setc from https://tex.stackexchange.com/questions/448#124781)

I am currently using braket for its nicer interface. However, recently I found that in same cases I'd like to specify the bracket size manually as in the third case of the mathtools example. Is it somehow possible to combine the features of both packages into one command?


Using xparse on the same basis, here is a solution that allows a more natural syntax – at least closer to what one writes by hand: \set{x ; P(x)}. More over it lets one type enumerated sets, such as \set{1, 2, 3,…}. The only constraint is that if you have to use ; in the argument of \set, you have to write it as {;}.

I also rewrite \set* as \Set, and chose to define a default optional argument to \set with a classical trick – namely \big. My experience learnt me that plain \set looks generally too small. However, if you need or want it, you'll just have to write \set[].

Any way, this is the demonstration:

\usepackage{fourier, heuristica}

\usepackage{mathtools, nccmath}

{\IfNoValueTF{#2}{#1}{\,#1\nonscript\;\delimsize\vert\nonscript\:\allowbreak #2\,}}

%% The following makes \big the default for the \set command:
\def\MaybeOptArgSet{\ifx[\testchar \let\next\OptArgSet
\else \let\next\NoOptArgSet \fi \next}


%%% Syntax: \set{x ; P(x)})

   & \set{x ; x > 5} & & \Set{x ; x > 5}\\[4pt]
   & \set[\bigg]{ \frac{x}{2} ; x > 5} & & \Set{ \frac{x}{2} ; x > 5}\\[4pt]
 & \set[\Bigg]{ \frac{1}{2},\frac{1}{3},\frac{1}{4},\dotsm} & & \Set{ \mfrac{1}{2},\mfrac{1}{3},\mfrac{1}{4},\dotsm}


enter image description here

|improve this answer|||||
  • Thanks for sharing an alternitive solution. Do you use this also in your own documents or is it crafted just for me? – Meinersbur Jun 19 '14 at 21:50
  • I made it a series of little things like that for a friend of mine, with a semi-colon as a set-builder symbol, but use your version for my documents. I guess I should use a key-value system to let the choice of the symbol to the final user. – Bernard Jun 19 '14 at 22:05

Thanks to the hint from @Manuel and @egreg's answer https://tex.stackexchange.com/a/182943/45603 I found a nice solution.



$\displaystyle \set{ \frac{x}{2} | x > 5 }$
$\displaystyle \set*{ \frac{x}{2} | x > 5 }$
$\displaystyle \set[\bigg]{ \frac{x}{2} | x > 5 }$
$\displaystyle \Set{ \frac{x}{2} | x > 5 }$  

(Kudos to cargo cult programming)

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.