summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/physics2/phy-braket.sty
blob: a6e88c13ccb7df93828078c143c4c7efd15c918c (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
%% 
%% This is file `phy-braket.sty',
%% the `braket' 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-braket.sty}
  [2023/01/25 `braket' module of `physics2.sty']
% Here we need to get the definition of \phy@abopen and \phy@abclose.
\phy@requiremodule{ab}
\ifdefined\phy@abb@bkv
  \PackageWarning{physics2}{You cannot load `ab.braket' and `braket'
    modules together.\MessageBreak Only `braket' module works now.}
\fi
% \bra
\DeclareDocumentCommand\bra{ s o m }{%
  \IfBooleanTF{#1}%
    {\mathopen\langle#3\mathclose\vert}%
    {\IfValueTF{#2}%
      {\csname#2l\endcsname\langle#3\csname#2r\endcsname\vert}%
      {\phy@abopen\langle#3\phy@abclose\vert}%
    }%
}
% \ket
\DeclareDocumentCommand\ket{ s o m }{%
  \IfBooleanTF{#1}%
    {\mathopen\vert#3\mathclose\rangle}%
    {\IfValueTF{#2}%
      {\csname#2l\endcsname\vert#3\csname#2r\endcsname\rangle}%
      {\phy@abopen\vert#3\phy@abclose\rangle}%
    }%
}
% \braket
\DeclareDocumentCommand\braket{ s O{} }{%
  \IfBooleanTF{#1}%
    {%
      \gdef\@phy@bk@argnum{ii}%
      \phy@bk@doopt{#2}%
      \gdef\@phy@bk@l{mathopen}%
      \gdef\@phy@bk@m{mathord}%
      \gdef\@phy@bk@r{mathclose}%
    }%
    {%
      \gdef\@phy@bk@argnum{ii}%
      \gdef\@phy@bk@l{phy@abopen}%
      \gdef\@phy@bk@m{middle}%
      \gdef\@phy@bk@r{phy@abclose}%
      \phy@bk@doopt{#2}%
    }%
  \csname phy@bk@in@\@phy@bk@argnum\endcsname%
}
% The internal version of \braket
\def\phy@bk@in@i#1{%
  \csname\@phy@bk@l\endcsname\langle{#1}%
  \csname\@phy@bk@r\endcsname\rangle}
\def\phy@bk@in@ii#1#2{%
  \csname\@phy@bk@l\endcsname\langle{#1}%
  \csname\@phy@bk@m\endcsname\vert{#2}%
  \csname\@phy@bk@r\endcsname\rangle}
\def\phy@bk@in@iii#1#2#3{%
  \csname\@phy@bk@l\endcsname\langle{#1}%
  \csname\@phy@bk@m\endcsname\vert{#2}%
  \csname\@phy@bk@m\endcsname\vert{#3}%
  \csname\@phy@bk@r\endcsname\rangle}
% Parse the optional argument of \braket.
\def\@phy@bk@do@pt#1,{\ifx#1\relax\@empty\else%
  \edef\reserved@a{\zap@space#1 \@empty}%
  \ifx\reserved@a\@empty\else%
    \ifcsname phy@del\expandafter\string\csname\reserved@a\endcsname\endcsname%
      \xdef\@phy@bk@l{\reserved@a l}%
      \xdef\@phy@bk@m{\reserved@a}% but not m (m stands for \mathrel)
      \xdef\@phy@bk@r{\reserved@a r}%
    \else%
      \ifnum\reserved@a>3%
        \PackageError{physics2}{\string\braket\space can only take 3
          mandatory arguments at most}{Check if you had written a number
          more than 3 in the [optional] argument.}%
      \fi%
      \xdef\@phy@bk@argnum{\romannumeral\reserved@a}%
    \fi%
  \fi%
\expandafter\@phy@bk@do@pt\fi}
\def\phy@bk@doopt#1{\@phy@bk@do@pt#1,\relax,}
% \ketbra
\DeclareDocumentCommand\ketbra{ s o m O{} m }{%
  \IfBooleanTF{#1}%
    {\mathopen\vert#3\mathclose\rangle#4\mathopen\langle#5\mathclose\vert}%
    {\IfValueTF{#2}%
      {\csname#2l\endcsname\vert#3\csname#2r\endcsname\rangle#4%
        \csname#2l\endcsname\langle#5\csname#2r\endcsname\vert}%
      {\begingroup%
        \phy@abopen\vert\mathopen{\phy@mathvphantom{#5}}#3\phy@abclose\rangle#4%
        \phy@abopen\langle#5\mathclose{\phy@mathvphantom{#3}}\phy@abclose\vert%
      \endgroup}%
    }%
}
\endinput
%% End of file `phy-braket.sty'.