Transcription

The physics packageSergio C. de la [email protected] 12, 2012Contents1 Before you start1.1 The purpose of this package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.2 Other required packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.3 Using physics in your LATEX document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11122 List2.12.22.32.42.52.62.72234556711.1of commandsAutomatic bracing . .Vector notation . . . .Operators . . . . . . .Quick quad text . . .Derivatives . . . . . .Dirac bra-ket notationMatrix macros . . . .Before you startThe purpose of this packageThe goal of this package is to make typesetting equations for physics simpler, faster, and more humanreadable. To that end, the commands included in this package have names that make the purpose of eachcommand immediately obvious and remove any ambiguity while reading and editing physics code. From apractical standpoint, it is handy to have a well-defined set of shortcuts for accessing the long-form of each ofthese commands. The commands listed below are therefore defined in terms of their long-form names andthen shown explicitly in terms of the default shorthand command sequences. These shorthand commandsare meant make it easy to remember both the shorthand names and what each one represents.1.2Other required packagesThe physics package requires xparse and amsmath to work properly in your LATEX document. The amsmathpackage comes standard with most LATEX distributions and is loaded by physics for your convenience. Youmay also already have xparse installed on your system as it is a popular package for defining LATEXmacros,however, if you are unsure you can either install it again using your local package manager (comes with mostdistributions) or by visiting the CTAN online package database, or you could even just try to use physics1

without worrying about it. Many modern LATEXcompilers will locate and offer to download missing packagesfor you.1.3Using physics in your LATEX documentTo use the physics package, simply insert \usepackage{physics} in the preamble of your document, before\begin{document} and after nt}22.1List of commandsAutomatic bracing\quantity\qty(\typical) ( )automatic ( ) braces\qty(\tall) \qty(\grande) \qty[\typical] [ ]\qty \typical \qty{\typical} { }\qty\big{} noautomatic [ ] bracesautomatic bracesautomatic { } bracesmanual sizing (works with any of theabove bracket types)\qty\Big{} \qty\bigg{} ()\qty\Bigg{} \absolutevalue \qty() \qty[] \qty \qty{} a alternative syntax; robust and moreLATEX-friendly\abs\Big{a} ainherits manual sizing syntax from de} \normautomatic sizing; equivalent to \qty a star for no resize\norm{a} kakautomatic sizing\norm\Big{a} amanual sizing\norm*{\grande} kkstar for no resize \evaluated\eval{x} 0 \infty xvertical bar for evaluation limits02

\eval(x 0 \infty alternate formx \eval[x 0 \infty x0 alternate form0 "\eval[\venti 0 \infty automatic sizing0 \order\eval*[\venti 0 \infty \order{x 2} O x2 star for no resize0order symbol; automatic sizing andspace handling \order\Big{x 2} O x2\order*{\grande} O(\commutatormanual sizing)star for no resize\comm{A}{B} [A, B]hi\comm\Big{A}{B} A, Bautomatic sizingmanual sizing\comm*{A}{\grande} [A,\anticommutator\poissonbracket2.2]star for no resize\acomm{A}{B} {A, B}\pb{A}{B} {A, B}same as \poissonbracketsame as \anticommutatorVector notation byThe default del symbol used in physics vector notation can be switched to appear with an arrow including the option arrowdel in the document preamble ivergence\curl\vb{a} a\vb*{a}, \vb*{\theta} a, θ\va{a} a\va*{a}, \va*{\theta} a, θ\vu{a} â\vu*{a}, \vu*{\theta} â, θ̂\vdot · as in a · b\cross as in a b\cp as in a b\grad \grad{\Psi} Ψ upright/no Greekitalic/Greekupright/no Greekitalic/Greekupright/no Greekitalic/Greeknote: \dp is a protected TEX primitivealternate nameshorthand namedefault mode\grad(\Psi \tall) Ψ h\grad[\Psi \tall] Ψ \div ·i\div{\vb{a}} · a \div(\vb{a} \tall) · a h\div[\vb{a} \tall] · a \curl \curl{\vb{a}} a \curl(\vb{a} \tall) a 3long-form (like \qty but also handlesspacing)note: amsmath symbol renamed\divisionsymboldefault mode long-formidefault mode long-form

hi\curl[\vb{a} \tall] a \laplacian 2\laplacian{\Psi} 2 Ψ \laplacian(\Psi \tall) 2 Ψ hi\laplacian[\Psi \tall] 2 Ψ \laplacian2.3default modelong-formOperatorsThe standard set of trig functions is redefined in physics to provide automatic braces that behave like\qty(). In addition, an optional power argument is provided. This behavior can be switched off by includingthe option notrig in the preamble \usepackage[notrig]{physics}.Example trig redefinitions:\sin \sin(\grande) sin automatic braces; old \sin renamed \sine2\sin[2](x) sin (x)\sin x sin xoptional powercan still use without an argumentThe full set of available trig functions in physics ) x)atan(x)acsc(x)asec(x)acot(x)The standard trig functions (plus a few that are missing in amsmath) are available without any automaticbracing under a new set of longer osecant\arcsecant\arccotangentSimilar behavior has also been extended to the \exp(\tall) exp \log(\tall) log \ln(\tall)ln old definitions \det(\tall) det \Pr(\tall)PrNew operators:\trace or \tr\Trace or gent\acosecant\asecant\acotangentfollowing determinant\Probability\tr\rho tr ρ also \tr(\tall) tr\Tr\rho Tr ρ\rank M rank M\erf(x) erf(x)\Res[f(z)] Res[f (z)]R\pv{\int f(z) \dd{z}} P fR(z) dz\PV{\int f(z) \dd{z}} P.V. f (z) dz4 trace; same bracing as trig functionsalternatematrix rankGauss error functionresidue; same bracing as trig functionsCauchy principal valuealternate

\Re{z} Re{z}\Im{z} Im{z}\Re\Im2.4old \Re renamed to \real old \Im renamed to \imaginary Quick quad textThis set of commands produces text in math-mode padded by \quad spacing on either side. This is meantto provide a quick way to insert simple words or phrases in a sequence of equations. Each of the followingcommands includes a starred version which pads the text only on the right side with \quad for use in alignedenvironments such as cases.General text:\qqtext\qq{}\qq{word or phrase} word or phrase\qq*{word or phrase} word or phraseSpecial macros:\qcomma or \qc ,\qcc c.c.\qif ifgeneral quick quad text with argumentnormal mode; left and right \quadstarred mode; right \quad onlyright \quad onlycomplex conjugate; left and right \quad unless starred \qcc* c.c.left and right \quad unless starred \qif* ifSimilar to \qif:\qthen, \qelse, \qotherwise, \qunless, \qgiven, \qusing, \qassume, \qsince,\qlet, \qfor, \qall, \qeven, \qodd, \qinteger, \qand, \qor, \qas, \qin2.5DerivativesThe default differential symbol d which is used in \differential and \derivative can be switched to anitalic form d by including the option italicdiff in the preamble ivative\partialderivative\dd d\dd x dx\dd{x} dx\dd[3]{x} d3 x\dd(\cos\theta) d(cos θ)d\dv{x} dxdf\dv{f}{x} dx nd f\dv[n]{f}{x} dxn d\dv{x}(\grande) dx\dv*{f}{x} df /dx \pderivative{x} x \pdv{x} x f\pdv{f}{x} x n f\pdv[n]{f}{x} xn5no spacing (not recommended)automatic spacing based on neighborsoptional powerlong-form; automatic bracesone argumenttwo argumentsoptional powerlong-form; automatic braces, spacinginline form using \flatfracalternate nameshorthand nametwo argumentsoptional power

x 2f\pdv{f}{x}{y} x y\pdv*{f}{x} f / x\var{F[g(x)]} δF [g(x)]\var(E-TS) δ(E T S)δ\fdv{g} δgδF\fdv{F}{g} δgδ\fdv{V}(E-TS) (E T S)δV\fdv*{F}{x} δF /δx\pdv{x}(\grande) \variation\functionalderivative2.6long-formmixed partialinline form using \flatfracfunctional variation (works like \dd)long-formfunctional derivative (works like \dv)long-forminline form using \flatfracDirac bra-ket notationThe following collection of macros for Dirac notation contains two fundamental commands, \bra and \ket,along with a set of more specialized macros which are essentially combinations of the fundamental pair. Thespecialized macros are both useful and descriptive from the perspective of generating physics code, however,the fundamental commands are designed to contract with one another algebraically when appropriate andare thus suggested for general use. For instance, the following code renders correctly1\bra{\phi}\ket{\psi} hφ ψias opposed tohφ ψiwhereas a similar construction with higher-level macros will not contract in a robust manner\bra{\phi}\dyad{\psi}{\xi} hφ ψihξ .On the other hand, the correct output can be generated by sticking to the fundamental commands,\bra{\phi}\ket{\psi}\bra{\xi} hφ ψi hξ allowing the user to type out complicated quantum mechanical expressions without worrying about bra-ketcontractions. That being said, the high-level macros do have a place in convenience and readability, as longas the user is aware of rendering issues that may arise due to an absence of automatic contractions.E\ket\ket{\tall} automatic sizing\bra\innerproduct\ket*{\tall} D ino resize\bra{\tall} automatic sizing\bra*{\tall} h \bra{\phi}\ket{\psi} hφ ψiDE\bra{\phi}\ket{\tall} φno resizeautomatic contraction\bra{\phi}\ket*{\tall} hφ i\bra*{\phi}\ket{\tall} hφ i\bra*{\phi}\ket*{\tall} hφ i\braket{a}{b} ha bi\braket{a} ha aia star on either term in the contractionprohibits resizingcontraction inherits automatic sizingtwo-argument braketone-argument (norm)1 Note the lack of a space between the bra and ket commands. This is necessary is order for the bra to find the correspondingket and form a contraction.6

D\braket{a}{\tall} a\outerproduct\expectationvalueE\braket*{a}{\tall} ha \ip{a}{b} ha bi\dyad{a}{b} aihb \dyad{a} aiha EDautomatic sizingino resizeshorthand nametwo-argument dyadone-argument (projector)\dyad{a}{\tall} aautomatic sizing\dyad*{a}{\tall} aih \ketbra{a}{b} aihb \op{a}{b} aihb \expval{A} hAi\expval{A}{\Psi} hΨ A Ψi\ev{A}{\Psi} hΨ A Ψino resizealternative nameshorthand nameimplicit formexplicit formshorthand name\ev{\grande}{\Psi} hΨ Ψi\ev*{\grande}{\tall} h \ev**{\grande}{\Psi} Ψ\matrixelementdefault sizing ignores middle argument iΨdouble star resizes based on all parts\matrixel{n}{A}{m} hn A mi\mel{n}{A}{m} hn A mirequires all three argumentsshorthand name\mel{n}{\grande}{m} hn default sizing ignores middle argument mi\mel*{n}{\grande}{\tall} hn i\mel**{n}{\grande}{m} nm2.7single star does no resizing whatsoeversingle star does no resizing whatsoeverdouble star resizes based on all partsMatrix macrosThe following matrix macros produce unformatted rows and columns of matrix elements for use as separatematrices as well as blocks within larger matrices. For example, the command \identitymatrix{2} whichhas also has the shortcut \imat{2} produces the elements of a 2 2 identity matrix 10 01 without braces orgrouping. This allows the command to also be used within another matrix, as in: \begin{pmatrix}1 0 0 1 \imat{2} \\ a & b \end{pmatrix}a bTo specify elements on the right of left sides of our \imat{2} sub-matrix we use the grouping command\matrixquantity or \mqty to effectively convert \imat{2} into a single matrix element of a larger matrix: \begin{pmatrix}1 0 a 0 1 b \mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e \end{pmatrix}c d eThe extra \mqty groups were required in this case in order to get the a and b elements to behave as a singleelement, since \mqty{\imat{2}} also acts like a single matrix element (the same can be said of the groupedc and d elements). Finally, the outermost pmatrix environment could have also been replaced with thephysics macro \mqty(), allowing the above example to be written on one line: 1 0 a 0 1 b \mqty(\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e) c d e7

ant\identitymatrixa bc d a b\mqty(a & b \\ c & d) c d a b \mqty*(a & b \\ c & d) c da b\mqty[a & b \\ c & d] c da b\mqty a & b \\ c & d c d\pmqty{} \mqty()\Pmqty{} \mqty*()\bmqty{} \mqty[]\vmqty{} \mqty \smqty{a & b \\ c & d} ac db\smqty() or \spmqty{}\smqty*() or \sPmqty{}\smqty[] or \sbmqty{}\smqty or \svmqty{}a b\mdet{a & b \\ c & d} c d\smdet{a & b \\ c & d} ac db\imat{n} \mqty{a & b \\ c & d} groups a set of matrix elements into asingle objectparenthesesalternate parenthesessquare bracketsvertical barsalternative syntax; robust and moreLATEX-friendlythe smallmatrix form of \mqtysmall version of \mqty()small version of \mqty*()small version of \mqty[]small version of \mqty matrix determinantsmall matrix determinantelements of n n identity matrix100\xmatrix\smqty(\imat{3}) 0 1 0001\xmat{x}{n}{m}1 1 1)\smqty(\xmat{1}{2}{3}) ( 111\smqty(\xmat*{a}{3}{3}) lmatrixa11 a12 a13a21 a22 a23 aa31 a32 a331a2a3( a1 a2 a3 )\smqty(\xmat*{a}{3}{1}) \smqty(\xmat*{a}{1}{3}) \zmat{n}{m}\smqty(\zmat{2}{2}) ( 00 00 )\pmat{n}\smqty(\pmat{0}) ( 10 01 )\smqty(\pmat{1}) ( 01 10 ) \smqty(\pmat{2}) 0i i0 0\smqty(\pmat{3}) 10 1\dmat{a,b,c,.} 1\mqty(\dmat{1,2,3}) 2formatted with \mqty or \smqtyelements of n m matrix filled with xformatted with \mqty or \smqty as a vector with indicesn m matrix filled with zerosequivalent to \xmat{0}{n}{m}nth Pauli matrixn {0, 1, 2, 3 or x, y, z} 3 1 0\mqty(\dmat[0]{1,2}) 20 12 3 \mqty(\dmat{1,2&3\\4&5}) 4 5\admat{a,b,c,.} 1 \mqty(\admat{1,2,3}) 238star for element indicesspecify up to eight diagonal or block diagonal elementsoptional argument to fill spacesenter matrix elements for each block asa single diagonal elementsame as syntax as \dmat