summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/jmsdelim/jmsdelim.dtx
blob: 868070471e6b87616963da47e3196e4d3095e3b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
% \iffalse meta-comment
%
%% 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
%%
%% -------------------------------------------------------------------------
%
%<*driver>
\documentclass[cs-f]{l3doc}
\usepackage{jmsdelim}
\usepackage{mlmodern}
\usepackage{mleftright}
\usepackage[capitalize]{cleveref}
\usepackage[protrusion=true,expansion=true,tracking=false]{microtype}
\microtypecontext{spacing=nonfrench}

\usepackage{xcolor}
\usepackage{zi4}
\definecolor{Matterhorn}{RGB}{77,77,77}
\definecolor{RedDevil}{RGB}{134,1,17}
\definecolor{RegalBlue}{RGB}{3,69,117}
\usepackage[backend=biber,natbib=true, doi=true, citestyle=alphabetic, backref=true, style=alphabetic, maxnames=1000]{biblatex}
\hypersetup{breaklinks=true,colorlinks=true,linkcolor=RedDevil,urlcolor=RegalBlue, citecolor=RegalBlue!70}
\addbibresource{refs.bib}
\setlength\parindent{0pt}
\setlength\parskip{.5em}
\renewcommand\bfdefault{b}
%
\let\oldmeta\meta
\renewcommand\meta[1]{\texttt{\oldmeta{#1}}}
%
% ripped from ebproof
\NewDocumentEnvironment{example}{}{%
  \VerbatimEnvironment
  \begin{VerbatimOut}{example.tex}%
}{%
  \end{VerbatimOut}
  \begin{center}
  \begin{minipage}{.4\textwidth}
    \input{example.tex}
  \end{minipage}%
  \begin{minipage}{.6\textwidth}
    \small\VerbatimInput[gobble=0]{example.tex}
  \end{minipage}%
  \end{center}
}
\NewDocumentEnvironment{wide-example}{}{%
  \VerbatimEnvironment
  \begin{VerbatimOut}{example.tex}%
}{%
  \end{VerbatimOut}
  \input{example.tex}
%
  \small\VerbatimInput[gobble=0]{example.tex}
}
%
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \title{The \pkg{jmsdelim} package}
%
% \author{Jonathan Sterling}
%
% \date{September 14, 2019}
%
% \maketitle
%
% \begin{documentation}
%
% \section{Overview}
%
% Sizing delimiters using \cs{left} and \cs{right} should be outlawed! The results are nearly always unaesthetic, primarily because the correct size of a mathematical delimiter is a typesetting consideration which does \emph{not} emanate from the physical size of the interior.
%
% Correctly sizing delimiters is very difficult, particularly in well-architected documents: a correctly engineered mathematical document will include macros for all operations, and these macros necessarily will include delimiters (such as parentheses). However, the correct size for the delimiter cannot be chosen ahead of time, because it will depend on the arguments; two options are available:
%
% \begin{enumerate}
%   \item Provide optional arguments to each notation macro for choosing delimiter sizes. This is nearly intractable to do in practice.
%   \item Ignore delimiter sizes.
% \end{enumerate}
%
% With \pkg{jmsdelim} we offer an alternative: the correct delimiter sizes can be set at the \emph{leaf nodes} of a mathematical expression, and magically bubble upward through the delimiters.
%
%
% \section{Document interface}
%
% \begin{function}{\DelimMin}
%   \begin{syntax}
%     \cs{DelimMin}\marg{intexpr_{min}}
%   \end{syntax}
%
%   This sets the minimum delimiter size to \meta{intexpr_{min}} outside the current location; delimiter sizes are
%   represented as natural numbers, with \verb|0| the smallest size.
% \end{function}
%
% \cs{DelimMin} is the work-horse of \pkg{jmsdelim}; let us consider an example of what one might do prior to adopting \pkg{jmsdelim}. Suppose we have defined a macro \cs{Psh} for the free co-completion, following the notation of the French school, and we wish to parenthesize an instance of it:
% \begin{example}
%   \NewDocumentCommand\Cat{}{\mathbf{Cat}}
%   \NewDocumentCommand\Psh{m}{\widehat{#1}}
%   \NewDocumentCommand\Hom{mmm}{
%     \operatorname{Hom}_{#1}(#2,#3)
%   }
%   \[ \Hom{\Cat}{1}{\Psh{\mathbb{C}}} \]
% \end{example}
%
% One might have tried to get a better result by using \cs{left} and \cs{right}:
% \begin{example}
%   \NewDocumentCommand\Cat{}{\mathbf{Cat}}
%   \NewDocumentCommand\Psh{m}{\widehat{#1}}
%   \NewDocumentCommand\HomX{mmm}{
%     \operatorname{Hom}_{#1}\left(#2,#3\right)
%   }
%   \NewDocumentCommand\Hom{mmm}{
%     \operatorname{Hom}_{#1}\mleft(#2,#3\mright)
%   }
%   \[ \Hom{\Cat}{1}{\Psh{\mathbb{C}}} \]
%   \[ \HomX{\Cat}{1}{\Psh{\mathbb{C}}} \]
% \end{example}
%
% The above is appallingly worse: the height of the hat does not in any way determine the correct size for the delimiter! The solution using \pkg{jmsdelim} is quite simple, however: first, we change \cs{Hom} to call \cs{DelimPrn}, and then we use \cs{DelimMin} within the \cs{Psh} notation.
% \begin{example}
%   \NewDocumentCommand\Cat{}{\mathbf{Cat}}
%   \NewDocumentCommand\Psh{m}{\DelimMin{1}\widehat{#1}}
%   \NewDocumentCommand\Hom{mmm}{
%     \operatorname{Hom}_{#1}\DelimPrn{#2,#3}
%   }
%   \[ \Hom{\Cat}{1}{\Psh{\mathbb{C}}} \]
% \end{example}
%
% \paragraph{Behavior under subscripts}
% By default, delimiter sizes are capped under subscripts and superscripts because the alternative is unaesthetic. For instance, consider the following somewhat contrived examples:
% \begin{example}
%   \NewDocumentCommand\Sum{mm}{%
%     \DelimMin{1}{\textstyle\sum}_{#1}{#2}%
%   }
%   \[
%     \int_{\DelimPrn{\Sum{i}{a_i}}}
%     \int_{\DelimPrn{\DelimMin{4}\Sum{i}{a_i}}}
%   \]
% \end{example}
%
% Because the emitted delimiter size under a subscript does \emph{not} determine the actual amount of space used, it is in most cases not correct for this delimiter size to have an effect on its non-subscript context. For this reason, judicious use of the \cs{DelimProtect} command is recommended in the case of subscripts.
%
%
%
% \subsection{Basic Delimiter commands}
%
% Like \pkg{mleftright}~\citep{oberdick:mleftright}, \pkg{jmsdelim} ensures the correct amount of space on the outside of the delimiters using \cs{mathopen} and \cs{mathclose}.
%
% \begin{function}{\DelimSurround}
%   \begin{syntax}
%     \cs{DelimSurround}\marg{left}\marg{right}\marg{body}
%   \end{syntax}
%   Surrounds \meta{body} with appropriately sized \meta{left} and \meta{right} delimiters respectively.
%   \begin{example}
%     \NewDocumentCommand\Sum{mm}{%
%       \DelimMin{1}{\textstyle\sum}_{#1}{#2}%
%     }
%     \[\DelimSurround{\vert}{\vert}{\Sum{i}{b_i}}\]
%   \end{example}
% \end{function}
%
% \begin{function}{\DelimBetween}
%   \begin{syntax}
%     \cs{DelimSurround}\marg{sep}\marg{lbody}\marg{rbody}
%   \end{syntax}
%   Places an appropriately sized \meta{sep} between \meta{lbody} and \meta{rbody}.
%   \begin{example}
%     \NewDocumentCommand\Sum{mm}{%
%       \DelimMin{1}{\textstyle\sum}_{#1}{#2}%
%     }
%     \[\DelimBetween{\Vert}{a}{\Sum{i}{b_i}}\]
%   \end{example}
% \end{function}
%
% \begin{function}{\DelimBetweenSurround}
%   \begin{syntax}
%     \cs{DelimSurround}\marg{left}\marg{sep}\marg{right}\marg{lbody}\marg{rbody}
%   \end{syntax}
%   Places an appropriately sized \meta{sep} between \meta{lbody} and \meta{rbody}, surrounding the result by \meta{left} and \meta{right} respectively.
%   \begin{example}
%     \NewDocumentCommand\Sum{mm}{%
%       \DelimMin{1}{\textstyle\sum}_{#1}{#2}%
%     }
%     \[
%       \DelimBetweenSurround{\lbrace}{\vert}{\rbrace}{
%         \Sum{i}{a\cdot b_i}
%       }{a\in A}
%     \]
%   \end{example}
% \end{function}
%
% \begin{function}{\DelimProtect}
%   \begin{syntax}
%     \cs{DelimProtect}\marg{body}
%   \end{syntax}
%   Executes \meta{body} in a sandbox, preventing its state updates from bubbling outward; this is useful in case of subscripts and superscripts.
%   The following command demonstrates incorrect sizing in the presence of a high delimiter size within a subscript:
%   \begin{example}
%     \NewDocumentCommand\Sum{mm}{%
%       \DelimMin{1}{\textstyle\sum}_{#1}{#2}%
%     }
%     \[
%       \DelimPrn{\Sum{\DelimPrn{\DelimMin{4}\Sum{i}{a_i}}}{F}}
%     \]
%   \end{example}
%
%   Using a combination of \cs{DelimProtect} and \cs{DelimMin}, the formatting can be corrected locally.
%   \begin{example}
%     \NewDocumentCommand\Sum{mm}{%
%       \DelimMin{1}{\textstyle\sum}_{\DelimProtect{#1}}{#2}%
%     }
%     \[
%       \DelimPrn{
%         \DelimMin{2}
%         \Sum{\DelimPrn{\DelimMin{4}\Sum{i}{a_i}}}{F}
%       }
%     \]
%   \end{example}
% \end{function}
%
% \subsection{Derived delimiter commands}
%
% \begin{function}{\DelimPrn}
%   \begin{syntax}
%     \cs{DelimPrn}\marg{body}
%   \end{syntax}
%   Surrounds \meta{body} in parentheses.
% \end{function}
%
% \begin{function}{\DelimBrk}
%   \begin{syntax}
%     \cs{DelimBrk}\marg{body}
%   \end{syntax}
%   Surrounds \meta{body} in square brackets.
% \end{function}
%
% \begin{function}{\DelimBrc}
%   \begin{syntax}
%     \cs{DelimBrc}\marg{body}
%   \end{syntax}
%   Surrounds \meta{body} in curly braces.
% \end{function}
%
% \begin{function}{\DelimGl}
%   \begin{syntax}
%     \cs{DelimGl}\marg{body}
%   \end{syntax}
%   Surrounds \meta{body} in angle brackets.
% \end{function}
%
% \begin{function}{\DelimVrt}
%   \begin{syntax}
%     \cs{DelimVrt}\marg{body}
%   \end{syntax}
%   Surrounds \meta{body} in vertical brackets.
% \end{function}
%
% \begin{function}{\DelimBbrk}
%   \begin{syntax}
%     \cs{DelimBbrk}\marg{body}
%   \end{syntax}
%   Surrounds \meta{body} in Scott brackets (requires \cs{llbracket}, \cs{rrbracket} to be defined).
% \end{function}
%
% \begin{function}{\DelimVvrt}
%   \begin{syntax}
%     \cs{DelimVvrt}\marg{body}
%   \end{syntax}
%   Surrounds \meta{body} in double vertical bars.
% \end{function}
%
%
% \subsection{Configuration and options}\label{sec:options}
% \begin{function}{\DelimSetup}
%   \begin{syntax}
%     \cs{DelimSetup}\marg{options}
%   \end{syntax}
%   \pkg{jmsdelim} can be customized along a few axes.
% \end{function}
%
% \begin{variable}{size commands}
%   The option \cmd{size commands} is a comma-separated list which contains a list of sizing commands for delimiters, from smallest to largest. By default, the standard \cs{big}, \cs{Big}, \cs{bigg}, \cs{Bigg} sequence is replaced by custom versions that behave differently in script size. This behavior can be overridden as follows:
%   \begin{verbatim}
%     \DelimSetup{
%       size commands = {\relax,\big,\Big,\bigg,\Bigg}
%     }
%   \end{verbatim}
% \end{variable}
%
%
%
% \section{Interface for macro authors}
%
% The internals of \pkg{jmsdelim} are implemented in \pkg{expl3}.
%
% \begin{function}{jmsdelim_scope:nn}
%   \begin{syntax}
%     "jmsdelim_scope:nn" \Arg{pre} \Arg{post}
%   \end{syntax}
%   This is the fundamental control structure for authors of custom delimiting commands; \meta{pre} is a block of code that renders things to temporary boxes, and \Arg{post} is code that \emph{uses} these boxes, placing them relative to some delimiters. The function of \cs{jmsdelim_scope:nn} is to watch for the delimiter size updates induced by \meta{pre}, and set the delimiter size commands correctly before executing \meta{post}. Both \meta{pre} and \meta{post} are to be executed in the same block level.
% \end{function}
%
% \begin{function}{jmsdelim_hbox_set:Nn}
%   \begin{syntax}
%     "jmsdelim_hbox_set:Nn" \Arg{box} \Arg{contents}
%   \end{syntax}
%   This command is meant to be used inside the \meta{pre} block of \cs{jmsdelim_scope:nn}; it typesets \meta{contents} in the box named by \meta{box}, correctly propagating the math style.
% \end{function}
%
% \begin{function}{jmsdelim_size_cmd:}
%   \begin{syntax}
%     "jmsdelim_size_cmd:"
%   \end{syntax}
%   This command is meant to be used inside the \meta{post} block of \cs{jmsdelim_scope:nn} to set the size of a given delimiter; it behaves like \cs{big}, etc.
% \end{function}
%
% \begin{function}{jmsdelim_surround:nnn}
%   \begin{syntax}
%     "jmsdelim_surround:nnn" \Arg{left} \Arg{right} \Arg{body}
%   \end{syntax}
%   This routine surrounds \meta{body} with the delimiters \meta{left} and \meta{right} of the appropriate size respectively.
% \end{function}
%
% \begin{function}{jmsdelim_between:nnn}
%   \begin{syntax}
%     "jmsdelim_between:nnn" \Arg{sep} \Arg{lbody} \Arg{rbody}
%   \end{syntax}
%   This routine separates \meta{lbody} and \meta{rbody} with a separator \meta{sep} of the appropriate size.
% \end{function}
%
% \begin{function}{jmsdelim_between:nnnnn}
%   \begin{syntax}
%     "jmsdelim_between:nnnnn" \Arg{left} \Arg{sep} \Arg{right} \Arg{lbody} \Arg{rbody}
%   \end{syntax}
%   This routine separates \meta{lbody} and \meta{rbody} with a separator \meta{sep} of the appropriate size, and surrounds the result by \meta{left} and \meta{right} respectively of the same size.
% \end{function}
%
% \begin{function}{jmsdelim_protect:n}
%   \begin{syntax}
%     "jmsdelim_protect:n" \Arg{body}
%   \end{syntax}
%   Executes \meta{body} in a sandbox, preventing its state updates from bubbling upward.
% \end{function}
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{jmsdelim} implementation}
% \label{sec:jmsdelim:implementation}
%
%
%    \begin{macrocode}
%<*package>
\RequirePackage{expl3}
\RequirePackage{l3keys2e}
\RequirePackage{xparse}
\RequirePackage{ifluatex}
\RequirePackage{scalerel}
\ProvidesExplPackage {jmsdelim} {2022/03/11} {0.2.0}
  {Compositional delimiter sizing}
%<@@=jmsdelim>
%    \end{macrocode}
%
% We first declare the options for the \pkg{jmsdelim} module, together with their default valeus.
%
%    \begin{macrocode}
\keys_define:nn { jmsdelim } {
  size~commands .clist_set:N = \l@@_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}}
}
%    \end{macrocode}
%
% Then, we set up the internal state that will be used by \pkg{jmsdelim}.
%    \begin{macrocode}
\int_new:N \g@@_size
\int_new:N \g@@_size_up
\int_gset:Nn \g@@_size {0}
\int_gset:Nn \g@@_size_up {0}
%    \end{macrocode}
%
% \subsection{Internals}
%
% \begin{macro}{\@@_clist_item:Nn}
% A version of \cs{clist_item:Nn} that takes the last item when the index is out of bounds.
%    \begin{macrocode}
\cs_new:Npn \@@_clist_item:Nn #1 #2 {
  \clist_item:Nn #1 {
    \int_min:nn { #2 } {\clist_count:N #1}
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{@@_setup_sizes:}
%    \begin{macrocode}
\cs_new:Npn \@@_setup_sizes: {
  \int_gset:Nn \g@@_size {
    \int_max:nn \g@@_size \g@@_size_up
  }

  \cs_set_eq:Nc \jmsdelim_size_cmd: {
    \@@_clist_item:Nn \l@@_size_cmds {
      \g@@_size + 1
    }
  }
}
%    \end{macrocode}
% \end{macro}

%
% \subsubsection{Preservation of math styles}
% It is fairly complicated and inefficient to preserve math styles across boxes. There is an appropriate way to do so in Lua\LaTeX, which we use conditionally if available; otherwise, we make use of \cs{ThisStyle} and \cs{SavedStyle} from \pkg{scalerel}~\citep{segletes:scalerel}, which are more inefficient. In fact, it becomes impossible to use \pkg{jmsdelim} in PDF\LaTeX{} when the nesting is sufficiently deep, whereas there is no corresponding blowup in Lua\LaTeX. The \cs{ignoremathstyle} and \cs{discernmathstyle} macros from \pkg{scalerel} can be used to turn off the inefficient preservation of math styles locally, such as in the case where no subscripts are used.

% \begin{macro}{@@_luatex_save_mathstyle:N}
%    \begin{macrocode}
\cs_new:Npn \@@_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
}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{@@_restore_mathstyle:n}
%    \begin{macrocode}
\cs_new:Npn \@@_restore_mathstyle: {
  \SavedStyle
}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{@@_save_mathstyle:n}
%    \begin{macrocode}
\cs_new:Npn \@@_save_mathstyle:n #1 {
  \ifluatex
    \@@_luatex_save_mathstyle:N \@@_restore_mathstyle:
    #1
  \else
    \ThisStyle{#1}
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Public interface for macro authors}
%
% \begin{macro}{jmsdelim_scope:nn}
%    \begin{macrocode}
\cs_new:Npn \jmsdelim_scope:nn #1 #2 {
  \group_begin:
    \int_set:Nn \l_tmpa_int \g@@_size_up
    \int_gset:Nn \g@@_size_up 0
    \int_gset:Nn \g@@_size 0
    \group_begin:
      \@@_save_mathstyle:n {
        #1
        \@@_setup_sizes:
        #2
      }
    \group_end:
    \int_gset:Nn \g@@_size_up {\int_max:nn \g@@_size_up \l_tmpa_int}
  \group_end:
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{jmsdelim_hbox_set:Nn}
%    \begin{macrocode}
\cs_new:Npn \jmsdelim_hbox_set:Nn #1 #2 {
   \mode_if_math:TF
     { \hbox_set:Nn #1 {$\m@th\@@_restore_mathstyle: #2$} }
     { \hbox_set:Nn #1 { #2 } }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{jmsdelim_surround:nnn}
%    \begin{macrocode}
\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}
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{jmsdelim_protect:n}
%    \begin{macrocode}
\cs_new:Npn \jmsdelim_protect:n #1 {
  \group_begin:
    \int_set:Nn \l_tmpa_int \g@@_size_up
    \int_set:Nn \l_tmpb_int \g@@_size
    \group_begin: #1 \group_end:
    \int_gset:Nn \g@@_size_up \l_tmpa_int
    \int_gset:Nn \g@@_size \l_tmpb_int
  \group_end:
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{jmsdelim_between:nnn}
%    \begin{macrocode}
\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
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{jmsdelim_between:nnnnn}
%    \begin{macrocode}
\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}
  }
}
%    \end{macrocode}
% \end{macro}

% \subsection{Document interace}


% \begin{macro}{DelimMin}
%    \begin{macrocode}
\NewDocumentCommand\DelimMin{m}{
  \int_gset:Nn \g@@_size_up {\int_max:nn \g@@_size_up {#1}}
}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{DelimSurround}
%    \begin{macrocode}
\NewDocumentCommand\DelimSurround{mmm}{
  \jmsdelim_surround:nnn {#1} {#2} {#3}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{DelimBetween}
%    \begin{macrocode}
\NewDocumentCommand\DelimBetween{mmm}{
  \jmsdelim_between:nnn {#1} {#2} {#3}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{DelimBetweenSurround}
%    \begin{macrocode}
\NewDocumentCommand\DelimBetweenSurround{mmmmm}{
  \jmsdelim_between:nnnnn {#1} {#2} {#3} {#4} {#5}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{DelimProtect}
%    \begin{macrocode}
\NewDocumentCommand\DelimProtect{m}{
  \jmsdelim_protect:n {#1}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{DelimPrn}
%    \begin{macrocode}
\NewDocumentCommand\DelimPrn{m}{
  \jmsdelim_surround:nnn {(} {)} {#1}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{DelimBrk}
%    \begin{macrocode}
\NewDocumentCommand\DelimBrk{m}{
  \jmsdelim_surround:nnn {[} {]} {#1}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{DelimBrc}
%    \begin{macrocode}
\NewDocumentCommand\DelimBrc{m}{
  \jmsdelim_surround:nnn {\lbrace} {\rbrace} {#1}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{DelimBbrk}
%    \begin{macrocode}
\NewDocumentCommand\DelimBbrk{m}{
  \jmsdelim_surround:nnn {\llbracket} {\rrbracket} {#1}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{DelimGl}
%    \begin{macrocode}
\NewDocumentCommand\DelimGl{m}{
  \jmsdelim_surround:nnn {\langle} {\rangle} {#1}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{DelimVrt}
%    \begin{macrocode}
\NewDocumentCommand\DelimVrt{m}{
  \jmsdelim_surround:nnn {\lvert} {\rvert} {#1}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{DelimVvrt}
%    \begin{macrocode}
\NewDocumentCommand\DelimVvrt{m}{
  \jmsdelim_surround:nnn {\lVert} {\rVert} {#1}
}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\ProcessKeysPackageOptions {jmsdelim}
%    \end{macrocode}
%
%\iffalse meta-comment
%</package>
%\fi
%
% \end{implementation}
%
% \printbibliography
% \PrintIndex
%
\endinput
%
% end of file