[Tex/LaTex] Extensible multiset, or bag, delimiters

delimitersmath-mode

The stmaryrd package provides two types of multiset, or bag, delimiters: \lbag and \rbag; and \Lbag and \Rbag.

When I use these commands with the delimiter sizing commands \left and \right (or even \bigl and \bigr), I get a "Missing delimiter" error. Is there a way to use the multiset delimiters in varying sizes?

I am open to using symbols from another package if necessary.

Best Answer

The \scaleleftright and stretchleftright macros of the scalerel package give similar functionality to the \left ... \right syntax. In this case, the optional argument gives the maximum width allowed on the scale. If the width is exceeded, the aspect ratio is adjusted to preserve the limiting width.

\documentclass{arlticle}
\usepackage{stmaryrd,scalerel}
\begin{document}
\[\Lbag xyz \Rbag\ = \scaleleftright[1.2ex]{\Lbag}{\frac{xyz}{XYZ}}{\Rbag}\]
\end{document}

enter image description here

And if you add a \strut to the numerator and denominator of the \frac, it will look like this:

enter image description here


In the comments discussion, I raised the question on what an extensible version of this glyph might look like. For fun, I constructed one by hand. I don't recommend the implementation, but thought it would be interesting to compare, in visual appearance, to my proposed solution above:

\documentclass{arlticle}
\usepackage{stmaryrd,scalerel,stackengine}
\setstackgap{S}{0pt}
\usepackage{adjustbox}
\def\LbagT{\clipbox{0pt 2.6pt 0pt 0pt}{$\Lbag$}}
\def\LbagB{\clipbox{0pt 0pt 0pt 8.5pt}{$\Lbag$}}
\def\RbagT{\clipbox{0pt 2.6pt 0pt 0pt}{$\Rbag$}}
\def\RbagB{\clipbox{0pt 0pt 0pt 8.5pt}{$\Rbag$}}
\begin{document}
\[\Lbag xyz \Rbag\ = \scaleleftright[1.2ex]{\Lbag}{\frac{xyz}{XYZ}}{\Rbag}\]

\[
\raisebox{-6pt}{\Shortstack{{\LbagT} {\rule{1pt}{2ex}\kern3pt} {\LbagB}}}
\frac{xyz}{XYZ}
\raisebox{-6pt}{\Shortstack{{\RbagT} {\kern2.95pt\rule{1pt}{2ex}} {\RbagB}}}
\]
\end{document}

enter image description here