Debian Codegraph @

texmf-dist/source/latex/physics3/physics3.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: physics3.dtx
4 % -----------------------------------------------------------------------
5 % Copyright (C) 2026 by Mingyu Xia <[email protected]> *
6 % Copyright (C) 2022-2024 by Tingxuan Zhang <[email protected]> *
7 % -----------------------------------------------------------------------
8 % This work may be distributed and/or modified under the conditions *
9 % of the LaTeX Project Public License (LPPL), either version 1.3c of *
10 % this license or (at your option) any later version. *
11 % The latest version of this license is in *
12 % *
13 % http://www.latex-project.org/lppl.txt *
14 % *
15 % and version 1.3c or later is part of all distributions of LaTeX *
16 % version 2008 or later. *
17 % *
18 % This work has the LPPL maintenance status `maintained'. *
19 % *
20 % The Current Maintainer of this work is Mingyu Xia. *
21 % -----------------------------------------------------------------------
22 % This work consists of the files physics3.dtx, *
23 % physics3.ins, *
24 % the derived files physics3.sty, *
25 % phx-ab.sty, *
26 % phx-ab.braket.sty, *
27 % phx-braket.sty, *
28 % phx-doubleprod.sty, *
29 % phx-diagmat.sty, *
30 % phx-xmat.sty, *
31 % phx-operator.sty, *
32 % phx-ab.legacy.sty, *
33 % phx-qtext.legacy.sty, *
34 % the documentation files physics3.pdf, *
35 % and README.md. *
36 % -----------------------------------------------------------------------
37 % *
38 % Any modification of this file should ensure that the copyright and *
39 % license information is placed in the derived files. *
40 % *
41 % -----------------------------------------------------------------------
42 %
43 %<*internal>
44 \iffalse
45 %</internal>
46 %
47 %<*readme>
48 [![CTAN Version](https://img.shields.io/ctan/v/physics3)](https://ctan.org/pkg/physics3)
49 [![GitHub Release](https://img.shields.io/github/v/release/myhsia/physics3)](https://github.com/myhsia/physics3/releases/latest)
50 [![GitHub Last Commit](https://img.shields.io/github/last-commit/myhsia/physics3)](https://github.com/myhsia/physics3/commits)
51 [![Actions Status](https://github.com/myhsia/physics3/actions/workflows/main.yaml/badge.svg?branch=main)](https://github.com/myhsia/physics3/actions)
52 [![GitHub Repo stars](https://img.shields.io/github/stars/myhsia/physics3)](https://github.com/myhsia/physics3)
53
54 The `physics3` Package
55 ======================
56
57 This package defines commands for typesetting math formulae faster and
58 more simply. `physics3` is a modularized package, each module provides its
59 own function while `physics3.sty` itself only provides very few functions.
60 Therefore you can load modules separately after loading `physics3`.
61
62 Modules of `physics3` provide the following supports:
63
64 - Automatic braces;
65 - Dirac bra-ket notation;
66 - Easy way to typeset diagonal matrices and matrices with similar entries;
67 - Double cross and double dot (binary) operators for tensors;
68
69 Issues
70 ------
71
72 The issue tracker for `physics3` is currently located
73 [on GitHub](https://github.com/myhsia/physics3).
74
75 Copyright and License
76 ---------------------
77
78 Copyright (C) 2026 by Mingyu Xia \<[email protected]\>
79
80 Copyright (C) 2022-2024 by Tingxuan Zhang \<[email protected]\>
81
82 This work may be distributed and/or modified under the conditions
83 of the LaTeX Project Public License (LPPL), either version 1.3c of
84 this license or (at your option) any later version.
85 The latest version of this license is in
86
87 http://www.latex-project.org/lppl.txt
88
89 and version 1.3c or later is part of all distributions of LaTeX
90 version 2008 or later.
91
92 This work has the LPPL maintenance status `maintained'.
93
94 The Current Maintainer of this work is **Mingyu Xia**.
95 %</readme>
96 %
97 %<*internal>
98 \fi
99 %</internal>
100 %
101 %<*driver>
102 \documentclass[11pt, letterpaper, cs-break = true]{l3doc}
103 \usepackage[osf, mono = false]{libertine}
104 \usepackage{mathtools, fixdif, derivative, xcolor}
105 \usepackage{physics3}
106 \usephxmodu{ab, ab.braket, diagmat, doubleprod, operator, xmat}
107 \usephxmodu{ab.legacy, qtext.legacy}
108 \setcounter{tocdepth}{1}
109 \ExplSyntaxOn \makeatletter
110 \newcommand \mail[1]{\href{mailto:#1}{\ttfamily #1}}
111 \DeclareDocumentCommand \key { s m }
112 {
113 \IfBooleanTF {#1} { \textcolor{red}{\ttfamily \bfseries #2} }
114 {
115 \ttfamily
116 \seq_set_from_clist:Nn \l_tmpa_seq {#2}
117 \seq_set_map:NNn \l_tmpb_seq \l_tmpa_seq
118 { \exp_not:n { \textcolor{red}{\bfseries ##1} } }
119 \seq_use:Nn \l_tmpb_seq { ,~ } \:=\:
120 }
121 }
122 \DeclareCommandCopy \val \meta
123 \def \TTF {\textup{\textbf{true}\makebox[0pt][r]{^^A
124 \underline {\phantom{\bfseries true}\kern-0.1em}}\textbar}false}
125 \def \TFF {true\textup{\textbar\textbf{false}\makebox[0pt][r]{^^A
126 \underline {\phantom{\bfseries false}\kern-0.1em}}}}
127 \newlist{keyval}{itemize}{10}
128 \setlist[keyval]{leftmargin = 0pt, labelsep = 0pt}
129 \newwrite\example@out
130 \def\example@name{\jobname.example.aux}
131 \long\def\example@start{\begingroup\@bsphack
132 \immediate\openout\example@out=\example@name
133 \let\do\@makeother\dospecials\catcode`\^^M\active
134 \def\verbatim@processline{\immediate\write\example@out{\the\verbatim@line}}^^A
135 \verbatim@start}
136 \long\def\example@end#1{\immediate\closeout\example@out\@esphack\endgroup
137 \catcode`\%14\relax
138 \everymath{\displaystyle}
139 \par\smallskip\noindent
140 \fbox{\parbox[c][#1]{.6\linewidth}{\small\verbatiminput \example@name}}^^A
141 \hfill
142 \fbox{\parbox[c][#1]{.36\linewidth}
143 {\centering\normalsize\input \example@name}}^^A
144 \par\smallskip
145 \catcode`\%9\relax}
146 \NewDocumentEnvironment{example}{m}{\example@start}
147 {\example@end{#1\baselineskip}}
148 \protect \def \pardanger {\noindent \hbox to \z@{\hss \dbend \enspace}}
149 \providecommand \modu[1]{\texorpdfstring{\texttt{#1}}{“#1”}}
150 \linespread{1.06}
151 \@addtoreset{CodelineNo}{section}
152 \newbox\@tempboxb
153 \DeclareDocumentCommand\macrodef{O{4em}O{.6}mo+m}{\leavevmode
154 \ensuremath{^^A
155 \setbox\@tempboxa\hbox to #1 {\hss\cs{#3}}^^A
156 \setbox\@tempboxb\vbox{\hsize=#2\textwidth
157 \textwidth=\hsize
158 \leftskip=\z@
159 \parindent=\z@
160 \textbf{begindef}\IfValueT{#4}{ \textcolor{gray}{(#4)}}\par
161 \begingroup\leftskip2em\parindent-1em#5\par\endgroup
162 \textbf{enddef}^^A
163 }^^A
164 \dp\@tempboxb=\dimexpr\ht\@tempboxb-\ht\@tempboxa\relax
165 \ht\@tempboxb=\ht\@tempboxa
166 \box\@tempboxa\leftarrow\box\@tempboxb
167 }}
168 \protected \long \def \macroifelse#1#2#3{\par
169 \textbf{if} #1 \textbf{then}\par
170 \begingroup\advance\leftskip1em#2\par\endgroup
171 \textbf{else}\par
172 \begingroup\advance\leftskip1em#3\par\endgroup
173 \textbf{endif}\par
174 }
175 \protected \def \macrocr{\par}
176 \newdimen\ttwd
177 \newdimen\sttwd
178 \protected\def\updatettwd{^^A
179 \setbox\@tempboxa\hbox{\normalsize\ttfamily x}
180 \ttwd=\wd\@tempboxa
181 \setbox\@tempboxb\hbox{\small\ttfamily x}
182 \sttwd=\wd\@tempboxb
183 }
184 \updatettwd
185 \makeatother \ExplSyntaxOff
186 \begin{document}
187 \DeleteShortVerb\|
188 \DocInput{\jobname.dtx}
189 \end{document}
190 %</driver>
191 % \fi
192 %
193 % \begin{documentation}
194 %
195 % \title{The \pkg{physics3} package\thanks{^^A
196 % \url{https://github.com/myhsia/physics3},
197 % \url{https://ctan.org/pkg/physics3}}
198 % }
199 %
200 % \author{Mingyu Xia\thanks{\mail{[email protected]}}}
201 %
202 % \date{Released 2026-02-07\quad \texttt{v0.2A}}
203 %
204 % \maketitle
205 %
206 % \begin{abstract}
207 % This is the document for \pkg{physics3} package, which defines commands for
208 % typesetting math formulae faster and more simply. \pkg{physics3} is a
209 % modularized package, each module provides its own function\footnote{^^A
210 % If you are a user of the legacy \pkg{physics} package, see
211 % Section~\ref{sec:physics-legacy} before you start.}.
212 % \end{abstract}
213 %
214 % \tableofcontents
215 %
216 % \clearpage
217 %
218 % \section{Introduction}
219 %
220 % The \pkg{physics3} package aims to provide a bundle of commands for
221 % typesetting math faster in different modules. The commands provided by
222 % \pkg{physics3} and its different modules are designed to be short and easy
223 % to memorize.
224 %
225 % \subsection{Packages required}
226 %
227 % The \pkg{physics3} package itself only requires the \pkg{keyval} package,
228 % which is part of the \pkg{latex-graphics} bundle. Almost every \LaTeX\
229 % distribution will include this bundle.
230 %
231 % Different modules of \pkg{physics3} might require different packages. It will
232 % be explained in the following sections that which module requires which
233 % package.
234 %
235 % The \pkg{physics3} package requires \LaTeXe\ kernel released after 2020/10.
236 % Please make sure that your \LaTeX\ distribution is not too old.
237 %
238 % \subsection{Loading \pkg{physics3} and its modules}
239 %
240 % Just like loading any package, write
241 % \begin{quote}
242 % "\usepackage{physics3}"
243 % \end{quote}
244 % in the preamble to load the \pkg{physics3} package. In the current version,
245 % \pkg{physics3} doesn't provide a package option.
246 %
247 % \pkg{physics3} itself doesn't provide many features.
248 % You need to load different modules of \pkg{physics3} by using the
249 % \cs{usephxmodu} command only \emph{after} loading this package in the
250 % preamble to have different features applied to your document.
251 % \begin{function}{\usephxmodu}
252 % \begin{syntax}
253 % \cs{usephxmodu} \oarg{options} \marg{module}
254 % \end{syntax}
255 % \end{function}
256 % The usage of \cs{usephxmodu} is similar to \cs{usepackage},
257 % so you can load several modules in one line. For example,
258 % \begin{quote}
259 % "\usephxmodu [tightbraces = true] {ab}"\\
260 % "\usephxmodu {ab.braket, doubleprod}"
261 % \end{quote}
262 % The options of a \pkg{physics3} module can be a comma-separated key-value
263 % list. These two lines load the \modu{ab} module with option
264 % "tightbraces = true" and load \modu{ab.braket} and \modu{doubleprod} modules.
265 %
266 % The following section introduce all the user-level modules of \pkg{physics3}.
267 % The modules have similar names like \meta{module}".legacy" are designed to
268 % provide solutions to maintain documents written with the legacy \pkg{physics}
269 % package. It's not suggested to use them in a new document.
270 %
271 % \section{Modules of \pkg{physics3}}
272 %
273 % \subsection{Features of the bare \pkg{physics3} package}
274 %
275 % The following commands are available once you load \pkg{physics3} in preamble.
276 % \begin{function}{\delopen, \delclose}
277 % \begin{syntax}
278 % \cs{delopen} \meta{math delimiter} ... \cs{delclose} \meta{math delimeter}
279 % \end{syntax}
280 % \cs{delopen} and \cs{delclose}, followed by a math delimiter. They can be
281 % regarded as abbreviations of ``open delimiter'' and ``close delimiter''. If
282 % you had heard of the \pkg{mleftright} package.
283 % You can regard \cs{delopen} and \cs{delclose} as a simpler version of
284 % \cs[no-index]{mleft} and \cs[no-index]{mright}.
285 % \end{function}
286 % For example,
287 % \iffalse
288 %<*example>
289 % \fi
290 \begin{example}{2}
291 $ 0 \left(\frac12\right) 3 $\quad
292 $ 0 \delopen(\frac12\delclose) 3 $
293 \end{example}
294 % \iffalse
295 %</example>
296 % \fi
297 % \cs{biggg} and \cs{Biggg}, followed by a math delimiter. They are even bigger
298 % than \cs{Bigg}. \cs{biggg} and \cs{Biggg} may be useful when you need to write
299 % something really tall in math mode, but most OpenType math font do not support
300 % \cs{langle} (or U+27E8) and \cs{rangle} (or U+27E9) in this large size. Take
301 % an example,
302 % \iffalse
303 %<*example>
304 % \fi
305 \begin{example}{3}
306 $ \Biggg(\biggg(\Bigg(\bigg(
307 \Big(\big(()\big)\Big)
308 \bigg)\Bigg)\biggg)\Biggg) $
309 \end{example}
310 % \iffalse
311 %</example>
312 % \fi
313 % \cs{bigggl}, \cs{bigggm}, \cs{bigggr}, \cs{Bigggl}, \cs{Bigggm}
314 % and~\cs{Bigggr} are also supported.
315 %
316 % \subsection{The \modu{ab} module --- automatic braces}
317 %
318 % This module provides the command \cs{ab}. The \cs{ab} command, as a shorthand
319 % of ``automatic braces'', would specify the size of the following pair of
320 % delimiters. The delimiters after \cs{ab} should not be out of the range
321 % described by the following chart.
322 % \begin{function}{\ab}
323 % \begin{syntax}
324 % \cs{ab}" ( ... ) " \cs{ab}" [ ... ] "
325 % \cs{ab}"\{ ... \}" or \cs{ab} \cs{lbrace} ... \cs{rbrace}
326 % \cs{ab}" < ... > " or \cs{ab} \cs{langle} ... \cs{rangle}
327 % \cs{ab}" | ... | " or \cs{ab} \cs{vert} ... \cs{vert}
328 % \cs{ab}"\| ... \|" or \cs{ab} \cs{Vert} ... \cs{Vert}
329 % \end{syntax}
330 % \end{function}
331 % For example, it's illegal to write an ``"\ab("'' without a ``")"'';
332 % it's also illegal to write "\ab=foo=". Take some correct examples:
333 % \iffalse
334 %<*example>
335 % \fi
336 \begin{example}{3}
337 $ \ab ( \frac12 ) $ \quad
338 $ \ab [ \frac12 ] $ \quad
339 $ \ab\{ \frac12 \} $
340 \end{example}
341 % \iffalse
342 %</example>
343 % \fi
344 % You can also write a command from \cs{big} to \cs{Biggg} between \cs{ab}
345 % and the first delimiter, which means to specify the size of
346 % delimiters manually.
347 % Also, you can write a star ("*") between \cs{ab} and the first delimiter,
348 % to prevent \cs{ab} from setting the size of delimiters. For example,
349 % \iffalse
350 %<*example>
351 % \fi
352 \begin{example}{3}
353 $ \ab <\frac12> $\quad
354 $ \ab\biggg|\frac12| $\quad
355 $ \ab* \|\frac12\| $
356 \end{example}
357 % \iffalse
358 %</example>
359 % \fi
360 % \pardanger
361 % Always remember, do not put an \cs{ab} separately at the end of math mode like
362 % "$\ab$", because \cs{ab} will try to absorb the following math shift
363 % character ("$") as its argument.
364 %
365 % \begin{texnote}
366 % The \modu{ab} module uses ``document commands''
367 % module of \LaTeXe\ kernel (source file: ltcmd.dtx). This \LaTeXe\ kernel
368 % module provides a document-level command parser. \cs{ab} is a complex
369 % encapsulation of some internal document-level commands. Take an example,
370 % if you define a document-level command like this:
371 % \begin{quote}
372 % "\NewDocumentCommand \foo { r() } {::#1::}"
373 % \end{quote}
374 % You can write "\foo(bar)" legally, but "\foo(()" will be regarded
375 % illegal when you write another document-level command or end the paragraph.
376 % Similarly, things like "\ab(()" will also cause errors.
377 % \end{texnote}
378 %
379 % The \modu{ab} module also provides \texttt{\textbackslash}$X$\texttt{ab}
380 % commands, where $X$ can be "p", "b", "B", "a", "v" and "V". These commands
381 % take a normal argument but not an argument delimited with paired delimiters.
382 % For example,
383 % \iffalse
384 %<*example>
385 % \fi
386 \begin{example}{3}
387 \def\0{\frac12}
388 $ \pab{\0} $ $ \bab{\0} $ $ \Bab{\0} $
389 $ \aab{\0} $ $ \vab{\0} $ $ \Vab{\0} $
390 \end{example}
391 % \iffalse
392 %</example>
393 % \fi
394 % These \texttt{\textbackslash$X$ab} commands can take an optional star and
395 % an optional \oarg{biggg} argument. Star stands for using the default sizes.
396 % For example,
397 % \iffalse
398 %<*example>
399 % \fi
400 \begin{example}{2}
401 \def\0{n+\frac12}
402 $ \pab[Big]{\0} $\quad $ \bab*{\0} $
403 \end{example}
404 % \iffalse
405 %</example>
406 % \fi
407 % \begin{keyval}
408 % \item[\key{tightbraces}]\val{\TTF}: Influences whether thin skips are
409 % reserved around the paired delimiters. It only works with the automatically
410 % sized delimiters.
411 % \end{keyval}
412 %
413 % \subsection{The \modu{ab.braket} and \modu{braket} module
414 % --- Dirac bra-ket notation}
415 %
416 % This two modules both contain four basic commands
417 % \begin{quote}
418 % \cs{bra},\quad \cs{ket},\quad \cs{braket},\quad \cs{ketbra}
419 % \end{quote}
420 % These commands in the two modules share the same goal, but differ in syntax.\\
421 % \DescribeOption{ab.braket}
422 % A star ("*") or a size command can follow these commands,
423 % which are similar to the syntaxes of \cs{ab} module. The size commands can
424 % take the control sequences:
425 % \begin{quote}
426 % \cs{big},\quad \cs{Big},\quad \cs{bigg},\quad \cs{Bigg},\quad
427 % \cs{biggg}\quad or\quad \cs{Biggg}.
428 % \end{quote}
429 % \DescribeOption{braket}
430 % A star ("*") or a square-bracket-delimited size option, the size option can
431 % take the following values:
432 % \begin{quote}
433 % " ""big",\quad " ""Big",\quad " ""bigg",\quad " ""Bigg",\quad
434 % " ""biggg"\quad or\quad " ""Biggg".
435 % \end{quote}
436 % The star in the two modules stands for ``do not size the bra-ket
437 % automatically''. Four basic commands' syntaxes are described as
438 % follows respectively.
439 % \textbf{Please notice that the two module are conflict with each other,
440 % so don't use them together.} One can choose one module according to
441 % personal habit.
442 % \begin{function}{\bra, \ket}
443 % \begin{syntax}
444 % \cs{bra} \meta{* or size command} \:"<"\meta{subformula}"|"^^A
445 % \hfill---> \makebox[16\sttwd][r]{\modu{ab.braket} module}
446 % \cs{ket} \meta{* or size command} \:"|"\meta{subformula}">"^^A
447 % \hfill---> \makebox[16\sttwd][r]{\modu{ab.braket} module}
448 % \cs{bra} \meta{* or \oarg{size option}} \marg{subformula}^^A
449 % \hfill---> \makebox[16\sttwd][r]{\modu{braket} module}
450 % \cs{ket} \meta{* or \oarg{size option}} \marg{subformula}^^A
451 % \hfill---> \makebox[16\sttwd][r]{\modu{braket} module}
452 % \end{syntax}
453 % \begin{itemize}[leftmargin = 0pt]
454 % \item In \modu{ab.braket} module,
455 % the argument of \cs{bra} should be delimited with "<" and "|", and
456 % the argument of \cs{ket} should be delimited with "|" and ">".\\
457 % \pardanger
458 % If you want to write ``$>$'' and ``$<$'' for relations in the argument of
459 % \cs{bra} and \cs{ket}, you can write "\mathrel{>}" and "\mathrel{<}".
460 % \item In \modu{braket} module, \cs{bra} and \cs{ket} take one mandatory
461 % argument, which should be braced with "{" and "}".
462 % \end{itemize}
463 % \end{function}
464 % For example, in \modu{ab.braket} module,
465 % \iffalse
466 %<*example>
467 % \fi
468 \begin{example}{5}
469 \def\0{\frac\phi2}
470 $ \bra<\0| $\quad $ \bra*<\0| $%
471 \quad $ \bra\Big<\phi| $\\[1ex]
472 $ \ket|\0> $\quad $ \ket*|\0> $%
473 \quad $ \ket\Big|\psi> $
474 \end{example}
475 % \iffalse
476 %</example>
477 % \fi
478 % and in \modu{braket} module
479 % \iffalse
480 %<*example>
481 % \fi
482 \begingroup
483 \makeatletter\def\RequirePhxmodu#1{}^^A
484 \def\PackageWarning#1#2{}^^A
485 \catcode`\%14\relax \input phx-braket.sty \catcode`\%9\relax \makeatother
486 \begin{example}{5}
487 \def\0{\frac\phi2}
488 $ \bra \0 $\quad $ \bra* \0 $%
489 \quad $ \bra[Big] \psi $\\[1ex]
490 $ \ket \0 $\quad $ \ket* \0 $%
491 \quad $ \ket[Big] \psi $
492 \end{example}
493 \endgroup
494 % \iffalse
495 %</example>
496 % \fi
497 % \begin{function}{\braket}
498 % \begin{syntax}
499 % \cs{braket} \meta{* or size command}\: "<"\meta{subformula}">"^^A
500 % \hfill---> \makebox[16\sttwd][r]{\modu{ab.braket} module}
501 % \cs{braket} \meta{* or \oarg{size option, i}} i*\marg{subformula}^^A
502 % \hfill---> \makebox[16\sttwd][r]{\modu{braket} module}
503 % \end{syntax}
504 % \begin{itemize}[leftmargin = 0pt]
505 % \item In \modu{ab.braket} module, the argument of \cs{braket} should be
506 % delimited with "<" and ">", every ``"|"'' will be regarded as an
507 % extensible vertical bar in the \meta{subformula} argument.
508 % \pardanger
509 % If you want to write ``$>$'' and ``$<$'' for relations in the argument of
510 % \cs{braket} and \cs{ketbra} in this module,
511 % you can write \cs{>} and \cs{<}.
512 % It is quite different from "\mathrel{>}" or "\mathrel{<}" because in these
513 % commands' argument, ">" and "<" will be redefined.
514 % \item In \modu{braket} module, the \cs{braket} command, in default, can
515 % take two arguments. If you want \cs{braket} to take one or three
516 % arguments, you can specific the number of arguments by number "i" in the
517 % square bracket, separate from the size option with a comma.
518 % \end{itemize}
519 % \end{function}
520 % For example, in \modu{ab.braket} and \modu{braket} module,
521 % \iffalse
522 %<*example>
523 % \fi
524 \begin{example}{7}
525 \def\0{\frac\phi2}
526 $ \braket < \hat A > $\quad
527 $ \braket <\0|\hat A|\psi> $\quad
528 $ \braket\big <\0|\psi> $\\[1ex]
529 $ \braket* <\0|\psi> $\quad
530 $ \braket\Big <\0|\psi> $\quad
531 $ \ab|{\braket<\psi|\hat A|\psi>}| $
532 \end{example}
533 % \iffalse
534 %</example>
535 % \fi
536 % \pardanger
537 % Commands from \modu{ab.braket} should not be placed barely in
538 % \cs{ab}"|"\meta{subformula}"|" or errors will arise.
539 % So, adding braces like the last line in the example above.
540 % \iffalse
541 %<*example>
542 % \fi
543 \begingroup
544 \makeatletter\def\RequirePhxmodu#1{}^^A
545 \def\PackageWarning#1#2{}^^A
546 \catcode`\%14\relax \input phx-braket.sty \catcode`\%9\relax \makeatother
547 \begin{example}{7}
548 \def\0{\frac\phi2}
549 $ \braket [1] {\hat A} $\quad
550 $ \braket [3] {\0}{\hat A}{\psi} $\quad
551 $ \braket[big] {\0}{\psi} $\\[1ex]
552 $ \braket* {\0}{\psi} $\quad
553 $ \braket[Big] {\0}{\psi} $\quad
554 $ \ab|{\braket[3]\psi{\hat A}\psi}| $
555 \end{example}
556 \endgroup
557 % \iffalse
558 %</example>
559 % \fi
560 % \begin{function}{\ketbra}
561 % \begin{syntax}
562 % \cs{ketbra} \meta{* or size command}\: "|"\meta{subformula_1}">"
563 % "" \meta{optional formula}\: "<"\meta{subformula_2}"|"^^A
564 % \hfill---> \makebox[16\sttwd][r]{\modu{ab.braket} module}
565 % \cs{ketbra} \meta{* or \oarg{size option}} \marg{subformula_1}
566 % "" \meta{optional formula} \:\marg{subformula_2}^^A
567 % \hfill---> \makebox[16\sttwd][r]{\modu{braket} module}
568 % \end{syntax}
569 % \begin{itemize}[leftmargin = 0pt]
570 % \item In \modu{ab.braket} module, the argument of \cs{ketbra} should be
571 % delimited with "|" and "|", ">" and "<" will be regarded as extensible
572 % $\rangle$ and $\langle$ in the argument.
573 % \item In \modu{braket} module, the \cs{ketbra} command takes two
574 % mandatory arguments by default, and one optional argument between the
575 % two mandatory arguments ($\rangle$ and $\langle$).
576 % \end{itemize}
577 % \end{function}
578 % For example, in \modu{ab.braket} and \modu{braket} module,
579 % \iffalse
580 %<*example>
581 % \fi
582 \begin{example}{4}
583 \def\0{\frac\phi2}
584 $ \ketbra | \0 >< \psi | $\quad
585 $ \ketbra* | \0 >< \psi | $\quad
586 $ \ketbra\Big | \0 >_x^y< \psi | $
587 \end{example}
588 % \iffalse
589 %</example>
590 % \fi
591 % \iffalse
592 %<*example>
593 % \fi
594 \begingroup
595 \makeatletter\def\RequirePhxmodu#1{}^^A
596 \def\PackageWarning#1#2{}^^A
597 \catcode`\%14\relax \input phx-braket.sty \catcode`\%9\relax \makeatother
598 \begin{example}{4}
599 \def\0{\frac\phi2}
600 $ \ketbra {\0} {\psi} $\quad
601 $ \ketbra* {\0} {\psi} $\quad
602 $ \ketbra [Big] {\0} [_x^y] {\psi} $
603 \end{example}
604 \endgroup
605 % \iffalse
606 %</example>
607 % \fi
608 % For convince, the two modules also contain three advanced commands
609 % \begin{quote}
610 % \cs{bknorm},\quad \cs{kbproj},\quad \cs{expval}
611 % \end{quote}
612 % These commands have the same syntax in the two modules.
613 % \begin{function}{\bknorm, \kbproj, \expval}
614 % \begin{syntax}
615 % \cs{bknorm} \meta{*} \oarg{size} \marg{basis}
616 % \cs{kbproj} \meta{*} \oarg{size} \marg{basis}
617 % \cs{expval} \meta{*} \oarg{basis, size} \marg{operator}
618 % \end{syntax}
619 % \end{function}
620 % For example,
621 % \iffalse
622 %<*example>
623 % \fi
624 \begin{example}{8}
625 \def \0{\frac\alpha2}
626 \edef\1{\uparrow,\downarrow}
627 $ \bknorm \0 $\quad $ \bknorm [big]\0 $
628 \quad $ \bknorm*\0 $\\[2ex]
629 $ \kbproj \0 $\quad $ \kbproj [big]\0 $
630 \quad $ \kbproj*\0 $\\[2ex]
631 $ \expval [Big, \1] {\hat A} $\quad
632 $ \expval*[Big, \psi]\0 $
633 \end{example}
634 % \iffalse
635 %</example>
636 % \fi
637 %
638 % \subsection{The \modu{doubleprod} module --- tensors' double product operator}
639 %
640 % This module provides the \cs{doublecross} and \cs{doubledot} commands,
641 % which are regarded as binary operators by \TeX.
642 % Take an example of this module:
643 % \iffalse
644 %<*example>
645 % \fi
646 \begin{example}{1}
647 $ A \doublecross B \doubledot C $
648 \end{example}
649 % \iffalse
650 %</example>
651 % \fi
652 % \begin{keyval}
653 % \item[\key{crossscale, dotscale}]\val{fp num}: Scales of ``$\times$''
654 % and ``$\cdot$'' (Default: ".8" and "1").
655 % \item[\key{crossopenup, dotopenup}]\val{fp num}: Spaces between
656 % ``$\times$''s and ``$\cdot$''s "=" \val{fp num} "*" font size
657 % (Default: ".02" and ".2").
658 % \item[\key{doubledot, crosssymbol}]\val{symbol}: Pieces of
659 % \cs{doublecross} and \cs{doubledot} (Default: \cs{times}, \cs{ldotp}).
660 % \end{keyval}
661 % Their default values can be configured in module option. For example,
662 % \begin{quote}
663 % "\usephxmodu[crossscale = .75, dotscale = 1.2,"\\
664 % " crossopenup = .05, dotopenup = .25]{doubleprod}"
665 % \end{quote}
666 %
667 % \subsection{The \modu{diagmat} module --- simple diagonal matrices}
668 %
669 % This module requires the \pkg{mathtools} package and provides six
670 % \cs[no-index]{*diagmat} commands:
671 % \begin{function}
672 % {\diagmat, \pdiagmat, \bdiagmat, \Bdiagmat, \vdiagmat, \Vdiagmat}
673 % \begin{syntax}
674 % \cs{\meta{delimiter type}diagmat}\meta{*} \oarg{options} \marg{diag}
675 % \end{syntax}
676 % where \meta{diag} is the diagonal of the diagonal matrix. The entries should
677 % be separated by commas.
678 % Prefixes like "p", "b", "V" have the same meanings as "pmatrix", "bmatrix" and
679 % "Vmatrix" in the \pkg{mathtools} package, a star ("*") follows the
680 % \cs[no-index]{*diagmat} commands correspond to "*smallmatrix" in the
681 % \pkg{mathtools} package.
682 % \end{function}
683 % \begin{keyval}
684 % \item[\key{empty}]\val{token list}:
685 % Value of \cs{diagmat}'s empty entries (Default is blanck).
686 % \item[\key{align}]\val{l\textup\textbar{c}\textup\textbar{r}}:
687 % Align of \cs{diagmat}'s diagonal entries (Default: "r").
688 %
689 % Their default values can be configured in the module option like this:
690 % \begin{quote}
691 % "\usephxmodu[empty = \cdot, align = r]{diagmat}"
692 % \end{quote}
693 % \end{keyval}
694 % For example,
695 % \iffalse
696 %<*example>
697 % \fi
698 \begin{example}{4}
699 $ \pdiagmat [empty = \mathbf O] {
700 \diagmat*[align = r]{1, \sqrt[3]4},
701 \diagmat*{a, b} } $,
702 $ \bdiagmat* {1, -1, -1, -1} $
703 \end{example}
704 % \iffalse
705 %</example>
706 % \fi
707 %
708 % \subsection{The \modu{xmat} module --- matrices with formatted entries}
709 %
710 % This module requires the \pkg{mathtools} package and provides six
711 % \cs[no-index]{*xmat} commands:
712 % \begin{function}{\xmat, \pxmat, \bxmat, \Bxmat, \vxmat, \Vxmat}
713 % \begin{syntax}
714 % \cs{\meta{delimeter type}xmat}\meta{*} \oarg{options} \marg{entry}^^A
715 % \marg{row label} \marg{col label}
716 % \end{syntax}
717 % Prefixes like "p", "b", "V" have the same meanings as "pmatrix", "bmatrix" and
718 % "Vmatrix" in the \pkg{mathtools} package, a star ("*") follows the
719 % \cs[no-index]{*xmat} commands correspond to "*smallmatrix" in the
720 % \pkg{mathtools} package.
721 % For example,
722 % \iffalse
723 %<*example>
724 % \fi
725 \begin{example}{1}
726 $ \vxmat*{a}{2}{3} $
727 \end{example}
728 % \iffalse
729 %</example>
730 % \fi
731 % \begin{keyval}
732 % \item[\key{align}]\val{l\textup\textbar{c}\textup\textbar{r}}:
733 % Similarly to the \modu{diagmat} module.
734 %
735 % If \meta{rows/col label} contains non-digit characters, dots will be
736 % added. For example,
737 % \iffalse
738 %<*example>
739 % \fi
740 \begin{example}{2}
741 $ \bxmat*[showtop = 1, showleft = 2,
742 align = l]{X}{m}{n} $
743 \end{example}
744 % \iffalse
745 %</example>
746 % \fi
747 % \item[\key{showtop, showleft}]\val{int num}: Numbers of rows and columns to
748 % be shown at the top and the left side (Default: "MaxMatrixCols - 2").
749 %
750 % Their default values can be configured in the module option like this:
751 % \begin{quote}
752 % "\usephxmodu[showtop = 1, showleft = 2]{xmat}"
753 % \end{quote}
754 % This will also influence ``\cs{xmat}''s with digital \meta{row label} and
755 % \meta{col label} they are larger than the values corresponding to "showtop"
756 % and "showleft". For example,
757 % \iffalse
758 %<*example>
759 % \fi
760 \begin{example}{2}
761 $ \pxmat*[showtop = 1,
762 showleft = 2]{A}{8}{8} $
763 \end{example}
764 % \iffalse
765 %</example>
766 % \fi
767 % The "format" option allows users to use a new entry format.
768 % \item[\key{format}]\val{custom entry format in terms of \#1, \#2, and \#3}:
769 % \begin{arguments}
770 % \item The common entry, or the first mandatory \meta{entry} argument
771 % of \cs{xmat};
772 % \par \vspace{-12pt}
773 % \begin{multicols}{2}
774 % \item The row index;
775 % \item The column index.
776 % \end{multicols}
777 % \par \vspace{-12pt}
778 % \end{arguments}
779 % This option should be only used in the optional argument of \cs{xmat}.
780 % For example,
781 % \iffalse
782 %<*example>
783 % \fi
784 \begin{example}{2}
785 $ \Bxmat*[showtop = 2, showleft = 1,
786 format = \texttt{#1[#2][#3]}]xmn $
787 \end{example}
788 % \iffalse
789 %</example>
790 % \fi
791 % \end{keyval}
792 % \end{function}
793 %
794 % \subsection{The \modu{operator} module --- log-like and
795 % nabla-related operators}
796 %
797 % This module provides a series of commands for log-like operators and some
798 % commands for nabla-related operators ($\nabla$)
799 % \begin{quote}
800 % "\asin \acos \atan \acsc \asec \acot \erf "\\
801 % "\erfc \Tr \tr \rank \Res \res \Re "\\
802 % "\Im \PV \pv \upe \iu \grad \curl"\\
803 % "\div \laplacian \identity \Identity "
804 % \end{quote}
805 % \begin{itemize}[leftmargin = 0pt]
806 % \item The first fifteen commands yield what they look like in math mode
807 % \item \cs{PV} yields ``$\PV$'' as an ordinary symbol and \cs{pv}
808 % yields ``$\pv$''.
809 % \item \cs{Re} and \cs{Im} are redefined as ``$\Re$'' and ``$\Im$''.
810 % $\Resymbol$ and $\Imsymbol$ are redefined as \cs{Resymbol} and
811 % \cs{Imsymbol}, in default.
812 % \item The ``$\divsymbol$'' symbol was redefined as \cs{divsymbol}.
813 % \item This module requires the \pkg{fixdif} package with file
814 % date "2023/01/31"
815 % at minimum.
816 % \end{itemize}
817 % \begin{keyval}
818 % \item[\key{ReIm}]\val{\TFF}: Determines whether to redefine \cs{Re}
819 % and \cs{Im}.
820 % If you want to reserve the definition of \cs{Re} and \cs{Im}, you can write
821 % like this:
822 % \begin{quote}
823 % "\usephxmodu[ReIm = false]{operator}"
824 % \end{quote}
825 % \end{keyval}
826 % This module also provides the \cs{identity} and \cs{Identity} commands for
827 % inputting the double-stroke ``1'' ($\identity$) and ``I'' ($\Identity$)
828 % respectively.
829 % \begin{function}{\identity, \Identity}
830 % \begin{syntax}
831 % \cs{identity} \oarg{font family} \cs{Identity} \oarg{font family}
832 % \end{syntax}
833 % The optional argument can config the font for the double-stroke glyphs,
834 % with the default value "bbold". One can also config it with the module option.
835 % \begin{keyval}
836 % \item[\key{identity}]\val{font family}:
837 % Default font family for the double-stroke \cs{identity} and \cs{Identity}.
838 % \end{keyval}
839 % \end{function}
840 % For example,
841 % \iffalse
842 %<*example>
843 % \fi
844 \begingroup
845 \makeatletter\def\RequirePhxmodu#1{}^^A
846 \def\PackageWarning#1#2{}^^A
847 \catcode`\%14\relax \input phx-braket.sty \catcode`\%9\relax \makeatother
848 \makeatletter \def\phx@oplega@id {bbold} \makeatother
849 \begin{example}{7}
850 % \usephxmodu[identity = bbold]{operator}
851 % \usephxmodu{braket}
852 $ \asin x $, $ \PV f(z) = \pv f(z) $\\[1ex]
853 $ \erfc(x) = 1 - \erf(x) $\\[1ex]
854 $ \identity = \Identity[bbold] = \int
855 \d^2 \alpha \kbproj \alpha/\pi $\\[1ex]
856 $ \Re z = \Im z = \exp(\iu\pi) = -1 $\\[1ex]
857 $ \grad V$, $\div (x,y,z)$, $ \curl(x,y,z) $
858 \end{example}
859 \endgroup
860 % \iffalse
861 %</example>
862 % \fi
863 %
864 % \subsection{The \modu{ab.legacy} module}
865 %
866 % \begin{function}{\abs, \norm, \eval, \peval, \beval, \order}
867 % This module provides the left commands.
868 % They share the same syntax as
869 % \begin{syntax}
870 % \cs{\meta{cmd}}"*"\oarg{biggg}\marg{subformula}.
871 % \end{syntax}
872 % Star and \meta{biggg} are optional. Star stands for ``use the default size''.
873 % For example,
874 % \iffalse
875 %<*example>
876 % \fi
877 \begin{example}{6}
878 \def\0{1+\frac12}
879 $ \abs\0 $, $ \norm[Big]\0 $, $ \order*\0 $
880 \def\0{1+\frac x2}
881 $ \eval {\0}_a^b $,
882 $ \peval* {\0}_a^b $,
883 $ \beval[big]{\0}_a^b $
884 \end{example}
885 % \iffalse
886 %</example>
887 % \fi
888 % You can set the ``order'' symbol in this module through
889 % the "order" option like this:
890 % \begin{quote}
891 % "\usephxmodu[order = O]{ab.legacy}"
892 % \end{quote}
893 % Then "$\order{N}$" yields $O(N)$.
894 % \end{function}
895 %
896 % \subsection{The \modu{qtext.legacy} module}
897 %
898 % The \modu{qtext.legacy} module provides the \cs{q}\meta{foo} commands
899 % for \cs{quad}-wrapped texts. These commands have the same syntax as
900 % \pkg{physics}. For example,
901 % \iffalse
902 %<*example>
903 % \fi
904 \begin{example}{4}
905 $ A \qq {foo bar} B $\\
906 $ A \qq*{foo bar} B $\\
907 $ C \qcc D \qcc* E $\\
908 $ F \qif G \qthen H $
909 \end{example}
910 % \iffalse
911 %</example>
912 % \fi
913 % All the commands described in \S2.4 of
914 % \href{http://mirrors.ctan.org/macros/latex/contrib/physics/physics.pdf}^^A
915 % {\textsf{physics} documentation} are supported when using
916 % \modu{qtext.legacy} module, but I don't recommend using this module unless
917 % you are maintaining a document written with \pkg{physics}'s \cs{q}\meta{foo}
918 % commands.
919 %
920 % \clearpage \appendix
921 %
922 % \section{For the legacy \pkg{physics} users}\label{sec:physics-legacy}
923 %
924 % This section describes \pkg{physics3} package for those who are
925 % used to the \pkg{physics} package, which is only a simple reference
926 % manual for:
927 % \begin{itemize}
928 % \item Frequent users of the legacy \pkg{physics} package;
929 % \item Those who have to maintain a document written with \pkg{physics};
930 % \item Users who failed to use \pkg{unicode-math} with \pkg{physics}.
931 % \end{itemize}
932 %
933 % In this section, the modules of \pkg{physics3} will be introduced in
934 % the same order as the \pkg{physics} documentation.
935 %
936 % \subsection{Legacy problems with \pkg{physics} package}^^A
937 % \label{subsec:physics-legacy-problems}
938 % The \pkg{physics} package provides \cs[no-index]{qty} command for
939 % automatic-sizing braces. The \cs[no-index]{qty} command would cause conflict
940 % with the \pkg{siunitx} package, which provides a unified method to typeset
941 % numbers and units correctly.
942 %
943 % Besides, after you loaded \pkg{physics}, when you
944 % type \cs[no-index]{homework} you will get Maxwell equations and Schr\"odinger
945 % equation. The \cs[no-index]{homework} command is ``declared'' in
946 % \file{physics.sty} but it was not described in the documentation. That is, if
947 % you have defined \cs[no-index]{homework} before loading \pkg{physics}
948 % package, \pkg{physics} would overwrite the definition ``silently''.
949 %
950 % The vector-notation part of \pkg{physics} uses \pkg{amsmath}'s (more
951 % exactly, \file{amsbsy.sty}'s) \cs[no-index]{boldsymbol} command to generate
952 % bold vectors. Commands for cross/dot product are defined
953 % with \cs[no-index]{boldsymbol}. \cs[no-index]{boldsymbol} uses
954 % \cs[no-index]{mathversion}, a \LaTeXe\ kernel command that works well with
955 % traditional TFM-based fonts but fails when using \pkg{unicode-math}.
956 %
957 % In the definition of \cs[no-index]{imat}, \cs[no-index]{xmat},~
958 % \cs[no-index]{dmat} and \cs[no-index]{admat} commands
959 % from \pkg{physics}, there is a \cs{newtoks} command which allocates a token
960 % list register and two \cs{newcount} commands allocating two count registers.
961 % Every time you write a command like \cs[no-index]{imat} in your document,
962 % then one token list register and two count registers will be wasted. What's
963 % even worse is that, if you wrote really too many matrix commands from
964 % \pkg{physics} (for example, 32767 \cs{imat}s in \hologo{LuaLaTeX}), there'd
965 % be no room for a new \cs{count}.
966 %
967 % \pkg{physics} integrated all the functions in one file (\texttt{physics.sty}),
968 % that is, you cannot load one of the total seven parts of functions; you have
969 % to load the seven parts altogether, even included the extra
970 % \cs[no-index]{homework} command we mentioned in the first paragraph.
971 %
972 % Moreover, the code of \file{physics.sty} ``abuses'' the "g"-type
973 % arguments of \pkg{xparse} package. Therefore the syntax of \pkg{physics}
974 % package looks kind of weird.
975 % See \href{https://tex.stackexchange.com/questions/470819/macros-dv-and-pdv-eat-the-subsequent-parenthesis-argument/470842#470842}
976 % {here} for more.
977 %
978 % \subsection{Loading \pkg{physics3}}
979 %
980 % The \pkg{physics3} package includes different modules, among which every
981 % module focuses on one single function.
982 %
983 % Write the following line in the preamble to load \pkg{physics3}:
984 % \begin{quote}
985 % "\usepackage{physics3}"
986 % \end{quote}
987 % But this is not enough. \pkg{physics3} contains different modules.
988 % If you want to load any module of \pkg{physics3}, write this line after
989 % loading \pkg{physics3} package:
990 % \begin{quote}
991 % \cs{usephxmodu}\marg{module list}
992 % \end{quote}
993 % For example, ``"\usephxmodu{ab, doubleprod}"'' loads the \modu{ab}
994 % module and the \modu{doubleprod} module.
995 %
996 % You can also load a module with options:
997 % \begin{quote}
998 % \cs{usephxmodu}\oarg{option list}\marg{module}
999 % \end{quote}
1000 % For example, ``"\usephxmodu[legacy]{ab}"'' loads \modu{ab} with the
1001 % option ``"legacy"''.
1002 %
1003 % \pardanger Attention, if you used any font package in your document, remember
1004 % that \pkg{physics3} requires to be loaded \emph{after} font packages.
1005 %
1006 % \subsection{List of commands}
1007 %
1008 % \subsubsection{Automatic bracing}
1009 % As mentioned in \S\ref{subsec:physics-legacy-problems}, the \cs{qty} command
1010 % from \pkg{physics} will conflict with \pkg{siunitx}. The command for
1011 % automatic braces in \pkg{physics3} is \cs{ab}, short for \textbf automatic
1012 % \textbf braces.
1013 %
1014 % \pkg{physics} also provides the following commands:
1015 % \begin{quote}
1016 % "\abs"\quad "\norm"\quad "\eval"\quad "\order"\quad
1017 % \begingroup\color{gray}^^A
1018 % "\comm"\quad "\acomm"\quad "\pb"
1019 % \endgroup
1020 % \end{quote}
1021 % \pardanger These commands are not originally supported by \pkg{physics3}, but
1022 % the first four commands can be used through the \modu{ab.legacy} module of
1023 % \pkg{physics3}:
1024 % \begin{quote}
1025 % "\usephxmodu{ab.legacy}"
1026 % \end{quote}
1027 % Users of the legacy \pkg{physics} package should notice that the syntax of
1028 % \cs{eval} has been changed. The \modu{ab.legacy} module abandoned the
1029 % "\eval(foo|"-like syntax. The new \cs{eval}'s syntax is just like other
1030 % commands in this module. There are also two variants of \cs{eval} ---
1031 % \cs{peval} and \cs{beval}.
1032 %
1033 % The \cs{comm}, \cs{acomm} and \cs{pb} (Poisson bracket) are not supported.
1034 % But you can write like "\ab[foo,baz]" or "\bab{foo,baz}" instead.
1035 %
1036 % By the way, you can set the ``order'' symbol in \modu{ab.legacy} through
1037 % the "order" option like this:
1038 % \begin{quote}
1039 % "\usephxmodu[order = O]{ab.legacy}"
1040 % \end{quote}
1041 % Then "$\order(N)$" yields $O(N)$.
1042 %
1043 % \subsubsection{Vector notation}
1044 %
1045 % Unfortunately, there is not a plan for \pkg{physics3} to support this part
1046 % of \pkg{physics} completely, but the rest of this section will show some
1047 % methods to maintain the document written with \pkg{physics}.
1048 %
1049 % The \cs{vb}("*"), \cs{va}("*") and \cs{vu}("*") are not supported
1050 % in any module of \pkg{physics3}. But these commands can be defined by copying
1051 % the following lines below and pasting them in the preamble:
1052 % \begin{quote}
1053 % "\makeatletter"\\
1054 % "\newcommand\vb{\@ifstar\boldsymbol\mathbf}"\\
1055 % "\newcommand\va[1]{\@ifstar{\vec{#1}}{\vec{\mathrm{#1}}}}"\\
1056 % "\newcommand\vu[1]{%"\\
1057 % "\@ifstar{\hat{\boldsymbol{#1}}}{\hat{\mathbf{#1}}}}"\\
1058 % "\makeatother"
1059 % \end{quote}
1060 % The \cs{boldsymbol} command requires the \pkg{amsmath} or \pkg{bm} package.
1061 % If you prefer to use \pkg{bm}, you can also use the \cs{bm} command.
1062 % What's more, if you tried the commands above, you might find that,
1063 % the result of \cs{va} above is different from that of \pkg{physics}.
1064 % This is because, if you choose to present a vector in bold, there's almost
1065 % no need to put a \cs{vec} ($\vec{\mskip9mu}$) sign above it.
1066 %
1067 % However, the method above may not work well with \pkg{unicode-math}
1068 % because there are so many OpenType math fonts without a bold version.
1069 % When using \pkg{unicode-math}, it's recommended to use \cs{symbf} and
1070 % \cs{symbfit} for a separate vector\footnote{See
1071 % \href{https://github.com/latex3/latex2e/issues/1991\#issuecomment-3822731957}
1072 % {Issue~\ttfamily\#1991} in the \LaTeXe\ repository
1073 % \href{https://github.com/latex3/latex2e}{on GitHub}, this bug will be
1074 % resolved someday.}.
1075 %
1076 % The \cs{vdot} and \cs{cross} commands are not supported in any module
1077 % of \pkg{physics3}. Actually, there is no need to use a bold ``$\cdot$''
1078 % or ``$\times$'' for the products of two vectors. Using \cs{cdot} and
1079 % \cs{times} is enough.
1080 %
1081 % The commands related to ``$\nabla$'' are supported through \modu{operator}
1082 % module. These commands are \cs{grad}, \cs{div} and \cs{curl}. These commands
1083 % should not be put in the end of a math formula either (just like \cs{ab}).
1084 % Notice that the former \cs{div} command for a ``$\divsymbol$'' (if there
1085 % exists one) is redefined as \cs{divsymbol}.
1086 %
1087 % Actually, the nabla-related commands end with \cs{ab}. Thus, the subformula
1088 % after these commands can be delimited with "()", "[]" and "\{\}".
1089 %
1090 % The \modu{operator} requires the \pkg{fixdif} package at least
1091 % version 2.0 (file date on or after 2023/01/31).
1092 %
1093 % \subsubsection{Operators}
1094 %
1095 % There's no plan for \pkg{physics3} to support this part of \pkg{physics}
1096 % completely. The syntax in this part of \pkg{physics} (such as "\tan[2](x)")
1097 % abuses \pkg{xparse}.
1098 %
1099 % It's suggested to write like this if you used the \modu{ab} module:
1100 % \begin{quote}
1101 % "$ \sin^2 \ab( \frac{\alpha}{2} ) $"
1102 % \end{quote}
1103 % Rather than take the superscript as an optional argument of the command of
1104 % log-like functions.
1105 %
1106 % The \pkg{physics} package provides a bundle of commands for log-like functions
1107 % that have not been defined in the \LaTeXe\ kernel. They can be used with the
1108 % \modu{operator} module; this module does not support the syntax
1109 % of \pkg{physics} either.
1110 %
1111 % The \cs{Re} and \cs{Im} commands are redefined as operators ``$\Re$'' and
1112 % ``$\Im$'', while $\Resymbol$ and $\Imsymbol$ are reserved as \cs{Resymbol} and
1113 % \cs{Imsymbol}. $\Resymbol$ and $\Imsymbol$ are ordinary symbols but $\Re$ and
1114 % $\Im$ are operators.
1115 %
1116 % \subsubsection{Quick quad text}
1117 %
1118 % All the commands described in \S2.4 of
1119 % \href{http://mirrors.ctan.org/macros/latex/contrib/physics/physics.pdf}^^A
1120 % {\textsf{physics} documentation} are supported when using
1121 % \modu{qtext.legacy} module. Click here to see the \modu{qtext.legacy} module.
1122 %
1123 % \subsubsection{Derivatives}
1124 %
1125 % There is no plan for \pkg{physics3} to support this part of \pkg{physics}. If
1126 % you want to typeset the differential operators on a better sense, you can try
1127 % the \pkg{fixdif} package; if you want an easy way to type derivatives, you
1128 % can try the \pkg{derivative} package. These two packages can be used
1129 % together. For example,
1130 % \iffalse
1131 %<*example>
1132 % \fi
1133 \begin{example}{3}
1134 % \usepackage{fixdif, derivative}
1135 $ \pdv{f}{x,y,z} \d x $\\[1ex]
1136 Math ($\d x$) v.s.\ Text (\d x)
1137 \end{example}
1138 % \iffalse
1139 %</example>
1140 % \fi
1141 % Here are the documentations of
1142 % \href{http://mirrors.ctan.org/macros/latex/contrib/fixdif/fixdif.pdf}
1143 % {\pkg{fixdif}} and
1144 % \href{http://mirrors.ctan.org/macros/latex/contrib/derivative/derivative.pdf}
1145 % {\pkg{derivative}}.
1146 % \pkg{fixdif}'s commands behave better in superscripts and subscripts.
1147 %
1148 % \subsubsection{Dirac bra-ket notation}
1149 %
1150 % There are two solutions to Dirac bra-ket in \pkg{physics3} ---
1151 % \modu{ab.braket} and \modu{braket}. These two modules are \emph{not}
1152 % compatible and neither of them supports \pkg{physics}'s syntax completely.
1153 % Click \hyperlink{para:ab.braket}{\textcolor{cyan}{here}} to see the
1154 % \modu{ab.braket} module and \hyperlink{para:braket}{\textcolor{cyan}{here}}
1155 % to see the \modu{braket} module.
1156 %
1157 % \subsubsection{Matrix macros}
1158 %
1159 % Unfortunately, \pkg{physics3} do not support the \cs{mqty} command from
1160 % \pkg{physics}. If you are used to this command, you can write like this:
1161 % \begin{quote}
1162 % "\newcommand\mqty[1]{\begin{matrix}#1\end{matrix}}"\\
1163 % "\newcommand\pmqty[1]{\begin{pmatrix}#1\end{pmatrix}}"\\
1164 % "$\ab(\mqty{foo})$" or "$\pmqty{foo}$"
1165 % \end{quote}
1166 % These are equal to physics's "\mqty(foo)" (require \pkg{amsmath}).
1167 %
1168 % \pkg{physics3}'s \modu{diagmat} module provides \cs{diagmat} command
1169 % for diagonal matrices.
1170 % \cs{pdiagmat}, \cs{bdiagmat}, \cs{Bdiagmat}, \cs{vdiagmat} and \cs{Vdiagmat}
1171 % are also available.
1172 %
1173 % \pkg{physics3}'s \modu{xmat} module provides \cs{xmat} command
1174 % for matrices with formatted entries.
1175 % \cs{pxmat}, \cs{bxmat}, \cs{Bxmat}, \cs{vxmat} and \cs{Vxmat} are
1176 % also available.
1177 % \end{documentation}
1178 % \clearpage
1179 % \begin{implementation}
1180 % \section{Code Implementation}
1181 % \subsection{The \pkg{physics3} package}
1182 % \begin{macrocode}
1183 %<*package>
1184 % \end{macrocode}
1185 % We use "phx" as the namespace for \pkg{physics3} modules.
1186 % \begin{macrocode}
1187 %<@@=phx>
1188 % \end{macrocode}
1189 % \begin{macrocode}
1190 \NeedsTeXFormat{LaTeX2e}[2020/10/01]
1191 \def \phx@date {2026-02-07}
1192 \def \phx@version {v0.2A}
1193 \ProvidesExplPackage {physics3} {\phx@date} {\phx@version}
1194 {Tools for typesetting math for physics.}
1195 % \end{macrocode}
1196 % \subsubsection{Common variables}
1197 % \begin{variable}{\l_@@_tmpa_box}
1198 % \begin{quote}
1199 % \cs{phx@temp}\meta{register type}\meta{a or b}
1200 % \end{quote}
1201 % Some \LaTeXe\ variables starting with ``"\phx@temp"''.
1202 % These variables can be shared by any module of \pkg{physics3}.
1203 % \begin{macrocode}
1204 \box_new:N \l_@@_tmpa_box
1205 % \end{macrocode}
1206 % \end{variable}
1207 % \subsubsection{Package requirements and module-loading methods}
1208 % \pkg{physics3} requires \pkg{keyval} (part of the graphics bundle) to
1209 % process options of modules.
1210 % \begin{macrocode}
1211 \RequirePackage{keyval}
1212 \def\phx@true{true}
1213 \def\phx@false{false}
1214 % \end{macrocode}
1215 % \begin{macro}{\@@_define_key:nnnn, \@@_setkeys:nn, \@@_processkeyopt:n}
1216 % \begin{quote}
1217 % \cs{phx@define@key} \marg{module} \marg{key}^^A
1218 % \oarg{default value} \marg{code}\\
1219 % \cs{phx@setkeys} \marg{module} \marg{key-val list}\\
1220 % \cs{phx@processkeyopt} \marg{module}
1221 % \end{quote}
1222 % The position of \cs{phx@processkeyopt} in a \pkg{physics3} module is just
1223 % the same as the position of \cs{ProcessOptions} in a regular
1224 % \LaTeX\ package.
1225 % \begin{macrocode}
1226 \cs_new_nopar:Npn \@@_define_key:nnnn #1#2#3#4
1227 { \define@key {phx-#1} {#2} [#3] {#4} }
1228 \cs_new_nopar:Npn \@@_setkeys:nn #1#2
1229 { \setkeys {phx-#1} {#2} }
1230 \cs_new:Npn \@@_processkeyopt:n #1
1231 {
1232 \let\reserved@a\@empty
1233 \edef\reserved@a{\@ptionlist{\@currname.\@currext}}%
1234 \edef\reserved@a{\noexpand\phx@setkeys{#1}{\reserved@a}}%
1235 \reserved@a% the next line thanks to `geometry'
1236 \AtEndOfPackage{\let\@unprocessedoptions\relax}
1237 }
1238 \cs_set_eq:NN \phx@define@key \@@_define_key:nnnn
1239 \cs_set_eq:NN \phx@setkeys \@@_setkeys:nn
1240 \cs_set_eq:NN \phx@processkeyopt \@@_processkeyopt:n
1241 % \end{macrocode}
1242 % \end{macro}
1243 % We use almost the same way to load \pkg{physics3} modules as \LaTeXe\ kernel
1244 % does. We use a lot of kernel commands in \LaTeXe.
1245 % \begin{macro}{\usephxmodu, \RequirePhxmodu}
1246 % \begin{quote}
1247 % \cs{usephxmodu} \oarg{key-val options}^^A
1248 % \marg{module} \oarg{key-val options}\\
1249 % \cs{RequirePhxmodu} \oarg{key-val options}^^A
1250 % \marg{module} \oarg{key-val options}
1251 % \end{quote}
1252 % \cs{usephxmodu} is a user command, and \cs{RequirePhxmodu} is a
1253 % developer command.
1254 % \begin{macrocode}
1255 \def\usephxmodu{\phx@FWoptions\@pkgextension}
1256 \let\RequirePhxmodu\usephxmodu
1257 \@onlypreamble\usephxmodu
1258 \def\phx@FWoptions#1{\@ifnextchar[%]
1259 {\phx@FW@ptions#1}{\phx@FW@ptions#1[]}}
1260 \@onlypreamble\phx@FWoptions
1261 \def\phx@FW@ptions#1[#2]#3{\@ifnextchar[%]
1262 {\phx@FW@pti@ns#1[{#2}]#3}{\phx@FW@pti@ns#1[{#2}]#3[]}}
1263 \@onlypreamble\phx@FW@ptions
1264 \def\phx@FW@pti@ns#1[#2]#3[#4]{%
1265 \def\reserved@b##1,{%
1266 \ifx\@nnil##1\relax\else
1267 \ifx\@nnil##1\@nnil\else
1268 \noexpand\@onefilewithoptions{phx-##1}[{\unexpanded{#2}}][{#4}]%
1269 \noexpand\@pkgextension
1270 \fi
1271 \expandafter\reserved@b
1272 \fi}%
1273 \edef\reserved@a{\zap@space#3~\@empty}%
1274 \edef\reserved@a{\expandafter\reserved@b\reserved@a,\@nnil,}%
1275 \reserved@a}
1276 \@onlypreamble\phx@FW@pti@ns
1277 % \end{macrocode}
1278 % \end{macro}
1279 % \subsubsection{The (used to be) \modu{common} module}
1280 % The code below used to be the automatically-loaded \modu{common} module,
1281 % but now we load it together with \pkg{physics3}'s code. This change may
1282 % bring better performance in Windows system.
1283 %
1284 % Check if \pkg{unicode-math} loaded and (re)define the vert symbols.
1285 % The \cs{relax}'s at the ends of \cs{vert} and \cs{Vert}'s definitions must
1286 % not be removed. They are for \cs{ifx} to compare. \pkg{unicode-math} sets
1287 % these symbols \cs{fam}1, \cs{symoperators} is equal to 1 in \LaTeXe\ kernel.
1288 % Moreover, we make \cs{mid} as a delimiter but it may not work.
1289 % \begin{macrocode}
1290 \AtBeginDocument{\ifcsname symrm\endcsname
1291 \protected\def\|{\Udelimiter 0 \symoperators "2016 }%
1292 \protected\def\vert{\Udelimiter 0 \symoperators "007C\relax}%
1293 \protected\def\Vert{\Udelimiter 0 \symoperators "2016\relax}%
1294 \protected\def\mid{\Udelimiter 3 \symoperators "007C }%
1295 \fi}
1296 \protected\def\Vert{\delimiter"026B30D\relax}
1297 \protected\def\mid{\delimiter"326A30C }
1298 % \end{macrocode}
1299 % \begin{macro}{\delopen, \delclose}
1300 % \begin{quote}
1301 % \cs{delopen} \meta{left delimiter}\\
1302 % \cs{delclose} \meta{right delimiter}
1303 % \end{quote}
1304 % Actually in \TeX, \cs{left} and \cs{right} will enclose the subformula as
1305 % ``inner'', but \cs{delopen} and \cs{delclose} will make the subformula an
1306 % empty open node and a non-empty close node.
1307 % \begin{macrocode}
1308 \DeclareRobustCommand\delopen{\mathopen{}\mathclose\bgroup\left}
1309 \DeclareRobustCommand\delclose{\aftergroup\egroup\right}
1310 % Extension to 2e kernel's or amsmath's biggggg commands.
1311 % \end{macrocode}
1312 % \end{macro}
1313 % \cs{bBigg@} is a command from \pkg{amsmath}. The code below should
1314 % update with \pkg{amsmath} together.
1315 % \begin{macrocode}
1316 \ifdefined\bBigg@
1317 \DeclareRobustCommand\biggg{\bBigg@{3}}
1318 \DeclareRobustCommand\Biggg{\bBigg@{3.5}}
1319 \else
1320 \DeclareRobustCommand\biggg[1]{\leavevmode@ifvmode
1321 {\hbox{$\left#1\vbox to20.5\p@{}\right.\n@space$}}}
1322 \DeclareRobustCommand\Biggg[1]{\leavevmode@ifvmode
1323 {\hbox{$\left#1\vbox to23.5\p@{}\right.\n@space$}}}
1324 \AtBeginDocument{\ifdefined\bBigg@
1325 \DeclareRobustCommand\biggg{\bBigg@{3}}%
1326 \DeclareRobustCommand\Biggg{\bBigg@{3.5}}%
1327 \fi}
1328 \fi
1329 \DeclareRobustCommand\bigggl{\mathopen\biggg}
1330 \DeclareRobustCommand\bigggm{\mathrel\biggg}
1331 \DeclareRobustCommand\bigggr{\mathclose\biggg}
1332 \DeclareRobustCommand\Bigggl{\mathopen\Biggg}
1333 \DeclareRobustCommand\Bigggm{\mathrel\Biggg}
1334 \DeclareRobustCommand\Bigggr{\mathclose\Biggg}
1335 % \end{macrocode}
1336 % \begin{macro}{\@@_mathvphantom:n}
1337 % \begin{quote}
1338 % \cs{phx@mathvphantom} \marg{math mode material}
1339 % \end{quote}
1340 % This command is just like \cs{vphantom} in \LaTeXe\ kernel but only works
1341 % in math mode.
1342 % \begin{macrocode}
1343 \cs_new:Npn \@@_mathvphantom:n #1
1344 {
1345 \hbox_set:Nn \l_@@_tmpa_box {}
1346 \tex_mathchoice:D
1347 {
1348 \hbox_set:Nn \l_tmpa_box { $\displaystyle#1$ }
1349 \box_set_ht:Nn \l_@@_tmpa_box { \box_ht:N \l_tmpa_box }
1350 \box_set_dp:Nn \l_@@_tmpa_box { \box_dp:N \l_tmpa_box }
1351 \box_use_drop:N \l_@@_tmpa_box
1352 }
1353 {
1354 \hbox_set:Nn \l_tmpa_box { $\textstyle#1$ }
1355 \box_set_ht:Nn \l_@@_tmpa_box { \box_ht:N \l_tmpa_box }
1356 \box_set_dp:Nn \l_@@_tmpa_box { \box_dp:N \l_tmpa_box }
1357 \box_use_drop:N \l_@@_tmpa_box
1358 }
1359 {
1360 \hbox_set:Nn \l_tmpa_box { $\scriptstyle#1$ }
1361 \box_set_ht:Nn \l_@@_tmpa_box { \box_ht:N \l_tmpa_box }
1362 \box_set_dp:Nn \l_@@_tmpa_box { \box_dp:N \l_tmpa_box }
1363 \box_use_drop:N \l_@@_tmpa_box
1364 }
1365 {
1366 \hbox_set:Nn \l_tmpa_box { $\scriptscriptstyle#1$ }
1367 \box_set_ht:Nn \l_@@_tmpa_box { \box_ht:N \l_tmpa_box }
1368 \box_set_dp:Nn \l_@@_tmpa_box { \box_dp:N \l_tmpa_box }
1369 \box_use_drop:N \l_@@_tmpa_box
1370 }
1371 }
1372 \cs_set_eq:NN \phx@mathvphantom \@@_mathvphantom:n
1373 % \end{macrocode}
1374 % \end{macro}
1375 % \subsubsection{The (used to be) \modu{explsetup} module}
1376 % \begin{variable}{\l_@@_tmpa_tl, \l_@@_tmpb_tl}
1377 % Some common variables and functions for experimental \LaTeX3 syntax.
1378 % \begin{macrocode}
1379 \tl_new:N \l_@@_tmpa_tl
1380 \tl_new:N \l_@@_tmpb_tl
1381 % \end{macrocode}
1382 % \end{variable}
1383 % \begin{macro}[int]
1384 % {
1385 % \phx@del*,
1386 % \phx@del\big,
1387 % \phx@del\Big,
1388 % \phx@del\bigg,
1389 % \phx@del\Bigg,
1390 % \phx@del\biggg,
1391 % \phx@del\Biggg
1392 % }
1393 % The syntax seems not important. These following lines seems only
1394 % for \cs{ifcsname} to judge if the commands are defined.
1395 % \begin{macrocode}
1396 \def\phx@del#1#2#3{\phx@abopen#1#3\phx@abclose#2}
1397 \expandafter\def\csname phx@del\string*\endcsname
1398 #1#2#3{\mathopen#1#3\mathclose#2}
1399 \expandafter\def\csname phx@del\string\big\endcsname
1400 #1#2#3{\bigl#1#3\bigr#2}
1401 \expandafter\def\csname phx@del\string\Big\endcsname
1402 #1#2#3{\Bigl#1#3\Bigr#2}
1403 \expandafter\def\csname phx@del\string\bigg\endcsname
1404 #1#2#3{\biggl#1#3\biggr#2}
1405 \expandafter\def\csname phx@del\string\Bigg\endcsname
1406 #1#2#3{\Biggl#1#3\Biggr#2}
1407 \expandafter\def\csname phx@del\string\biggg\endcsname
1408 #1#2#3{\bigggl#1#3\bigggr#2}
1409 \expandafter\def\csname phx@del\string\Biggg\endcsname
1410 #1#2#3{\Bigggl#1#3\Bigggr#2}
1411 % \end{macrocode}
1412 % \end{macro}
1413 % Parsing the clist in optional argument.
1414 % \begin{macrocode}
1415 \def\@phx@ev@do@pt#1,{\ifx#1\relax\@empty\else
1416 \edef\reserved@a{\zap@space#1~\@empty}%
1417 \ifx\reserved@a\@empty\else
1418 \ifcsname phx@del\expandafter \string \expandafter
1419 \csname \expandafter \detokenize{\reserved@a}\endcsname \endcsname
1420 \xdef\@phx@ev{\reserved@a}%
1421 \else
1422 \xdef\@phx@ev@basis{\reserved@a}%
1423 \fi
1424 \fi
1425 \expandafter\@phx@ev@do@pt\fi}
1426 \def\phx@ev@doopt#1{%
1427 \edef\@phx@ev{\@empty}\edef\@phx@ev@basis{\@empty}\@phx@ev@do@pt#1,\relax,}
1428 % \end{macrocode}
1429 % \begin{macrocode}
1430 \file_input_stop:
1431 % \end{macrocode}
1432 % \begin{macrocode}
1433 %</package>
1434 % \end{macrocode}
1435 % Temporally disable the namespace.
1436 % \begin{macrocode}
1437 %<@@=>
1438 % \end{macrocode}
1439 % \subsection{The \modu{ab} module}
1440 % \begingroup\color{gray}^^A
1441 % \noindent$\langle*\hbox{\sffamily gibberish}\rangle$\par
1442 % This module is important but the code is hard to read. One of the motivations
1443 % I manage \pkg{physics3} with \pkg{DocStrip} is that, when I tried to write a
1444 % new module based on \modu{ab} after 5 months when I maintained \pkg{physics3}
1445 % the last time, I found that I could not understand the code I wrote at all!
1446 % Therefore, it's significant to comment out the alien code in \modu{ab}.\par
1447 % \noindent$\langle/\hbox{\sffamily gibberish}\rangle$\par
1448 % \endgroup
1449 % \begin{macrocode}
1450 %<*ab>
1451 \ProvidesFile {phx-ab.sty} [\phx@date\ `ab' (autobraces) module of physics3]
1452 % \end{macrocode}
1453 % If you don't know when to use \cs{phx@define@key}, \cs{phx@setkeys} and
1454 % \cs{phx@processkeyopt} in a module, see ahead. In \modu{ab}, the |tightbraces|
1455 % option can control if the automatically-sized braces are tight or not. Do you
1456 % remember \cs{delopen} and \cs{delclose}?
1457 % \begin{macrocode}
1458 \phx@define@key{ab}{tightbraces}{true}{\def\@phx@abtight{#1}}
1459 \phx@setkeys{ab}{tightbraces=true}
1460 \phx@processkeyopt{ab}
1461 % \end{macrocode}
1462 % \begin{macro}[int]{\phx@abopen, \phx@abclose}
1463 % \begin{quote}
1464 % \cs{phx@abopen} \meta{left delimiter}\\
1465 % \cs{phx@abclose} \meta{right delimiter}
1466 % \end{quote}
1467 % They are defined either \{\cs{delopen}, \cs{delclose}\} or
1468 % \{\cs{left}, \cs{right}\}. If a module requires \modu{ab},
1469 % these two commands are likely to be used.
1470 % \begin{macrocode}
1471 \ifx\@phx@abtight\phx@true
1472 \let\phx@abopen\delopen
1473 \let\phx@abclose\delclose
1474 \else
1475 \let\phx@abopen\left
1476 \let\phx@abclose\right
1477 \fi
1478 % \end{macrocode}
1479 % \end{macro}
1480 % \subsubsection{The implementation of \cs{ab}}
1481 % This is the alienest part of \modu{ab}. It's better to draw something rather
1482 % than write boring comments. First let's take a look at \cs{ab}'s syntax.
1483 % After \cs{ab} should be a pair of delimiters; take \texttt{()} as an example.
1484 % Between \cs{ab} and ``\texttt{(}'' can be a biggg command or star, or even
1485 % nothing. \cs{ab} is defined as follows:
1486 % \[ \macrodef{ab}{\cs{phx@d@lx} \texttt{\{mb\}} \texttt{\{ab\}}} \]
1487 % where \texttt{ab} is the branch name of "\ab()", and \texttt{mb} is the branch
1488 % name of "\ab\big()" and "\ab*()". Then let's see the syntax of \cs{phx@d@lx}.
1489 % \begin{quote}
1490 % \cs{phx@d@lx} \marg{biggg or star branch name}\\
1491 % \marg{automatic branch name} "{#3}"
1492 % \end{quote}
1493 % Here exists an \texttt{\#3}. \texttt{\#3} is one token immediately following
1494 % \cs{ab}, which can be \{\,a biggg command or a star\,\} or a ``\texttt{(}'',
1495 % under our assumption.
1496 %
1497 % \cs{phx@d@lx} is defined as follows:
1498 % \[
1499 % \macrodef {phx@d@lx} [
1500 % \#1: biggg or star branch name, \meta{mb};
1501 % \#2: automatic branch name, \meta{ab};
1502 % \#3, the token after \cs{ab} ]
1503 % {%
1504 % \macroifelse {\#3 == biggg or \#3 == star
1505 % ($\Leftrightarrow$ csname \{phx@del\cs{string}\#3\} is defined)}
1506 % {let \meta{next cs} = csname \{phx@d@lx\meta{mb}\}}
1507 % {let \meta{next cs} = csname \{phx@d@lx\meta{ab}\}}
1508 % \meta{next cs} \#3
1509 % }
1510 % \]
1511 % The condition should be true when \#3 is "\big" or "*", and it should be
1512 % false when \#3 is ``"("''. Accordingly, in math mode,
1513 % \begin{align*}
1514 % \hbox{\cs{ab} \cs{big} "("} & \quad \to \quad
1515 % \hbox{\cs{phx@d@lxmb} \cs{big} "("} \\
1516 % \hbox{\cs{ab} \phantom{\cs{big}} "("} & \quad \to \quad
1517 % \hbox{\cs{phx@d@lxab} \phantom{\cs{big}} "("}
1518 % \end{align*}
1519 % Then we meet two new commands --- \cs{phx@d@lxmb} and \cs{phx@d@lxab}. Syntax
1520 % is as follows.
1521 % \begin{quote}
1522 % \cs{phx@d@lxmb} \meta{biggg or *} \meta{left delimiter}\\
1523 % " "\meta{subformula} \meta{right delimiter} \\
1524 % \cs{phx@d@lxab} \phantom{\meta{biggg or *}} \meta{left delimiter}\\
1525 % " "\meta{subformula} \meta{right delimiter}
1526 % \end{quote}
1527 % Notice that \texttt{ab} and \texttt{mb} in the above commands are names of
1528 % \cs{ab}'s two branches --- they are like namespaces. \cs{phx@d@lxmb} and
1529 % \cs{phx@d@lxab} are defined by the following two lines:
1530 % \begin{quote}
1531 % "\phx@d@l@genxm{mb}"
1532 % "\phx@d@l@genxa{ab}"
1533 % \end{quote}
1534 % \cs{phx@d@l@genxm} and \cs{phx@d@l@genxa} are defined as follows:
1535 % \begin{align*}
1536 % & \macrodef {phx@d@l@genxm} [\#1: biggg or star branch name, \meta{mb}]
1537 % {%
1538 % \macrodef [12\ttwd] {phx@d@lx\meta{mb}}
1539 % [\#\#1: biggg or star; \#\#2: left delimiter]
1540 % {%
1541 % \cs{begingroup}
1542 % \macroifelse {\#\#1 == star}
1543 % {\meta{temp} $\gets$ \cs{relax}}
1544 % {\meta{temp} $\gets$ \#\#1}
1545 % csname \{phx@\meta{mb}@\cs{string}\#\#2\} \meta{temp} \#\#2 \macrocr
1546 % \% requires an \cs{endgroup} after the right delimiter
1547 % }
1548 % } \\[1ex]
1549 % & \macrodef {phx@d@l@genxa} [\#1: automatic branch name, \meta{ab}]
1550 % {%
1551 % \macrodef [12\ttwd] {phx@d@lx\meta{ab}} [\#\#1: left delimiter]
1552 % {%
1553 % csname \{phx@\meta{ab}@\cs{string}\#\#1\} \#\#1
1554 % }
1555 % }
1556 % \end{align*}
1557 % So we can get
1558 % \begin{align*}
1559 % \hbox{\ttfamily\cs{ab} \cs{big} (}&\quad\to\quad
1560 % \hbox{\cs{begingroup} csname \{phx@mb@(\} \cs{big}\hskip2\ttwd\ \texttt(}\\
1561 % \hbox{\ttfamily\cs{ab} *\phantom{big} (}&\quad\to\quad
1562 % \hbox{\cs{begingroup} csname \{phx@mb@(\} \cs{relax} \texttt(}\\
1563 % \hbox{\ttfamily\cs{ab} \phantom{\cs{big}} (}&\quad\to\quad
1564 % \hbox{\hskip11\ttwd\ csname \{phx@ab@(\} \texttt(}
1565 % \end{align*}
1566 % The csnames above (\cs{phx@mb@(} and \cs{phx@ab@(}) are generated
1567 % with \cs{phx@AB@gen}.
1568 % \begin{quote}
1569 % \cs{phx@AB@gen} \marg{branch name} \meta{left delimiter}\\
1570 % " "\marg{arg spec} \marg{definition}
1571 % \end{quote}
1572 % If \meta{branch name} is \texttt{mb}, \marg{arg spec} should be "mr()",
1573 % where "m" is for biggg or star;
1574 % If \meta{branch name} is \texttt{ab}, \marg{arg spec} should be "r()".
1575 % \begin{texnote}
1576 % The ``"("'' in the example above must not be replaced by a subformula braced
1577 % by a pair of "{}".
1578 % \end{texnote}
1579 % \begin{macro}[int]{\phx@AB@gen}
1580 % \begin{quote}
1581 % \cs{phx@AB@gen} \marg{branch name} \meta{left delimiter}\\
1582 % " "\marg{arg spec} \marg{definition}
1583 % \end{quote}
1584 % \begin{macrocode}
1585 \def\phx@AB@gen#1#2{\expandafter
1586 \DeclareDocumentCommand\csname phx@#1@\string#2\endcsname}
1587 \phx@AB@gen{ab}({r()}%
1588 {\phx@abopen(#1\phx@abclose)}
1589 \phx@AB@gen{ab}[{r[]}%
1590 {\phx@abopen[#1\phx@abclose]}
1591 \phx@AB@gen{ab}\{{r\{\}}%
1592 {\phx@abopen\{#1\phx@abclose\}}
1593 \phx@AB@gen{ab}|{r||}%
1594 {\phx@abopen|#1\phx@abclose|}
1595 \phx@AB@gen{ab}\|{r\|\|}%
1596 {\phx@abopen\|#1\phx@abclose\|}
1597 \phx@AB@gen{ab}<{r<>}%
1598 {\phx@abopen<#1\phx@abclose>}
1599 \phx@AB@gen{ab}\lbrace{r\lbrace\rbrace}%
1600 {\phx@abopen\lbrace#1\phx@abclose\rbrace}
1601 \phx@AB@gen{ab}\vert{r\vert\vert}%
1602 {\phx@abopen\vert#1\phx@abclose\vert}
1603 \phx@AB@gen{ab}\Vert{r\Vert\Vert}%
1604 {\phx@abopen\Vert#1\phx@abclose\Vert}
1605 \phx@AB@gen{ab}\langle{r\langle\rangle}%
1606 {\phx@abopen\langle#1\phx@abclose\rangle}
1607 % \end{macrocode}
1608 % \cs{endgroup}'s in the end of the following definitions are corresponding to
1609 % \cs{begingroup}'s in the definition of \cs{phx@d@l@genxm}.
1610 % \begin{macrocode}
1611 \phx@AB@gen{mb}({mr()}%
1612 {\mathopen#1(#2\mathclose#1)\endgroup}
1613 \phx@AB@gen{mb}[{mr[]}%
1614 {\mathopen#1[#2\mathclose#1]\endgroup}
1615 \phx@AB@gen{mb}\{{mr\{\}}%
1616 {\mathopen#1\lbrace#2\mathclose#1\rbrace\endgroup}
1617 \phx@AB@gen{mb}|{mr||}%
1618 {\mathopen#1\vert#2\mathclose#1\vert\endgroup}
1619 \phx@AB@gen{mb}\|{mr\|\|}%
1620 {\mathopen#1\Vert#2\mathclose#1\Vert\endgroup}
1621 \phx@AB@gen{mb}<{mr<>}%
1622 {\mathopen#1\langle#2\mathclose#1\rangle\endgroup}
1623 \phx@AB@gen{mb}\lbrace{mr\lbrace\rbrace}%
1624 {\mathopen#1\lbrace#2\mathclose#1\rbrace\endgroup}
1625 \phx@AB@gen{mb}\vert{mr\vert\vert}%
1626 {\mathopen#1\vert#2\mathclose#1\vert\endgroup}
1627 \phx@AB@gen{mb}\Vert{mr\Vert\Vert}%
1628 {\mathopen#1\Vert#2\mathclose#1\Vert\endgroup}
1629 \phx@AB@gen{mb}\langle{mr\langle\rangle}%
1630 {\mathopen#1\langle#2\mathclose#1\rangle\endgroup}
1631 % \end{macrocode}
1632 % \end{macro}
1633 % \begin{macro}[int]{\phx@d@lx}
1634 % \begin{quote}
1635 % \cs{phx@d@lx} \marg{biggg or star branch name} ^^A
1636 % \marg{automatic branch name} "{#3}"
1637 % \end{quote}
1638 % \begin{macrocode}
1639 \def\phx@d@lx#1#2#3{%
1640 \ifcsname phx@del\string#3\endcsname
1641 \def\reserved@a{#1}% #3 is star or \biggg
1642 \else
1643 \def\reserved@a{#2}% #3 is delimiter
1644 \fi
1645 \csname phx@d@lx\reserved@a\endcsname#3}
1646 % \end{macrocode}
1647 % \end{macro}
1648 % \begin{macro}[int]{\phx@d@l@genxm, \phx@d@l@genxa}
1649 % \begin{quote}
1650 % \cs{phx@d@l@genxm} \marg{biggg or star branch name}\\
1651 % \cs{phx@d@l@genxa} \marg{automatic branch name}
1652 % \end{quote}
1653 % \begin{macrocode}
1654 \def\phx@d@l@genxm#1{%
1655 \expandafter\def\csname phx@d@lx#1\endcsname##1##2{%
1656 \begingroup % \endgroup is at the end of #4 of \phx@AB@gen
1657 \ifx##1*\let\phx@tempa=\relax\else\let\phx@tempa=##1\fi
1658 \csname phx@#1@\string##2\endcsname\phx@tempa##2}}
1659 \def\phx@d@l@genxa#1{%
1660 \expandafter\def\csname phx@d@lx#1\endcsname##1{%
1661 \csname phx@#1@\string##1\endcsname##1}}
1662 % \end{macrocode}
1663 % \end{macro}
1664 % \begin{macro}[int]{\phx@d@lxmb, \phx@d@lxab}
1665 % \begin{quote}
1666 % \cs{phx@d@lxmb} \meta{biggg or *} \meta{left delimiter}\\
1667 % " "\meta{subformula} \meta{right delimiter}\\
1668 % \cs{phx@d@lxab} \phantom{\meta{biggg or *}} \meta{left delimiter}\\
1669 % " "\meta{subformula} \meta{right delimiter}
1670 % \end{quote}
1671 % \begin{macrocode}
1672 \phx@d@l@genxm{mb}
1673 \phx@d@l@genxa{ab}
1674 % \end{macrocode}
1675 % \end{macro}
1676 % \begin{macro}{\ab}
1677 % The users' command \cs{ab}.
1678 % \begin{macrocode}
1679 \DeclareRobustCommand\ab{\phx@d@lx{mb}{ab}}
1680 % \end{macrocode}
1681 % \end{macro}
1682 % \subsubsection{\cs{pab}-like commands}
1683 % This is so simple. No need to comment a lot.
1684 % \begin{macro}[int]{\phx@d@l@geny}
1685 % \begin{quote}
1686 % \cs{phx@d@l@geny} \meta{command} ^^A
1687 % \meta{left delimiter} \meta{right delimiter}
1688 % \end{quote}
1689 % This command used to define commands like \cs{pab}.
1690 % \begin{macrocode}
1691 \def\phx@d@l@geny#1#2#3{%
1692 % \end{macrocode}
1693 % \begin{multicols}{3}
1694 % \begin{arguments}
1695 % \item star;
1696 % \item bigg (csname);
1697 % \item subformula.
1698 % \end{arguments}
1699 % \end{multicols}
1700 % \begin{macrocode}
1701 \DeclareDocumentCommand#1{som}{
1702 \IfBooleanTF{##1}%
1703 {#2##3#3}%
1704 {\IfValueTF{##2}%
1705 {\csname##2l\endcsname#2##3\csname##2r\endcsname#3}%
1706 {\phx@abopen#2##3\phx@abclose#3}%
1707 }%
1708 }%
1709 }
1710 \phx@d@l@geny\pab()
1711 \phx@d@l@geny\bab[]
1712 \phx@d@l@geny\Bab\lbrace\rbrace
1713 \phx@d@l@geny\vab\vert\vert
1714 \phx@d@l@geny\aab\langle\rangle
1715 \phx@d@l@geny\Vab\Vert\Vert
1716 % \end{macrocode}
1717 % \begin{macrocode}
1718 \protect \endinput
1719 % \end{macrocode}
1720 % \begin{macrocode}
1721 %</ab>
1722 % \end{macrocode}
1723 % \end{macro}
1724 % \subsection{The \modu{ab.braket} module}
1725 % \begin{macrocode}
1726 %<*ab.braket>
1727 \ProvidesFile {phx-ab.braket.sty} [\phx@date\ `ab.braket' module of physics3]
1728 % \end{macrocode}
1729 % This module requires \cs{phx@abopen} and \cs{phx@abclose} from \modu{ab}.
1730 % This module may have conflict with \modu{braket}.
1731 % \begin{macrocode}
1732 \RequirePhxmodu{ab}
1733 \ifdefined\phx@bra@@
1734 \PackageWarning{physics3}{You cannot load `ab.braket' and `braket'
1735 modules together.\MessageBreak Only `ab.braket' module works now.}
1736 \fi
1737 % \end{macrocode}
1738 % \begin{macro}{\bra}
1739 % \begin{quote}
1740 % \cs{bra} \char`\<\ \meta{subformula} \char`\|
1741 % \end{quote}
1742 % \end{macro}
1743 % \begin{macrocode}
1744 \phx@AB@gen{br.m}<{mr<|}{\mathopen#1\langle#2\mathclose#1\vert\endgroup}
1745 \phx@AB@gen{br.a}<{r<|}{\phx@abopen\langle#1\phx@abclose\vert}
1746 \phx@d@l@genxm{br.m}
1747 \phx@d@l@genxa{br.a}
1748 \DeclareRobustCommand\bra{\phx@d@lx{br.m}{br.a}}
1749 % \end{macrocode}
1750 % \begin{macro}{\ket}
1751 % \begin{quote}
1752 % \cs{ket} \char`\|\ \meta{subformula} \char`\>
1753 % \end{quote}
1754 % \end{macro}
1755 % \begin{macrocode}
1756 \phx@AB@gen{kt.m}|{mr|>}{\mathopen#1\vert#2\mathclose#1\rangle\endgroup}
1757 \phx@AB@gen{kt.a}|{r|>}{\phx@abopen\vert#1\phx@abclose\rangle}
1758 \phx@d@l@genxm{kt.m}
1759 \phx@d@l@genxa{kt.a}
1760 \DeclareRobustCommand\ket{\phx@d@lx{kt.m}{kt.a}}
1761 % \end{macrocode}
1762 % \begin{macro}{\braket}
1763 % \begin{quote}
1764 % \cs{braket} "<"\meta{subformula_1} "|" \meta{subformula_2} ^^A
1765 % {\color{gray}["|" \meta{subformula_3} \dots"]"} ">"
1766 % \end{quote}
1767 % \begin{macrocode}
1768 \begingroup
1769 \catcode`\|=\active
1770 \gdef\phx@@mb@bk#1#2{\begingroup
1771 \mathcode`\|="8000\def|{\egroup#1\vert\bgroup}%
1772 \def\<{\mathrel{<}}\def\>{\mathrel{>}}%
1773 \mathopen#1\langle\bgroup#2\egroup\mathclose#1\rangle\endgroup}
1774 \gdef\phx@@ab@bk#1{\begingroup
1775 \mathcode`\|="8000\def|{\egroup\phx@abb@bkv\bgroup}%
1776 \def\<{\mathrel{<}}\def\>{\mathrel{>}}%
1777 \phx@abopen\langle\bgroup#1\egroup\phx@abclose\rangle\endgroup}
1778 \endgroup
1779 \def\phx@abb@bkv{\middle\vert}
1780 \phx@AB@gen{bk.m}<{mr<>}{\phx@@mb@bk#1{#2}\endgroup}
1781 \phx@AB@gen{bk.a}<{r<>}{\phx@@ab@bk{#1}}
1782 \phx@d@l@genxm{bk.m}
1783 \phx@d@l@genxa{bk.a}
1784 \DeclareRobustCommand \braket {\phx@d@lx{bk.m}{bk.a}}
1785 % \end{macrocode}
1786 % \end{macro}
1787 % \begin{macro}{\ketbra}
1788 % \begin{quote}
1789 % \cs{braket} "|"\meta{subformula_1}">" \meta{subformula_2} ^^A
1790 % "<"\meta{subformula_3}"|"
1791 % \end{quote}
1792 % \begin{macrocode}
1793 \begingroup
1794 \catcode`\<=\active
1795 \catcode`\>=\active
1796 \gdef\phx@@mb@kb#1#2{\begingroup
1797 \mathcode`\<="8000 \mathcode`\>="8000%
1798 \def<{#1\langle}\def>{#1\rangle}%
1799 \def\<{\phx@abb@l}\def\>{\phx@abb@r}%
1800 \mathopen#1\vert#2\mathclose#1\vert\endgroup}
1801 \endgroup
1802 \gdef\phx@@ab@kb#1>#2<#3\phx@@end{\begingroup
1803 \def\<{\phx@abb@l}\def\>{\phx@abb@r}%
1804 \phx@abopen\vert\mathopen{\phx@mathvphantom{#3}}#1\phx@abclose\rangle#2%
1805 \phx@abopen\langle#3\mathclose{\phx@mathvphantom{#1}}\phx@abclose\vert
1806 \endgroup}
1807 \AtBeginDocument{\ifcsname symbf\endcsname
1808 \def\phx@abb@l{\Umathchar 3 \symoperators "003C }%
1809 \def\phx@abb@r{\Umathchar 3 \symoperators "003E }%
1810 \fi}
1811 \def\phx@abb@l{\mathchar"313C }
1812 \def\phx@abb@r{\mathchar"313E }
1813 \phx@AB@gen{kb.m}|{mr||}{\phx@@mb@kb#1{#2}\endgroup}
1814 \phx@AB@gen{kb.a}|{r||}{\phx@@ab@kb#1\phx@@end}
1815 \phx@d@l@genxm{kb.m}
1816 \phx@d@l@genxa{kb.a}
1817 \DeclareRobustCommand \ketbra {\phx@d@lx{kb.m}{kb.a}}
1818 % \end{macrocode}
1819 % \end{macro}
1820 % \begin{macro}{\bknorm, \kbproj, \expval}
1821 % Define some high-level commands for inner product, outer product of basis
1822 % and expectation value.
1823 % \begin{macrocode}
1824 \DeclareDocumentCommand \bknorm { s o m }
1825 {%
1826 \IfBooleanTF{#1} {\mathopen\langle#3\vert #3\mathclose\rangle}
1827 {%
1828 \IfValueTF{#2}
1829 {\expanded{\noexpand\phx@d@lx{bk.m}{bk.a}%
1830 \expandafter\noexpand\csname #2\endcsname}<#3|#3>}
1831 {\phx@d@lx{bk.m}{bk.a}<#3|#3>}%
1832 }%
1833 }
1834 \DeclareDocumentCommand \kbproj { s o m }
1835 {%
1836 \IfBooleanTF{#1}
1837 {%
1838 \mathopen\vert#3\mathclose\rangle
1839 \mathopen\langle#3\mathclose\vert
1840 }
1841 {%
1842 \IfValueTF{#2}
1843 {\expanded{\noexpand\phx@d@lx{kb.m}{kb.a}%
1844 \expandafter\noexpand\csname #2\endcsname}|#3><#3|}
1845 {\phx@d@lx{kb.m}{kb.a}|#3><#3|}%
1846 }%
1847 }
1848 % \end{macrocode}
1849 % \begin{macrocode}
1850 \DeclareDocumentCommand \expval { s o m }
1851 {%
1852 \phx@ev@doopt{#2}%
1853 \IfValueTF {#2}
1854 {%
1855 \ifx\@phx@ev\@empty
1856 \ifx \@phx@ev@basis\@empty \else
1857 \IfBooleanTF{#1}
1858 {\phx@d@lx{bk.m}{bk.a}*<\@phx@ev@basis|#3|\@phx@ev@basis>}
1859 {\phx@d@lx{bk.m}{bk.a}<\@phx@ev@basis |#3|\@phx@ev@basis>}%
1860 \fi
1861 \else
1862 \ifx\@phx@ev@basis\@empty
1863 \IfBooleanTF{#1} {\phx@d@lx{bk.m}{bk.a}*<#3>}
1864 {%
1865 \expanded{%
1866 \noexpand \phx@d@lx{bk.m}{bk.a}\expandafter \noexpand
1867 \csname \@phx@ev\endcsname}<#3>%
1868 }%
1869 \else
1870 \IfBooleanTF{#1}
1871 {%
1872 \phx@d@lx{bk.m}{bk.a}*<\@phx@ev@basis|#3|\@phx@ev@basis>%
1873 }
1874 {%
1875 \expanded{%
1876 \noexpand \phx@d@lx{bk.m}{bk.a}\expandafter
1877 \noexpand \csname \@phx@ev\endcsname}%
1878 <\@phx@ev@basis|#3|\@phx@ev@basis>%
1879 }%
1880 \fi
1881 \fi
1882 }
1883 {%
1884 \IfBooleanTF{#1}
1885 {\phx@d@lx{bk.m}{bk.a}*<#3>} {\phx@d@lx{bk.m}{bk.a}<#3>}%
1886 }%
1887 }
1888 % \end{macrocode}
1889 % \end{macro}
1890 % \begin{macrocode}
1891 \protect \endinput
1892 % \end{macrocode}
1893 % \begin{macrocode}
1894 %</ab.braket>
1895 % \end{macrocode}
1896 % \subsection{The \modu{braket} module}
1897 % \begin{macrocode}
1898 %<*braket>
1899 \ProvidesFile {phx-braket.sty} [\phx@date\ `braket' module of physics3]
1900 % \end{macrocode}
1901 % This module requires \cs{phx@abopen} and \cs{phx@abclose} from \modu{ab}.
1902 % This module may have conflict with \modu{ab.braket}.
1903 % \begin{macrocode}
1904 \RequirePhxmodu{ab}
1905 \ifdefined\phx@abb@bkv
1906 \PackageWarning{physics3}{You cannot load `ab.braket' and `braket'
1907 modules together.\MessageBreak Only `braket' module works now.}
1908 \fi
1909 % \end{macrocode}
1910 % \begin{macro}{\bra}
1911 % \begin{quote}
1912 % \cs{bra} * \oarg{biggg} \marg{subformula}
1913 % \end{quote}
1914 % \begin{macrocode}
1915 \DeclareDocumentCommand\bra{ s o m }{%
1916 \IfBooleanTF{#1}
1917 {\mathopen\langle#3\mathclose\vert}
1918 {\IfValueTF{#2}
1919 {\csname#2l\endcsname\langle#3\csname#2r\endcsname\vert}
1920 {\phx@abopen\langle#3\phx@abclose\vert}%
1921 }%
1922 }
1923 % \end{macrocode}
1924 % \end{macro}
1925 % \begin{macro}{\ket}
1926 % \begin{quote}
1927 % \cs{ket} * \oarg{biggg} \marg{subformula}
1928 % \end{quote}
1929 % \begin{macrocode}
1930 \DeclareDocumentCommand\ket{ s o m }{%
1931 \IfBooleanTF{#1}
1932 {\mathopen\vert#3\mathclose\rangle}
1933 {\IfValueTF{#2}
1934 {\csname#2l\endcsname\vert#3\csname#2r\endcsname\rangle}
1935 {\phx@abopen\vert#3\phx@abclose\rangle}%
1936 }%
1937 }
1938 % \end{macrocode}
1939 % \end{macro}
1940 % \begin{macro}{\braket}
1941 % \begin{quote}
1942 % \cs{ket} * [\meta{biggg}, $n \in \{1,2,3\}$] \marg{subformula 1} \dots
1943 % \marg{subformula $n$}
1944 % \end{quote}
1945 % \begin{macrocode}
1946 \DeclareDocumentCommand \braket { s O{} }
1947 {%
1948 \IfBooleanTF{#1}
1949 {%
1950 \gdef\@phx@bk@argnum{ii}%
1951 \phx@bk@doopt{#2}%
1952 \gdef\@phx@bk@l{mathopen}%
1953 \gdef\@phx@bk@m{mathord}%
1954 \gdef\@phx@bk@r{mathclose}%
1955 }
1956 {%
1957 \gdef\@phx@bk@argnum{ii}%
1958 \gdef\@phx@bk@l{phx@abopen}%
1959 \gdef\@phx@bk@m{middle}%
1960 \gdef\@phx@bk@r{phx@abclose}%
1961 \phx@bk@doopt{#2}%
1962 }%
1963 \csname phx@bk@in@\@phx@bk@argnum\endcsname
1964 }
1965 % \end{macrocode}
1966 % \end{macro}
1967 % \begin{macro}[int]{\phx@bk@in@i, \phx@bk@in@ii, \phx@bk@in@iii}
1968 % \begin{quote}
1969 % \cs{phx@bk@in@\meta{n.roman}} \marg{subformula 1} \dots
1970 % \marg{subformula $n$}
1971 % \end{quote}
1972 % \meta{n.roman} is $n$ in roman lowercase, where $n \in \{1,2,3\}$.
1973 % \begin{macrocode}
1974 \def\phx@bk@in@i#1{%
1975 \csname\@phx@bk@l\endcsname\langle{#1}%
1976 \csname\@phx@bk@r\endcsname\rangle}
1977 \def\phx@bk@in@ii#1#2{%
1978 \csname\@phx@bk@l\endcsname\langle{#1}%
1979 \csname\@phx@bk@m\endcsname\vert{#2}%
1980 \csname\@phx@bk@r\endcsname\rangle}
1981 \def\phx@bk@in@iii#1#2#3{%
1982 \csname\@phx@bk@l\endcsname\langle{#1}%
1983 \csname\@phx@bk@m\endcsname\vert{#2}%
1984 \csname\@phx@bk@m\endcsname\vert{#3}%
1985 \csname\@phx@bk@r\endcsname\rangle}
1986 % \end{macrocode}
1987 % \end{macro}
1988 % \begin{macro}[int]{\phx@bk@doopt, \phx@bk@do@pt}
1989 % \begin{quote}
1990 % \cs{phx@bk@doopt} \marg{clist}
1991 % \end{quote}
1992 % Parse the optional argument of \cs{braket}. This will add 3 entries to hash.
1993 % \begin{macrocode}
1994 \def\@phx@bk@do@pt#1,{\ifx#1\relax\@empty\else
1995 \edef\reserved@a{\zap@space#1 \@empty}%
1996 \ifx\reserved@a\@empty\else
1997 \ifcsname phx@del\expandafter\string\csname\reserved@a\endcsname\endcsname
1998 \xdef\@phx@bk@l{\reserved@a l}%
1999 \xdef\@phx@bk@m{\reserved@a}% but not m (m stands for \mathrel)
2000 \xdef\@phx@bk@r{\reserved@a r}%
2001 \else
2002 \ifnum\reserved@a>3%
2003 \PackageError{physics3}{\string\braket\space can only take 3
2004 mandatory arguments at most}{Check if you had written a number
2005 more than 3 in the [optional] argument.}%
2006 \fi
2007 \xdef\@phx@bk@argnum{\romannumeral\reserved@a}%
2008 \fi
2009 \fi
2010 \expandafter\@phx@bk@do@pt\fi}
2011 \def\phx@bk@doopt#1{\@phx@bk@do@pt#1,\relax,}
2012 % \end{macrocode}
2013 % \end{macro}
2014 % \begin{macro}{\ketbra}
2015 % \begin{quote}
2016 % \cs{ketbra} * [\meta{biggg}] \marg{subformula 1}\\
2017 % " "\oarg{between 1 and 2} \marg{subformula 2}
2018 % \end{quote}
2019 % \begin{macrocode}
2020 \DeclareDocumentCommand \ketbra { s o m O{} m }
2021 {%
2022 \IfBooleanTF{#1}
2023 {%
2024 \mathopen\vert#3\mathclose\rangle#4%
2025 \mathopen\langle#5\mathclose\vert
2026 }
2027 {%
2028 \IfValueTF{#2}
2029 {\csname#2l\endcsname\vert#3\csname#2r\endcsname\rangle#4%
2030 \csname#2l\endcsname\langle#5\csname#2r\endcsname\vert}
2031 {\begingroup
2032 \phx@abopen\vert
2033 \mathopen{\phx@mathvphantom{#5}}#3\phx@abclose\rangle#4%
2034 \phx@abopen\langle#5
2035 \mathclose{\phx@mathvphantom{#3}}\phx@abclose\vert
2036 \endgroup}%
2037 }%
2038 }
2039 % \end{macrocode}
2040 % \end{macro}
2041 % \begin{macro}{\bknorm, \kbproj, \expval}
2042 % Define some high-level commands for inner product, outer product of basis
2043 % and expectation value.
2044 % \begin{macrocode}
2045 \DeclareDocumentCommand \bknorm { s o m }
2046 {%
2047 \IfBooleanTF{#1}
2048 {%
2049 \gdef\@phx@bk@l{mathopen}%
2050 \gdef\@phx@bk@m{mathord}%
2051 \gdef\@phx@bk@r{mathclose}%
2052 }
2053 {%
2054 \gdef\@phx@bk@l{phx@abopen}%
2055 \gdef\@phx@bk@m{middle}%
2056 \gdef\@phx@bk@r{phx@abclose}%
2057 \IfValueT{#2}
2058 {%
2059 \ifcsname phx@del\expandafter\string\csname#2\endcsname\endcsname
2060 \xdef\@phx@bk@l{#2l}%
2061 \xdef\@phx@bk@m{#2}%
2062 \xdef\@phx@bk@r{#2r}%
2063 \fi
2064 }%
2065 }%
2066 \phx@bk@in@ii {#3} {#3}%
2067 }
2068 \DeclareDocumentCommand \kbproj { s o m }
2069 {%
2070 \IfBooleanTF{#1}
2071 {%
2072 \mathopen\vert#3\mathclose\rangle
2073 \mathopen\langle#3\mathclose\vert
2074 }
2075 {%
2076 \IfValueTF{#2}
2077 {\csname#2l\endcsname\vert#3\csname#2r\endcsname\rangle
2078 \csname#2l\endcsname\langle#3\csname#2r\endcsname\vert}
2079 {\begingroup
2080 \phx@abopen\vert
2081 \mathopen{\phx@mathvphantom{#3}}#3\phx@abclose\rangle
2082 \phx@abopen\langle#3
2083 \mathclose{\phx@mathvphantom{#3}}\phx@abclose\vert
2084 \endgroup}%
2085 }%
2086 }
2087 \DeclareDocumentCommand \expval { s O{} m }
2088 {
2089 \phx@ev@doopt{#2}%
2090 \IfBooleanTF{#1}
2091 {%
2092 \gdef\@phx@bk@l{mathopen}%
2093 \gdef\@phx@bk@m{mathord}%
2094 \gdef\@phx@bk@r{mathclose}%
2095 }
2096 {%
2097 \gdef\@phx@bk@l{phx@abopen}%
2098 \gdef\@phx@bk@m{middle}%
2099 \gdef\@phx@bk@r{phx@abclose}%
2100 \ifx \@phx@ev\@empty \else
2101 \xdef\@phx@bk@l{\@phx@ev l}%
2102 \xdef\@phx@bk@m{\@phx@ev}%
2103 \xdef\@phx@bk@r{\@phx@ev r}%
2104 \fi
2105 }%
2106 \ifx \@phx@ev@basis\@empty
2107 \phx@bk@in@i {#3}%
2108 \else
2109 \phx@bk@in@iii {\@phx@ev@basis} {#3} {\@phx@ev@basis}%
2110 \fi
2111 }
2112 % \end{macrocode}
2113 % \end{macro}
2114 % \begin{macrocode}
2115 \protect \endinput
2116 % \end{macrocode}
2117 % \begin{macrocode}
2118 %</braket>
2119 % \end{macrocode}
2120 % Restore the namespace.
2121 % \begin{macrocode}
2122 %<@@=phx>
2123 % \end{macrocode}
2124 % \subsection{The \modu{doubleprod} module}
2125 % \begin{macrocode}
2126 %<*doubleprod>
2127 \ProvidesExplFile {phx-doubleprod.sty} {\phx@date} {\phx@version}
2128 {`doubleprod' (vertically stacked binary operators) module of physics3}
2129 % \end{macrocode}
2130 % Boolean options.
2131 % \begin{macrocode}
2132 \@@_define_key:nnnn { doubleprod } { crosssymbol } { } { \def\@phx@dbl@c {#1} }
2133 \@@_define_key:nnnn { doubleprod } { dotsymbol } { } { \def\@phx@dbl@d {#1} }
2134 \@@_define_key:nnnn { doubleprod } { crossscale } { } { \def\@phx@dbl@sc{#1} }
2135 \@@_define_key:nnnn { doubleprod } { dotscale } { } { \def\@phx@dbl@sd{#1} }
2136 \@@_define_key:nnnn { doubleprod } { crossopenup } { } { \def\@phx@dbl@oc{#1} }
2137 \@@_define_key:nnnn { doubleprod } { dotopenup } { } { \def\@phx@dbl@od{#1} }
2138 \@@_setkeys:nn { doubleprod }
2139 {
2140 crosssymbol = \times, crossscale = 0.8, crossopenup = .02,
2141 dotsymbol = \ldotp, dotscale = 1, dotopenup = .2
2142 }
2143 \@@_processkeyopt:n { doubleprod }
2144 \def\phx@dbl@gen#1#2#3#4{%
2145 \DeclareRobustCommand#1{\mathbin{\vcenter{\baselineskip\z@skip%
2146 \lineskip#4\phx@dblcurrf@size%
2147 \hbox_set:Nn \l_tmpa_box {\fontsize{#2\phx@dblcurrf@size}\z@$#3$}
2148 \box_use:N \l_tmpa_box \box_use_drop:N \l_tmpa_box}}}}
2149 \def\phx@dblcurrf@size{\dimexpr\f@size pt\relax}
2150 \phx@dbl@gen\doublecross\@phx@dbl@sc\@phx@dbl@c\@phx@dbl@oc
2151 \phx@dbl@gen\doubledot\@phx@dbl@sd\@phx@dbl@d\@phx@dbl@od
2152 % \end{macrocode}
2153 % \begin{macrocode}
2154 \file_input_stop:
2155 % \end{macrocode}
2156 % \begin{macrocode}
2157 %</doubleprod>
2158 % \end{macrocode}
2159 % \subsection{The \modu{diagmat} module}
2160 % \begin{macrocode}
2161 %<*diagmat>
2162 \ProvidesExplFile {phx-diagmat.sty} {\phx@date} {\phx@version}
2163 {`diagmat' module of physics3}
2164 % \end{macrocode}
2165 % This module requires \pkg{mathtools} and \pkg{xpatch}.
2166 % \begin{macrocode}
2167 \RequirePackage { mathtools, etoolbox }
2168 % \end{macrocode}
2169 % Do expansion of column specification argument (thanks @egreg
2170 % on \href{https://tex.stackexchange.com/a/758530/299948}^^A
2171 % {\TeX\ \textsf{Stack\textbf{Exchange}}}).
2172 % \begin{macrocode}
2173 \patchcmd \MT_matrix_begin:N { \exp_args:Ne \array } { \exp_args:Ne \array } {}
2174 { \patchcmd \MT_matrix_begin:N { \array } { \exp_args:Ne \array } {} {} }
2175 % \end{macrocode}
2176 % \begin{macrocode}
2177 \@@_define_key:nnnn { diagmat } { empty } { }
2178 { \tl_gset:Nn \l_@@_mat_empty_tl { #1 } }
2179 \@@_define_key:nnnn { diagmat } { align } { r }
2180 { \tl_gset:Nn \l_@@_mat_align_tl { #1 } }
2181 % \end{macrocode}
2182 % \begin{variable}
2183 % {
2184 % \l_@@_mat_diag_clist,
2185 % \l_@@_mat_dim_int,
2186 % \l_@@_mat_line_tl,
2187 % \l_@@_diagmat_tl,
2188 % \l_@@_mat_empty_tl,
2189 % \l_@@_mat_align_tl,
2190 % \l_@@_xmat_align_c_tl,
2191 % }
2192 % This module requires some new variables.
2193 % \begin{macrocode}
2194 \clist_new:N \l_@@_mat_diag_clist
2195 \int_new:N \l_@@_mat_dim_int
2196 \tl_new:N \l_@@_mat_line_tl
2197 \tl_new:N \l_@@_diagmat_tl
2198 \tl_new:N \l_@@_mat_empty_tl
2199 \tl_new:N \l_@@_mat_align_tl
2200 \tl_const:Nn \l_@@_mat_align_c_tl { c }
2201 \@@_processkeyopt:n { diagmat }
2202 \keys_define:nn { phy / diagmat }
2203 {
2204 empty .tl_set:N = \l_@@_mat_empty_tl,
2205 align .tl_set:N = \l_@@_mat_align_tl,
2206 }
2207 % \end{macrocode}
2208 % \end{variable}
2209 % \begin{macro}{\diagmat, \pdiagmat, \bdiagmat, \Bdiagmat, \vdiagmat, \Vdiagmat}
2210 % \begin{quote}
2211 % \cs{\meta{delimiter type}diagmat} \oarg{key-val list} \marg{diagonal}
2212 % \end{quote}
2213 % \begin{macrocode}
2214 \clist_map_inline:nn { {}, p, b, B, v, V }
2215 {
2216 \exp_args:Nc \DeclareDocumentCommand { #1diagmat } { s O{} m }
2217 {
2218 \IfBooleanTF { ##1 }
2219 { \@@_diagmat_type:nnn { #1small } { ##2 } { ##3 } }
2220 { \@@_diagmat_type:nnn { #1 } { ##2 } { ##3 } }
2221 }
2222 }
2223 % \end{macrocode}
2224 % \end{macro}
2225 % \begin{macro}{\_@@_diagmat_type:nnn}
2226 % \begin{quote}
2227 % \cs{@@_diagmat_type:nnn} \marg{delimiter type}\\
2228 % " "\marg{key-val list} \marg{diagonal}
2229 % \end{quote}
2230 % \begin{macrocode}
2231 \cs_new:Npn \_@@_diagmat_type:nnn #1#2#3
2232 {
2233 \group_begin:
2234 \clist_set:Nn \l_@@_mat_diag_clist {#3}
2235 \int_set:Nn \l_@@_mat_dim_int { \clist_count:N \l_@@_mat_diag_clist }
2236 \int_compare:nNnT { \l_@@_mat_dim_int } > { \value { MaxMatrixCols } }
2237 { \setcounter { MaxMatrixCols } { \l_@@_mat_dim_int } }
2238 \keys_set:nn { phy / diagmat } {#2}
2239 \tl_gclear:N \l_@@_diagmat_tl
2240 \int_step_inline:nnn { 1 } { \l_@@_mat_dim_int }
2241 {
2242 \int_step_inline:nnn { 1 } { \l_@@_mat_dim_int }
2243 {
2244 \int_compare:nNnTF { ##1 } = { ####1 }
2245 {
2246 \clist_gpop:NN \l_@@_mat_diag_clist \l_@@_tmpa_tl
2247 \tl_if_empty:NTF \l_@@_tmpa_tl
2248 { \tl_gput_right:Nn \l_@@_mat_line_tl { \l_@@_mat_empty_tl } }
2249 % \end{macrocode}
2250 % Maybe it's better to use
2251 % "\expandafter\scantokens\expandafter{"\cs{l_@@_tmpa_tl}"}" in the next line.
2252 % \begin{macrocode}
2253 { \tl_gput_right:No \l_@@_mat_line_tl { \l_@@_tmpa_tl } }
2254 }
2255 { \tl_gput_right:Nn \l_@@_mat_line_tl { \l_@@_mat_empty_tl } }
2256 \int_compare:nNnTF { ####1 } = { \l_@@_mat_dim_int }
2257 {
2258 \tl_gput_right:Nn \l_@@_mat_line_tl { \\ }
2259 }
2260 {
2261 \tl_gput_right:Nn \l_@@_mat_line_tl { & }
2262 }
2263 }
2264 \tl_gput_right:No \l_@@_diagmat_tl { \l_@@_mat_line_tl }
2265 \tl_gclear:N \l_@@_mat_line_tl
2266 }
2267 \bool_lazy_or:nnTF
2268 { \tl_if_empty_p:N \l_@@_mat_align_tl }
2269 { \tl_if_eq_p:NN \l_@@_mat_align_tl \l_@@_mat_align_c_tl }
2270 {
2271 \begin { #1 matrix }
2272 \tl_use:N \l_@@_diagmat_tl
2273 \end { #1 matrix }
2274 }
2275 {
2276 \begin { #1 matrix* } [ \l_@@_mat_align_tl ]
2277 \tl_use:N \l_@@_diagmat_tl
2278 \end { #1 matrix* }
2279 }
2280 \group_end:
2281 }
2282 % \end{macrocode}
2283 % \end{macro}
2284 % \begin{macrocode}
2285 \file_input_stop:
2286 % \end{macrocode}
2287 % \begin{macrocode}
2288 %</diagmat>
2289 % \end{macrocode}
2290 % \subsection{The \modu{xmat} module}
2291 % \begin{macrocode}
2292 %<*xmat>
2293 \ProvidesExplFile {phx-xmat.sty} {\phx@date} {\phx@version}
2294 {`xmat' module of physics3}
2295 % \end{macrocode}
2296 % This module requires \pkg{mathtools} and \pkg{xpatch}.
2297 % \begin{macrocode}
2298 \RequirePackage { mathtools, etoolbox }
2299 % \end{macrocode}
2300 % Do expansion of column specification argument (thanks @egreg
2301 % on \href{https://tex.stackexchange.com/a/758530/299948}^^A
2302 % {\TeX\ \textsf{Stack\textbf{Exchange}}}).
2303 % \begin{macrocode}
2304 \patchcmd \MT_matrix_begin:N { \exp_args:Ne \array } { \exp_args:Ne \array } {}
2305 { \patchcmd \MT_matrix_begin:N { \array } { \exp_args:Ne \array } {} {} }
2306 % \end{macrocode}
2307 % \begin{macrocode}
2308 \@@_define_key:nnnn { xmat } { showtop } { }
2309 { \int_gset:Nn \l_@@_xmat_showtop_int { #1 } }
2310 \@@_define_key:nnnn { xmat } { showleft } { }
2311 { \int_gset:Nn \l_@@_xmat_showleft_int { #1 } }
2312 \@@_define_key:nnnn { diagmat } { align } { r }
2313 { \tl_gset:Nn \l_@@_xmat_align_tl { #1 } }
2314 % \end{macrocode}
2315 % \begin{variable}
2316 % {
2317 % \l_@@_xmat_extra_vdots_bool,
2318 % \l_@@_xmat_extra_cdots_bool,
2319 % \l_@@_xmat_showtop_int,
2320 % \l_@@_xmat_showleft_int,
2321 % \l_@@_xmat_tl,
2322 % \l_@@_xmat_align_tl,
2323 % \l_@@_xmat_align_c_tl,
2324 % }
2325 % This module requires some new variables.
2326 % \begin{macrocode}
2327 \bool_new:N \l_@@_xmat_extra_vdots_bool
2328 \bool_new:N \l_@@_xmat_extra_cdots_bool
2329 \int_new:N \l_@@_xmat_showtop_int
2330 \int_new:N \l_@@_xmat_showleft_int
2331 \tl_new:N \l_@@_xmat_tl
2332 \tl_new:N \l_@@_xmat_align_tl
2333 \tl_const:Nn \l_@@_xmat_align_c_tl { c }
2334 \int_gset:Nn \l_@@_xmat_showtop_int { \value { MaxMatrixCols } - 2 }
2335 \int_gset:Nn \l_@@_xmat_showleft_int { \value { MaxMatrixCols } - 2 }
2336 % \end{macrocode}
2337 % \end{variable}
2338 % \begin{macrocode}
2339 \cs_new:Npn \_@@_xmat_entry_format:nnn #1#2#3
2340 {
2341 #1 \c_math_subscript_token { #2 #3 }
2342 }
2343 \@@_processkeyopt:n { xmat }
2344 \clist_map_inline:nn { {}, p, b, B, v, V }
2345 {
2346 \exp_args:Nc \DeclareDocumentCommand { #1xmat } { s O{} m m m }
2347 {
2348 \IfBooleanTF { ##1 }
2349 { \_@@_xmat_type:nnnnn { #1small } { ##2 } { ##3 } { ##4 } { ##5 } }
2350 { \_@@_xmat_type:nnnnn { #1 } { ##2 } { ##3 } { ##4 } { ##5 } }
2351 }
2352 }
2353 \keys_define:nn { phx / xmat }
2354 {
2355 format .cs_set:Np = \_@@_xmat_entry_format:nnn #1#2#3 ,
2356 showtop .int_set:N = \l_@@_xmat_showtop_int ,
2357 showleft.int_set:N = \l_@@_xmat_showleft_int ,
2358 align .tl_set:N = \l_@@_xmat_align_tl ,
2359 }
2360 % \end{macrocode}
2361 % \begin{macro}[pTF]{\_@@_if_digits_only:n}
2362 % \begin{quote}
2363 % \cs{@@_if_digits_only:nTF} \marg{token list} ^^A
2364 % \marg{true code} \marg{flase code}
2365 % \end{quote}
2366 % Use \LaTeX3 regular expression to tell if \meta{token list}
2367 % (the numbers of rows or columns) contain digits only.
2368 % \end{macro}
2369 % \begin{macrocode}
2370 \prg_new_conditional:Npnn \_@@_if_digits_only:n #1 { TF }
2371 {
2372 \regex_match:nnTF { \A [[:digit:]]* \Z } { #1 }
2373 { \prg_return_true: } { \prg_return_false: }
2374 }
2375 % \end{macrocode}
2376 % \begin{macro}{\_@@_xmat_type:nnnnn}
2377 % \begin{quote}
2378 % \cs{@@_xmat_type:nnnnn} \marg{delimiter type} \marg{key-val list}\\
2379 % " "\marg{common entry} \marg{row number} \marg{column number}
2380 % \end{quote}
2381 % \end{macro}
2382 % \begin{macrocode}
2383 \cs_new:Npn \_@@_xmat_type:nnnnn #1#2#3#4#5
2384 {
2385 \group_begin:
2386 \tl_gclear:N \l_@@_xmat_tl
2387 \keys_set:nn { phx / xmat } { #2 } %
2388 \_@@_if_digits_only:nTF { #4 }
2389 {
2390 \int_compare:nNnTF { #4 } < { \l_@@_xmat_showtop_int + 1 }
2391 {
2392 \int_set:Nn \l_@@_xmat_showtop_int { #4 }
2393 \bool_set_false:N \l_@@_xmat_extra_vdots_bool
2394 }
2395 {
2396 \bool_set_true:N \l_@@_xmat_extra_vdots_bool
2397 }
2398 }
2399 {
2400 \bool_set_true:N \l_@@_xmat_extra_vdots_bool
2401 }
2402 \_@@_if_digits_only:nTF { #5 }
2403 {
2404 \int_compare:nNnTF { #5 } < { \l_@@_xmat_showleft_int + 1 }
2405 {
2406 \int_set:Nn \l_@@_xmat_showleft_int { #5 }
2407 \bool_set_false:N \l_@@_xmat_extra_cdots_bool
2408 }
2409 {
2410 \bool_set_true:N \l_@@_xmat_extra_cdots_bool
2411 }
2412 }
2413 {
2414 \bool_set_true:N \l_@@_xmat_extra_cdots_bool
2415 }
2416 \int_step_inline:nn { \l_@@_xmat_showtop_int }
2417 {
2418 \tl_put_right:Nn \l_@@_xmat_tl
2419 { \_@@_xmat_entry_format:nnn { #3 } { ##1 } { 1 } }
2420 \int_step_inline:nnn { 2 } { \l_@@_xmat_showleft_int }
2421 {
2422 \tl_put_right:Nn \l_@@_xmat_tl
2423 { & \_@@_xmat_entry_format:nnn { #3 } { ##1 } { ####1 } }
2424 }
2425 \bool_if:NT \l_@@_xmat_extra_cdots_bool
2426 {
2427 \tl_put_right:Nn \l_@@_xmat_tl
2428 { & \cdots & \_@@_xmat_entry_format:nnn { #3 } { ##1 } { #5 } }
2429 }
2430 \tl_put_right:Nn \l_@@_xmat_tl { \\ }
2431 }
2432 \bool_if:NT \l_@@_xmat_extra_vdots_bool
2433 {
2434 \tl_put_right:Nn \l_@@_xmat_tl { \vdots }
2435 \prg_replicate:nn { \l_@@_xmat_showleft_int - 1 }
2436 {
2437 \tl_put_right:Nn \l_@@_xmat_tl { & \vdots }
2438 }
2439 % Add \ddots if vdots_bool and cdots_bool be true simultaneously.
2440 \bool_if:NT \l_@@_xmat_extra_cdots_bool
2441 {
2442 \tl_put_right:Nn \l_@@_xmat_tl { & \ddots & \vdots }
2443 } % else relax
2444 \tl_put_right:Nn \l_@@_xmat_tl { \\ }
2445 % The last row.
2446 \tl_put_right:Nn \l_@@_xmat_tl
2447 { \_@@_xmat_entry_format:nnn { #3 } { #4 } { 1 } }
2448 \int_step_inline:nnn { 2 } { \l_@@_xmat_showleft_int }
2449 {
2450 \tl_put_right:Nn \l_@@_xmat_tl
2451 { & \_@@_xmat_entry_format:nnn { #3 } { #4 } { ##1 } }
2452 }
2453 \bool_if:NT \l_@@_xmat_extra_cdots_bool
2454 {
2455 \tl_put_right:Nn \l_@@_xmat_tl
2456 { & \cdots & \_@@_xmat_entry_format:nnn { #3 } { #4 } { #5 } }
2457 }
2458 } % else relax
2459 \bool_lazy_or:nnTF
2460 { \tl_if_empty_p:N \l_@@_xmat_align_tl }
2461 { \tl_if_eq_p:NN \l_@@_xmat_align_tl \l_@@_xmat_align_c_tl }
2462 {
2463 \begin { #1 matrix }
2464 \tl_use:N \l_@@_xmat_tl
2465 \end { #1 matrix }
2466 }
2467 {
2468 \begin { #1 matrix* } [ \l_@@_xmat_align_tl ]
2469 \tl_use:N \l_@@_xmat_tl
2470 \end { #1 matrix* }
2471 }
2472 \group_end:
2473 }
2474 % \end{macrocode}
2475 % \begin{macrocode}
2476 \file_input_stop:
2477 % \end{macrocode}
2478 % \begin{macrocode}
2479 %</xmat>
2480 % \end{macrocode}
2481 % \subsection{The \modu{operator} module}
2482 % \begin{macrocode}
2483 %<*operator>
2484 \ProvidesExplFile {phx-operator.sty} {\phx@date} {\phx@version}
2485 {`operator' module of physics3}
2486 \@@_define_key:nnnn { operator } { ReIm } { true }
2487 { \def\phx@reserveda {#1} }
2488 \@@_define_key:nnnn { operator } { identity } { } { \def\phx@oplega@id {#1} }
2489 \@@_define_key:nnnn { operator } { PV } { } { \def\@phx@oplega@PV{#1} }
2490 \@@_define_key:nnnn { operator } { pv } { } { \def\@phx@oplega@pv{#1} }
2491 \@@_setkeys:nn { operator }
2492 { PV = \mathcal{P}, pv = {p.v.}, ReIm = true, identity = bbold }
2493 \@@_processkeyopt:n { operator }
2494 % \end{macrocode}
2495 % \begin{macro}[int]
2496 % {
2497 % \asin, \acos, \atan, \acsc, \asec,
2498 % \acot, \erf, \erfc, \Tr, \tr,
2499 % \rank, \Res, \res, \PV, \pv,
2500 % \upe, \iu, \grad, \curl, \div,
2501 % \laplacian,\identity, \Identity
2502 % }
2503 % \begin{macrocode}
2504 \clist_map_inline:nn
2505 { asin, acos, atan, acsc, asec, acot, erf, erfc, Tr, tr, rank, Res, res }
2506 {
2507 \exp_args:Nc \DeclareRobustCommand {#1}
2508 { \mathop { \operator@font #1 } \nolimits }
2509 }
2510 \DeclareRobustCommand\PV {\mathord{\@phx@oplega@PV}}
2511 \DeclareRobustCommand\pv {\mathop{\operator@font\@phx@oplega@pv{}}\nolimits}
2512 \DeclareRobustCommand\upe {\mathrm e}
2513 \DeclareRobustCommand\iu {\mathrm i\mkern1mu}
2514 \clist_map_inline:nn { i, I }
2515 {
2516 \exp_args:Nc \DeclareDocumentCommand {#1dentity} { o }
2517 {
2518 \group_begin:
2519 \mode_if_math:TF
2520 {
2521 \mbox
2522 {
2523 \fontencoding{U} \fontseries{m} \fontshape{n}
2524 \IfValueTF { ##1 }
2525 { \fontfamily { ##1 } } { \fontfamily { \phx@oplega@id } }
2526 \selectfont
2527 \tl_if_eq:nnT {#1} { i } { 1 }
2528 \tl_if_eq:nnT {#1} { I } { I }
2529 }
2530 }
2531 {
2532 \exp_args:Nnx \msg_error:nn { physics3 }
2533 {
2534 The ~ \expandafter\string\csname #1dentity\endcsname\space
2535 command ~ requires ~ math ~ mode.
2536 }
2537 }
2538 \group_end:
2539 }
2540 }
2541 % \end{macrocode}
2542 % \end{macro}
2543 % \begin{macro}[int]{\Re, \Im}
2544 % Restore \cs{Re} and \cs{Im} in \cs{Resymbol} and \cs{Imsymbol}.
2545 % The \cs{AtBeginDocument}
2546 % hook is used for the compatibility of \pkg{unicode-math}.
2547 % \begin{macrocode}
2548 \ifx \phx@reserveda \phx@true
2549 \AtBeginDocument
2550 {
2551 \let\Resymbol\Re
2552 \let\Imsymbol\Im
2553 \DeclareRobustCommand\Re{\mathop{\operator@font Re}\nolimits}%
2554 \DeclareRobustCommand\Im{\mathop{\operator@font Im}\nolimits}%
2555 }
2556 \fi
2557 % \end{macrocode}
2558 % \end{macro}
2559 % Requires \pkg{fixdif} version 2.$x$.
2560 % \begin{macrocode}
2561 \RequirePackage{fixdif}[2023/01/31]
2562 \letdif\phx@nl@nabla{nabla}
2563 % \end{macrocode}
2564 % \begin{macro}[int]{\grad, \div, \curl, \laplacian}
2565 % $\nabla$-related operators.
2566 % \begin{macrocode}
2567 \RequirePhxmodu{ab}
2568 \AtBeginDocument
2569 {
2570 \ifcsname div\endcsname\let\divsymbol\div\fi
2571 \DeclareRobustCommand \grad {\phx@nl@nabla\ab}
2572 \DeclareRobustCommand \div {\phx@nl@nabla\cdot\ab}
2573 \DeclareRobustCommand \curl {\phx@nl@nabla\times\ab}
2574 \DeclareRobustCommand \laplacian{\phx@nl@nabla^2\ab}
2575 }
2576 % \end{macrocode}
2577 % \end{macro}
2578 % \begin{macrocode}
2579 \file_input_stop:
2580 % \end{macrocode}
2581 % \begin{macrocode}
2582 %</operator>
2583 % \end{macrocode}
2584 % \subsection{The \modu{ab.legacy} module}
2585 % \begin{macrocode}
2586 %<*ab.legacy>
2587 \ProvidesFile {phx-ab.legacy.sty} [\phx@date\ `ab.legacy' module of physics3]
2588 % \end{macrocode}
2589 % Requires \modu{ab}'s "tight" option.
2590 % \begin{macrocode}
2591 \RequirePhxmodu{ab}
2592 \phx@define@key{ab.legacy}{order}{\mathcal O}{\def\phx@ab@ordersym{#1}}
2593 \phx@setkeys{ab.legacy}{order}
2594 \phx@processkeyopt{ab.legacy}
2595 \phx@d@l@geny\abs\vert\vert
2596 \phx@d@l@geny\norm\Vert\Vert
2597 \DeclareDocumentCommand\order{som}{%
2598 \phx@ab@ordersym
2599 \IfBooleanTF{#1} {(#3)}
2600 {\IfValueTF{#2}
2601 {\csname#2l\endcsname(#3\csname#2r\endcsname)}
2602 {\phx@abopen(#3\phx@abclose)}%
2603 }%
2604 }
2605 \phx@d@l@geny\eval.\vert
2606 \phx@d@l@geny\peval(\vert
2607 \phx@d@l@geny\beval[\vert
2608 % \end{macrocode}
2609 % \begin{macrocode}
2610 \protect \endinput
2611 % \end{macrocode}
2612 % \begin{macrocode}
2613 %</ab.legacy>
2614 % \end{macrocode}
2615 % \subsection{The \modu{qtext.legacy} module}
2616 % This module is written for the compatibility with the bad commands provided by
2617 % \pkg{physics} only. The commands in this module should NEVER be used!
2618 % \begin{macrocode}
2619 %<*qtext.legacy>
2620 \ProvidesExplFile {phx-qtext.legacy.sty} {\phx@date} {\phx@version}
2621 {`qtext.legacy' module of physics3.sty}
2622 \RequirePackage{amstext}
2623 \def\phx@qtext@#1#2{#1\text{#2}\quad}
2624 \DeclareRobustCommand\qqtext{\@ifstar{\phx@qtext@{}}{\phx@qtext@\quad}}
2625 \DeclareRobustCommand\qq {\qqtext}
2626 \DeclareRobustCommand\qcomma{,\quad}
2627 \DeclareRobustCommand\qc {\qcomma}
2628 \DeclareRobustCommand\qcc
2629 {\@ifstar{\phx@qtext@{}{c.c}}{\phx@qtext@\quad{c.c}}}
2630 \clist_map_inline:nn
2631 {
2632 if, then, else, otherwise, unless,
2633 give, using, unless, assume, since,
2634 let, for, all, even, odd,
2635 integer, and, or, as, in
2636 }
2637 {
2638 \exp_args:Nc \DeclareRobustCommand { q#1 }
2639 { \@ifstar{ \phx@qtext@ {} {#1} } { \phx@qtext@ \quad {#1} } }
2640 }
2641 % \end{macrocode}
2642 % \begin{macrocode}
2643 \file_input_stop:
2644 % \end{macrocode}
2645 % \begin{macrocode}
2646 %</qtext.legacy>
2647 % \end{macrocode}
2648 % \end{implementation}
2649 % \PrintIndex