2

I want to define a stretchable delimiter made of several brackets, so that they are stretched to the same height, i. e. if I declare

\DeclarePairedDelimiter{\double}{((}{))}

then \double{...} should make the outer () the same size as the inner, like

enter image description here

the code for this fraction is

\delimitershortfall=0pt

\[
    \left(\left( \dfrac{x}{y}\right)\right)
\]

But right now I get some weird behaviour:

enter image description here

How can I fix it?

Full MWE

\documentclass{article}

\usepackage{mathtools}

\usepackage{unicode-math}

\setmathfont{STIX Two Math}

\DeclarePairedDelimiter{\double}{((}{))}

\DeclarePairedDelimiter{\triple}{\{[(}{>)]}

\DeclarePairedDelimiter{\dif}{(}{))}


\begin{document}

    \begin{align}
        \double{x}\\
        \double*{\dfrac{n}{k}}\\
        \triple{x}\\
        \triple*{\dfrac{a}{b}}\\
        \dif*{\dfrac{x}{y}}
    \end{align}

\end{document}
6

The size command is only applied to the first delimiter, not to the following ones; there's no error message, but what you get is a byproduct of the actual implementation.

You can use \DeclarePairedDelimiterX:

\documentclass{article}

\usepackage{mathtools}
\usepackage{unicode-math}

\setmathfont{STIX Two Math}

\DeclarePairedDelimiterX{\double}[1]{(}{)}{\delimsize(#1\delimsize)}
\DeclarePairedDelimiterX{\triple}[1]{\{}{]}{%
  \delimsize[\delimsize(#1\delimsize\rangle\delimsize)%
}
\DeclarePairedDelimiterX{\dif}[1]{(}{)}{#1\delimsize)}

\begin{document}

\begin{align}
\double{x}\\
\double*{\dfrac{n}{k}}\\
\triple{x}\\
\triple*{\dfrac{a}{b}}\\
\dif*{\dfrac{x}{y}}
\end{align}

\end{document}

enter image description here

A full reimplementation, but the numbers of delimiters must match, use . for balancing.

\documentclass{article}

\usepackage{mathtools,mleftright}
\usepackage{unicode-math}

\setmathfont{STIX Two Math}

\ExplSyntaxOn
\NewDocumentCommand{\DeclareMultiPairedDelimiter}{mmm}
 {
  \NewDocumentCommand{#1}{sO{}m}
   {
    \IfBooleanTF{##1}
     { \fraiman_multi_open_lr:n { #2 } }
     { \fraiman_multi_open:nn { ##2 } { #2 } }
    ##3
    \IfBooleanTF{##1}
     { \fraiman_multi_close_lr:n { #3 } }
     { \fraiman_multi_close:nn { ##2 }{ #3 } }
   }
 }

\cs_new_protected:Nn \fraiman_multi_open_lr:n
 {
  \tl_map_inline:nn { #1 } { \mleft ##1 }
 }
\cs_new_protected:Nn \fraiman_multi_close_lr:n
 {
  \tl_map_inline:nn { #1 } { \mright ##1 }
 }
\cs_new_protected:Nn \fraiman_multi_open:nn
 {
  \mathopen { \tl_map_inline:nn { #2 } {\tl_if_eq:nnF { ##1 } { . } { #1 ##1 } } }
 }
\cs_new_protected:Nn \fraiman_multi_close:nn
 {
  \mathclose { \tl_map_inline:nn { #2 } {\tl_if_eq:nnF { ##1 } { . } { #1 ##1 } } }
 }
\ExplSyntaxOff

\DeclareMultiPairedDelimiter{\double}{((}{))}
\DeclareMultiPairedDelimiter{\triple}{\{[(}{>)]}
\DeclareMultiPairedDelimiter{\dif}{(.}{))}

\begin{document}

\begin{align}
\double{x}\\
\double*{\dfrac{n}{k}}\\
\triple{x}\\
\triple*{\dfrac{a}{b}}\\
\dif*{\dfrac{x}{y}}
\end{align}

\end{document}
| improve this answer | |
1
\usepackage{xparse,mleftright}

\ExplSyntaxOn

\NewDocumentCommand \double { s o m }
 {
  \IfBooleanTF {#1}
   { \mleft(\mleft( #3 \mright)\mright) }
   {
    \IfValueTF {#2}
     {
      \use:c { \cs_to_str:N #2 l } (
      \use:c { \cs_to_str:N #2 l } (
      #3
      \use:c { \cs_to_str:N #2 r } )
      \use:c { \cs_to_str:N #2 r } )
     }
     { (( #3 )) }
   }
 }

\ExplSyntaxOff
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.