14

I am using the amsmath package and I'd like to control the size of my delimiters manually, i.e. using the \bigl, \Bigl, ... , \Bigr, \bigr commands, instead of \left, \middle, \right.

Now I want to create macros which include delimiters and I want to have the size as an argument. For example, if I have a \set macro:

\newcommand{\set}[2]{ \left\{ #1 \,\middle\vert\, #2\right\} }

I want to change it into a command, where I can give the size as an argument, i.e.

\set{A}{B}{Big}

should produce \Bigl\{ A \,\Big\vert\, B\Bigr\} or, even better, \set{A}{B}{2} produces this result.

Is there any command like \leftdelimitersize to implement this kind of macros?

3
  • The mathtools package has features that should help you.
    – egreg
    Commented Mar 17, 2013 at 13:20
  • And also this question. Which has a different way of implementing it than the mathtools package.
    – Manuel
    Commented Mar 17, 2013 at 13:24
  • Something here tex.stackexchange.com/questions/100966/… might help. In that case, \scalerel was used, but if you wish to define the size, the sister routine \scaleto or \stretchto might suffice. Commented Mar 17, 2013 at 15:17

2 Answers 2

16

The package mathtools already provides the necessary features; you just have to add the possibility of using numbers instead of the commands \big and siblings.

\documentclass{article}
\usepackage{mathtools}

\DeclarePairedDelimiterX{\innset}[2]{\lbrace}{\rbrace}{%
  #1\;\delimsize\vert\;#2}

\newcommand{\set}[3][0]{%
  \ifcase#1\relax
    \innset{#2}{#3}\or         % 0
    \innset[\big]{#2}{#3}\or   % 1
    \innset[\Big]{#2}{#3}\or   % 2
    \innset[\bigg]{#2}{#3}\or  % 3
    \innset[\Bigg]{#2}{#3}     % 4
  \else
    \innset*{#2}{#3}
  \fi}

\begin{document}
\begin{gather*}
\set{A}{\frac{B}{C}}\\
\set[0]{A}{\frac{B}{C}}\\
\set[1]{A}{\frac{B}{C}}\\
\set[2]{A}{\frac{B}{C}}\\
\set[3]{A}{\frac{B}{C}}\\
\set[4]{A}{\frac{B}{C}}\\
\set[-1]{A}{\frac{B}{C}}
\end{gather*}
\end{document}

With a number not in the range 0–4, the version with \left, \middle and \right would be used.

enter image description here

1
  • 1
    The numbers are much more memorable than the names!
    – Ryan Reich
    Commented Mar 17, 2013 at 14:44
11

If you are prepared to take something like Big as an argument then a simple solution to your request is to use \csname ...\endcsname to generate command names as needed, e.g.,

\newcommand\set[3]{\csname #3l\endcsname\{#1%
                   \,\csname#3\endcsname\vert\,%
                   #2\csname #3r\endcsname\}}

If you want to generate the needed commands via a numerical argument consider using \ifcase.

You must log in to answer this question.

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