summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/physics2/phy-ab.sty
blob: 4436a65214dfd3e87251aeb2f7cef53560215ea4 (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
%% 
%% This is file `phy-ab.sty',
%% the `ab' module of `physics2' package.
%% 
%% ******************************************************
%% * This work may be distributed and/or modified under *
%% * the conditions of the LaTeX Project Public License *
%% *                                                    *
%% *     http://www.latex-project.org/lppl.txt          *
%% *                                                    *
%% * either version 1.3c of this license or any later   *
%% * version.                                           *
%% ******************************************************
%% 
%% This work has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is Zhang Tingxuan.
%% 
\ProvidesFile{phy-ab.sty}
  [2023/02/07 `ab' (autobraces) module of `physics2.sty']
% \phy@requiremodule{common}
% The `tightbraces' bool option, true or false.
\phy@define@key{ab}{tightbraces}[true]{\def\@phy@abtight{#1}}
% Execute the default values to keys in this module.
\phy@setkeys{ab}{tightbraces=true}
\phy@processkeyopt{ab}
% \phy@abopen and \phy@abclose,
% internal definition for all commands in this module.
\ifx\@phy@abtight\phy@true
  \let\phy@abopen\delopen
  \let\phy@abclose\delclose
\else
  \let\phy@abopen\left
  \let\phy@abclose\right
\fi
% The internal version of \ab. #1: `ab' or `mb'; #2: open symbol; (#3: arg-spec; #4: definition)
\def\phy@AB@gen#1#2{\expandafter\DeclareDocumentCommand\csname phy@#1@\string#2\endcsname}
% #1 (r<token1><token2>): inner content.
\phy@AB@gen{ab}({r()}{\phy@abopen(#1\phy@abclose)}
\phy@AB@gen{ab}[{r[]}{\phy@abopen[#1\phy@abclose]}
\phy@AB@gen{ab}\{{r\{\}}{\phy@abopen\{#1\phy@abclose\}}
\phy@AB@gen{ab}|{r||}{\phy@abopen|#1\phy@abclose|}
\phy@AB@gen{ab}\|{r\|\|}{\phy@abopen\|#1\phy@abclose\|}
\phy@AB@gen{ab}<{r<>}{\phy@abopen<#1\phy@abclose>}
\phy@AB@gen{ab}\lbrace{r\lbrace\rbrace}{\phy@abopen\lbrace#1\phy@abclose\rbrace}
\phy@AB@gen{ab}\vert{r\vert\vert}{\phy@abopen\vert#1\phy@abclose\vert}
\phy@AB@gen{ab}\Vert{r\Vert\Vert}{\phy@abopen\Vert#1\phy@abclose\Vert}
\phy@AB@gen{ab}\langle{r\langle\rangle}{\phy@abopen\langle#1\phy@abclose\rangle}
% #1 (m): \biggg; #2 (r<token1><token2>): inner content.
\phy@AB@gen{mb}({mr()}{\mathopen#1(#2\mathclose#1)}
\phy@AB@gen{mb}[{mr[]}{\mathopen#1[#2\mathclose#1]}
\phy@AB@gen{mb}\{{mr\{\}}{\mathopen#1\lbrace#2\mathclose#1\rbrace}
\phy@AB@gen{mb}|{mr||}{\mathopen#1\vert#2\mathclose#1\vert}
\phy@AB@gen{mb}\|{mr\|\|}{\mathopen#1\Vert#2\mathclose#1\Vert}
\phy@AB@gen{mb}<{mr<>}{\mathopen#1\langle#2\mathclose#1\rangle}
\phy@AB@gen{mb}\lbrace{mr\lbrace\rbrace}{\mathopen#1\lbrace#2\mathclose#1\rbrace}
\phy@AB@gen{mb}\vert{mr\vert\vert}{\mathopen#1\vert#2\mathclose#1\vert}
\phy@AB@gen{mb}\Vert{mr\Vert\Vert}{\mathopen#1\Vert#2\mathclose#1\Vert}
\phy@AB@gen{mb}\langle{mr\langle\rangle}{\mathopen#1\langle#2\mathclose#1\rangle}
% \phy@del, the automatic braces. #1: opensymbol; #2: close symbol; #3
\def\phy@del#1#2#3{\phy@abopen#1#3\phy@abclose#2}
\expandafter\def\csname phy@del\string*\endcsname#1#2#3{\mathopen#1#3\mathclose#2}
\expandafter\def\csname phy@del\string\big\endcsname#1#2#3{\bigl#1#3\bigr#2}
\expandafter\def\csname phy@del\string\Big\endcsname#1#2#3{\Bigl#1#3\Bigr#2}
\expandafter\def\csname phy@del\string\bigg\endcsname#1#2#3{\biggl#1#3\biggr#2}
\expandafter\def\csname phy@del\string\Bigg\endcsname#1#2#3{\Biggl#1#3\Biggr#2}
\expandafter\def\csname phy@del\string\biggg\endcsname#1#2#3{\bigggl#1#3\bigggr#2}
\expandafter\def\csname phy@del\string\Biggg\endcsname#1#2#3{\Bigggl#1#3\Bigggr#2}
% \phy@d@lx (phy_del_x): the internal defination of \ab.
% #1: `mb', according to \phy@AB@gen; #2: `ab'; #3: star or big or left delimiter.
\def\phy@d@lx#1#2#3{%
  \ifcsname phy@del\string#3\endcsname%
    \def\reserved@a{#1}% #3 is star or biggg, then get the next argument.
  \else%
    \def\reserved@a{#2}% #3 is delimiter, the braces are automatic.
  \fi%
  \csname phy@d@lx\reserved@a\endcsname#3}
% The first two arguments of \phy@d@lx need to be generated by the following two commands.
\def\phy@d@l@genxm#1{% generate arguments like `mb'
  \expandafter\def\csname phy@d@lx#1\endcsname##1##2{%
    \ifx##1*\let\phy@tempa=\relax\else\let\phy@tempa=##1\fi
    \csname phy@#1@\string##2\endcsname\phy@tempa##2}}
\def\phy@d@l@genxa#1{% generate arguments like `ab'
  \expandafter\def\csname phy@d@lx#1\endcsname##1{%
    \csname phy@#1@\string##1\endcsname##1}}
% Generate the `mb' and `ab' arguments.
\phy@d@l@genxm{mb}
\phy@d@l@genxa{ab}
% \ab(<subformula>), after \ab can be a star or \biggg.
\DeclareRobustCommand\ab{\phy@d@lx{mb}{ab}}
% \phy@d@l@geny: define commands like \pab. #1: cs; #2: open symbol; #3: close symbol.
\def\phy@d@l@geny#1#2#3{%
  \DeclareDocumentCommand#1{som}{% ##1: star; ##2: bigg (csname); ##3: subformula.
    \IfBooleanTF{##1}%
      {#2##3#3}%
      {\IfValueTF{##2}%
        {\csname##2l\endcsname#2##3\csname##2r\endcsname#3}%
        {\phy@abopen#2##3\phy@abclose#3}%
      }%
  }%
}
\phy@d@l@geny\pab()
\phy@d@l@geny\bab[]
\phy@d@l@geny\Bab\lbrace\rbrace
\phy@d@l@geny\vab\vert\vert
\phy@d@l@geny\aab\langle\rangle
\phy@d@l@geny\Vab\Vert\Vert
\endinput
%% End of file `phy-ab.sty'.