\documentclass{article}
\usepackage{amssymb}
\usepackage[synonym=Setb]{setbuilder}
\usepackage[margin=3cm]{geometry}
\usepackage{parskip}
\usepackage[hidelinks]{hyperref}

\newcommand\pkg{\textsf{setbuilder}}
\makeatletter
\NewDocumentCommand\demo{v}{%
  \par\noindent
  \begin{minipage}[c]{0.56\linewidth}\ttfamily\small #1\end{minipage}%
  \hfill
  \begin{minipage}[c]{0.40\linewidth}\raggedleft
    $\displaystyle\demo@run{#1}$%
  \end{minipage}\par\medskip}
\newcommand\demo@run[1]{\begingroup\endlinechar=-1 \scantokens{#1}\endgroup}
\makeatother

\title{The \pkg\ package\\[1ex]
  \large Smart set-builder notation\\with correctly scaled braces and separator}
\author{Vseslav Sekorin\\\texttt{vssekorin@gmail.com}}
\date{2026/07/19 \quad v0.1\\[1ex]
  \small\url{https://github.com/vssekorin/setbuilder}}

\begin{document}
\maketitle

\section{Introduction}

Typesetting set-builder notation correctly in \LaTeX{} is surprisingly
fiddly. The naive markup
\begin{center}\ttfamily \char`\\\char`\{\ x \char`\\mid\ x > 0 \char`\\\char`\}\end{center}
breaks down as soon as the contents grow: the braces stay small. The
robust alternative,
\begin{center}\ttfamily
\char`\\left\char`\\\char`\{\ ...\ \char`\\middle\char`\\vert\ ...\ \char`\\right\char`\\\char`\}\end{center}
makes the markup unreadable, and the thin spaces around the bar must be
inserted by hand---and removed again by hand in subscripts.

The \pkg\ package reduces all of this to one command:
\demo{\set{x \in \mathbb{R} \given x^2 < 2}}
with correct spacing around the separator, automatic or fixed scaling of
\emph{both} the braces and the bar, spaces that vanish in sub- and
superscripts, and a permitted line break after the bar in inline formulas.

\section{Usage}

\begin{verbatim}
\usepackage{setbuilder}
\end{verbatim}

\subsection{The \texttt{\string\set} command}

\demo{\set{1, 2, 3, \dots}}
\demo{\set{x \in \mathbb{R} \given x^2 < 2}}

The separator is written \verb|\given| (or its synonym \verb|\suchthat|).
Both raise a helpful error when used outside \verb|\set|.

\subsection{Auto-scaling: \texttt{\string\set*}}

The starred form wraps the contents in
\verb|\left|\dots\verb|\middle|\dots\verb|\right|, so the braces
\emph{and} the bar grow together:

\demo{\set*{\frac{n}{n+1} \given n \in \mathbb{N}}}
\demo{\set*{A \subseteq \mathbb{N} \given \sum_{a \in A} \frac{1}{a} < \infty}}

\subsection{Fixed size: \texttt{\string\set[\string\Big]}}

When auto-scaling overshoots (the classic \verb|\left\right| complaint),
pick the size yourself:

\demo{\set[\Big]{x \given f(x) = \max_{y} f(y)}}

\subsection{Correct spacing in scripts}

The thin spaces around the separator are inserted with
\verb|\nonscript\:|, so they disappear in sub- and superscripts where
they would look bloated:
\[
  \bigcup_{i \in \set{n \given n \ge 1}} A_i
  \qquad\text{compare hand-made:}\qquad
  \bigcup_{i \in \{\,n \,\mid\, n \ge 1\,\}} A_i
\]

\subsection{Nesting}

\demo{\set*{\set{x \given x \sim y} \given y \in Y}}

\section{Package options}

Options use the key--value syntax of the modern \LaTeX{} kernel.

\begin{description}
\item[\texttt{bar} (default)] The separator is a vertical bar:
  $\set{x \given x > 0}$.
\item[\texttt{colon}] The separator is a colon throughout the document,
  as preferred in some traditions: $\{\,x : x > 0\,\}$.
\item[\texttt{synonym=$\langle$name$\rangle$}] Additionally defines
  \verb|\|$\langle$name$\rangle$ as a full copy of \verb|\set|,
  including the starred and fixed-size variants. This document, for
  instance, is compiled with \verb|synonym=Setb|:
  \demo|\Setb*{\frac{1}{n} \given n \ge 1}|
\end{description}

\subsection{What if \texttt{\string\set} is already taken?}

Some packages define their own \verb|\set|. In that case \pkg\
\emph{never} overwrites the existing command. Instead:

\begin{itemize}
\item if a synonym was requested, the synonym silently becomes the way
  to access the functionality:
\begin{verbatim}
\usepackage[synonym=mkset]{setbuilder}
\end{verbatim}
\item if no synonym was requested, the package issues a warning with
  exactly this advice, and the document still compiles.
\end{itemize}

Requesting a synonym whose name is itself taken
(\verb|synonym=section|) produces a clear error message.

\section{Requirements}

The package loads \textsf{mathtools} and requires a \LaTeX{} kernel from
2022-06-01 or newer (for key--value package options and
\verb|\NewCommandCopy|).

\section{Implementation notes}

The command is built with \verb|\DeclarePairedDelimiterX| from
\textsf{mathtools}, which provides the plain, starred and sized variants
uniformly. Inside the delimiter body, \verb|\given| is redefined locally
to typeset the separator at the current delimiter size
(\verb|\delimsize|). The separator itself is
\begin{verbatim}
\nonscript\: <bar> \allowbreak \nonscript\: \mathopen{}
\end{verbatim}
where the trailing \verb|\mathopen{}| makes a following unary minus
space correctly, and \verb|\allowbreak| permits a line break after the
bar in inline material.

\section{Changes}

\begin{description}
\item[v0.1 (2026-07-19)] First public version.
\end{description}

\end{document}
