[Tex/LaTex] Easily change behavior of \DeclarePairedDelimiter

bracketsdelimitersmath-modemathtoolsspacing

After seeing the answer to this question I realized that I preferred the way of working of Juan A. Navarro's answer:

  • I.e., \DeclarePairedDelimiter{\parens}{\lparen}{\rparen} from mathtools is a great tool, it gives you
    • \parens{…} which doesn't adjust the height,
    • \parens*{…}, which automatically adjusts the height,
    • and i.e., \parens[\bigg]{…}, which result in the size you specified.
  • \newdelimcommand{\parens}{\lparen}{\rparen} from the answer I linked results in
    • \parens{…} which automatically adjusts the height,
    • \parens*{…}, which doesn't adjust the height,
    • and i.e., \parens[bigg]{…}, which result in the size you specified.

I prefer the second way of working than mathtools. But, the spacing you get is wrong (like if you were using \left( instead of \biggl(). I tried using \usepackage{mleftright} \mleftright before the code from Juan A. Navarro, but it didn't work. So my question is

How could I get the style of the answer I linked but with correct spacing (like mathtools)?

May be it is easier to exchange the behavior in mathtools starred and unstarred (plus the bigg instead of \bigg), or may be it's easier to rewrite Juan A. Navarro's code.

EDIT:
Well, reading I got here, and then here. Were the last absolutely answers my question except that the starred version doesn't work.

Here is the code:

\documentclass{scrartcl}
\usepackage{mathtools}
\usepackage{etextools}
\usepackage{ifthen}

\makeatletter
    \newcommand{\DeclarePairedDelimiterCase}[2]{%
        \newcommand#1[1][]{%
            \ifthenelse{\equal{##1}{normal}}%
            {#2}%
            {%
                \ifthenelse{\equal{##1}{big}\OR\equal{##1}{Big}\OR\equal{##1}{bigg}\OR\equal{##1}{Bigg}}%
                {\expandnext{#2[}{\csname##1\endcsname}]}%
                {#2*}%        % standard case using \left and \right
            }%
        }%
    }
    \newcommand{\DeclarePairedDelimiterY}[4][Temp]{%
        \expandafter\DeclarePairedDelimiter\csname#2#1\endcsname{#3}{#4}%
        \expandnext{\expandnext{\DeclarePairedDelimiterCase}{\csname#2\endcsname}}{\csname#2#1\endcsname}%
    }
    \newcommand{\DeclarePairedDelimiterXY}[6][Temp]{%
        \expandafter\DeclarePairedDelimiterX\csname#2#1\endcsname[#3]{#4}{#5}{#6}%
        \expandnext{\expandnext{\DeclarePairedDelimiterCase}{\csname#2\endcsname}}{\csname#2#1\endcsname}%
    }
\makeatother
\DeclarePairedDelimiterY{set}{\lbrace}{\rbrace}
\DeclarePairedDelimiter{\pa}{\lparen}{\rparen}

\begin{document}

\begin{align*}
    \liminf \set*{\sum}
\end{align*}

\end{document}

And then I get lim inf{*}∑ instead of what I want lim inf{∑}.

EDIT2:
I realized that the one I used before had some extra options I do need:

  • \parens{…} and \parens[auto]{…} should be autosize.
  • \parens*{…} and \parens[base]{…} should be the basic ones (without scaling).
  • The rest as I described before \parens[bigg]{…}, etc. to manually scale.

Best Answer

I continue to believe that one should use \left and \right where really needed and any sort of automatism for this is bad.

However, here's a simple and working implementation of your macro, that I call \xDeclarePairedDelimiter

\documentclass{scrartcl}
\usepackage{mleftright,xparse}

\NewDocumentCommand\xDeclarePairedDelimiter{mmm}
 {%
  \NewDocumentCommand#1{som}{%
   \IfNoValueTF{##2}
    {\IfBooleanTF{##1}{#2##3#3}{\mleft#2##3\mright#3}}
    {\mathopen{##2#2}##3\mathclose{##2#3}}%
  }%
 }
\xDeclarePairedDelimiter{\set}{\lbrace}{\rbrace}

\begin{document}

\begin{align*}
&\liminf \set{\sum}\\
&\liminf \set*{\sum}\\
&\liminf \set[\big]{\sum}\\
&\liminf \set[\Big]{\sum}
\end{align*}

\end{document}

enter image description here

Related Question