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

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


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




% but:



enter image description here

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?

Thanks in advance

  • 1
    Look for \middle
    – egreg
    Apr 10, 2018 at 21:25

1 Answer 1


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.

{\IfNoValueTF{#2}{#1} {#1\nonscript\:\delimsize\vert\allowbreak\nonscript\:\mathopen{}#2}}%


 & \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}


enter image description here

  • Very excellent. Is correct in English language :-)?
    – Sebastiano
    Apr 10, 2018 at 21:46
  • What is correct in English language?
    – Bernard
    Apr 10, 2018 at 21:49
  • Very excellent are words that are they used?
    – Sebastiano
    Apr 10, 2018 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, 2018 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, 2018 at 22:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .