physics.sty 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. \ProvidesPackage{physics}
  2. % physics 1.3
  3. % This material is subject to the LaTeX Project Public License.
  4. % See http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html for the details of that license.
  5. %
  6. % Handy commands for physicists including macros for vectors, calculus, matrices, and bra-ket (Dirac) notation
  7. % Requires xparse package, which comes bundled with l3packages and l3kernel
  8. % This package loads amsmath, which comes standard with most latex distributions
  9. % The commands defined in this package will silently overwrite previous commands with the same name, if such commands exist
  10. %
  11. % Created by Sergio C. de la Barrera
  12. % Updated on December 12, 2012
  13. % Uploaded on December 20, 2012
  14. \RequirePackage{xparse}
  15. \RequirePackage{amsmath}
  16. % Options
  17. \DeclareOption{trig}{\let\trigopt = 1}
  18. \DeclareOption{notrig}{\let\trigopt = 0}
  19. \DeclareOption{uprightdiff}{\def\diffd{\mathrm{d}}} % Upright differentials
  20. \DeclareOption{italicdiff}{\def\diffd{d}} % Italic differentials
  21. \DeclareOption{bolddel}{\DeclareDocumentCommand\vnabla{}{\boldsymbol\nabla}} % Vector bold \nabla symbol
  22. \DeclareOption{arrowdel}{\DeclareDocumentCommand\vnabla{}{\vec{\boldsymbol\nabla}}} % Vector arrow \nabla symbol
  23. \ExecuteOptions{trig,uprightdiff,bolddel}
  24. \ProcessOptions\relax
  25. % Symbols
  26. \ProvideDocumentCommand\varE{}{\mathcal{E}} % Curly 'E'
  27. \ProvideDocumentCommand\ordersymbol{}{\mathcal{O}} % Order symbol --> O(x^2)
  28. \ProvideDocumentCommand\lparen{}{(} % Left parenthesis
  29. \ProvideDocumentCommand\rparen{}{)} % Right parenthesis
  30. % Brackets and braces
  31. \DeclareDocumentCommand\quantity{}{{\ifnum\z@=`}\fi\@quantity}
  32. \DeclareDocumentCommand\@quantity{ t\big t\Big t\bigg t\Bigg g o d() d|| }
  33. { % Flexible automatic bracketing of an expression in () or [] or {} or ||
  34. % Handles manual override of sizing
  35. \IfBooleanTF{#1}{\let\ltag\bigl \let\rtag\bigr}{
  36. \IfBooleanTF{#2}{\let\ltag\Bigl \let\rtag\Bigr}{
  37. \IfBooleanTF{#3}{\let\ltag\biggl \let\rtag\biggr}{
  38. \IfBooleanTF{#4}
  39. {\let\ltag\Biggl \let\rtag\Biggr}
  40. {\let\ltag\left \let\rtag\right}
  41. }
  42. }
  43. }
  44. % Handles actual bracketing
  45. \IfNoValueTF{#5}{
  46. \IfNoValueTF{#6}{
  47. \IfNoValueTF{#7}{
  48. \IfNoValueTF{#8}
  49. {()}
  50. {\ltag\lvert{#8}\rtag\rvert}
  51. }
  52. {\ltag(#7\rtag) \IfNoValueTF{#8}{}{|#8|}}
  53. }
  54. {\ltag[#6\rtag] \IfNoValueTF{#7}{}{(#7)} \IfNoValueTF{#8}{}{|#8|}}
  55. }
  56. {\ltag\lbrace#5\rtag\rbrace \IfNoValueTF{#6}{}{[#6]} \IfNoValueTF{#7}{}{(#7)} \IfNoValueTF{#8}{}{|#8|}}
  57. \ifnum\z@=`{\fi}
  58. }
  59. \DeclareDocumentCommand\qty{}{\quantity} % Shorthand for \quantity
  60. \DeclareDocumentCommand\pqty{ l m }{\braces#1{\lparen}{\rparen}{#2}}
  61. \DeclareDocumentCommand\bqty{ l m }{\braces#1{\lbrack}{\rbrack}{#2}}
  62. \DeclareDocumentCommand\Bqty{ l m }{\braces#1{\lbrace}{\rbrace}{#2}}
  63. \DeclareDocumentCommand\vqty{ l m }{\braces#1{\lvert}{\rvert}{#2}}
  64. \DeclareDocumentCommand\pmqty{m}{\begin{pmatrix}#1\end{pmatrix}}
  65. \DeclareDocumentCommand\Pmqty{m}{\left\lgroup\begin{matrix}#1\end{matrix}\right\rgroup}
  66. \DeclareDocumentCommand\bmqty{m}{\begin{bmatrix}#1\end{bmatrix}}
  67. \DeclareDocumentCommand\vmqty{m}{\begin{vmatrix}#1\end{vmatrix}}
  68. \DeclareDocumentCommand\matrixquantity{}{{\ifnum\z@=`}\fi\@matrixquantity}
  69. \DeclareDocumentCommand\@matrixquantity{ s g o d() d|| }
  70. {
  71. \mathord{
  72. \IfNoValueTF{#2}
  73. {
  74. \IfNoValueTF{#3}
  75. {
  76. \IfNoValueTF{#4}
  77. {
  78. \IfNoValueTF{#5}
  79. {()}
  80. {\vmqty{#5}}
  81. }
  82. {
  83. \IfBooleanTF{#1}
  84. {\Pmqty{#4}}
  85. {\pmqty{#4}}
  86. \IfNoValueTF{#5}{}{|#5|}
  87. }
  88. }
  89. {\bmqty{#3} \IfNoValueTF{#4}{}{(#4)} \IfNoValueTF{#5}{}{|#5|}}
  90. }
  91. {\begin{matrix}#2\end{matrix} \IfNoValueTF{#3}{}{[#3]} \IfNoValueTF{#4}{}{(#4)} \IfNoValueTF{#5}{}{|#5|}}
  92. }
  93. \ifnum\z@=`{\fi}
  94. }
  95. \DeclareDocumentCommand\mqty{}{\matrixquantity} % Shorthand for \matrixquantity
  96. \DeclareDocumentCommand\matrixdeterminant{m}{\vmqty{#1}} % Matrix determinant
  97. \DeclareDocumentCommand\mdet{}{\matrixdeterminant} % Shorthand for matrix determinant
  98. \DeclareDocumentCommand\spmqty{m}{\pqty{\begin{smallmatrix}#1\end{smallmatrix}}}
  99. \DeclareDocumentCommand\sPmqty{m}{\left\lgroup\begin{smallmatrix}#1\end{smallmatrix}\right\rgroup}
  100. \DeclareDocumentCommand\sbmqty{m}{\bqty{\begin{smallmatrix}#1\end{smallmatrix}}}
  101. \DeclareDocumentCommand\svmqty{m}{\vqty{\begin{smallmatrix}#1\end{smallmatrix}}}
  102. \DeclareDocumentCommand\smallmatrixquantity{ s g o d() d|| }
  103. {
  104. \mathord{
  105. \IfNoValueTF{#2}
  106. {
  107. \IfNoValueTF{#3}
  108. {
  109. \IfNoValueTF{#4}
  110. {
  111. \IfNoValueTF{#5}
  112. {()}
  113. {\svmqty{#5}}
  114. }
  115. {
  116. \IfBooleanTF{#1}
  117. {\sPmqty{#4}}
  118. {\spmqty{#4}}
  119. \IfNoValueTF{#5}{}{|#5|}
  120. }
  121. }
  122. {\sbmqty{#3} \IfNoValueTF{#4}{}{(#4)} \IfNoValueTF{#5}{}{|#5|}}
  123. }
  124. {\begin{smallmatrix}#2\end{smallmatrix} \IfNoValueTF{#3}{}{[#3]} \IfNoValueTF{#4}{}{(#4)} \IfNoValueTF{#5}{}{|#5|}}
  125. }
  126. }
  127. \DeclareDocumentCommand\smqty{}{\smallmatrixquantity} % Shorthand for \smallmatrixquantity
  128. \DeclareDocumentCommand\smallmatrixdeterminant{m}{\svmqty{#1}} % Small matrix determinant
  129. \DeclareDocumentCommand\smdet{}{\smallmatrixdeterminant} % Shorthand for small matrix determinant
  130. \DeclareDocumentCommand\argopen{s}{\IfBooleanTF{#1}{\mathopen{}\mathclose\bgroup}{\mathopen{}\mathclose\bgroup\left}} % Special open grouping for argument of a function
  131. \DeclareDocumentCommand\argclose{s}{\IfBooleanTF{#1}{\egroup}{\aftergroup\egroup\right}} % Special close grouping for argument of a function
  132. \DeclareDocumentCommand\braces{}{{\ifnum\z@=`}\fi\@braces}
  133. \DeclareDocumentCommand\@braces{ s t\big t\Big t\bigg t\Bigg m m m }
  134. { % General braces with automatic and manual sizing
  135. \IfBooleanTF{#1}
  136. {\left#6\smash{#8}\right#7\vphantom{#8}}
  137. {
  138. \IfBooleanTF{#2}{\bigl#6{#8}\bigr#7}{
  139. \IfBooleanTF{#3}{\Bigl#6{#8}\Bigr#7}{
  140. \IfBooleanTF{#4}{\biggl#6{#8}\biggr#7}{
  141. \IfBooleanTF{#5}{\Biggl#6{#8}\Biggr#7}{\left#6{#8}\right#7}
  142. }
  143. }
  144. }
  145. }
  146. \ifnum\z@=`{\fi}
  147. }
  148. \DeclareDocumentCommand\fbraces{ s t\big t\Big t\bigg t\Bigg m m m m }
  149. { % Function braces with automatic and manual sizing
  150. #8
  151. \IfBooleanTF{#1}
  152. {\argopen#6\smash{#9}\argclose#7\vphantom{#9}}
  153. {
  154. \IfBooleanTF{#2}{\argopen*\bigl#6{#9}\argclose*\bigr#7}{
  155. \IfBooleanTF{#3}{\argopen*\Bigl#6{#9}\argclose*\Bigr#7}{
  156. \IfBooleanTF{#4}{\argopen*\biggl#6{#9}\argclose*\biggr#7}{
  157. \IfBooleanTF{#5}
  158. {\argopen*\Biggl#6{#9}\argclose*\Biggr#7}
  159. {\argopen#6{#9}\argclose#7}
  160. }
  161. }
  162. }
  163. }
  164. }
  165. \DeclareDocumentCommand\absolutevalue{ l m }{\braces#1{\lvert}{\rvert}{#2}} % Absolute value/complex modulus
  166. \DeclareDocumentCommand\abs{}{\absolutevalue} % Shorthand for \absolutevalue
  167. \DeclareDocumentCommand\norm{ l m }{\braces#1{\lVert}{\rVert}{#2}} % Norm
  168. \DeclareDocumentCommand\order{ l m }{\fbraces#1{\lparen}{\rparen}{\ordersymbol}{#2}} % Order notation -> O(x^2)
  169. \DeclareDocumentCommand\evaluated{ s g d[| d(| }
  170. { % Vertical evaluation bar
  171. \IfNoValueTF{#2}
  172. {
  173. \IfNoValueTF{#3}
  174. {
  175. \IfNoValueTF{#4}
  176. {\argopen.\vphantom{\int}\argclose\rvert}
  177. {\IfBooleanTF{#1}{\vphantom{#4}}{}\left(\IfBooleanTF{#1}{\smash{#4}}{#4}\vphantom{\int}\right\rvert}
  178. }
  179. {\IfBooleanTF{#1}{\vphantom{#3}}{}\left[\IfBooleanTF{#1}{\smash{#3}}{#3}\vphantom{\int}\right\rvert \IfNoValueTF{#4}{}{(#4|}}
  180. }
  181. {\IfBooleanTF{#1}{\vphantom{#2}}{}\left.\IfBooleanTF{#1}{\smash{#2}}{#2}\vphantom{\int}\right\rvert \IfNoValueTF{#3}{}{[#3|} \IfNoValueTF{#4}{}{(#4|}}
  182. }
  183. \DeclareDocumentCommand\eval{}{\evaluated} % Shorthand for evaluated
  184. \DeclareDocumentCommand\poissonbracket{ l m m }{\braces#1{\lbrace}{\rbrace}{#2,#3}} % Poisson bracket [same as anti-commutator]
  185. \DeclareDocumentCommand\pb{}{\poissonbracket} % Shorthand for \poissonbracket
  186. % Commutators
  187. \DeclareDocumentCommand\commutator{ l m m }{\braces#1{\lbrack}{\rbrack}{#2,#3}} % Commutator
  188. \DeclareDocumentCommand\comm{}{\commutator} % Shorthand for \commutator
  189. \DeclareDocumentCommand\anticommutator{ l m m }{\braces#1{\lbrace}{\rbrace}{#2,#3}} % Anticommutator [same as Poisson bracket]
  190. \DeclareDocumentCommand\acommutator{}{\anticommutator} % Shorthand for \anticommutator
  191. \DeclareDocumentCommand\acomm{}{\anticommutator} % Shorthand for \anticommutator
  192. % Vector notation
  193. \DeclareDocumentCommand\vectorbold{ s m }{\IfBooleanTF{#1}{\boldsymbol{#2}}{\mathbf{#2}}} % Vector bold [star for Greek and italic Roman]
  194. \DeclareDocumentCommand\vb{}{\vectorbold} % Shorthand for \vectorbold
  195. \DeclareDocumentCommand\vectorarrow{ s m }{\IfBooleanTF{#1}{\vec{\boldsymbol{#2}}}{\vec{\mathbf{#2}}}} % Vector arrow + bold [star for Greek and italic Roman]
  196. \DeclareDocumentCommand\va{}{\vectorarrow} % Shorthand for \vectorarrow
  197. \DeclareDocumentCommand\vectorunit{ s m }{\IfBooleanTF{#1}{\boldsymbol{\hat{#2}}}{\mathbf{\hat{#2}}}} % Unit vector [star for Greek and italic Roman]
  198. \DeclareDocumentCommand\vu{}{\vectorunit} % Shorthand for \vectorunit
  199. \DeclareDocumentCommand\dotproduct{}{\boldsymbol\cdot} % Vector dot product symbol
  200. \DeclareDocumentCommand\vdot{}{\dotproduct} % Shorthand for \dotproduct [note that the command sequence \dp is protected]
  201. \DeclareDocumentCommand\crossproduct{}{\boldsymbol\times} % Vector cross product symbol
  202. \DeclareDocumentCommand\cross{}{\crossproduct} % Shorthand for \crossproduct
  203. \DeclareDocumentCommand\cp{}{\crossproduct} % Shorthand for \crossproduct
  204. \DeclareDocumentCommand\gradient{ g o d() }{ % Gradient
  205. \IfNoValueTF{#1}{
  206. \IfNoValueTF{#2}{
  207. \IfNoValueTF{#3}{\vnabla}{\fbraces{\lparen}{\rparen}{\vnabla}{#3}}
  208. }
  209. {\fbraces{\lbrack}{\rbrack}{\vnabla}{#2} \IfNoValueTF{#3}{}{(#3)}}
  210. }
  211. {\vnabla #1 \IfNoValueTF{#2}{}{[#2]} \IfNoValueTF{#3}{}{(#3)}}
  212. }
  213. \DeclareDocumentCommand\grad{}{\gradient} % Shorthand for \gradient
  214. \DeclareDocumentCommand\divergence{ g o d() }{ % Divergence
  215. \IfNoValueTF{#1}{
  216. \IfNoValueTF{#2}{
  217. \IfNoValueTF{#3}{\vnabla \vdot}{\vnabla \vdot \quantity(#3)}
  218. }
  219. {\vnabla \vdot \quantity[#2] \IfNoValueTF{#3}{}{(#3)}}
  220. }
  221. {\vnabla \vdot #1 \IfNoValueTF{#2}{}{[#2]} \IfNoValueTF{#3}{}{(#3)}}
  222. }
  223. \let\divisionsymbol\div % Rename \div [division symbol] in order to free up control sequence for \divergence
  224. \let\div\relax
  225. \DeclareDocumentCommand\div{}{\divergence} % Shorthand for \divergence
  226. \DeclareDocumentCommand\curl{ g o d() }{ % Curl
  227. \IfNoValueTF{#1}{
  228. \IfNoValueTF{#2}{
  229. \IfNoValueTF{#3}{\vnabla \cross}{\vnabla \cross \quantity(#3)}
  230. }
  231. {\vnabla \cross \quantity[#2] \IfNoValueTF{#3}{}{(#3)}}
  232. }
  233. {\vnabla \cross #1 \IfNoValueTF{#2}{}{[#2]} \IfNoValueTF{#3}{}{(#3)}}
  234. }
  235. \DeclareDocumentCommand\laplacian{ g o d() }{ % Laplacian
  236. \IfNoValueTF{#1}{
  237. \IfNoValueTF{#2}{
  238. \IfNoValueTF{#3}{\nabla^2}{\fbraces{\lparen}{\rparen}{\nabla^2}{#3}}
  239. }
  240. {\fbraces{\lbrack}{\rbrack}{\nabla^2}{#2} \IfNoValueTF{#3}{}{(#3)}}
  241. }
  242. {\nabla^2 #1 \IfNoValueTF{#2}{}{[#2]} \IfNoValueTF{#3}{}{(#3)}}
  243. }
  244. % Operators
  245. \DeclareMathOperator{\trace}{tr} % Trace of a matrix
  246. \DeclareMathOperator{\Trace}{Tr} % Trace of a matrix (alternate)
  247. \DeclareMathOperator{\rank}{rank} % Rank of a matrix
  248. \DeclareMathOperator{\erf}{erf} % Gauss error function
  249. \DeclareMathOperator{\Residue}{Res} % Residue
  250. \DeclareDocumentCommand\principalvalue{g}{\IfNoValueTF{#1}{\mathcal{P}}{\mathcal{P}\mathord{#1}}}
  251. \DeclareDocumentCommand\pv{}{\principalvalue}
  252. \DeclareDocumentCommand\PV{g}{\IfNoValueTF{#1}{\mathrm{P.V.}}{\mathrm{P.V.}\mathord{#1}}}
  253. \let\real\Re \DeclareDocumentCommand\Re{g}{\IfNoValueTF{#1}{\operatorname{Re}}{\fbraces{\lbrace}{\rbrace}{\operatorname{Re}}{#1}}}
  254. \let\imaginary\Im \DeclareDocumentCommand\Im{g}{\IfNoValueTF{#1}{\operatorname{Im}}{\fbraces{\lbrace}{\rbrace}{\operatorname{Im}}{#1}}}
  255. \DeclareDocumentCommand\opbraces{ m g o d() }
  256. {
  257. \IfNoValueTF{#2}
  258. {
  259. \IfNoValueTF{#3}
  260. {
  261. \IfNoValueTF{#4}
  262. {#1}
  263. {\fbraces{\lparen}{\rparen}{#1}{#4}}
  264. }
  265. {
  266. \fbraces{\lbrack}{\rbrack}{#1}{#3}
  267. \IfNoValueTF{#4}{}{(#4)}
  268. }
  269. }
  270. {
  271. \fbraces{\lbrace}{\rbrace}{#1}{#2}
  272. \IfNoValueTF{#3}{}{[#3]}
  273. \IfNoValueTF{#4}{}{(#4)}
  274. }
  275. }
  276. \DeclareDocumentCommand\trigbraces{ m o d() }
  277. {
  278. \IfNoValueTF{#3}
  279. {#1 \IfNoValueTF{#2}{}{[#2]}}
  280. {#1 \IfNoValueTF{#2}{}{^{#2}} \argopen(#3\argclose)}
  281. }
  282. % Trig function and operator redefinitions
  283. \ifx\trigopt 1
  284. \let\sine\sin \DeclareDocumentCommand\sin{}{\trigbraces{\sine}}
  285. \let\cosine\cos \DeclareDocumentCommand\cos{}{\trigbraces{\cosine}}
  286. \let\tangent\tan \DeclareDocumentCommand\tan{}{\trigbraces{\tangent}}
  287. \let\cosecant\csc \DeclareDocumentCommand\csc{}{\trigbraces{\cosecant}}
  288. \let\secant\sec \DeclareDocumentCommand\sec{}{\trigbraces{\secant}}
  289. \let\cotangent\cot \DeclareDocumentCommand\cot{}{\trigbraces{\cotangent}}
  290. \let\arcsine\arcsin \DeclareDocumentCommand\arcsin{}{\trigbraces{\arcsine}}
  291. \let\arccosine\arccos \DeclareDocumentCommand\arccos{}{\trigbraces{\arccosine}}
  292. \let\arctangent\arctan \DeclareDocumentCommand\arctan{}{\trigbraces{\arctangent}}
  293. \DeclareMathOperator{\arccosecant}{arccsc}
  294. \DeclareDocumentCommand\arccsc{}{\trigbraces{\arccosecant}}
  295. \DeclareMathOperator{\arcsecant}{arcsec}
  296. \DeclareDocumentCommand\arcsec{}{\trigbraces{\arcsecant}}
  297. \DeclareMathOperator{\arccotangent}{arccot}
  298. \DeclareDocumentCommand\arccot{}{\trigbraces{\arccotangent}}
  299. \DeclareMathOperator{\asine}{asin}
  300. \DeclareDocumentCommand\asin{}{\trigbraces{\asine}}
  301. \DeclareMathOperator{\acosine}{acos}
  302. \DeclareDocumentCommand\acos{}{\trigbraces{\acosine}}
  303. \DeclareMathOperator{\atangent}{atan}
  304. \DeclareDocumentCommand\atan{}{\trigbraces{\atangent}}
  305. \DeclareMathOperator{\acosecant}{acsc}
  306. \DeclareDocumentCommand\acsc{}{\trigbraces{\acosecant}}
  307. \DeclareMathOperator{\asecant}{asec}
  308. \DeclareDocumentCommand\asec{}{\trigbraces{\asecant}}
  309. \DeclareMathOperator{\acotangent}{acot}
  310. \DeclareDocumentCommand\acot{}{\trigbraces{\acotangent}}
  311. \let\hypsine\sinh \DeclareDocumentCommand\sinh{}{\trigbraces{\hypsine}}
  312. \let\hypcosine\cosh \DeclareDocumentCommand\cosh{}{\trigbraces{\hypcosine}}
  313. \let\hyptangent\tanh \DeclareDocumentCommand\tanh{}{\trigbraces{\hyptangent}}
  314. \DeclareMathOperator{\hypcosecant}{csch}
  315. \DeclareDocumentCommand\csch{}{\trigbraces{\hypcosecant}}
  316. \DeclareMathOperator{\hypsecant}{sech}
  317. \DeclareDocumentCommand\sech{}{\trigbraces{\hypsecant}}
  318. \let\hypcotangent\coth \DeclareDocumentCommand\coth{}{\trigbraces{\hypcotangent}}
  319. \let\exponential\exp \DeclareDocumentCommand\exp{}{\opbraces{\exponential}}
  320. \let\logarithm\log \DeclareDocumentCommand\log{}{\trigbraces{\logarithm}}
  321. \let\naturallogarithm\ln \DeclareDocumentCommand\ln{}{\trigbraces{\naturallogarithm}}
  322. \let\determinant\det \DeclareDocumentCommand\det{}{\opbraces{\determinant}}
  323. \let\Probability\Pr \DeclareDocumentCommand\Pr{}{\opbraces{\Probability}}
  324. \DeclareDocumentCommand\tr{}{\opbraces{\trace}}
  325. \DeclareDocumentCommand\Tr{}{\opbraces{\Trace}}
  326. \DeclareDocumentCommand\Res{}{\opbraces{\Residue}}
  327. \else
  328. \DeclareMathOperator{\arccsc}{arccsc}
  329. \DeclareMathOperator{\arcsec}{arcsec}
  330. \DeclareMathOperator{\arccot}{arccot}
  331. \DeclareMathOperator{\asin}{asin}
  332. \DeclareMathOperator{\acos}{acos}
  333. \DeclareMathOperator{\atan}{atan}
  334. \DeclareMathOperator{\acsc}{acsc}
  335. \DeclareMathOperator{\asec}{asec}
  336. \DeclareMathOperator{\acot}{acot}
  337. \DeclareMathOperator{\csch}{csch}
  338. \DeclareMathOperator{\sech}{sech}
  339. \DeclareDocumentCommand\tr{}{\trace}
  340. \DeclareDocumentCommand\Tr{}{\Trace}
  341. \DeclareDocumentCommand\Res{}{\Residue}
  342. \fi
  343. % Quick quad text (math-mode text with \quad spacing)
  344. \DeclareDocumentCommand\qqtext{ s m }{\IfBooleanTF{#1}{}{\quad}\text{#2}\quad}
  345. \DeclareDocumentCommand\qq{}{\qqtext}
  346. \DeclareDocumentCommand\qcomma{}{,\quad}
  347. \DeclareDocumentCommand\qc{}{\qcomma}
  348. \DeclareDocumentCommand\qif{s}{\IfBooleanTF{#1}{}{\quad}\text{if}\quad}
  349. \DeclareDocumentCommand\qthen{s}{\IfBooleanTF{#1}{}{\quad}\text{then}\quad}
  350. \DeclareDocumentCommand\qelse{s}{\IfBooleanTF{#1}{}{\quad}\text{else}\quad}
  351. \DeclareDocumentCommand\qotherwise{s}{\IfBooleanTF{#1}{}{\quad}\text{otherwise}\quad}
  352. \DeclareDocumentCommand\qunless{s}{\IfBooleanTF{#1}{}{\quad}\text{unless}\quad}
  353. \DeclareDocumentCommand\qgiven{s}{\IfBooleanTF{#1}{}{\quad}\text{given}\quad}
  354. \DeclareDocumentCommand\qusing{s}{\IfBooleanTF{#1}{}{\quad}\text{using}\quad}
  355. \DeclareDocumentCommand\qassume{s}{\IfBooleanTF{#1}{}{\quad}\text{assume}\quad}
  356. \DeclareDocumentCommand\qsince{s}{\IfBooleanTF{#1}{}{\quad}\text{since}\quad}
  357. \DeclareDocumentCommand\qlet{s}{\IfBooleanTF{#1}{}{\quad}\text{let}\quad}
  358. \DeclareDocumentCommand\qfor{s}{\IfBooleanTF{#1}{}{\quad}\text{for}\quad}
  359. \DeclareDocumentCommand\qall{s}{\IfBooleanTF{#1}{}{\quad}\text{all}\quad}
  360. \DeclareDocumentCommand\qeven{s}{\IfBooleanTF{#1}{}{\quad}\text{even}\quad}
  361. \DeclareDocumentCommand\qodd{s}{\IfBooleanTF{#1}{}{\quad}\text{odd}\quad}
  362. \DeclareDocumentCommand\qinteger{s}{\IfBooleanTF{#1}{}{\quad}\text{integer}\quad}
  363. \DeclareDocumentCommand\qand{s}{\IfBooleanTF{#1}{}{\quad}\text{and}\quad}
  364. \DeclareDocumentCommand\qor{s}{\IfBooleanTF{#1}{}{\quad}\text{or}\quad}
  365. \DeclareDocumentCommand\qas{s}{\IfBooleanTF{#1}{}{\quad}\text{as}\quad}
  366. \DeclareDocumentCommand\qin{s}{\IfBooleanTF{#1}{}{\quad}\text{in}\quad}
  367. \DeclareDocumentCommand\qcc{s}{\IfBooleanTF{#1}{}{\quad}\text{c.c.}\quad}
  368. % Derivatives
  369. \DeclareDocumentCommand\differential{ o g d() }{ % Differential 'd'
  370. % o: optional n for nth differential
  371. % g: optional argument for readability and to control spacing
  372. % d: long-form as in d(cos x)
  373. \IfNoValueTF{#2}{
  374. \IfNoValueTF{#3}
  375. {\diffd\IfNoValueTF{#1}{}{^{#1}}}
  376. {\mathinner{\diffd\IfNoValueTF{#1}{}{^{#1}}\argopen(#3\argclose)}}
  377. }
  378. {\mathinner{\diffd\IfNoValueTF{#1}{}{^{#1}}#2} \IfNoValueTF{#3}{}{(#3)}}
  379. }
  380. \DeclareDocumentCommand\dd{}{\differential} % Shorthand for \differential
  381. \DeclareDocumentCommand\derivative{ s o m g d() }
  382. { % Total derivative
  383. % s: star for \flatfrac flat derivative
  384. % o: optional n for nth derivative
  385. % m: mandatory (x in df/dx)
  386. % g: optional (f in df/dx)
  387. % d: long-form d/dx(...)
  388. \IfBooleanTF{#1}
  389. {\let\fractype\flatfrac}
  390. {\let\fractype\frac}
  391. \IfNoValueTF{#4}
  392. {
  393. \IfNoValueTF{#5}
  394. {\fractype{\diffd \IfNoValueTF{#2}{}{^{#2}}}{\diffd #3\IfNoValueTF{#2}{}{^{#2}}}}
  395. {\fractype{\diffd \IfNoValueTF{#2}{}{^{#2}}}{\diffd #3\IfNoValueTF{#2}{}{^{#2}}} \argopen(#5\argclose)}
  396. }
  397. {\fractype{\diffd \IfNoValueTF{#2}{}{^{#2}} #3}{\diffd #4\IfNoValueTF{#2}{}{^{#2}}}}
  398. }
  399. \DeclareDocumentCommand\dv{}{\derivative} % Shorthand for \derivative
  400. \DeclareDocumentCommand\partialderivative{ s o m g g d() }
  401. { % Partial derivative
  402. % s: star for \flatfrac flat derivative
  403. % o: optional n for nth derivative
  404. % m: mandatory (x in df/dx)
  405. % g: optional (f in df/dx)
  406. % g: optional (y in d^2f/dxdy)
  407. % d: long-form d/dx(...)
  408. \IfBooleanTF{#1}
  409. {\let\fractype\flatfrac}
  410. {\let\fractype\frac}
  411. \IfNoValueTF{#4}
  412. {
  413. \IfNoValueTF{#6}
  414. {\fractype{\partial \IfNoValueTF{#2}{}{^{#2}}}{\partial #3\IfNoValueTF{#2}{}{^{#2}}}}
  415. {\fractype{\partial \IfNoValueTF{#2}{}{^{#2}}}{\partial #3\IfNoValueTF{#2}{}{^{#2}}} \argopen(#6\argclose)}
  416. }
  417. {
  418. \IfNoValueTF{#5}
  419. {\fractype{\partial \IfNoValueTF{#2}{}{^{#2}} #3}{\partial #4\IfNoValueTF{#2}{}{^{#2}}}}
  420. {\fractype{\partial^2 #3}{\partial #4 \partial #5}}
  421. }
  422. }
  423. \DeclareDocumentCommand\pderivative{}{\partialderivative} % Shorthand for \partialderivative
  424. \DeclareDocumentCommand\pdv{}{\partialderivative} % Shorthand for \partialderivative
  425. \DeclareDocumentCommand\variation{ o g d() }{ % Functional variation
  426. % o: optional n for nth differential
  427. % g: optional argument for readability and to control spacing
  428. % d: long-form as in d(F(g))
  429. \IfNoValueTF{#2}{
  430. \IfNoValueTF{#3}
  431. {\delta \IfNoValueTF{#1}{}{^{#1}}}
  432. {\mathinner{\delta \IfNoValueTF{#1}{}{^{#1}}\argopen(#3\argclose)}}
  433. }
  434. {\mathinner{\delta \IfNoValueTF{#1}{}{^{#1}}#2} \IfNoValueTF{#3}{}{(#3)}}
  435. }
  436. \DeclareDocumentCommand\var{}{\variation} % Shorthand for \variation
  437. \DeclareDocumentCommand\functionalderivative{ s o m g d() }
  438. { % Functional derivative
  439. % s: star for \flatfrac flat derivative
  440. % o: optional n for nth derivative
  441. % m: mandatory (g in dF/dg)
  442. % g: optional (F in dF/dg)
  443. % d: long-form d/dx(...)
  444. \IfBooleanTF{#1}
  445. {\let\fractype\flatfrac}
  446. {\let\fractype\frac}
  447. \IfNoValueTF{#4}
  448. {
  449. \IfNoValueTF{#5}
  450. {\fractype{\variation \IfNoValueTF{#2}{}{^{#2}}}{\variation #3\IfNoValueTF{#2}{}{^{#2}}}}
  451. {\fractype{\variation \IfNoValueTF{#2}{}{^{#2}}}{\variation #3\IfNoValueTF{#2}{}{^{#2}}} \argopen(#5\argclose)}
  452. }
  453. {\fractype{\variation \IfNoValueTF{#2}{}{^{#2}} #3}{\variation #4\IfNoValueTF{#2}{}{^{#2}}}}
  454. }
  455. \DeclareDocumentCommand\fderivative{}{\functionalderivative} % Shorthand for \functionalderivative
  456. \DeclareDocumentCommand\fdv{}{\functionalderivative} % Shorthand for \functionalderivative
  457. % Bra-ket notation
  458. \DeclareDocumentCommand\bra{ s m t\ket s g }
  459. { % Bra
  460. \IfBooleanTF{#3}
  461. { % Contraction
  462. \IfBooleanTF{#1}
  463. { % Bra has a star: no resize
  464. \IfNoValueTF{#5}
  465. {\braket*{#2}{} \IfBooleanTF{#4}{*}{}}
  466. {\braket*{#2}{#5}}
  467. }
  468. {
  469. \IfBooleanTF{#4}
  470. { % Ket has a star: no resize
  471. \IfNoValueTF{#5}
  472. {\braket{#2}{} *}
  473. {\braket*{#2}{#5}}
  474. }
  475. {\braket{#2}{\IfNoValueTF{#5}{}{#5}}} % Neither term is starred: auto sizing
  476. }
  477. }
  478. { % No contraction
  479. \IfBooleanTF{#1}
  480. {\vphantom{#2}\left\langle\smash{#2}\right\rvert}
  481. {\left\langle{#2}\right\rvert}
  482. \IfBooleanTF{#4}{*}{}
  483. \IfNoValueTF{#5}{}{#5}
  484. }
  485. }
  486. \DeclareDocumentCommand\ket{ s m }
  487. { % Ket
  488. \IfBooleanTF{#1}
  489. {\vphantom{#2}\left\lvert\smash{#2}\right\rangle} % No resize
  490. {\left\lvert{#2}\right\rangle} % Auto sizing
  491. }
  492. \DeclareDocumentCommand\innerproduct{ s m g }
  493. { % Inner product
  494. \IfBooleanTF{#1}
  495. { % No resize
  496. \IfNoValueTF{#3}
  497. {\vphantom{#2}\left\langle\smash{#2}\middle\vert\smash{#2}\right\rangle}
  498. {\vphantom{#2#3}\left\langle\smash{#2}\middle\vert\smash{#3}\right\rangle}
  499. }
  500. { % Auto resize
  501. \IfNoValueTF{#3}
  502. {\left\langle{#2}\middle\vert{#2}\right\rangle}
  503. {\left\langle{#2}\middle\vert{#3}\right\rangle}
  504. }
  505. }
  506. \DeclareDocumentCommand\braket{}{\innerproduct} % Alternative for \innerproduct
  507. \DeclareDocumentCommand\ip{}{\innerproduct} % Shorthand for \innerproduct
  508. \DeclareDocumentCommand\outerproduct{ s m g }
  509. { % Dyad
  510. \IfBooleanTF{#1}
  511. { % No resize
  512. \IfNoValueTF{#3}
  513. {\vphantom{#2}\left\lvert\smash{#2}\middle\rangle\!\middle\langle\smash{#2}\right\rvert}
  514. {\vphantom{#2#3}\left\lvert\smash{#2}\middle\rangle\!\middle\langle\smash{#3}\right\rvert}
  515. }
  516. { % Auto resize
  517. \IfNoValueTF{#3}
  518. {\left\lvert{#2}\middle\rangle\!\middle\langle{#2}\right\rvert}
  519. {\left\lvert{#2}\middle\rangle\!\middle\langle{#3}\right\rvert}
  520. }
  521. }
  522. \DeclareDocumentCommand\dyad{}{\outerproduct} % Alternative for \outerproduct
  523. \DeclareDocumentCommand\op{}{\dyad} % Shorthand for \outerproduct
  524. \DeclareDocumentCommand\ketbra{}{\dyad} % Alternative for \outerproduct
  525. \DeclareDocumentCommand\expectationvalue{ s s m g }
  526. { % Expectation value
  527. \IfNoValueTF{#4}
  528. {
  529. \IfBooleanTF{#1}
  530. {\vphantom{#3}\left\langle\smash{#3}\right\rangle} % Starred implicit form: no resizing
  531. {\left\langle{#3}\right\rangle} % Normal implicit form: auto sizing
  532. }
  533. {
  534. \IfBooleanTF{#1}
  535. {
  536. \IfBooleanTF{#2}
  537. {\left\langle{#4}\middle\vert{#3}\middle\vert{#4}\right\rangle} % Double starred explicit form: total auto sizing
  538. {\vphantom{#3#4}\left\langle\smash{#4}\middle\vert\smash{#3}\middle\vert\smash{#4}\right\rangle} % Starred explicit form: no resizing
  539. }
  540. {\vphantom{#3}\left\langle{#4}\middle\vert\smash{#3}\middle\vert{#4}\right\rangle} % Normal explicit form: only resize based on bra/ket arguments
  541. }
  542. }
  543. \DeclareDocumentCommand\expval{}{\expectationvalue} % Shorthand for \expectationvalue
  544. \DeclareDocumentCommand\ev{}{\expectationvalue} % Shorthand for \expectationvalue
  545. \DeclareDocumentCommand\vev{ m }{\expectationvalue{#1}{0}} % Vacuum expectation value
  546. \DeclareDocumentCommand\matrixelement{ s s m m m }
  547. { % Matrix element
  548. \IfBooleanTF{#1}
  549. {
  550. \IfBooleanTF{#2}
  551. {\left\langle{#3}\middle\vert{#4}\middle\vert{#5}\right\rangle} % Double starred: total resizing
  552. {\vphantom{#3#4#5}\left\langle\smash{#3}\middle\vert\smash{#4}\middle\vert\smash{#5}\right\rangle} % Starred: no resizing
  553. }
  554. {\vphantom{#4}\left\langle{#3}\middle\vert\smash{#4}\middle\vert{#5}\right\rangle} % Normal: only resize based on bra/ket arguments
  555. }
  556. \DeclareDocumentCommand\matrixel{}{\matrixelement} % Shorthand for \matrixelement
  557. \DeclareDocumentCommand\mel{}{\matrixelement} % Shorthand for \matrixelement
  558. % Matrix macros
  559. \DeclareDocumentCommand\identitymatrix{m}
  560. {
  561. {
  562. \newtoks\matrixtoks
  563. \global\matrixtoks = {}
  564. \newcount\rowcount
  565. \newcount\colcount
  566. \loop
  567. \colcount = 0
  568. \advance \rowcount by 1
  569. {
  570. \loop
  571. \advance \colcount by 1
  572. \edef\addtoks
  573. {
  574. \ifnum \colcount = 1 \else & \fi
  575. \ifnum \colcount = \rowcount 1 \else 0 \fi
  576. }
  577. \global\matrixtoks = \expandafter{\the\expandafter\matrixtoks\addtoks}
  578. \ifnum \colcount < #1
  579. \repeat
  580. }
  581. \ifnum \rowcount < #1
  582. \global\matrixtoks = \expandafter{\the\matrixtoks \\ }
  583. \repeat
  584. }
  585. \the\matrixtoks
  586. }
  587. \DeclareDocumentCommand\imat{}{\identitymatrix}
  588. \DeclareDocumentCommand\xmatrix{ s m m m }
  589. {
  590. {
  591. \newtoks\matrixtoks
  592. \global\matrixtoks = {}
  593. \newcount\rowcount
  594. \newcount\colcount
  595. \loop
  596. \colcount = 0
  597. \advance \rowcount by 1
  598. {
  599. \loop
  600. \advance \colcount by 1
  601. \edef\addtoks{\ifnum \colcount = 1 \else & \fi #2 \IfBooleanTF{#1}{_{\ifnum #3 > 1 \the\rowcount \fi \ifnum #4 > 1 \the\colcount \fi}}{}}
  602. \global\matrixtoks = \expandafter{\the\expandafter\matrixtoks\addtoks}
  603. \ifnum \colcount < #4
  604. \repeat
  605. }
  606. \ifnum \rowcount < #3
  607. \global\matrixtoks = \expandafter{\the\matrixtoks \\ }
  608. \repeat
  609. }
  610. \the\matrixtoks
  611. }
  612. \DeclareDocumentCommand\xmat{}{\xmatrix}
  613. \DeclareDocumentCommand\zeromatrix{ m g }{\IfNoValueTF{#2}{\xmatrix{0}{#1}{#1}}{\xmatrix{0}{#1}{#2}}}
  614. \DeclareDocumentCommand\zmat{}{\zeromatrix}
  615. \DeclareDocumentCommand\paulixmatrix{}{0&1\\1&0}
  616. \DeclareDocumentCommand\pauliymatrix{}{0&-i\\i&0}
  617. \DeclareDocumentCommand\paulizmatrix{}{1&0\\0&-1}
  618. \DeclareDocumentCommand\paulimatrix{m}
  619. {
  620. \let\argin=#1
  621. \ifx\argin 0 \identitymatrix{2} \else
  622. \ifx\argin 1 \paulixmatrix \else
  623. \ifx\argin 2 \pauliymatrix \else
  624. \ifx\argin 3 \paulizmatrix \else
  625. \ifx\argin x \paulixmatrix \else
  626. \ifx\argin y \pauliymatrix \else
  627. \ifx\argin z \paulizmatrix \fi\fi\fi\fi\fi\fi\fi
  628. }
  629. \DeclareDocumentCommand\pmat{}{\paulimatrix}
  630. \DeclareDocumentCommand\diagonalmatrix{O{} >{\SplitList{,}}m }{\@dmat{#1}#2}
  631. \DeclareDocumentCommand\@dmat{mmggggggg}
  632. {
  633. \newtoks\matrixtoks
  634. \global\matrixtoks = {}
  635. \IfNoValueTF{#3}
  636. {#2}
  637. {
  638. \IfNoValueTF{#4}
  639. {\global\matrixtoks = \expandafter{\mqty{#2}&#1\\#1&\mqty{#3}}}
  640. {
  641. \IfNoValueTF{#5}
  642. {\global\matrixtoks = \expandafter{\mqty{#2}&#1&#1\\#1&\mqty{#3}&#1\\#1&#1&\mqty{#4}}}
  643. {
  644. \IfNoValueTF{#6}
  645. {\global\matrixtoks = \expandafter{\mqty{#2}&#1&#1&#1\\#1&\mqty{#3}&#1&#1\\#1&#1&\mqty{#4}&#1\\#1&#1&#1&\mqty{#5}}}
  646. {
  647. \IfNoValueTF{#7}
  648. {\global\matrixtoks = \expandafter{\mqty{#2}&#1&#1&#1&#1\\#1&\mqty{#3}&#1&#1&#1\\#1&#1&\mqty{#4}&#1&#1\\#1&#1&#1&\mqty{#5}&#1\\#1&#1&#1&#1&\mqty{#6}}}
  649. {
  650. \IfNoValueTF{#8}
  651. {\global\matrixtoks = \expandafter{\mqty{#2}&#1&#1&#1&#1&#1\\#1&\mqty{#3}&#1&#1&#1&#1\\#1&#1&\mqty{#4}&#1&#1&#1\\#1&#1&#1&\mqty{#5}&#1&#1\\#1&#1&#1&#1&\mqty{#6}&#1\\#1&#1&#1&#1&#1&\mqty{#7}}}
  652. {
  653. \IfNoValueTF{#9}
  654. {\global\matrixtoks = \expandafter{\mqty{#2}&#1&#1&#1&#1&#1&#1\\#1&\mqty{#3}&#1&#1&#1&#1&#1\\#1&#1&\mqty{#4}&#1&#1&#1&#1\\#1&#1&#1&\mqty{#5}&#1&#1&#1\\#1&#1&#1&#1&\mqty{#6}&#1&#1\\#1&#1&#1&#1&#1&\mqty{#7}&#1\\#1&#1&#1&#1&#1&#1&\mqty{#8}}}
  655. {\global\matrixtoks = \expandafter{\mqty{#2}&#1&#1&#1&#1&#1&#1&#1\\#1&\mqty{#3}&#1&#1&#1&#1&#1&#1\\#1&#1&\mqty{#4}&#1&#1&#1&#1&#1\\#1&#1&#1&\mqty{#5}&#1&#1&#1&#1\\#1&#1&#1&#1&\mqty{#6}&#1&#1&#1\\#1&#1&#1&#1&#1&\mqty{#7}&#1&#1\\#1&#1&#1&#1&#1&#1&\mqty{#8}&#1\\#1&#1&#1&#1&#1&#1&#1&\mqty{#9}}}
  656. }
  657. }
  658. }
  659. }
  660. }
  661. }
  662. \the\matrixtoks
  663. }
  664. \DeclareDocumentCommand\dmat{}{\diagonalmatrix}
  665. \DeclareDocumentCommand\antidiagonalmatrix{O{} >{\SplitList{,}}m }{\@admat{#1}#2}
  666. \DeclareDocumentCommand\@admat{mmggggggg}
  667. {
  668. \newtoks\matrixtoks
  669. \global\matrixtoks = {}
  670. \IfNoValueTF{#3}
  671. {#2}
  672. {
  673. \IfNoValueTF{#4}
  674. {\global\matrixtoks = \expandafter{#1&\mqty{#2}\\\mqty{#3}&#1}}
  675. {
  676. \IfNoValueTF{#5}
  677. {\global\matrixtoks = \expandafter{#1&#1&\mqty{#2}\\#1&\mqty{#3}&#1\\\mqty{#4}&#1&#1}}
  678. {
  679. \IfNoValueTF{#6}
  680. {\global\matrixtoks = \expandafter{#1&#1&#1&\mqty{#2}\\#1&#1&\mqty{#3}&#1\\#1&\mqty{#4}&#1&#1\\\mqty{#5}&#1&#1&#1}}
  681. {
  682. \IfNoValueTF{#7}
  683. {\global\matrixtoks = \expandafter{#1&#1&#1&#1&\mqty{#2}\\#1&#1&#1&\mqty{#3}&#1\\#1&#1&\mqty{#4}&#1&#1\\#1&\mqty{#5}&#1&#1&#1\\\mqty{#6}&#1&#1&#1&#1}}
  684. {
  685. \IfNoValueTF{#8}
  686. {\global\matrixtoks = \expandafter{#1&#1&#1&#1&#1&\mqty{#2}\\#1&#1&#1&#1&\mqty{#3}&#1\\#1&#1&#1&\mqty{#4}&#1&#1\\#1&#1&\mqty{#5}&#1&#1&#1\\#1&\mqty{#6}&#1&#1&#1&#1\\\mqty{#7}&#1&#1&#1&#1&#1}}
  687. {
  688. \IfNoValueTF{#9}
  689. {\global\matrixtoks = \expandafter{#1&#1&#1&#1&#1&#1&\mqty{#2}\\#1&#1&#1&#1&#1&\mqty{#3}&#1\\#1&#1&#1&#1&\mqty{#4}&#1&#1\\#1&#1&#1&\mqty{#5}&#1&#1&#1\\#1&#1&\mqty{#6}&#1&#1&#1&#1\\#1&\mqty{#7}&#1&#1&#1&#1&#1\\\mqty{#8}&#1&#1&#1&#1&#1&#1}}
  690. {\global\matrixtoks = \expandafter{#1&#1&#1&#1&#1&#1&#1&\mqty{#2}\\#1&#1&#1&#1&#1&#1&\mqty{#3}&#1\\#1&#1&#1&#1&#1&\mqty{#4}&#1&#1\\#1&#1&#1&#1&\mqty{#5}&#1&#1&#1\\#1&#1&#1&\mqty{#6}&#1&#1&#1&#1\\#1&#1&\mqty{#7}&#1&#1&#1&#1&#1\\#1&\mqty{#8}&#1&#1&#1&#1&#1&#1\\\mqty{#9}&#1&#1&#1&#1&#1&#1&#1}}
  691. }
  692. }
  693. }
  694. }
  695. }
  696. }
  697. \the\matrixtoks
  698. }
  699. \DeclareDocumentCommand\admat{}{\antidiagonalmatrix}
  700. % Misc
  701. \DeclareDocumentCommand\flatfrac{ m m }{\left.#1\middle\slash#2\right.}
  702. \DeclareDocumentCommand\homework{}{ % You can try it
  703. \ensuremath{
  704. \div{\vb{E}}=\frac{\rho}{\epsilon_0} \qc
  705. \div{\vb{B}}=0 \qc
  706. \curl{\vb{E}}=-\pdv{\vb{B}}{t}\qc
  707. \curl{\vb{B}}=\mu_0\vb{J}+\frac{1}{c^2}\pdv{\vb{E}}{t}\qc
  708. H\ket{\Psi}=i\hbar\pdv{}{t}\ket{\Psi},
  709. \qq{all else follows.}
  710. }
  711. }