Debian Codegraph @

texmf-dist/doc/latex/physics2/physics2-legacy.tex

raw
1 %% ******************************************************
2 %% * This work may be distributed and/or modified under *
3 %% * the conditions of the LaTeX Project Public License *
4 %% * http://www.latex-project.org/lppl.txt *
5 %% * either version 1.3c of this license or any later *
6 %% * version. *
7 %% ******************************************************
8 \documentclass[11pt,letterpaper]{article}
9 \usepackage{amsmath}
10 \usepackage{unicode-math}
11 \setmainfont{Libertinus Serif}
12 \setsansfont{Libertinus Sans}
13 \setmonofont{NotoSansMono}[
14 Scale=MatchLowercase,
15 Extension=.ttf,
16 UprightFont=*-Light,
17 BoldFont=*-Medium
18 ]
19 \setmathfont{Libertinus Math}
20 \usepackage{physics2}
21 \usephysicsmodule{ab}
22 \usephysicsmodule{ab.legacy,nabla.legacy}
23 \usephysicsmodule{op.legacy,qtext.legacy}
24 \usephysicsmodule{ab.braket}
25 \usephysicsmodule{diagmat}
26 \usephysicsmodule[showleft=3,showtop=3]{xmat}
27 \usepackage{derivative}
28 \input{phy2docdef.tex}
29 \title{\pkg{physics2} manual for the legacy \pkg{physics} users}
30 \begin{document}
31 \maketitle
32
33 \begin{abstract}
34 This short document describes \pkg*{physics2} package for those who are
35 used to the \pkg*{physics} package. This document is only a simple reference
36 manual for:
37 \begin{itemize}
38 \item Frequent users of the legacy \pkg{physics} package;
39 \item Those who have to maintain a document written with \pkg{physics};
40 \item Users who failed to use \pkg*{unicode-math} with \pkg{physics}.
41 \end{itemize}
42 It seems no reason for any other user to read \emph{this} document instead of
43 the \href{./physics2.pdf}{package documentation} of \pkg{physics2},
44 because this document cannot describe the package in detail.
45
46 In this document, the modules of \pkg{physics2} will be introduced in
47 the same order as the \pkg{physics} documentation.
48 \end{abstract}
49
50 \section*{Contents}
51 \begin{multicols}{2}
52 \contentsonly
53 \end{multicols}
54 \ifnum\value{page}=1 \vfil\clearpage\fi
55
56 \section{Before you start}
57 \subsection{Legacy problems with \pkg{physics} package}
58 \label{subsec:physics-legacy-problems}
59 The \pkg{physics} package provides \cs{qty} command for automatic-sizing
60 braces. The \cs{qty} command would cause conflict with the \pkg{siunitx}
61 package, which provides a unified method to typeset numbers and units
62 correctly.
63
64 Besides, after you loaded \pkg{physics}, when you type \cs{homework} you
65 will get Maxwell equations and Schrödinger equation. The \cs{homework}
66 command is ``declared'' in \texttt{physics.sty} but it was not described
67 in the documentation. That is, if you have defined \cs{homework} before
68 loading \pkg{physics} package, \pkg{physics} would overwrite the definition
69 ``silently''.
70
71 The vector-notation part of \pkg{physics} uses \pkg*{amsmath}'s (more exactly,
72 \texttt{amsbsy.sty}'s) \cs{boldsymbol} command to generate bold vectors.
73 Commands for cross/dot product are defined with \cs{boldsymbol}.
74 \cs{boldsymbol} uses \cs{mathversion}, a \LaTeXe\ kernel command that works
75 well with traditional TFM-based fonts but fails when using \pkg{unicode-math}.
76
77 In the definition of \cs{imat}, \cs{xmat}, \cs{dmat} and \cs{admat} commands
78 from \pkg{physics}, there is a \cs{newtoks} command which allocates a token
79 list register and two \cs{newcount} commands allocating two count registers.
80 Every time you write a command like \cs{imat} in your document, then one token
81 list register and two count registers will be wasted. What's even worse is
82 that, if you wrote really too many matrix commands from \pkg{physics} (for
83 example, 32767 \cs{imat}s in \hologo{LuaLaTeX}), there'd be no room for a new
84 \cs{count}.
85
86 \pkg{physics} integrated all the functions in one file (\texttt{physics.sty}),
87 that is, you cannot load one of the total seven parts of functions; you have
88 to load the seven parts altogether, even included the extra \cs{homework}
89 command we mentioned in the first paragraph.
90
91 Moreover, the code of \texttt{physics.sty} ``abuses'' the \texttt{g}-type
92 arguments of \pkg*{xparse} package. Therefore the syntax of \pkg{physics} package
93 looks kind of weird. See \href{https://tex.stackexchange.com/questions/%
94 470819/macros-dv-and-pdv-eat-the-subsequent-parenthesis-argument/470842#470842}%
95 {here} for more.
96
97 \subsection{Loading \pkg{physics2}}
98 The \pkg{physics2} package includes different modules, among which every module
99 focuses on one single function.
100
101 Write the following line in the preamble to load \pkg{physics2}:
102 \begin{Verbatim}
103 \usepackage{physics2}
104 \end{Verbatim}
105 But this is not enough. \pkg{physics2} contains different modules.
106 If you want to load any module of \pkg{physics2}, write this line after loading
107 \pkg{physics2} package:
108 \begin{displayed}
109 \cs{usephysicsmodule}\marg{module list}
110 \end{displayed}
111 For example, ``\verb|\usephysicsmodule{ab,doubleprod}|'' loads the \modu{ab}
112 module and the \modu{doubleprod} module.
113
114 You can also load a module with options:
115 \begin{displayed}
116 \cs{usephysicsmodule}\oarg{option list}\marg{module}
117 \end{displayed}
118 For example, ``\verb|\usephysicsmodule[legacy]{ab}|'' loads \modu{ab} with the
119 option ``\opt{legacy}''.
120
121 \pardanger Attention, if you used any font package in your document, remember
122 that \pkg{physics2} requires to be loaded \emph{after} font packages.
123
124
125 \section{List of commands}
126 \subsection{Automatic bracing}\label{subsec:ab-and-legacy}
127 As mentioned in \S\ref{subsec:physics-legacy-problems}, the \cs{qty} command
128 from \pkg{physics} would cause conflicts with \pkg{siunitx}. The command for
129 automatic braces in \pkg{physics2} is \cs{ab}, a shorthand for
130 {\bfseries a}utomatic {\bfseries b}races.
131
132 The \cs{ab} command requires the \modu{ab} module, so don't forget to write
133 \verb|\usephysicsmodule{ab}| in the preamble after you loaded \pkg{physics2}.
134 Always remember, \emph{do not put an \cs{ab} separately in the end of a math
135 formula}. Take some examples:
136 \begin{example}
137 \[ \ab ( \frac12 ) \quad
138 \ab [ \frac12 ] \quad
139 \ab\{ \frac12 \} \]
140 \end{example}
141 \cs{ab} can modify a delimiter-braced subformula. But the delimiters should
142 not be out of the range described by the following chart:
143 \begin{center}
144 \begin{tabular}{c@{\hskip2em}l@{\hskip2em}c}
145 \opt{(},\quad\opt{)} && \\
146 \opt{[},\quad\opt{]} && \\
147 \cs{\{},\quad\cs{\}} &or& \cs{lbrace},\quad\cs{rbrace} \\
148 \opt{<},\quad\opt{>} &or& \cs{langle},\quad\cs{rangle} \\
149 \opt{|},\quad\opt{|} &or& \cs{vert},\quad\cs{vert} \\
150 \cs{|},\quad\cs{|} &or& \cs{Vert},\quad\cs{Vert}
151 \end{tabular}
152 \end{center}
153 For example, \verb|$\ab{foo}$| and \verb|$\ab(foo]$| are illegal, but
154 \verb|$\ab\{foo\}$| and \verb|$\ab(foo)$| are okay; \verb|$\ab([)$|
155 is okay but \verb|$\ab(()$| is illegal.
156
157 \pardanger Attention, if you want to delimit a subformula with ``\{'' and
158 ``\}'', you can only write \verb|\{|, \verb|\}| or \cs{lbrace}, \cs{rbrace}
159 around it. \verb|{| and \verb|}| are not supported in \modu{ab} module.
160
161 Between \cs{ab} and the first delimiter can be a ``biggg'' command, that is,
162 from \cs{big} to \cs{Bigg}. Actually, you can also write \cs{biggg} and
163 \cs{Biggg} because \pkg{physics2} defines these after you load it. For example,
164 \begin{example}
165 \[ \ab\Big \| \frac12 \| \quad
166 \ab\Bigg < \frac12 > \quad
167 \ab\Biggg| \frac12 | \]
168 \end{example}
169 Between \cs{ab} and the first delimiter can also be a star (\opt{*}), which
170 means ``use the default size of delimiters''. But in this situation, you
171 needn't use the \cs{ab} command at all.
172
173 The \pkg{physics} package provides commands like \cs{pqty}, \cs{bqty}. In
174 the \modu{ab} module of \pkg{physics2}, these commands have changed to
175 \cs{pab}, \cs{bab}, etc. The following example shows all the
176 \texttt{\textbackslash}$X$\texttt{ab} commands in \modu{ab} module:
177 \begin{example}
178 \def\0{\frac12}
179 \[ \pab{\0} \quad \bab{\0}
180 \quad \Bab{\0} \]
181 \[ \aab{\0} \quad \vab{\0}
182 \quad \Vab{\0} \]
183 \end{example}
184 \texttt{\textbackslash$X$ab} can take an optional star and an optional \oarg{biggg}
185 argument. For example,
186 \begin{example}
187 \def\0{\frac12}
188 \[ \pab[Big]{\0} \quad \bab*{\0} \]
189 \end{example}
190
191 \pkg{physics} also provides the following commands:
192 \begin{Verbatim}[fontsize=\small]
193 \abs \norm \eval \order \comm \acomm \pb
194 \end{Verbatim}
195 \pardanger These commands are not originally supported by \pkg{physics2}, but
196 the first four commands can be used through the \modu{ab.legacy} module of
197 \pkg{physics2}:
198 \begin{Verbatim}
199 \usephysicsmodule{ab.legacy}
200 \end{Verbatim}
201 For example,
202 \begin{example}
203 \def\0{\frac12}
204 \[ \abs{\0} \quad \abs[big]{\0}
205 \quad \abs*{\0} \]
206 \end{example}
207 Users of the legacy \pkg{physics} package should notice that the syntax of
208 \cs{eval} has been changed. The \modu{ab.legacy} module abandoned the
209 \verb"\eval(foo|"-like syntax. The new \cs{eval}'s syntax is just like other
210 commands in this module. There are also two variants of \cs{eval} --- \cs{peval}
211 and \cs{beval}. For example,
212 \begin{example}
213 \def\0{1+\frac12x}
214 \[ \eval{\0}_a^b \quad
215 \peval*{\0}_a^b \quad
216 \beval[big]{\0}_a^b \]
217 \end{example}
218 The \cs{comm}, \cs{acomm} and \cs{pb} (Poisson bracket) are not supported.
219 But you can write like \verb|\ab[foo,baz]| or \verb|\bab{foo,baz}| instead.
220
221 By the way, you can set the ``order'' symbol in \modu{ab.legacy} through
222 the \opt{order} option like this:
223 \begin{Verbatim}
224 \usephysicsmodule[order=O]{ab.legacy}
225 \end{Verbatim}
226 Then \verb|$\order(N)$| yields $O(N)$.
227
228 \subsection{Vector notation}
229 Unfortunately, there is not a plan for \pkg{physics2} to support this part
230 of \pkg{physics} completely, but the rest of this section will show some
231 methods to maintain the document written with \pkg{physics}.
232
233 The \cs{vb}(\opt{*}), \cs{va}(\opt{*}) and \cs{vu}(\opt{*}) are not supported
234 in any module of \pkg{physics2}. But these commands can be defined by copying
235 the following lines below and pasting them in the preamble:
236 \begin{Verbatim}[fontsize=\small]
237 \makeatletter
238 \newcommand\vb{\@ifstar\boldsymbol\mathbf}
239 \newcommand\va[1]{\@ifstar{\vec{#1}}{\vec{\mathrm{#1}}}}
240 \newcommand\vu[1]{%
241 \@ifstar{\hat{\boldsymbol{#1}}}{\hat{\mathbf{#1}}}}
242 \makeatother
243 \end{Verbatim}
244 The \cs{boldsymbol} command requires the \pkg*{amsmath} or \pkg*{bm} package.
245 If you prefer to use \pkg{bm}, you can also use the \cs{bm} command.
246 What's more, if you tried the commands above, you might find that,
247 the result of \cs{va} above is different from that of \pkg{physics}.
248 This is because, if you choose to present a vector in bold, there's almost
249 no need to put a \cs{vec} ($\vec{\mskip9mu}$) sign above it.
250
251 However, the method above may not work well with \pkg*{unicode-math}
252 because there are so many OpenType math fonts without a bold version.
253 When using \pkg{unicode-math}, it's recommended to use \cs{symbf} and
254 \cs{symbfit} for a separate vector. For example, \verb|$\symbf{0}$| yields
255 $\symbf{0}$, and \verb|$\symbfit{A}$| yields $\symbfit{A}$.
256
257 The \cs{vdot} and \cs{cross} commands are not supported in any module
258 of \pkg{physics2}. Actually, there is no need to use a bold ``$\cdot$''
259 or ``$\times$'' for the products of two vectors. Using \cs{cdot} and
260 \cs{times} is enough.
261
262 The commands related to ``$\nabla$'' are supported through \modu{nabla.legacy}
263 module. These commands are \cs{grad}, \cs{div} and \cs{curl}. These commands
264 should not be put in the end of a math formula either (just like \cs{ab}).
265 Notice that the former \cs{div} command for a ``$\divsymbol$'' (if there
266 exists one) is redefined as \cs{divsymbol}. For example,
267 \begin{example}
268 % \usephysicsmodule{nabla.legacy}
269 \[ \grad F \quad
270 \grad(\frac G2) \]
271 \[ \div\Bigg[X] \quad
272 \curl*\{\frac Y2\} \]
273 \[ 2 \divsymbol 1 \]
274 \end{example}
275 Actually, the nabla-related commands end with \cs{ab}. Thus, the subformula
276 after these commands can be delimited with \verb|()|, \verb|[]| and \verb|\{\}|.
277
278 The \modu{nabla.legacy} requires the \pkg*{fixdif} package at least
279 version 2.0 (file date: 2023/01/31 or after 2023/01/31).
280
281 By the way, if you are used to writing \cs{bm} for a vector but interested in
282 \pkg{unicode-math}, the \modu{bm-um.legacy} module would be a passable
283 alternative to \pkg{bm} package. Notice that the \cs{bm} command from the
284 \modu{bm-um.legacy} module can only take \emph{one} letter (or \emph{one} digit)
285 as its argument.
286
287 \subsection{Operators}
288 There's no plan for \pkg{physics2} to support this part of \pkg{physics}
289 completely. The syntax in this part of \pkg{physics} (such as \verb|\tan[2](x)|)
290 abuses \pkg*{xparse}.
291
292 It's suggested to write like this if you used the \modu{ab} module:
293 \begin{Verbatim}[fontsize=\small]
294 $ \sin^2 \ab( \frac{\alpha}{2} ) $
295 \end{Verbatim}
296 Rather than take the superscript as an optional argument of the command of
297 log-like functions.
298
299 The \pkg{physics} package provides a bundle of commands for log-like functions
300 that have not been defined in the \LaTeXe\ kernel. Those log-like functions
301 can be used with the \modu{op.legacy} module; this module does not support
302 the syntax of \pkg{physics} either. For example:
303 \begin{example}
304 % \usephysicsmodule{op.legacy}
305 \[ \asin^2 x \quad \rank \{ A \} \]
306 \end{example}
307 The \cs{Re} and \cs{Im} commands are redefined as operators ``$\Re$'' and
308 ``$\Im$'', while $\Resymbol$ and $\Imsymbol$ are reserved as \cs{Resymbol} and
309 \cs{Imsymbol}. $\Resymbol$ and $\Imsymbol$ are ordinary symbols but $\Re$ and
310 $\Im$ are operators.
311
312 \subsection{Quick quad text}\label{subsec:qtext}
313 The \modu{qtext.legacy} module provides the \cs{q}\meta{foo} commands
314 for \cs{quad}-wrapped texts. These commands have the same syntax as
315 \pkg{physics}. For example,
316 \begin{example}
317 % \usephysicsmodule{qtext.legacy}
318 \[ A \qq {foo bar} B \]
319 \[ A \qq*{foo bar} B \]
320 \[ C \qcc D \qcc* E \]
321 \[ F \qif G \qthen H \]
322 \end{example}
323 All the commands described in \S2.4 of
324 \href{http://mirrors.ctan.org/macros/latex/contrib/physics/physics.pdf}%
325 {\textsf{physics} documentation} are supported when using \modu{qtext.legacy}
326 module, but I don't recommend using this module unless you are maintaining a
327 document written with \pkg{physics}'s \cs{q}\meta{foo} commands.
328
329 \subsection{Derivatives}
330 There is no plan for \pkg{physics2} to support this part of \pkg{physics}. If
331 you want to typeset the differential operators on a better sense, you can try
332 the \pkg*{fixdif} package; if you want an easy way to type derivatives, you
333 can try the \pkg*{derivative} package. These two packages can be used
334 together. For example,
335 \begin{example}
336 % \usepackage{fixdif,derivative}
337 \[ \pdv{f}{x,y,z} \d x \]
338 Math ($\d x$) v.s.\ Text (\d x)
339 \end{example}
340 Here are the documentations of
341 \href{http://mirrors.ctan.org/macros/latex/contrib/fixdif/fixdif.pdf}%
342 {\textsf{fixdif}} and
343 \href{http://mirrors.ctan.org/macros/latex/contrib/derivative/derivative%
344 .pdf}{\textsf{derivative}}.
345
346 \pkg{fixdif}'s commands behave better in superscripts and subscripts.
347
348 \subsection{Dirac bra-ket notation}
349 There are two solutions to Dirac bra-ket in \pkg{physics2} --- \modu{ab.braket}
350 and \modu{braket}. These two modules are \emph{not} compatible and neither of
351 them supports \pkg{physics}'s syntax completely.
352 Click \hyperlink{para:ab.braket}{\textcolor{cyan}{here}} to see the
353 \modu{ab.braket} module and \hyperlink{para:braket}{\textcolor{cyan}{here}}
354 to see the \modu{braket} module.
355
356 \paragraph{The \modu{ab.braket} module}
357 \hypertarget{para:ab.braket}{This} module provides four commands --- \cs{bra}, \cs{ket}, \cs{braket} and
358 \cs{ketbra}. After these commands can be a star (\opt{*}) or a ``biggg''
359 command. These commands share similar syntaxes like \cs{ab}'s syntax. But,
360 \emph{the bra-ket commands from \modu{ab.braket} module are completely different
361 from \cs{ab}}. Their internal structures are different.
362
363 The argument of \cs{bra} should be delimited with \opt{<} and \opt{|}, that is,
364 \begin{center}
365 \cs{bra} \opt{<} \meta{subformula} \opt{|}
366 \end{center}
367 For example,
368 \begin{example}
369 \[ \bra < \frac \phi 2 | \]
370 \[ \bra*< \frac \phi 2 | \]
371 \[ \bra\Big< \phi | \]
372 \end{example}
373 The argument of \cs{ket} should be delimited with \opt{|} and \opt{>}, that is,
374 \begin{center}
375 \cs{ket} \opt{|} \meta{subformula} \opt{>}
376 \end{center}
377 For example,
378 \begin{example}
379 \[ \ket | \frac \psi 2 > \]
380 \[ \ket*| \frac \psi 2 > \]
381 \[ \ket\Big| \psi > \]
382 \end{example}
383 \pardanger
384 If you want to write ``$>$'' and ``$<$'' for relations in the argument of
385 \cs{bra} and \cs{ket}, you can write \verb|\mathrel{>}| and \verb|\mathrel{<}|
386 (although there is almost no such need).
387
388 The argument of \cs{braket} should be delimited with \opt{<} and \opt{>},
389 that is,
390 \begin{center}
391 \cs{braket} \opt{<} \meta{subformula} \opt{>}
392 \end{center}
393 In the \meta{subformula} argument, every ``\opt{|}'' will be regarded as an
394 extensible vertical bar. For example,
395 \begin{example}
396 \[ \braket< \phi > \]
397 \[ \braket< \phi | \psi > \]
398 \[ \braket< \phi | A | \psi > \]
399 \end{example}
400 \begin{example}
401 \def\0{\frac\phi2}
402 \[ \braket < \0 | \psi > \]
403 \[ \braket* < \0 | \psi > \]
404 \[ \braket\Bigg< \0 | \psi > \]
405 \end{example}
406 The argument of \cs{ketbra} should be delimited with \opt{|} and \opt{|}.
407 In the argument, \opt{>} and \opt{<} will be regarded as extensible $\rangle$
408 and $\langle$. That is,
409 \begin{center}
410 \cs{ketbra} \opt{|} \meta{subformula$_1$} \opt{>} \meta{optional}
411 \opt{<} \meta{subformula$_2$} \opt{|}
412 \end{center}
413 For example,
414 \begin{example}
415 \def\0{\frac\phi2}
416 \[ \ketbra | \0 >< \psi | \]
417 \[ \ketbra* | \0 >< \psi | \]
418 \[ \ketbra\Bigg| \0 >< \psi | \]
419 \end{example}
420 \begin{example}
421 \def\0{\frac\phi2}
422 \[ \ketbra| \0 >_x^y < \psi | \]
423 \end{example}
424 \pardanger
425 If you want to write ``$>$'' and ``$<$'' for relations in the argument of
426 \cs{braket} and \cs{ketbra}, you can write \cs{>} and \cs{<} (although there
427 is almost no such need). It is quite different from \verb|\mathrel{>}| or
428 \verb|\mathrel{<}| because in these commands' argument, \opt{>} and \opt{<}
429 will be redefined.
430
431 \paragraph{The \modu{braket} module}
432 \begingroup
433 \makeatletter\def\phy@requiremodule#1{}%
434 \def\PackageWarning#1#2{}%
435 \input phy-braket.sty\makeatother
436 \hypertarget{para:braket}{This} module contains four commands --- \cs{bra},
437 \cs{ket}, \cs{braket} and \cs{ketbra}. After these commands can be a star
438 (\opt{*}) or a square-bracket-delimited size option, the size option can
439 take the following values:
440 \begin{center}
441 \opt{big},\quad\opt{Big},\quad\opt{bigg},\quad\opt{Bigg},\quad
442 \opt{biggg}\quad or\quad\opt{Biggg}.
443 \end{center}
444 Star stands for ``do not size the bra-ket automatically''.
445
446 The argument(s) of these four commands are braced with \verb|{| and \verb|}|.
447 \cs{bra} and \cs{ket} take one mandatory argument. For example,
448 \begin{example}
449 \def\0{\frac\phi2}
450 \[ \bra {\0} \quad \bra* {\0}
451 \quad \bra[Big] {\0} \]
452 \[ \ket {\0} \quad \ket* {\0}
453 \quad \ket[Big] {\0} \]
454 \end{example}
455 The \cs{braket} command, in default, can take two arguments.
456 \begin{example}
457 \def\0{\frac\phi2}
458 \[ \braket {\0} {\psi} \quad
459 \braket*{\0} {\psi} \quad
460 \braket[big] {\0} {\psi} \]
461 \end{example}
462 If you want \cs{braket} to take one or three arguments, you can write the
463 number of arguments in the square bracket. If you need to specify the size
464 of bra-ket simultaneously, you need to separate the number and the size with
465 a comma:
466 \begin{example}
467 \def\0{\frac\phi2}
468 \[ \braket [1] {\0} \quad
469 \braket*[1] {\0} \]
470 \[ \braket [3] {\0}{A}{\psi} \]
471 \[ \braket[3,big] {\0}{A}{\psi}
472 \quad
473 \braket[Big,3] {\0}{A}{\psi} \]
474 \end{example}
475 The \cs{ketbra} command takes two mandatory arguments. It can also take an
476 optional argument between the two mandatory arguments. The optional argument
477 will be placed between $\rangle$ and $\langle$:
478 \begin{example}
479 \def\0{\frac\phi2}
480 \[ \ketbra {\0} {\psi} \quad
481 \ketbra* {\0} {\psi} \]
482 \[ \ketbra [Bigg] {\0} {\psi} \]
483 \[ \ketbra {\0} [_x^y] {\psi} \]
484 \end{example}
485 \endgroup
486
487 \subsection{Matrix macros}
488 Unfortunately, \pkg{physics2} do not support the \cs{mqty} command from
489 \pkg{physics}. If you are used to this command, you can write like this:
490 \begin{Verbatim}[fontsize=\small]
491 \newcommand\mqty[1]{\begin{matrix}#1\end{matrix}}
492 \newcommand\pmqty[1]{\begin{pmatrix}#1\end{pmatrix}}
493 $\ab(\mqty{foo})$ or $\pmqty{foo}$
494 \end{Verbatim}
495 These are equal to physics's \verb|\mqty(foo)| (require \pkg{amsmath}).
496
497 \pkg{physics2}'s \modu{diagmat} module provides \cs{diagmat} command
498 for diagonal matrices. For example,
499 \begin{example}
500 \[
501 \diagmat { 1, 2, 3 }
502 \]
503 \end{example}
504 \begin{example}
505 \[
506 \pdiagmat [ empty = {} ]
507 { a, b, c, d }
508 \]
509 \end{example}
510 \cs{pdiagmat}, \cs{bdiagmat}, \cs{Bdiagmat}, \cs{vdiagmat} and \cs{Vdiagmat}
511 are also available.
512
513 \pkg{physics2}'s \modu{xmat} module provides \cs{xmat} command
514 for matrices with formatted entries. For example,
515 \begin{example}
516 \[
517 \xmat{a}{2}{3}
518 \]
519 \end{example}
520 \begin{example}
521 % \usephysicsmodule
522 % [showleft=3,showtop=3]{xmat}
523 \[
524 \pxmat{X}{m}{n}
525 \]
526 \end{example}
527 \begin{example}
528 \[
529 \xmat [showleft=2,showtop=2,
530 format=\texttt{#1[#2][#3]}]
531 {x}{m}{n}
532 \]
533 \end{example}
534 \cs{pxmat}, \cs{bxmat}, \cs{Bxmat}, \cs{vxmat} and \cs{Vxmat} are also available.
535
536
537
538
539
540
541
542
543
544 \end{document}