%%
%% This is file `jmsdelim.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% jmsdelim.dtx  (with options: `package')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from jmsdelim.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file jmsdelim.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%% File: jmsdelim.dtx Copyright (C) 2020 Jonathan Sterling
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version.  The latest version
%% of this license is in the file
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% -------------------------------------------------------------------------
\RequirePackage{expl3}
\RequirePackage{l3keys2e}
\RequirePackage{xparse}
\RequirePackage{ifluatex}
\RequirePackage{scalerel}
\ProvidesExplPackage {jmsdelim} {2022/03/11} {0.2.0}
  {Compositional delimiter sizing}
\keys_define:nn { jmsdelim } {
  size~commands .clist_set:N = \l__jmsdelim_size_cmds,
}
\keys_set:nn { jmsdelim } {
  size~commands = {relax,jmsdelim_big:n,jmsdelim_Big:n,jmsdelim_bigg:n,jmsdelim_Bigg:n},
}

\cs_new:Npn \jmsdelim_big:n #1 {
  {\mathchoice{\big #1} {\big #1}{\big #1}{#1}}
}

\cs_new:Npn \jmsdelim_Big:n #1 {
  {\mathchoice{\Big #1} {\Big #1}{\big #1}{#1}}
}

\cs_new:Npn \jmsdelim_bigg:n #1 {
  {\mathchoice{\bigg #1} {\bigg #1}{\big #1}{#1}}
}

\cs_new:Npn \jmsdelim_Bigg:n #1 {
  {\mathchoice{\Bigg #1} {\Bigg #1}{\big #1}{#1}}
}
\int_new:N \g__jmsdelim_size
\int_new:N \g__jmsdelim_size_up
\int_gset:Nn \g__jmsdelim_size {0}
\int_gset:Nn \g__jmsdelim_size_up {0}
\cs_new:Npn \__jmsdelim_clist_item:Nn #1 #2 {
  \clist_item:Nn #1 {
    \int_min:nn { #2 } {\clist_count:N #1}
  }
}
\cs_new:Npn \__jmsdelim_setup_sizes: {
  \int_gset:Nn \g__jmsdelim_size {
    \int_max:nn \g__jmsdelim_size \g__jmsdelim_size_up
  }

  \cs_set_eq:Nc \jmsdelim_size_cmd: {
    \__jmsdelim_clist_item:Nn \l__jmsdelim_size_cmds {
      \g__jmsdelim_size + 1
    }
  }
}


\cs_new:Npn \__jmsdelim_luatex_save_mathstyle:N #1 {
  \ifcase \mathstyle
    \cs_set_eq:NN #1 \displaystyle
  \or
    \cs_set_eq:NN #1 \crampeddisplaystyle
  \or
    \cs_set_eq:NN #1 \textstyle
  \or
    \cs_set_eq:NN #1 \crampedtextstyle
  \or
    \cs_set_eq:NN #1 \scriptstyle
  \or
    \cs_set_eq:NN #1 \crampedscriptstyle
  \or
    \cs_set_eq:NN #1 \scriptscriptstyle
  \or
    \cs_set_eq:NN #1 \crampedscriptscriptstyle
  \fi
}

\cs_new:Npn \__jmsdelim_restore_mathstyle: {
  \SavedStyle
}

\cs_new:Npn \__jmsdelim_save_mathstyle:n #1 {
  \ifluatex
    \__jmsdelim_luatex_save_mathstyle:N \__jmsdelim_restore_mathstyle:
    #1
  \else
    \ThisStyle{#1}
  \fi
}
\cs_new:Npn \jmsdelim_scope:nn #1 #2 {
  \group_begin:
    \int_set:Nn \l_tmpa_int \g__jmsdelim_size_up
    \int_gset:Nn \g__jmsdelim_size_up 0
    \int_gset:Nn \g__jmsdelim_size 0
    \group_begin:
      \__jmsdelim_save_mathstyle:n {
        #1
        \__jmsdelim_setup_sizes:
        #2
      }
    \group_end:
    \int_gset:Nn \g__jmsdelim_size_up {\int_max:nn \g__jmsdelim_size_up \l_tmpa_int}
  \group_end:
}
\cs_new:Npn \jmsdelim_hbox_set:Nn #1 #2 {
   \mode_if_math:TF
     { \hbox_set:Nn #1 {$\m@th\__jmsdelim_restore_mathstyle: #2$} }
     { \hbox_set:Nn #1 { #2 } }
}
\cs_new:Npn \jmsdelim_surround:nnn #1 #2 #3 {
  \jmsdelim_scope:nn {
    \jmsdelim_hbox_set:Nn \l_tmpa_box {#3}
  }{
    \mathopen\jmsdelim_size_cmd: {#1}
    \box_use:N \l_tmpa_box
    \mathclose\jmsdelim_size_cmd: {#2}
  }
}
\cs_new:Npn \jmsdelim_protect:n #1 {
  \group_begin:
    \int_set:Nn \l_tmpa_int \g__jmsdelim_size_up
    \int_set:Nn \l_tmpb_int \g__jmsdelim_size
    \group_begin: #1 \group_end:
    \int_gset:Nn \g__jmsdelim_size_up \l_tmpa_int
    \int_gset:Nn \g__jmsdelim_size \l_tmpb_int
  \group_end:
}
\cs_new:Npn \jmsdelim_between:nnn #1 #2 #3 {
  \jmsdelim_scope:nn {
    \jmsdelim_hbox_set:Nn \l_tmpa_box {#2}
    \jmsdelim_hbox_set:Nn \l_tmpb_box {#3}
  }{
    \box_use:N \l_tmpa_box
    \mathrel{\jmsdelim_size_cmd: {#1}}
    \box_use:N \l_tmpb_box
  }
}
\cs_new:Npn \jmsdelim_between:nnnnn #1 #2 #3 #4 #5 {
  \jmsdelim_scope:nn {
    \jmsdelim_hbox_set:Nn \l_tmpa_box {#4}
    \jmsdelim_hbox_set:Nn \l_tmpb_box {#5}
  }{
    \mathopen\jmsdelim_size_cmd: {#1}
    \box_use:N \l_tmpa_box
    \mathrel{\jmsdelim_size_cmd: {#2}}
    \box_use:N \l_tmpb_box
    \mathclose\jmsdelim_size_cmd: {#3}
  }
}


\NewDocumentCommand\DelimMin{m}{
  \int_gset:Nn \g__jmsdelim_size_up {\int_max:nn \g__jmsdelim_size_up {#1}}
}

\NewDocumentCommand\DelimSurround{mmm}{
  \jmsdelim_surround:nnn {#1} {#2} {#3}
}
\NewDocumentCommand\DelimBetween{mmm}{
  \jmsdelim_between:nnn {#1} {#2} {#3}
}
\NewDocumentCommand\DelimBetweenSurround{mmmmm}{
  \jmsdelim_between:nnnnn {#1} {#2} {#3} {#4} {#5}
}
\NewDocumentCommand\DelimProtect{m}{
  \jmsdelim_protect:n {#1}
}
\NewDocumentCommand\DelimPrn{m}{
  \jmsdelim_surround:nnn {(} {)} {#1}
}
\NewDocumentCommand\DelimBrk{m}{
  \jmsdelim_surround:nnn {[} {]} {#1}
}
\NewDocumentCommand\DelimBrc{m}{
  \jmsdelim_surround:nnn {\lbrace} {\rbrace} {#1}
}
\NewDocumentCommand\DelimBbrk{m}{
  \jmsdelim_surround:nnn {\llbracket} {\rrbracket} {#1}
}
\NewDocumentCommand\DelimGl{m}{
  \jmsdelim_surround:nnn {\langle} {\rangle} {#1}
}
\NewDocumentCommand\DelimVrt{m}{
  \jmsdelim_surround:nnn {\lvert} {\rvert} {#1}
}
\NewDocumentCommand\DelimVvrt{m}{
  \jmsdelim_surround:nnn {\lVert} {\rVert} {#1}
}
\ProcessKeysPackageOptions {jmsdelim}
\endinput
%%
%% End of file `jmsdelim.sty'.
