diff options
Diffstat (limited to 'Master')
-rw-r--r-- | Master/texmf-dist/doc/latex/physics/README | 26 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/physics/physics.pdf | bin | 220722 -> 249731 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/physics/physics.tex | 315 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/physics/physics.sty | 680 |
4 files changed, 813 insertions, 208 deletions
diff --git a/Master/texmf-dist/doc/latex/physics/README b/Master/texmf-dist/doc/latex/physics/README index 8e4725a840e..a4a44bcdb78 100644 --- a/Master/texmf-dist/doc/latex/physics/README +++ b/Master/texmf-dist/doc/latex/physics/README @@ -1,21 +1,25 @@ README for physics.sty -physics 1.20 +physics 1.3 Created by Sergio C. de la Barrera -Updated October 31, 2012 +Updated December 12, 2012 -E-mail comments and suggestions to: -physics.tex@gmail.com +E-mail comments and suggestions to: physics.tex@gmail.com This material is subject to the LaTeX Project Public License. -See http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html for the details of that license. +See http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html for +the details of that license. -This packages defines simple, yet flexible macros for typesetting equations in the languages of vector calculus and linear algebra via Dirac notation. The goal of this package is to make typesetting equations for physics simpler, faster, and more human-readable. To that end, the commands included in this package have names that make the purpose of each command immediately obvious and remove any ambiguity while reading and editing code for physics equations. From a practical standpoint, it is handy to have a well-dened set of shortcuts for accessing the long-form of each of these commands. The commands included in this package therefore possess both long-form names and shorthand names that are meant make it easy to remember both the shorthand names and what each one represents. - -This packages defines macros for: +This packages defines simple, yet flexible macros for typesetting equations via: *Automatic bracing *Vector notation -*Operators -*Quick quad text *Derivatives -*Dirac bra-ket notation
\ No newline at end of file +*Dirac bra-ket notation +*Matrix macros +*Additional trig functions and other convenient operators +*Flat fractions and other useful miscellaneous math macros + +The goal of this package is to make typesetting equations for physics simpler, +faster, and more human-readable. To that end, the commands included in this package +have names that make the purpose of each command immediately obvious and remove any +ambiguity while reading and editing code for physics equations.
\ No newline at end of file diff --git a/Master/texmf-dist/doc/latex/physics/physics.pdf b/Master/texmf-dist/doc/latex/physics/physics.pdf Binary files differindex 8e8061b9e0a..132aeaa78a2 100644 --- a/Master/texmf-dist/doc/latex/physics/physics.pdf +++ b/Master/texmf-dist/doc/latex/physics/physics.pdf diff --git a/Master/texmf-dist/doc/latex/physics/physics.tex b/Master/texmf-dist/doc/latex/physics/physics.tex index 5a634b1ee95..34081efbc5e 100644 --- a/Master/texmf-dist/doc/latex/physics/physics.tex +++ b/Master/texmf-dist/doc/latex/physics/physics.tex @@ -2,19 +2,39 @@ \usepackage{fullpage} \usepackage{parskip} \usepackage{physics} +\usepackage{amssymb} +\usepackage{xcolor} \usepackage[colorlinks,urlcolor=blue]{hyperref} \usepackage{array} \usepackage{longtable} \usepackage{multirow} -\newcommand\Vtextvisiblespace[1][.3em]{% +\newcolumntype{M}{>{$\displaystyle}c<{$}} +\newcolumntype{L}{>{$\displaystyle}l<{$}} + +\newcommand\Vtextvisiblespace[1][.3em] +{% \mbox{\kern.06em\vrule height.3ex}% \vbox{\hrule width#1}% - \hbox{\vrule height.3ex}} + \hbox{\vrule height.3ex} +} + +\newcommand{\cbox}[2][cyan] +{\mathchoice + {\setlength{\fboxsep}{0pt}\colorbox{#1}{$\displaystyle#2$}} + {\setlength{\fboxsep}{0pt}\colorbox{#1}{$\textstyle#2$}} + {\setlength{\fboxsep}{0pt}\colorbox{#1}{$\scriptstyle#2$}} + {\setlength{\fboxsep}{0pt}\colorbox{#1}{$\scriptscriptstyle#2$}} +} + +\newcommand{\typical}{\cbox{\phantom{A}}} +\newcommand{\tall}{\cbox{\phantom{A^{\vphantom{x^x}}_x}}} +\newcommand{\grande}{\cbox{\phantom{\frac{1}{xx}}}} +\newcommand{\venti}{\cbox{\phantom{\sum_x^x}}} -% physics 1.20 +% physics 1.30 \title{The \texttt{physics} package} -\author{Sergio C. de la Barrera} +\author{Sergio C. de la Barrera \\ \texttt{physics.tex@gmail.com}} \begin{document} \maketitle @@ -42,29 +62,44 @@ To use the \texttt{physics} package, simply insert \verb|\usepackage{physics}| i \section{List of commands} \subsection{Automatic bracing} \begin{longtable}[l]{ l l p{6cm} } -\verb|\quantity| & \verb|\qty(a+b)| $\rightarrow \qty(a+b)$ & automatic $\qty(\;)$ braces \\ -& \verb|\qty[a+b]| $\rightarrow \qty[a+b]$ & automatic $\qty[\;]$ braces \\ -& \verb|\qty| \!\!\texttt{|}\!\! \verb|a+b| \!\!\texttt{|} $\rightarrow \qty|a+b|$ & automatic $\qty|\;|$ braces \\ -& \verb|\qty{a+b}| $\rightarrow \qty{a+b}$ & automatic $\qty{\;}$ braces \\ +\verb|\quantity| & \verb|\qty(\typical)| $\displaystyle\rightarrow \qty(\typical)$ & automatic $\qty(\;)$ braces \\ +& \verb|\qty(\tall)| $\displaystyle\rightarrow \qty(\tall)$ & \\ +& \verb|\qty(\grande)| $\displaystyle\rightarrow \qty(\grande)$ & \\ +& \verb|\qty[\typical]| $\rightarrow \qty[\typical]$ & automatic $\qty[\;]$ braces \\ +& \verb+\qty|\typical|+ $\rightarrow \qty|\typical|$ & automatic $\qty|\;|$ braces \\ +& \verb|\qty{\typical}| $\rightarrow \qty{\typical}$ & automatic $\qty{\;}$ braces \\ & \verb|\qty\big{}| $\rightarrow \qty\big{}$ & \multirow{2}{*}{\parbox{6cm}{manual sizing (works with any of the above bracket types)}} \\ & \verb|\qty\Big{}| $\rightarrow \qty\Big{}$ & \\ & \verb|\qty\bigg{}| $\rightarrow \qty\bigg{}$ & \\ & \verb|\qty\Bigg{}| $\rightarrow \qty\Bigg{}$ & \\ +& \verb|\pqty{}| $\leftrightarrow$ \verb|\qty()| & \multirow{2}{*}{\parbox{6cm}{alternative syntax; robust and more \LaTeX-friendly}} \\ +& \verb|\bqty{}| $\leftrightarrow$ \verb|\qty[]| & \\ +& \verb+\vqty{}+ $\leftrightarrow$ \verb+\qty||+ & \\ +& \verb|\Bqty{}| $\leftrightarrow$ \verb|\qty{}| & \\ \verb|\absolutevalue| & \verb|\abs{a}| $\rightarrow \abs{a}$ & automatic sizing; equivalent to \verb|\qty| \!\!\texttt{|a|} \\ & \verb|\abs\Big{a}| $\rightarrow \abs\Big{a}$ & inherits manual sizing syntax from \verb|\qty| \\ +& \verb|\abs*{\grande}| $\displaystyle\rightarrow \abs*{\grande}$ & star for no resize \\ \verb|\norm| & \verb|\norm{a}| $\rightarrow \norm{a}$ & automatic sizing \\ & \verb|\norm\Big{a}| $\rightarrow \norm\Big{a}$ & manual sizing \\ -\verb|\evaluated| & \verb|\eval{x}_0^\infty| $\displaystyle\rightarrow \eval{x}_0^\infty$ & automatic right vertical bar for evaluation limits \\ -& \verb|\eval(x)_y| $\displaystyle\rightarrow \eval(x)_y$ & parenthetical form for holding values constant \\ +& \verb|\norm*{\grande}| $\displaystyle\rightarrow \norm*{\grande}$ & star for no resize \\ +\verb|\evaluated| & \verb|\eval{x}_0^\infty| $\displaystyle\rightarrow \eval{x}_0^\infty$ & vertical bar for evaluation limits \\ +& \verb|\eval(x| \!\!\texttt{|}\!\! \verb|_0^\infty| $\displaystyle\rightarrow \eval(x|_0^\infty$ & alternate form \\ +& \verb|\eval[x| \!\!\texttt{|}\!\! \verb|_0^\infty| $\displaystyle\rightarrow \eval[x|_0^\infty$ & alternate form \\ +& \verb|\eval[\venti| \!\!\texttt{|}\!\! \verb|_0^\infty| $\displaystyle\rightarrow \eval[\venti|_0^\infty$ & automatic sizing\\ +& \verb|\eval*[\venti| \!\!\texttt{|}\!\! \verb|_0^\infty| $\displaystyle\rightarrow \eval*[\venti|_0^\infty$ & star for no resize \\ \verb|\order| & \verb|\order{x^2}| $\rightarrow \order{x^2}$ & order symbol; automatic sizing and space handling \\ & \verb|\order\Big{x^2}| $\rightarrow \order\Big{x^2}$ & manual sizing \\ +& \verb|\order*{\grande}| $\displaystyle\rightarrow \order*{\grande}$ & star for no resize \\ \verb|\commutator| & \verb|\comm{A}{B}| $\rightarrow \comm{A}{B}$ & automatic sizing \\ +& \verb|\comm\Big{A}{B}| $\rightarrow \comm\Big{A}{B}$ & manual sizing \\ +& \verb|\comm*{A}{\grande}| $\displaystyle\rightarrow \comm*{A}{\grande}$ & star for no resize \\ \verb|\anticommutator| & \verb|\acomm{A}{B}| $\rightarrow \acomm{A}{B}$ & same as \verb|\poissonbracket| \\ -& \verb|\acommutator{A}{B}| $\rightarrow \acommutator{A}{B}$ & alternate name \\ +%& \verb|\acommutator{A}{B}| $\rightarrow \acommutator{A}{B}$ & alternate name \\ \verb|\poissonbracket| & \verb|\pb{A}{B}| $\rightarrow \pb{A}{B}$ & same as \verb|\anticommutator| \end{longtable} \subsection{Vector notation} +The default del symbol $\vnabla$ used in \texttt{physics} vector notation can be switched to appear with an arrow $\vec{\vnabla}$ by including the option \texttt{arrowdel} in the document preamble $\rightarrow$ \verb|\usepackage[arrowdel]{physics}|. \begin{longtable}[l]{ l l p{6cm} } \verb|\vectorbold| & \verb|\vb{a}| $\rightarrow \vb{a}$ & upright/no Greek \\ & \verb|\vb*{a}|, \verb|\vb*{\theta}| $\rightarrow \vb*{a}$, $\vb*{\theta}$ & italic/Greek \\ @@ -72,56 +107,105 @@ To use the \texttt{physics} package, simply insert \verb|\usepackage{physics}| i & \verb|\va*{a}|, \verb|\va*{\theta}| $\rightarrow \va*{a}$, $\va*{\theta}$ & italic/Greek \\ \verb|\vectorunit| & \verb|\vu{a}| $\rightarrow \vu{a}$ & upright/no Greek \\ & \verb|\vu*{a}|, \verb|\vu*{\theta}| $\rightarrow \vu*{a}$, $\vu*{\theta}$ & italic/Greek \\ -\verb|\dotproduct| & \verb|\vdot| $\rightarrow \vdot$ as in $\vb{a} \vdot \vb{b}$ & note that \verb|\dp| is a protected \TeX\ primitive \\ -\verb|\crossproduct| & \verb|\cross| $\rightarrow \cross$ as in $\vb{a} \cross \vb{b}$ & \\ -& \verb|\cp| $\rightarrow \cp$ as in $\vb{a} \cp \vb{b}$ & alternate name \\ -\verb|\vnabla| & \verb|\vnabla| $\rightarrow \vnabla$ versus $\nabla$ & low-level macro for bold version \\ +\verb|\dotproduct| & \verb|\vdot| $\rightarrow \vdot$ as in $\vb{a} \vdot \vb{b}$ & note: \verb|\dp| is a protected \TeX\ primitive \\ +\verb|\crossproduct| & \verb|\cross| $\rightarrow \cross$ as in $\vb{a} \cross \vb{b}$ & alternate name \\ +& \verb|\cp| $\rightarrow \cp$ as in $\vb{a} \cp \vb{b}$ & shorthand name \\ \verb|\gradient| & \verb|\grad| $\rightarrow \grad$ & \\ & \verb|\grad{\Psi}| $\rightarrow \grad{\Psi}$ & default mode \\ -& \verb|\grad(\Psi+\Phi)| $\rightarrow \grad(\Psi+\Phi)$ & long-form (like \verb|\qty| but also handles spacing) \\ -& \verb|\grad[\Psi+\Phi]| $\rightarrow \grad[\Psi+\Phi]$ & \\ -\verb|\divergence| & \verb|\div| $\rightarrow \div$ & note \texttt{amsmath} symbol $\divisionsymbol$ renamed \verb|\divisionsymbol| \\ +& \verb|\grad(\Psi+\tall)| $\displaystyle\rightarrow \grad(\Psi+\tall)$ & long-form (like \verb|\qty| but also handles spacing) \\ +& \verb|\grad[\Psi+\tall]| $\displaystyle\rightarrow \grad[\Psi+\tall]$ & \\ +\verb|\divergence| & \verb|\div| $\rightarrow \div$ & note: \texttt{amsmath} symbol $\divisionsymbol$ renamed \verb|\divisionsymbol| \\ & \verb|\div{\vb{a}}| $\rightarrow \div{\vb{a}}$ & default mode \\ -& \verb|\div(\vb{a}+\vb{b})| $\rightarrow \div(\vb{a}+\vb{b})$ & long-form \\ -& \verb|\div[\vb{a}+\vb{b}]| $\rightarrow \div[\vb{a}+\vb{b}]$ & \\ +& \verb|\div(\vb{a}+\tall)| $\displaystyle\rightarrow \div(\vb{a}+\tall)$ & long-form \\ +& \verb|\div[\vb{a}+\tall]| $\displaystyle\rightarrow \div[\vb{a}+\tall]$ & \\ \verb|\curl| & \verb|\curl| $\rightarrow \curl$ & \\ & \verb|\curl{\vb{a}}| $\rightarrow \curl{\vb{a}}$ & default mode \\ -& \verb|\curl(\vb{a}+\vb{b}})| $\rightarrow \curl(\vb{a}+\vb{b})$ & long-form \\ -& \verb|\curl[\vb{a}+\vb{b}]| $\rightarrow \curl[\vb{a}+\vb{b}]$ & \\ +& \verb|\curl(\vb{a}+\tall)| $\displaystyle\rightarrow \curl(\vb{a}+\tall)$ & long-form \\ +& \verb|\curl[\vb{a}+\tall]| $\displaystyle\rightarrow \curl[\vb{a}+\tall]$ & \\ \verb|\laplacian| & \verb|\laplacian| $\rightarrow \laplacian$ & \\ & \verb|\laplacian{\Psi}| $\rightarrow \laplacian{\Psi}$ & default mode \\ -& \verb|\laplacian(\Psi+\Phi)| $\rightarrow \laplacian(\Psi+\Phi)$ & long-form \\ -& \verb|\laplacian[\Psi+\Phi]| $\rightarrow \laplacian[\Psi+\Phi]$ & +& \verb|\laplacian(\Psi+\tall)| $\displaystyle\rightarrow \laplacian(\Psi+\tall)$ & long-form \\ +& \verb|\laplacian[\Psi+\tall]| $\displaystyle\rightarrow \laplacian[\Psi+\tall]$ & \end{longtable} \subsection{Operators} -The standard set of trig functions is redefined in \texttt{physics} to provide automatic braces that behave like \verb|\qty()|. In addition, an optional power argument is provided. The old definition of each trig function is stored in a long form version as in \verb|\sin| $\rightarrow$ \verb|\sine|, \verb|\cos| $\rightarrow$ \verb|\cosine|, and so on. -\begin{longtable}[l]{ l l p{8cm} } -\multicolumn{3}{l}{Trig redefinitions:} \\ -\verb|\sin| & \verb|\sin(x)| $\rightarrow \sin(x)$ & automatic braces; old \verb|\sin| renamed \verb|\sine| \\ +The standard set of trig functions is redefined in \texttt{physics} to provide automatic braces that behave like \verb|\qty()|. In addition, an optional power argument is provided. This behavior can be switched off by including the option \texttt{notrig} in the preamble $\rightarrow$ \verb|\usepackage[notrig]{physics}|. + +\begin{tabular}[l]{ l l p{8cm} } +\multicolumn{3}{l}{Example trig redefinitions:} \\ +\verb|\sin| & \verb|\sin(\grande)| $\displaystyle\rightarrow \sin(\grande)$ & automatic braces; old \verb|\sin| renamed \verb|\sine| \\ & \verb|\sin[2](x)| $\rightarrow \sin[2](x)$ & optional power \\ -\verb|\cos| & \verb|\cos(x)| $\rightarrow \cos(x)$ & works with all trig functions \\ -\verb|\tan| & \verb|\tan x| $\rightarrow \tan x$ & can still use without an argument \\ -$\quad\vdots$ & & $\qquad\vdots$ \\ +& \verb|\sin x| $\rightarrow \sin x$ & can still use without an argument +\end{tabular} + +The full set of available trig functions in \texttt{physics} includes: + +\begin{tabular}{llll} +\verb|\sin(x)| & \verb|\sinh(x)| & \verb|\arcsin(x)| & \verb|\asin(x)| \\ +\verb|\cos(x)| & \verb|\cosh(x)| & \verb|\arccos(x)| & \verb|\acos(x)| \\ +\verb|\tan(x)| & \verb|\tanh(x)| & \verb|\arctan(x)| & \verb|\atan(x)| \\ +\verb|\csc(x)| & \verb|\csch(x)| & \verb|\arccsc(x)| & \verb|\acsc(x)| \\ +\verb|\sec(x)| & \verb|\sech(x)| & \verb|\arcsec(x)| & \verb|\asec(x)| \\ +\verb|\cot(x)| & \verb|\coth(x)| & \verb|\arccot(x)| & \verb|\acot(x)| +\end{tabular}$\Rightarrow$ +\begin{tabular}{MMMM} +\sin(x) & \sinh(x) & \arcsin(x) & \asin(x) \\ +\cos(x) & \cosh(x) & \arccos(x) & \acos(x) \\ +\tan(x) & \tanh(x) & \arctan(x) & \atan(x) \\ +\csc(x) & \csch(x) & \arccsc(x) & \acsc(x) \\ +\sec(x) & \sech(x) & \arcsec(x) & \asec(x) \\ +\cot(x) & \coth(x) & \arccot(x) & \acot(x) +\end{tabular} + +The standard trig functions (plus a few that are missing in \texttt{amsmath}) are available without any automatic bracing under a new set of longer names: + +\begin{tabular}{llll} +\verb|\sine| & \verb|\hypsine| & \verb|\arcsine| & \verb|\asine| \\ +\verb|\cosine| & \verb|\hypcosine| & \verb|\arccosine| & \verb|\acosine| \\ +\verb|\tangent| & \verb|\hyptangent| & \verb|\arctangent| & \verb|\atangent| \\ +\verb|\cosecant| & \verb|\hypcosecant| & \verb|\arccosecant| & \verb|\acosecant| \\ +\verb|\secant| & \verb|\hypsecant| & \verb|\arcsecant| & \verb|\asecant| \\ +\verb|\cotangent| & \verb|\hypcotangent| & \verb|\arccotangent| & \verb|\acotangent| +\end{tabular} + +Similar behavior has also been extended to the following functions: + +\begin{tabular}{l>{$}l<{$}ll} +\verb|\exp(\tall)| & \exp(\tall) & & \verb|\exponential| \\ +\verb|\log(\tall)| & \log(\tall) & & \verb|\logarithm| \\ +\verb|\ln(\tall)| & \ln(\tall) & old definitions $\Rightarrow$ & \verb|\naturallogarithm| \\ +\verb|\det(\tall)| & \det(\tall) & & \verb|\determinant| \\ +\verb|\Pr(\tall)| & \Pr(\tall) & & \verb|\Probability| +\end{tabular} + +\begin{longtable}[l]{ l l p{8cm} } \multicolumn{3}{l}{New operators:} \\ -\verb|\tr| & \verb|\tr\rho| $\rightarrow \tr\rho$ & trace \\ +\verb|\trace| or \verb|\tr| & \verb|\tr\rho| $\rightarrow \tr\rho$ also \verb|\tr(\tall)| $\rightarrow \tr(\tall)$ & trace; same bracing as trig functions \\ +\verb|\Trace| or \verb|\Tr| & \verb|\Tr\rho| $\rightarrow \Tr\rho$ & alternate \\ \verb|\rank| & \verb|\rank M| $\rightarrow \rank M$ & matrix rank \\ -\verb|\erf| & \verb|\erf(x)|$\rightarrow \erf(x)$ & Gauss error function +\verb|\erf| & \verb|\erf(x)|$\rightarrow \erf(x)$ & Gauss error function \\ +\verb|\Res| & \verb|\Res[f(z)]|$\rightarrow \Res[f(z)]$ & residue; same bracing as trig functions \\ +\verb|\principalvalue| & \verb|\pv{\int f(z) \dd{z}}|$\rightarrow \pv{\int f(z) \dd{z}}$ & Cauchy principal value \\ +& \verb|\PV{\int f(z) \dd{z}}|$\rightarrow \PV{\int f(z) \dd{z}}$ & alternate \\ +\verb|\Re| & \verb|\Re{z}| $\rightarrow \Re{z}$ & old \verb|\Re| renamed to \verb|\real| $\rightarrow \real$ \\ +\verb|\Im| & \verb|\Im{z}| $\rightarrow \Im{z}$ & old \verb|\Im| renamed to \verb|\imaginary| $\rightarrow \imaginary$ \end{longtable} \subsection{Quick quad text} This set of commands produces text in math-mode padded by \verb|\quad| spacing on either side. This is meant to provide a quick way to insert simple words or phrases in a sequence of equations. Each of the following commands includes a starred version which pads the text only on the right side with \verb|\quad| for use in aligned environments such as \texttt{cases}. -\begin{longtable}[l]{ l l p{6cm} } + +\begin{tabular}[l]{ l l p{6cm} } General text: & & \\ \verb|\qqtext| & \verb|\qq{}| & general quick quad text with argument \\ & \verb|\qq{word or phrase}| $\rightarrow$\Vtextvisiblespace[1em]$\text{word or phrase}$\Vtextvisiblespace[1em] & normal mode; left and right \verb|\quad| \\ & \verb|\qq*{word or phrase}| $\rightarrow \text{word or phrase}$\Vtextvisiblespace[1em] & starred mode; right \verb|\quad| only -\end{longtable} +\end{tabular} + \begin{longtable}[l]{ l l } Special macros: & \\ \verb|\qcomma| or \verb|\qc| $\rightarrow ,$\Vtextvisiblespace[1em] & right \verb|\quad| only \\ \verb|\qcc| $\rightarrow$\Vtextvisiblespace[1em]$\text{c.c.}$\Vtextvisiblespace[1em] & complex conjugate; left and right \verb|\quad| unless starred \verb|\qcc*| $\rightarrow \text{c.c.}$\Vtextvisiblespace[1em] \\ -\verb|\qif| $\rightarrow$\Vtextvisiblespace[1em]$\text{if}$\Vtextvisiblespace[1em] & left and right \verb|\quad| unless starred \verb|\qif*| $\rightarrow \text{if}$\Vtextvisiblespace[1em] \\ +\verb|\qif| $\rightarrow$\Vtextvisiblespace[1em]$\text{if}$\Vtextvisiblespace[1em] & left and right \verb|\quad| unless starred \verb|\qif*| $\rightarrow \text{if}$\Vtextvisiblespace[1em] \end{longtable} \begin{longtable}[l]{ l } Similar to \verb|\qif|: \\ @@ -130,27 +214,31 @@ Similar to \verb|\qif|: \\ \end{longtable} \subsection{Derivatives} +The default differential symbol $\dd$ which is used in \verb|\differential| and \verb|\derivative| can be switched to an italic form $d$ by including the option \texttt{italicdiff} in the preamble $\rightarrow$ \verb|\usepackage[italicdiff]{physics}|. \begin{longtable}[l]{ l l p{6cm} } \verb|\differential| & \verb|\dd| $\rightarrow \dd$ & \\ -& \verb|\dd x| $\rightarrow \dd x$ & no spacing; use in braces, fractions \\ -& \verb|\dd{x}| $\rightarrow \dd{x}$\!\textvisiblespace & proper spacing for typical equations \\ -& \verb|\dd[3]{x}| $\rightarrow \dd[3]{x}$\!\textvisiblespace & optional power \\ +& \verb|\dd x| $\rightarrow \dd x$ & no spacing (not recommended) \\ +& \verb|\dd{x}| $\rightarrow$ \textvisiblespace\,$\dd{x}$\textvisiblespace & automatic spacing based on neighbors \\ +& \verb|\dd[3]{x}| $\rightarrow \dd[3]{x}$ & optional power \\ & \verb|\dd(\cos\theta)| $\rightarrow \dd(\cos\theta)$ & long-form; automatic braces \\ \verb|\derivative| & \verb|\dv{x}| $\displaystyle\rightarrow \dv{x}$ & one argument \\ & \verb|\dv{f}{x}| $\displaystyle\rightarrow \dv{f}{x}$ & two arguments \\ & \verb|\dv[n]{f}{x}| $\displaystyle\rightarrow \dv[n]{f}{x}$ & optional power \\ -& \verb|\dv{x}(x^2+x)| $\displaystyle\rightarrow \dv{x}(x^2+x)$ & long-form; automatic braces, spacing \\ +& \verb|\dv{x}(\grande)| $\displaystyle\rightarrow \dv{x}(\grande)$ & long-form; automatic braces, spacing \\ +& \verb|\dv*{f}{x}| $\displaystyle\rightarrow \dv*{f}{x}$ & inline form using \verb|\flatfrac| \\ \verb|\partialderivative| & \verb|\pderivative{x}| $\displaystyle\rightarrow \pderivative{x}$ & alternate name \\ & \verb|\pdv{x}| $\displaystyle\rightarrow \pdv{x}$ & shorthand name \\ & \verb|\pdv{f}{x}| $\displaystyle\rightarrow \pdv{f}{x}$ & two arguments \\ & \verb|\pdv[n]{f}{x}| $\displaystyle\rightarrow \pdv[n]{f}{x}$ & optional power \\ -& \verb|\pdv{x}(x+y)| $\displaystyle\rightarrow \pdv{x}(x+y)$ & long-form \\ +& \verb|\pdv{x}(\grande)| $\displaystyle\rightarrow \pdv{x}(\grande)$ & long-form \\ & \verb|\pdv{f}{x}{y}| $\displaystyle\rightarrow \pdv{f}{x}{y}$ & mixed partial \\ +& \verb|\pdv*{f}{x}| $\displaystyle\rightarrow \pdv*{f}{x}$ & inline form using \verb|\flatfrac| \\ \verb|\variation| & \verb|\var{F[g(x)]}| $\rightarrow \var{F[g(x)]}$ & functional variation (works like \verb|\dd|) \\ & \verb|\var(E-TS)| $\rightarrow \var(E-TS)$ & long-form \\ \verb|\functionalderivative| & \verb|\fdv{g}| $\displaystyle\rightarrow \fdv{g}$ & functional derivative (works like \verb|\dv|) \\ & \verb|\fdv{F}{g}| $\displaystyle\rightarrow \fdv{F}{g}$ & \\ -& \verb|\fdv{V}(E-TS)| $\displaystyle\rightarrow \fdv{V}(E-TS)$ & long-form +& \verb|\fdv{V}(E-TS)| $\displaystyle\rightarrow \fdv{V}(E-TS)$ & long-form \\ +& \verb|\fdv*{F}{x}| $\displaystyle\rightarrow \fdv*{F}{x}$ & inline form using \verb|\flatfrac| \end{longtable} \subsection{Dirac bra-ket notation} @@ -167,25 +255,128 @@ On the other hand, the correct output can be generated by sticking to the fundam \verb|\bra{\phi}\ket{\psi}\bra{\xi}| \rightarrow \bra{\phi}\ket{\psi}\bra{\xi} \end{displaymath} allowing the user to type out complicated quantum mechanical expressions without worrying about bra-ket contractions. That being said, the high-level macros do have a place in convenience and readability, as long as the user is aware of rendering issues that may arise due to an absence of automatic contractions. -\begin{longtable}[l]{ l l p{6cm} } -\verb|\ket| & \verb|\ket{\psi}| $\rightarrow \ket{\psi}$ & automatic sizing \\ -& \verb|\ket*{\psi}| $\rightarrow \ket*{\psi}$ & complex conjugate (looks like \verb|\bra| but does not inherit contraction) \\ -\verb|\bra| & \verb|\bra{\psi}| $\rightarrow \bra{\psi}$ & automatic sizing \\ -& \verb|\bra*{\psi}| $\rightarrow \bra*{\psi}$ & complex conjugate (looks like \verb|\ket| but does not inherit contraction) \\ -& \verb|\bra{\phi}\ket{\psi}| $\rightarrow \bra{\phi}\ket{\psi}$ & automatic contraction \\ -\verb|\innerproduct| & \verb|\braket{a}{b}| $\rightarrow \braket{a}{b}$ & two-argument contraction; automatic sizing \\ -& \verb|\braket{a}| $\rightarrow \braket{a}$ & single-argument; produces norm \\ -& \verb|\braket*{a}{b}| $\rightarrow \braket*{a}{b}$ & complex conjugate; swaps arguments \\ -& \verb|\ip{a}{b}| $\rightarrow \ip{a}{b}$ & shorthand name \\ -\verb|\outerproduct| & \verb|\dyad{a}{b}| $\rightarrow \dyad{a}{b}$ & two-argument dyad; automatic sizing \\ -& \verb|\dyad{a}| $\rightarrow \dyad{a}$ & single-argument; produces projector \\ -& \verb|\dyad*{a}{b}| $\rightarrow \dyad*{a}{b}$ & complex conjugate; swaps arguments \\ -& \verb|\ketbra{a}{b}| $\rightarrow \ketbra{a}{b}$ & alternative name \\ -& \verb|\op{a}{b}| $\rightarrow \op{a}{b}$ & shorthand name \\ -\verb|\expectationvalue| & \verb|\expval{A}| $\rightarrow \expval{A}$ & implicit form \\ -& \verb|\expval{A}{\Psi}| $\rightarrow \expval{A}{\Psi}$ & explicit form \\ -& \verb|\ev{A}{\Psi}| $\rightarrow \ev{A}{\Psi}$ & shorthand name \\ -\verb|\matrixelement| & \verb|\matrixel{n}{A}{m}| $\rightarrow \matrixel{n}{A}{m}$ & requires all three arguments \\ -& \verb|\mel{n}{A}{m}| $\rightarrow \mel{n}{A}{m}$ & shorthand name \\ +\begin{longtable}[l]{ l L p{6cm} } +\verb|\ket| & \verb|\ket{\tall}| \rightarrow \ket{\tall} & automatic sizing \\ +& \verb|\ket*{\tall}| \rightarrow \ket*{\tall} & no resize \\ +\verb|\bra| & \verb|\bra{\tall}| \rightarrow \bra{\tall} & automatic sizing \\ +& \verb|\bra*{\tall}| \rightarrow \bra*{\tall} & no resize \\ +& \verb|\bra{\phi}\ket{\psi}| \rightarrow \bra{\phi}\ket{\psi} & automatic contraction \\ +& \verb|\bra{\phi}\ket{\tall}| \rightarrow \bra{\phi}\ket{\tall} & contraction inherits automatic sizing \\ +& \verb|\bra{\phi}\ket*{\tall}| \rightarrow \bra{\phi}\ket*{\tall} & \multirow{2}{*}{\parbox{6cm}{a star on either term in the contraction prohibits resizing}} \\ +& \verb|\bra*{\phi}\ket{\tall}| \rightarrow \bra*{\phi}\ket{\tall} & \\ +& \verb|\bra*{\phi}\ket*{\tall}| \rightarrow \bra*{\phi}\ket*{\tall} & \\ +\verb|\innerproduct| & \verb|\braket{a}{b}| \rightarrow \braket{a}{b} & two-argument braket \\ +& \verb|\braket{a}| \rightarrow \braket{a} & one-argument (norm) \\ +& \verb|\braket{a}{\tall}| \rightarrow \braket{a}{\tall} & automatic sizing \\ +& \verb|\braket*{a}{\tall}| \rightarrow \braket*{a}{\tall} & no resize \\ +& \verb|\ip{a}{b}| \rightarrow \ip{a}{b} & shorthand name \\ +\verb|\outerproduct| & \verb|\dyad{a}{b}| \rightarrow \dyad{a}{b} & two-argument dyad \\ +& \verb|\dyad{a}| \rightarrow \dyad{a} & one-argument (projector) \\ +& \verb|\dyad{a}{\tall}| \rightarrow \dyad{a}{\tall} & automatic sizing \\ +& \verb|\dyad*{a}{\tall}| \rightarrow \dyad*{a}{\tall} & no resize \\ +& \verb|\ketbra{a}{b}| \rightarrow \ketbra{a}{b} & alternative name \\ +& \verb|\op{a}{b}| \rightarrow \op{a}{b} & shorthand name \\ +\verb|\expectationvalue| & \verb|\expval{A}| \rightarrow \expval{A} & implicit form \\ +& \verb|\expval{A}{\Psi}| \rightarrow \expval{A}{\Psi} & explicit form \\ +& \verb|\ev{A}{\Psi}| \rightarrow \ev{A}{\Psi} & shorthand name \\ +& \verb|\ev{\grande}{\Psi}| \rightarrow \ev{\grande}{\Psi} & default sizing ignores middle argument \\ +& \verb|\ev*{\grande}{\tall}| \rightarrow \ev*{\grande}{\tall} & single star does no resizing whatsoever \\ +& \verb|\ev**{\grande}{\Psi}| \rightarrow \ev**{\grande}{\Psi} & double star resizes based on all parts \\ +\verb|\matrixelement| & \verb|\matrixel{n}{A}{m}| \rightarrow \matrixel{n}{A}{m} & requires all three arguments \\ +& \verb|\mel{n}{A}{m}| \rightarrow \mel{n}{A}{m} & shorthand name \\ +& \verb|\mel{n}{\grande}{m}| \rightarrow \mel{n}{\grande}{m} & default sizing ignores middle argument \\ +& \verb|\mel*{n}{\grande}{\tall}| \rightarrow \mel*{n}{\grande}{\tall} & single star does no resizing whatsoever \\ +& \verb|\mel**{n}{\grande}{m}| \rightarrow \mel**{n}{\grande}{m} & double star resizes based on all parts \end{longtable} + +\subsection{Matrix macros} +The following matrix macros produce unformatted rows and columns of matrix elements for use as separate matrices as well as blocks within larger matrices. For example, the command \verb|\identitymatrix{2}| which has also has the shortcut \verb|\imat{2}| produces the elements of a $2 \times 2$ identity matrix $\smqty{\imat{2}}$ without braces or grouping. This allows the command to also be used within another matrix, as in: + +\begin{minipage}{3cm} +\begin{verbatim} +\begin{pmatrix} +\imat{2} \\ a & b +\end{pmatrix} +\end{verbatim} +\end{minipage} +\begin{minipage}{6cm} +\begin{displaymath} +\Rightarrow\qquad +\begin{pmatrix} +\imat{2} \\ a & b +\end{pmatrix} +\end{displaymath} +\end{minipage} + +To specify elements on the right of left sides of our \verb|\imat{2}| sub-matrix we use the grouping command \verb|\matrixquantity| or \verb|\mqty| to effectively convert \verb|\imat{2}| into a single matrix element of a larger matrix: + +\begin{minipage}{9cm} +\begin{verbatim} +\begin{pmatrix} +\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e +\end{pmatrix} +\end{verbatim} +\end{minipage} +\begin{minipage}{6cm} +\begin{displaymath} +\Rightarrow\qquad +\begin{pmatrix} +\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e +\end{pmatrix} +\end{displaymath} +\end{minipage} + +The extra \verb|\mqty| groups were required in this case in order to get the $a$ and $b$ elements to behave as a single element, since \verb|\mqty{\imat{2}}| also acts like a single matrix element (the same can be said of the grouped $c$ and $d$ elements). Finally, the outermost \texttt{pmatrix} environment could have also been replaced with the \texttt{physics} macro \verb|\mqty()|, allowing the above example to be written on one line: + +\begin{minipage}{9cm} +\begin{verbatim} +\mqty(\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e) +\end{verbatim} +\end{minipage} +\begin{minipage}{6cm} +\begin{displaymath} +\Rightarrow\qquad +\mqty(\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e) +\end{displaymath} +\end{minipage} + +\begin{longtable}[l]{ l L p{6cm} } +\verb|\matrixquantity| & \verb|\mqty{a & b \\ c & d}| \rightarrow \mqty{a & b \\ c & d} & groups a set of matrix elements into a single object \\ +& \verb|\mqty(a & b \\ c & d)| \rightarrow {\mqty(a & b \\ c & d)} & parentheses \\ +& \verb|\mqty*(a & b \\ c & d)| \rightarrow {\mqty*(a & b \\ c & d)} & alternate parentheses \\ +& \verb|\mqty[a & b \\ c & d]| \rightarrow {\mqty[a & b \\ c & d]} & square brackets \\ +& \verb|\mqty| \texttt{|} \verb|a & b \\ c & d| \texttt{|} \rightarrow {\mqty|a & b \\ c & d|} & vertical bars \\ +& \verb|\pmqty{}| \leftrightarrow \verb|\mqty()| & \multirow{2}{*}{\parbox{6cm}{alternative syntax; robust and more \LaTeX-friendly}} \\ +& \verb|\Pmqty{}| \leftrightarrow \verb|\mqty*()| & \\ +& \verb|\bmqty{}| \leftrightarrow \verb|\mqty[]| & \\ +& \verb|\vmqty{}| \leftrightarrow \verb+\mqty||+ & \\ +\verb|\smallmatrixquantity| & \verb|\smqty{a & b \\ c & d}| \rightarrow \smqty{a & b \\ c & d} & the \texttt{smallmatrix} form of \verb|\mqty| \\ +& \verb|\smqty()| \qor \verb|\spmqty{}| & small version of \verb|\mqty()| \\ +& \verb|\smqty*()| \qor \verb|\sPmqty{}| & small version of \verb|\mqty*()|\\ +& \verb|\smqty[]| \qor \verb|\sbmqty{}| & small version of \verb|\mqty[]| \\ +& \verb+\smqty||+ \qor \verb|\svmqty{}| & small version of \verb+\mqty||+ \\ +\verb|\matrixdeterminant| & \verb|\mdet{a & b \\ c & d}| \rightarrow {\mdet{a & b \\ c & d}} & matrix determinant \\ +& \verb|\smdet{a & b \\ c & d}| \rightarrow {\smdet{a & b \\ c & d}} & small matrix determinant \\ +\verb|\identitymatrix| & \verb|\imat{n}| & elements of $n \times n$ identity matrix \\ +& \verb|\smqty(\imat{3})| \rightarrow \smqty(\imat{3}) & formatted with \verb|\mqty| or \verb|\smqty| \\ +\verb|\xmatrix| & \verb|\xmat{x}{n}{m}| & elements of $n \times m$ matrix filled with $x$ \\ +& \verb|\smqty(\xmat{1}{2}{3})| \rightarrow \smqty(\xmat{1}{2}{3}) & formatted with \verb|\mqty| or \verb|\smqty| \\ +& \verb|\smqty(\xmat*{a}{3}{3})| \rightarrow \smqty(\xmat*{a}{3}{3}) & star for element indices \\ +& \verb|\smqty(\xmat*{a}{3}{1})| \rightarrow \smqty(\xmat*{a}{3}{1}) & as a vector with indices \\ +& \verb|\smqty(\xmat*{a}{1}{3})| \rightarrow \smqty(\xmat*{a}{1}{3}) & \\ +\verb|\zeromatrix| & \verb|\zmat{n}{m}| & $n \times m$ matrix filled with zeros \\ +& \verb|\smqty(\zmat{2}{2})| \rightarrow \smqty(\zmat{2}{2}) & equivalent to \verb|\xmat{0}{n}{m}| \\ +\verb|\paulimatrix| & \verb|\pmat{n}| & $n^\text{th}$ Pauli matrix \\ +& \verb|\smqty(\pmat{0})| \rightarrow \smqty(\pmat{0}) & $n\in \lbrace 0,1,2,3$ or $x,y,z \rbrace$ \\ +& \verb|\smqty(\pmat{1})| \rightarrow \smqty(\pmat{1}) & \\ +& \verb|\smqty(\pmat{2})| \rightarrow \smqty(\pmat{2}) & \\ +& \verb|\smqty(\pmat{3})| \rightarrow \smqty(\pmat{3}) & \\ +\verb|\diagonalmatrix| & \verb|\dmat{a,b,c,...}| & \multirow{2}{*}{\parbox{6cm}{specify up to eight diagonal or block diagonal elements}} \\ +& \verb|\mqty(\dmat{1,2,3})| \rightarrow \mqty(\dmat{1,2,3}) & \\ +& \verb|\mqty(\dmat[0]{1,2})| \rightarrow \mqty(\dmat[0]{1,2}) & optional argument to fill spaces \\ +& \verb|\mqty(\dmat{1,2&3\\4&5})| \rightarrow \mqty(\dmat{1,2&3\\4&5}) & \parbox{6cm}{enter matrix elements for each block as a single diagonal element} \\ +\verb|\antidiagonalmatrix| & \verb|\admat{a,b,c,...}| & same as syntax as \verb|\dmat| \\ +& \verb|\mqty(\admat{1,2,3})| \rightarrow \mqty(\admat{1,2,3}) & \\ +\end{longtable} + \end{document}
\ No newline at end of file diff --git a/Master/texmf-dist/tex/latex/physics/physics.sty b/Master/texmf-dist/tex/latex/physics/physics.sty index 36c23bf66bc..2eafc4940e5 100644 --- a/Master/texmf-dist/tex/latex/physics/physics.sty +++ b/Master/texmf-dist/tex/latex/physics/physics.sty @@ -1,94 +1,206 @@ \ProvidesPackage{physics} -% physics 1.20 +% physics 1.3 % This material is subject to the LaTeX Project Public License. % See http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html for the details of that license. % -% Handy commands for physicists including macros for vectors, calculus, and bra-ket (Dirac) notation +% Handy commands for physicists including macros for vectors, calculus, matrices, and bra-ket (Dirac) notation % Requires xparse package, which comes bundled with l3packages and l3kernel % This package loads amsmath, which comes standard with most latex distributions % The commands defined in this package will silently overwrite previous commands with the same name, if such commands exist % % Created by Sergio C. de la Barrera -% Updated on October 31, 2012 -% Uploaded on November 1, 2012 +% Updated on December 12, 2012 +% Uploaded on December 20, 2012 \RequirePackage{xparse} \RequirePackage{amsmath} +% Options +\DeclareOption{trig}{\let\trigopt = 1} +\DeclareOption{notrig}{\let\trigopt = 0} +\DeclareOption{uprightdiff}{\def\diffd{\mathrm{d}}} % Upright differentials +\DeclareOption{italicdiff}{\def\diffd{d}} % Italic differentials +\DeclareOption{bolddel}{\DeclareDocumentCommand\vnabla{}{\boldsymbol\nabla}} % Vector bold \nabla symbol +\DeclareOption{arrowdel}{\DeclareDocumentCommand\vnabla{}{\vec{\boldsymbol\nabla}}} % Vector arrow \nabla symbol +\ExecuteOptions{trig,uprightdiff,bolddel} +\ProcessOptions\relax + +% Symbols +\ProvideDocumentCommand\varE{}{\mathcal{E}} % Curly 'E' +\ProvideDocumentCommand\ordersymbol{}{\mathcal{O}} % Order symbol --> O(x^2) +\ProvideDocumentCommand\lparen{}{(} % Left parenthesis +\ProvideDocumentCommand\rparen{}{)} % Right parenthesis + % Brackets and braces -\DeclareDocumentCommand\quantity{ t\big t\Big t\bigg t\Bigg g o d() d|| }{ % Flexible automatic bracketing of an expression in () or [] or {} or || +\DeclareDocumentCommand\quantity{}{{\ifnum\z@=`}\fi\@quantity} +\DeclareDocumentCommand\@quantity{ t\big t\Big t\bigg t\Bigg g o d() d|| } +{ % Flexible automatic bracketing of an expression in () or [] or {} or || % Handles manual override of sizing \IfBooleanTF{#1}{\let\ltag\bigl \let\rtag\bigr}{ \IfBooleanTF{#2}{\let\ltag\Bigl \let\rtag\Bigr}{ \IfBooleanTF{#3}{\let\ltag\biggl \let\rtag\biggr}{ \IfBooleanTF{#4} - {\let\ltag\Biggl \let\rtag\Biggr} - {\let\ltag\left \let\rtag\right} - } + {\let\ltag\Biggl \let\rtag\Biggr} + {\let\ltag\left \let\rtag\right} } } + } % Handles actual bracketing \IfNoValueTF{#5}{ \IfNoValueTF{#6}{ \IfNoValueTF{#7}{ \IfNoValueTF{#8} - {()} - {\ltag\lvert{#8}\rtag\rvert} - } - {\ltag(#7\rtag) \IfNoValueTF{#8}{}{|#8|}} + {()} + {\ltag\lvert{#8}\rtag\rvert} } - {\ltag[#6\rtag] \IfNoValueTF{#7}{}{(#7)} \IfNoValueTF{#8}{}{|#8|}} + {\ltag(#7\rtag) \IfNoValueTF{#8}{}{|#8|}} } - {\ltag\lbrace#5\rtag\rbrace \IfNoValueTF{#6}{}{[#6]} \IfNoValueTF{#7}{}{(#7)} \IfNoValueTF{#8}{}{|#8|}} + {\ltag[#6\rtag] \IfNoValueTF{#7}{}{(#7)} \IfNoValueTF{#8}{}{|#8|}} } + {\ltag\lbrace#5\rtag\rbrace \IfNoValueTF{#6}{}{[#6]} \IfNoValueTF{#7}{}{(#7)} \IfNoValueTF{#8}{}{|#8|}} + \ifnum\z@=`{\fi} +} \DeclareDocumentCommand\qty{}{\quantity} % Shorthand for \quantity +\DeclareDocumentCommand\pqty{ l m }{\braces#1{\lparen}{\rparen}{#2}} +\DeclareDocumentCommand\bqty{ l m }{\braces#1{\lbrack}{\rbrack}{#2}} +\DeclareDocumentCommand\Bqty{ l m }{\braces#1{\lbrace}{\rbrace}{#2}} +\DeclareDocumentCommand\vqty{ l m }{\braces#1{\lvert}{\rvert}{#2}} + -\DeclareDocumentCommand\absolutevalue{ t\big t\Big t\bigg t\Bigg m }{ % Absolute value/complex modulus - \IfBooleanTF{#1}{\quantity\big|#5|}{ - \IfBooleanTF{#2}{\quantity\Big|#5|}{ - \IfBooleanTF{#3}{\quantity\bigg|#5|}{ - \IfBooleanTF{#4}{\quantity\Bigg|#5|}{\quantity|#5|} +\DeclareDocumentCommand\pmqty{m}{\begin{pmatrix}#1\end{pmatrix}} +\DeclareDocumentCommand\Pmqty{m}{\left\lgroup\begin{matrix}#1\end{matrix}\right\rgroup} +\DeclareDocumentCommand\bmqty{m}{\begin{bmatrix}#1\end{bmatrix}} +\DeclareDocumentCommand\vmqty{m}{\begin{vmatrix}#1\end{vmatrix}} +\DeclareDocumentCommand\matrixquantity{}{{\ifnum\z@=`}\fi\@matrixquantity} +\DeclareDocumentCommand\@matrixquantity{ s g o d() d|| } +{ + \mathord{ + \IfNoValueTF{#2} + { + \IfNoValueTF{#3} + { + \IfNoValueTF{#4} + { + \IfNoValueTF{#5} + {()} + {\vmqty{#5}} + } + { + \IfBooleanTF{#1} + {\Pmqty{#4}} + {\pmqty{#4}} + \IfNoValueTF{#5}{}{|#5|} } } + {\bmqty{#3} \IfNoValueTF{#4}{}{(#4)} \IfNoValueTF{#5}{}{|#5|}} + } + {\begin{matrix}#2\end{matrix} \IfNoValueTF{#3}{}{[#3]} \IfNoValueTF{#4}{}{(#4)} \IfNoValueTF{#5}{}{|#5|}} } + \ifnum\z@=`{\fi} } -\DeclareDocumentCommand\abs{}{\absolutevalue} % Shorthand for \absolutevalue +\DeclareDocumentCommand\mqty{}{\matrixquantity} % Shorthand for \matrixquantity +\DeclareDocumentCommand\matrixdeterminant{m}{\vmqty{#1}} % Matrix determinant +\DeclareDocumentCommand\mdet{}{\matrixdeterminant} % Shorthand for matrix determinant -\DeclareDocumentCommand\norm{ t\big t\Big t\bigg t\Bigg m }{ % Norm - \IfBooleanTF{#1}{\bigl\lVert{#5}\bigr\rVert}{ - \IfBooleanTF{#2}{\Bigl\lVert{#5}\Bigr\rVert}{ - \IfBooleanTF{#3}{\biggl\lVert{#5}\biggr\rVert}{ - \IfBooleanTF{#4}{\Biggl\lVert{#5}\Biggr\rVert}{\left\lVert{#5}\right\rVert} +\DeclareDocumentCommand\spmqty{m}{\pqty{\begin{smallmatrix}#1\end{smallmatrix}}} +\DeclareDocumentCommand\sPmqty{m}{\left\lgroup\begin{smallmatrix}#1\end{smallmatrix}\right\rgroup} +\DeclareDocumentCommand\sbmqty{m}{\bqty{\begin{smallmatrix}#1\end{smallmatrix}}} +\DeclareDocumentCommand\svmqty{m}{\vqty{\begin{smallmatrix}#1\end{smallmatrix}}} +\DeclareDocumentCommand\smallmatrixquantity{ s g o d() d|| } +{ + \mathord{ + \IfNoValueTF{#2} + { + \IfNoValueTF{#3} + { + \IfNoValueTF{#4} + { + \IfNoValueTF{#5} + {()} + {\svmqty{#5}} + } + { + \IfBooleanTF{#1} + {\sPmqty{#4}} + {\spmqty{#4}} + \IfNoValueTF{#5}{}{|#5|} } } + {\sbmqty{#3} \IfNoValueTF{#4}{}{(#4)} \IfNoValueTF{#5}{}{|#5|}} + } + {\begin{smallmatrix}#2\end{smallmatrix} \IfNoValueTF{#3}{}{[#3]} \IfNoValueTF{#4}{}{(#4)} \IfNoValueTF{#5}{}{|#5|}} } } -\DeclareDocumentCommand\order{ t\big t\Big t\bigg t\Bigg m }{ % Order symbol -> O(x^2) - \IfBooleanTF{#1}{\mathcal{O}\IfNoValueTF{#5}{}{\!\quantity\big(#5)}}{ - \IfBooleanTF{#2}{\mathcal{O}\IfNoValueTF{#5}{}{\!\quantity\Big(#5)}}{ - \IfBooleanTF{#3}{\mathcal{O}\IfNoValueTF{#5}{}{\!\quantity\bigg(#5)}}{ - \IfBooleanTF{#4}{\mathcal{O}\IfNoValueTF{#5}{}{\!\quantity\Bigg(#5)}}{\mathcal{O}\IfNoValueTF{#5}{}{\!\quantity(#5)}} +\DeclareDocumentCommand\smqty{}{\smallmatrixquantity} % Shorthand for \smallmatrixquantity +\DeclareDocumentCommand\smallmatrixdeterminant{m}{\svmqty{#1}} % Small matrix determinant +\DeclareDocumentCommand\smdet{}{\smallmatrixdeterminant} % Shorthand for small matrix determinant + +\DeclareDocumentCommand\argopen{s}{\IfBooleanTF{#1}{\mathopen{}\mathclose\bgroup}{\mathopen{}\mathclose\bgroup\left}} % Special open grouping for argument of a function +\DeclareDocumentCommand\argclose{s}{\IfBooleanTF{#1}{\egroup}{\aftergroup\egroup\right}} % Special close grouping for argument of a function + +\DeclareDocumentCommand\braces{}{{\ifnum\z@=`}\fi\@braces} +\DeclareDocumentCommand\@braces{ s t\big t\Big t\bigg t\Bigg m m m } +{ % General braces with automatic and manual sizing + \IfBooleanTF{#1} + {\left#6\smash{#8}\right#7\vphantom{#8}} + { + \IfBooleanTF{#2}{\bigl#6{#8}\bigr#7}{ + \IfBooleanTF{#3}{\Bigl#6{#8}\Bigr#7}{ + \IfBooleanTF{#4}{\biggl#6{#8}\biggr#7}{ + \IfBooleanTF{#5}{\Biggl#6{#8}\Biggr#7}{\left#6{#8}\right#7} + } } } } + \ifnum\z@=`{\fi} } -\DeclareDocumentCommand\evaluated{ g d() }{ % Vertical evaluation bar or parentheses - \IfNoValueTF{#1}{ - \IfNoValueTF{#2} - {\rvert} - {\quantity(#2)} + +\DeclareDocumentCommand\fbraces{ s t\big t\Big t\bigg t\Bigg m m m m } +{ % Function braces with automatic and manual sizing + #8 + \IfBooleanTF{#1} + {\argopen#6\smash{#9}\argclose#7\vphantom{#9}} + { + \IfBooleanTF{#2}{\argopen*\bigl#6{#9}\argclose*\bigr#7}{ + \IfBooleanTF{#3}{\argopen*\Bigl#6{#9}\argclose*\Bigr#7}{ + \IfBooleanTF{#4}{\argopen*\biggl#6{#9}\argclose*\biggr#7}{ + \IfBooleanTF{#5} + {\argopen*\Biggl#6{#9}\argclose*\Biggr#7} + {\argopen#6{#9}\argclose#7} + } + } } - {\left.{#1}\right\rvert \IfNoValueTF{#2}{}{(#2)}} } +} + +\DeclareDocumentCommand\absolutevalue{ l m }{\braces#1{\lvert}{\rvert}{#2}} % Absolute value/complex modulus +\DeclareDocumentCommand\abs{}{\absolutevalue} % Shorthand for \absolutevalue +\DeclareDocumentCommand\norm{ l m }{\braces#1{\lVert}{\rVert}{#2}} % Norm +\DeclareDocumentCommand\order{ l m }{\fbraces#1{\lparen}{\rparen}{\ordersymbol}{#2}} % Order notation -> O(x^2) + +\DeclareDocumentCommand\evaluated{ s g d[| d(| } +{ % Vertical evaluation bar + \IfNoValueTF{#2} + { + \IfNoValueTF{#3} + { + \IfNoValueTF{#4} + {\argopen.\vphantom{\int}\argclose\rvert} + {\IfBooleanTF{#1}{\vphantom{#4}}{}\left(\IfBooleanTF{#1}{\smash{#4}}{#4}\vphantom{\int}\right\rvert} + } + {\IfBooleanTF{#1}{\vphantom{#3}}{}\left[\IfBooleanTF{#1}{\smash{#3}}{#3}\vphantom{\int}\right\rvert \IfNoValueTF{#4}{}{(#4|}} + } + {\IfBooleanTF{#1}{\vphantom{#2}}{}\left.\IfBooleanTF{#1}{\smash{#2}}{#2}\vphantom{\int}\right\rvert \IfNoValueTF{#3}{}{[#3|} \IfNoValueTF{#4}{}{(#4|}} +} \DeclareDocumentCommand\eval{}{\evaluated} % Shorthand for evaluated -\DeclareDocumentCommand\poissonbracket{ m m }{{\left\lbrace{#1},{#2}\right\rbrace}} % Poisson bracket [same as anti-commutator] + +\DeclareDocumentCommand\poissonbracket{ l m m }{\braces#1{\lbrace}{\rbrace}{#2,#3}} % Poisson bracket [same as anti-commutator] \DeclareDocumentCommand\pb{}{\poissonbracket} % Shorthand for \poissonbracket % Commutators -\DeclareDocumentCommand\commutator{ m m }{\left[{#1},{#2}\right]} % Commutator +\DeclareDocumentCommand\commutator{ l m m }{\braces#1{\lbrack}{\rbrack}{#2,#3}} % Commutator \DeclareDocumentCommand\comm{}{\commutator} % Shorthand for \commutator - -\DeclareDocumentCommand\anticommutator{ m m }{\left\lbrace{#1},{#2}\right\rbrace} % Anticommutator [same as Poisson bracket] +\DeclareDocumentCommand\anticommutator{ l m m }{\braces#1{\lbrace}{\rbrace}{#2,#3}} % Anticommutator [same as Poisson bracket] \DeclareDocumentCommand\acommutator{}{\anticommutator} % Shorthand for \anticommutator \DeclareDocumentCommand\acomm{}{\anticommutator} % Shorthand for \anticommutator @@ -109,13 +221,12 @@ \DeclareDocumentCommand\cross{}{\crossproduct} % Shorthand for \crossproduct \DeclareDocumentCommand\cp{}{\crossproduct} % Shorthand for \crossproduct -\DeclareDocumentCommand\vnabla{}{\boldsymbol\nabla} % Vector bold \nabla symbol \DeclareDocumentCommand\gradient{ g o d() }{ % Gradient \IfNoValueTF{#1}{ \IfNoValueTF{#2}{ - \IfNoValueTF{#3}{\vnabla}{\vnabla\!\quantity(#3)} + \IfNoValueTF{#3}{\vnabla}{\fbraces{\lparen}{\rparen}{\vnabla}{#3}} } - {\vnabla\!\quantity[#2] \IfNoValueTF{#3}{}{(#3)}} + {\fbraces{\lbrack}{\rbrack}{\vnabla}{#2} \IfNoValueTF{#3}{}{(#3)}} } {\vnabla #1 \IfNoValueTF{#2}{}{[#2]} \IfNoValueTF{#3}{}{(#3)}} } @@ -147,44 +258,120 @@ \DeclareDocumentCommand\laplacian{ g o d() }{ % Laplacian \IfNoValueTF{#1}{ \IfNoValueTF{#2}{ - \IfNoValueTF{#3}{\nabla^2}{\nabla^2\!\quantity(#3)} + \IfNoValueTF{#3}{\nabla^2}{\fbraces{\lparen}{\rparen}{\nabla^2}{#3}} } - {\nabla^2\!\quantity[#2] \IfNoValueTF{#3}{}{(#3)}} + {\fbraces{\lbrack}{\rbrack}{\nabla^2}{#2} \IfNoValueTF{#3}{}{(#3)}} } {\nabla^2 #1 \IfNoValueTF{#2}{}{[#2]} \IfNoValueTF{#3}{}{(#3)}} } % Operators -\let\sine\sin -\let\cosine\cos -\let\tangent\tan -\let\cosecant\csc -\let\secant\sec -\let\cotangent\cot -\let\arcsine\arcsin -\let\arccosine\arccos -\let\arctangent\arctan -\let\hypsine\sinh -\let\hypcosine\cosh -\let\hyptangent\tanh -\let\hypcotangent\coth -\DeclareDocumentCommand\sin{ o d() }{\IfNoValueTF{#2}{\sine \IfNoValueTF{#1}{}{[#1]}}{\sine \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} -\DeclareDocumentCommand\cos{ o d() }{\IfNoValueTF{#2}{\cosine \IfNoValueTF{#1}{}{[#1]}}{\cosine \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} -\DeclareDocumentCommand\tan{ o d() }{\IfNoValueTF{#2}{\tangent \IfNoValueTF{#1}{}{[#1]}}{\tangent \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} -\DeclareDocumentCommand\csc{ o d() }{\IfNoValueTF{#2}{\cosecant \IfNoValueTF{#1}{}{[#1]}}{\cosecant \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} -\DeclareDocumentCommand\sec{ o d() }{\IfNoValueTF{#2}{\secant \IfNoValueTF{#1}{}{[#1]}}{\secant \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} -\DeclareDocumentCommand\cot{ o d() }{\IfNoValueTF{#2}{\cotangent \IfNoValueTF{#1}{}{[#1]}}{\cotangent \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} -\DeclareDocumentCommand\arcsin{ o d() }{\IfNoValueTF{#2}{\arcsine \IfNoValueTF{#1}{}{[#1]}}{\arcsine \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} -\DeclareDocumentCommand\arccos{ o d() }{\IfNoValueTF{#2}{\arccosine \IfNoValueTF{#1}{}{[#1]}}{\arccosine \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} -\DeclareDocumentCommand\arctan{ o d() }{\IfNoValueTF{#2}{\arctangent \IfNoValueTF{#1}{}{[#1]}}{\arctangent \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} -\DeclareDocumentCommand\sinh{ o d() }{\IfNoValueTF{#2}{\hypsine \IfNoValueTF{#1}{}{[#1]}}{\hypsine \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} -\DeclareDocumentCommand\cosh{ o d() }{\IfNoValueTF{#2}{\hypcosine \IfNoValueTF{#1}{}{[#1]}}{\hypcosine \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} -\DeclareDocumentCommand\tanh{ o d() }{\IfNoValueTF{#2}{\hyptangent \IfNoValueTF{#1}{}{[#1]}}{\hyptangent \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} -\DeclareDocumentCommand\coth{ o d() }{\IfNoValueTF{#2}{\hypcotangent \IfNoValueTF{#1}{}{[#1]}}{\hypcotangent \IfNoValueTF{#1}{}{^{#1}} \!\quantity(#2)}} - -\DeclareMathOperator{\tr}{tr} % Trace and partial trace [w/subscript] +\DeclareMathOperator{\trace}{tr} % Trace of a matrix +\DeclareMathOperator{\Trace}{Tr} % Trace of a matrix (alternate) \DeclareMathOperator{\rank}{rank} % Rank of a matrix \DeclareMathOperator{\erf}{erf} % Gauss error function +\DeclareMathOperator{\Residue}{Res} % Residue +\DeclareDocumentCommand\principalvalue{g}{\IfNoValueTF{#1}{\mathcal{P}}{\mathcal{P}\mathord{#1}}} +\DeclareDocumentCommand\pv{}{\principalvalue} +\DeclareDocumentCommand\PV{g}{\IfNoValueTF{#1}{\mathrm{P.V.}}{\mathrm{P.V.}\mathord{#1}}} +\let\real\Re \DeclareDocumentCommand\Re{g}{\IfNoValueTF{#1}{\operatorname{Re}}{\fbraces{\lbrace}{\rbrace}{\operatorname{Re}}{#1}}} +\let\imaginary\Im \DeclareDocumentCommand\Im{g}{\IfNoValueTF{#1}{\operatorname{Im}}{\fbraces{\lbrace}{\rbrace}{\operatorname{Im}}{#1}}} +\DeclareDocumentCommand\opbraces{ m g o d() } +{ + \IfNoValueTF{#2} + { + \IfNoValueTF{#3} + { + \IfNoValueTF{#4} + {#1} + {\fbraces{\lparen}{\rparen}{#1}{#4}} + } + { + \fbraces{\lbrack}{\rbrack}{#1}{#3} + \IfNoValueTF{#4}{}{(#4)} + } + } + { + \fbraces{\lbrace}{\rbrace}{#1}{#2} + \IfNoValueTF{#3}{}{[#3]} + \IfNoValueTF{#4}{}{(#4)} + } +} +\DeclareDocumentCommand\trigbraces{ m o d() } +{ + \IfNoValueTF{#3} + {#1 \IfNoValueTF{#2}{}{[#2]}} + {#1 \IfNoValueTF{#2}{}{^{#2}} \argopen(#3\argclose)} +} + +% Trig function and operator redefinitions +\ifx\trigopt 1 + \let\sine\sin \DeclareDocumentCommand\sin{}{\trigbraces{\sine}} + \let\cosine\cos \DeclareDocumentCommand\cos{}{\trigbraces{\cosine}} + \let\tangent\tan \DeclareDocumentCommand\tan{}{\trigbraces{\tangent}} + \let\cosecant\csc \DeclareDocumentCommand\csc{}{\trigbraces{\cosecant}} + \let\secant\sec \DeclareDocumentCommand\sec{}{\trigbraces{\secant}} + \let\cotangent\cot \DeclareDocumentCommand\cot{}{\trigbraces{\cotangent}} + + \let\arcsine\arcsin \DeclareDocumentCommand\arcsin{}{\trigbraces{\arcsine}} + \let\arccosine\arccos \DeclareDocumentCommand\arccos{}{\trigbraces{\arccosine}} + \let\arctangent\arctan \DeclareDocumentCommand\arctan{}{\trigbraces{\arctangent}} + \DeclareMathOperator{\arccosecant}{arccsc} + \DeclareDocumentCommand\arccsc{}{\trigbraces{\arccosecant}} + \DeclareMathOperator{\arcsecant}{arcsec} + \DeclareDocumentCommand\arcsec{}{\trigbraces{\arcsecant}} + \DeclareMathOperator{\arccotangent}{arccot} + \DeclareDocumentCommand\arccot{}{\trigbraces{\arccotangent}} + + \DeclareMathOperator{\asine}{asin} + \DeclareDocumentCommand\asin{}{\trigbraces{\asine}} + \DeclareMathOperator{\acosine}{acos} + \DeclareDocumentCommand\acos{}{\trigbraces{\acosine}} + \DeclareMathOperator{\atangent}{atan} + \DeclareDocumentCommand\atan{}{\trigbraces{\atangent}} + \DeclareMathOperator{\acosecant}{acsc} + \DeclareDocumentCommand\acsc{}{\trigbraces{\acosecant}} + \DeclareMathOperator{\asecant}{asec} + \DeclareDocumentCommand\asec{}{\trigbraces{\asecant}} + \DeclareMathOperator{\acotangent}{acot} + \DeclareDocumentCommand\acot{}{\trigbraces{\acotangent}} + + \let\hypsine\sinh \DeclareDocumentCommand\sinh{}{\trigbraces{\hypsine}} + \let\hypcosine\cosh \DeclareDocumentCommand\cosh{}{\trigbraces{\hypcosine}} + \let\hyptangent\tanh \DeclareDocumentCommand\tanh{}{\trigbraces{\hyptangent}} + \DeclareMathOperator{\hypcosecant}{csch} + \DeclareDocumentCommand\csch{}{\trigbraces{\hypcosecant}} + \DeclareMathOperator{\hypsecant}{sech} + \DeclareDocumentCommand\sech{}{\trigbraces{\hypsecant}} + \let\hypcotangent\coth \DeclareDocumentCommand\coth{}{\trigbraces{\hypcotangent}} + + \let\exponential\exp \DeclareDocumentCommand\exp{}{\opbraces{\exponential}} + \let\logarithm\log \DeclareDocumentCommand\log{}{\trigbraces{\logarithm}} + \let\naturallogarithm\ln \DeclareDocumentCommand\ln{}{\trigbraces{\naturallogarithm}} + \let\determinant\det \DeclareDocumentCommand\det{}{\opbraces{\determinant}} + \let\Probability\Pr \DeclareDocumentCommand\Pr{}{\opbraces{\Probability}} + \DeclareDocumentCommand\tr{}{\opbraces{\trace}} + \DeclareDocumentCommand\Tr{}{\opbraces{\Trace}} + \DeclareDocumentCommand\Res{}{\opbraces{\Residue}} +\else + \DeclareMathOperator{\arccsc}{arccsc} + \DeclareMathOperator{\arcsec}{arcsec} + \DeclareMathOperator{\arccot}{arccot} + + \DeclareMathOperator{\asin}{asin} + \DeclareMathOperator{\acos}{acos} + \DeclareMathOperator{\atan}{atan} + \DeclareMathOperator{\acsc}{acsc} + \DeclareMathOperator{\asec}{asec} + \DeclareMathOperator{\acot}{acot} + + \DeclareMathOperator{\csch}{csch} + \DeclareMathOperator{\sech}{sech} + + \DeclareDocumentCommand\tr{}{\trace} + \DeclareDocumentCommand\Tr{}{\Trace} + \DeclareDocumentCommand\Res{}{\Residue} +\fi % Quick quad text (math-mode text with \quad spacing) \DeclareDocumentCommand\qqtext{ s m }{\IfBooleanTF{#1}{}{\quad}\text{#2}\quad} @@ -221,43 +408,56 @@ % d: long-form as in d(cos x) \IfNoValueTF{#2}{ \IfNoValueTF{#3} - {\mathrm{d}\IfNoValueTF{#1}{}{^{#1}}} - {\mathrm{d}\IfNoValueTF{#1}{}{^{#1}}\!\quantity(#3)} + {\diffd\IfNoValueTF{#1}{}{^{#1}}} + {\mathinner{\diffd\IfNoValueTF{#1}{}{^{#1}}\argopen(#3\argclose)}} } - {\mathrm{d}\IfNoValueTF{#1}{}{^{#1}} #2 \,} + {\mathinner{\diffd\IfNoValueTF{#1}{}{^{#1}}#2} \IfNoValueTF{#3}{}{(#3)}} } \DeclareDocumentCommand\dd{}{\differential} % Shorthand for \differential -\DeclareDocumentCommand\derivative{ o m g d() }{ % Total derivative +\DeclareDocumentCommand\derivative{ s o m g d() } +{ % Total derivative + % s: star for \flatfrac flat derivative % o: optional n for nth derivative % m: mandatory (x in df/dx) % g: optional (f in df/dx) % d: long-form d/dx(...) - \IfNoValueTF{#3}{ - \IfNoValueTF{#4} - {\frac{\dd \IfNoValueTF{#1}{}{^{#1}}}{\dd #2\IfNoValueTF{#1}{}{^{#1}}}} - {\frac{\dd \IfNoValueTF{#1}{}{^{#1}}}{\dd #2\IfNoValueTF{#1}{}{^{#1}}} \!\quantity(#4)} - } - {\frac{\dd \IfNoValueTF{#1}{}{^{#1}} #2}{\dd #3\IfNoValueTF{#1}{}{^{#1}}}} + \IfBooleanTF{#1} + {\let\fractype\flatfrac} + {\let\fractype\frac} + \IfNoValueTF{#4} + { + \IfNoValueTF{#5} + {\fractype{\diffd \IfNoValueTF{#2}{}{^{#2}}}{\diffd #3\IfNoValueTF{#2}{}{^{#2}}}} + {\fractype{\diffd \IfNoValueTF{#2}{}{^{#2}}}{\diffd #3\IfNoValueTF{#2}{}{^{#2}}} \argopen(#5\argclose)} } + {\fractype{\diffd \IfNoValueTF{#2}{}{^{#2}} #3}{\diffd #4\IfNoValueTF{#2}{}{^{#2}}}} +} \DeclareDocumentCommand\dv{}{\derivative} % Shorthand for \derivative - -\DeclareDocumentCommand\partialderivative{ o m g g d() }{ % Partial derivative + +\DeclareDocumentCommand\partialderivative{ s o m g g d() } +{ % Partial derivative + % s: star for \flatfrac flat derivative % o: optional n for nth derivative % m: mandatory (x in df/dx) % g: optional (f in df/dx) % g: optional (y in d^2f/dxdy) % d: long-form d/dx(...) - \IfNoValueTF{#3}{ + \IfBooleanTF{#1} + {\let\fractype\flatfrac} + {\let\fractype\frac} + \IfNoValueTF{#4} + { + \IfNoValueTF{#6} + {\fractype{\partial \IfNoValueTF{#2}{}{^{#2}}}{\partial #3\IfNoValueTF{#2}{}{^{#2}}}} + {\fractype{\partial \IfNoValueTF{#2}{}{^{#2}}}{\partial #3\IfNoValueTF{#2}{}{^{#2}}} \argopen(#6\argclose)} + } + { \IfNoValueTF{#5} - {\frac{\partial \IfNoValueTF{#1}{}{^{#1}}}{\partial #2\IfNoValueTF{#1}{}{^{#1}}}} - {\frac{\partial \IfNoValueTF{#1}{}{^{#1}}}{\partial #2\IfNoValueTF{#1}{}{^{#1}}} \!\quantity(#5)} - }{ - \IfNoValueTF{#4} - {\frac{\partial \IfNoValueTF{#1}{}{^{#1}} #2}{\partial #3\IfNoValueTF{#1}{}{^{#1}}}} - {\frac{\partial^2 #2}{\partial #3 \partial #4}} - } + {\fractype{\partial \IfNoValueTF{#2}{}{^{#2}} #3}{\partial #4\IfNoValueTF{#2}{}{^{#2}}}} + {\fractype{\partial^2 #3}{\partial #4 \partial #5}} } +} \DeclareDocumentCommand\pderivative{}{\partialderivative} % Shorthand for \partialderivative \DeclareDocumentCommand\pdv{}{\partialderivative} % Shorthand for \partialderivative @@ -268,80 +468,290 @@ \IfNoValueTF{#2}{ \IfNoValueTF{#3} {\delta \IfNoValueTF{#1}{}{^{#1}}} - {\delta \IfNoValueTF{#1}{}{^{#1}}\!\quantity(#3)} + {\mathinner{\delta \IfNoValueTF{#1}{}{^{#1}}\argopen(#3\argclose)}} } - {\delta \IfNoValueTF{#1}{}{^{#1}} #2 \,} + {\mathinner{\delta \IfNoValueTF{#1}{}{^{#1}}#2} \IfNoValueTF{#3}{}{(#3)}} } \DeclareDocumentCommand\var{}{\variation} % Shorthand for \variation -\DeclareDocumentCommand\functionalderivative{ o m g d() }{ % Functional derivative +\DeclareDocumentCommand\functionalderivative{ s o m g d() } +{ % Functional derivative + % s: star for \flatfrac flat derivative % o: optional n for nth derivative % m: mandatory (g in dF/dg) % g: optional (F in dF/dg) % d: long-form d/dx(...) - \IfNoValueTF{#3}{ - \IfNoValueTF{#4} - {\frac{\variation \IfNoValueTF{#1}{}{^{#1}}}{\variation #2\IfNoValueTF{#1}{}{^{#1}}}} - {\frac{\variation \IfNoValueTF{#1}{}{^{#1}}}{\variation #2\IfNoValueTF{#1}{}{^{#1}}} \!\quantity(#4)} - } - {\frac{\variation \IfNoValueTF{#1}{}{^{#1}} #2}{\variation #3\IfNoValueTF{#1}{}{^{#1}}}} + \IfBooleanTF{#1} + {\let\fractype\flatfrac} + {\let\fractype\frac} + \IfNoValueTF{#4} + { + \IfNoValueTF{#5} + {\fractype{\variation \IfNoValueTF{#2}{}{^{#2}}}{\variation #3\IfNoValueTF{#2}{}{^{#2}}}} + {\fractype{\variation \IfNoValueTF{#2}{}{^{#2}}}{\variation #3\IfNoValueTF{#2}{}{^{#2}}} \argopen(#5\argclose)} } + {\fractype{\variation \IfNoValueTF{#2}{}{^{#2}} #3}{\variation #4\IfNoValueTF{#2}{}{^{#2}}}} +} \DeclareDocumentCommand\fderivative{}{\functionalderivative} % Shorthand for \functionalderivative \DeclareDocumentCommand\fdv{}{\functionalderivative} % Shorthand for \functionalderivative % Bra-ket notation -\DeclareDocumentCommand\bra{ s m t\ket{g} }{ % Bra - \IfBooleanTF{#1} - {\left\lvert{#2}\right\rangle \IfNoValueTF{#4}{}{#4}} % Complex conjugate - {\IfBooleanTF{#3}{\braket{#2}{\IfNoValueTF{#4}{}{#4}}}{\left\langle{#2}\right\rvert \IfNoValueTF{#4}{}{#4}}} % No star --- allow contraction +\DeclareDocumentCommand\bra{ s m t\ket s g } +{ % Bra + \IfBooleanTF{#3} + { % Contraction + \IfBooleanTF{#1} + { % Bra has a star: no resize + \IfNoValueTF{#5} + {\braket*{#2}{} \IfBooleanTF{#4}{*}{}} + {\braket*{#2}{#5}} + } + { + \IfBooleanTF{#4} + { % Ket has a star: no resize + \IfNoValueTF{#5} + {\braket{#2}{} *} + {\braket*{#2}{#5}} + } + {\braket{#2}{\IfNoValueTF{#5}{}{#5}}} % Neither term is starred: auto sizing + } } - -\DeclareDocumentCommand\ket{ s m }{ % Ket + { % No contraction + \IfBooleanTF{#1} + {\vphantom{#2}\left\langle\smash{#2}\right\rvert} + {\left\langle{#2}\right\rvert} + \IfBooleanTF{#4}{*}{} + \IfNoValueTF{#5}{}{#5} + } +} + +\DeclareDocumentCommand\ket{ s m } +{ % Ket \IfBooleanTF{#1} - {\left\langle{#2}\right\rvert} % Complex conjugate - {\left\lvert{#2}\right\rangle} % No star + {\vphantom{#2}\left\lvert\smash{#2}\right\rangle} % No resize + {\left\lvert{#2}\right\rangle} % Auto sizing +} + +\DeclareDocumentCommand\innerproduct{ s m g } +{ % Inner product + \IfBooleanTF{#1} + { % No resize + \IfNoValueTF{#3} + {\vphantom{#2}\left\langle\smash{#2}\middle\vert\smash{#2}\right\rangle} + {\vphantom{#2#3}\left\langle\smash{#2}\middle\vert\smash{#3}\right\rangle} } - -\DeclareDocumentCommand\innerproduct{ s m g }{ % Inner product - \IfNoValueTF{#3} - {\left\langle{#2}\vert{#2}\right\rangle} - { % Two arguments - \IfBooleanTF{#1} - {\left\langle{#3}\middle\vert{#2}\right\rangle} % Complex conjugate - {\left\langle{#2}\middle\vert{#3}\right\rangle} % No star - } + { % Auto resize + \IfNoValueTF{#3} + {\left\langle{#2}\middle\vert{#2}\right\rangle} + {\left\langle{#2}\middle\vert{#3}\right\rangle} } -\DeclareDocumentCommand\braket{}{\innerproduct} % Shorthand for \innerproduct +} +\DeclareDocumentCommand\braket{}{\innerproduct} % Alternative for \innerproduct \DeclareDocumentCommand\ip{}{\innerproduct} % Shorthand for \innerproduct -\DeclareDocumentCommand\outerproduct{ s m g }{ % Dyad - \IfNoValueTF{#3} +\DeclareDocumentCommand\outerproduct{ s m g } +{ % Dyad + \IfBooleanTF{#1} + { % No resize + \IfNoValueTF{#3} + {\vphantom{#2}\left\lvert\smash{#2}\middle\rangle\!\middle\langle\smash{#2}\right\rvert} + {\vphantom{#2#3}\left\lvert\smash{#2}\middle\rangle\!\middle\langle\smash{#3}\right\rvert} + } + { % Auto resize + \IfNoValueTF{#3} {\left\lvert{#2}\middle\rangle\!\middle\langle{#2}\right\rvert} - { % Two arguments - \IfBooleanTF{#1} - {\left\lvert{#3}\middle\rangle\!\middle\langle{#2}\right\rvert} - {\left\lvert{#2}\middle\rangle\!\middle\langle{#3}\right\rvert} - } + {\left\lvert{#2}\middle\rangle\!\middle\langle{#3}\right\rvert} } +} \DeclareDocumentCommand\dyad{}{\outerproduct} % Alternative for \outerproduct \DeclareDocumentCommand\op{}{\dyad} % Shorthand for \outerproduct \DeclareDocumentCommand\ketbra{}{\dyad} % Alternative for \outerproduct - -\DeclareDocumentCommand\expectationvalue{ m g }{ % Expectation value - \IfNoValueTF{#2} - {\left\langle{#1}\right\rangle} - {\left\langle{#2}\middle\vert{#1}\middle\vert{#2}\right\rangle} + +\DeclareDocumentCommand\expectationvalue{ s s m g } +{ % Expectation value + \IfNoValueTF{#4} + { + \IfBooleanTF{#1} + {\vphantom{#3}\left\langle\smash{#3}\right\rangle} % Starred implicit form: no resizing + {\left\langle{#3}\right\rangle} % Normal implicit form: auto sizing + } + { + \IfBooleanTF{#1} + { + \IfBooleanTF{#2} + {\left\langle{#4}\middle\vert{#3}\middle\vert{#4}\right\rangle} % Double starred explicit form: total auto sizing + {\vphantom{#3#4}\left\langle\smash{#4}\middle\vert\smash{#3}\middle\vert\smash{#4}\right\rangle} % Starred explicit form: no resizing + } + {\vphantom{#3}\left\langle{#4}\middle\vert\smash{#3}\middle\vert{#4}\right\rangle} % Normal explicit form: only resize based on bra/ket arguments } +} \DeclareDocumentCommand\expval{}{\expectationvalue} % Shorthand for \expectationvalue \DeclareDocumentCommand\ev{}{\expectationvalue} % Shorthand for \expectationvalue \DeclareDocumentCommand\vev{ m }{\expectationvalue{#1}{0}} % Vacuum expectation value - -\DeclareDocumentCommand\matrixelement{ m m m }{\left\langle{#1}\middle\vert{#2}\middle\vert{#3}\right\rangle} % Matrix element + +\DeclareDocumentCommand\matrixelement{ s s m m m } +{ % Matrix element + \IfBooleanTF{#1} + { + \IfBooleanTF{#2} + {\left\langle{#3}\middle\vert{#4}\middle\vert{#5}\right\rangle} % Double starred: total resizing + {\vphantom{#3#4#5}\left\langle\smash{#3}\middle\vert\smash{#4}\middle\vert\smash{#5}\right\rangle} % Starred: no resizing + } + {\vphantom{#4}\left\langle{#3}\middle\vert\smash{#4}\middle\vert{#5}\right\rangle} % Normal: only resize based on bra/ket arguments +} \DeclareDocumentCommand\matrixel{}{\matrixelement} % Shorthand for \matrixelement \DeclareDocumentCommand\mel{}{\matrixelement} % Shorthand for \matrixelement +% Matrix macros +\DeclareDocumentCommand\identitymatrix{m} +{ + { + \newtoks\matrixtoks + \global\matrixtoks = {} + \newcount\rowcount + \newcount\colcount + \loop + \colcount = 0 + \advance \rowcount by 1 + { + \loop + \advance \colcount by 1 + \edef\addtoks + { + \ifnum \colcount = 1 \else & \fi + \ifnum \colcount = \rowcount 1 \else 0 \fi + } + \global\matrixtoks = \expandafter{\the\expandafter\matrixtoks\addtoks} + \ifnum \colcount < #1 + \repeat + } + \ifnum \rowcount < #1 + \global\matrixtoks = \expandafter{\the\matrixtoks \\ } + \repeat + } + \the\matrixtoks +} +\DeclareDocumentCommand\imat{}{\identitymatrix} + +\DeclareDocumentCommand\xmatrix{ s m m m } +{ + { + \newtoks\matrixtoks + \global\matrixtoks = {} + \newcount\rowcount + \newcount\colcount + \loop + \colcount = 0 + \advance \rowcount by 1 + { + \loop + \advance \colcount by 1 + \edef\addtoks{\ifnum \colcount = 1 \else & \fi #2 \IfBooleanTF{#1}{_{\ifnum #3 > 1 \the\rowcount \fi \ifnum #4 > 1 \the\colcount \fi}}{}} + \global\matrixtoks = \expandafter{\the\expandafter\matrixtoks\addtoks} + \ifnum \colcount < #4 + \repeat + } + \ifnum \rowcount < #3 + \global\matrixtoks = \expandafter{\the\matrixtoks \\ } + \repeat + } + \the\matrixtoks +} +\DeclareDocumentCommand\xmat{}{\xmatrix} + +\DeclareDocumentCommand\zeromatrix{ m g }{\IfNoValueTF{#2}{\xmatrix{0}{#1}{#1}}{\xmatrix{0}{#1}{#2}}} +\DeclareDocumentCommand\zmat{}{\zeromatrix} + +\DeclareDocumentCommand\paulixmatrix{}{0&1\\1&0} +\DeclareDocumentCommand\pauliymatrix{}{0&-i\\i&0} +\DeclareDocumentCommand\paulizmatrix{}{1&0\\0&-1} +\DeclareDocumentCommand\paulimatrix{m} +{ + \let\argin=#1 + \ifx\argin 0 \identitymatrix{2} \else + \ifx\argin 1 \paulixmatrix \else + \ifx\argin 2 \pauliymatrix \else + \ifx\argin 3 \paulizmatrix \else + \ifx\argin x \paulixmatrix \else + \ifx\argin y \pauliymatrix \else + \ifx\argin z \paulizmatrix \fi\fi\fi\fi\fi\fi\fi +} +\DeclareDocumentCommand\pmat{}{\paulimatrix} + +\DeclareDocumentCommand\diagonalmatrix{O{} >{\SplitList{,}}m }{\@dmat{#1}#2} +\DeclareDocumentCommand\@dmat{mmggggggg} +{ + \newtoks\matrixtoks + \global\matrixtoks = {} + \IfNoValueTF{#3} + {#2} + { + \IfNoValueTF{#4} + {\global\matrixtoks = \expandafter{\mqty{#2}\\#1&\mqty{#3}}} + { + \IfNoValueTF{#5} + {\global\matrixtoks = \expandafter{\mqty{#2}\\#1&\mqty{#3}\\#1&\mqty{#4}}} + { + \IfNoValueTF{#6} + {\global\matrixtoks = \expandafter{\mqty{#2}\\#1&\mqty{#3}\\#1&\mqty{#4}\\#1&\mqty{#5}}} + { + \IfNoValueTF{#7} + {\global\matrixtoks = \expandafter{\mqty{#2}\\#1&\mqty{#3}\\#1&\mqty{#4}\\#1&\mqty{#5}\\#1&\mqty{#6}}} + { + \IfNoValueTF{#8} + {\global\matrixtoks = \expandafter{\mqty{#2}\\#1&\mqty{#3}\\#1&\mqty{#4}\\#1&\mqty{#5}\\#1&\mqty{#6}\\#1&\mqty{#7}}} + { + \IfNoValueTF{#9} + {\global\matrixtoks = \expandafter{\mqty{#2}\\#1&\mqty{#3}\\#1&\mqty{#4}\\#1&\mqty{#5}\\#1&\mqty{#6}\\#1&\mqty{#7}\\#1&\mqty{#8}}} + {\global\matrixtoks = \expandafter{\mqty{#2}\\#1&\mqty{#3}\\#1&\mqty{#4}\\#1&\mqty{#5}\\#1&\mqty{#6}\\#1&\mqty{#7}\\#1&\mqty{#8}\\#1&\mqty{#9}}} + } + } + } + } + } + } + \the\matrixtoks +} +\DeclareDocumentCommand\dmat{}{\diagonalmatrix} + +\DeclareDocumentCommand\antidiagonalmatrix{O{} >{\SplitList{,}}m }{\@admat{#1}#2} +\DeclareDocumentCommand\@admat{mmggggggg} +{ + \newtoks\matrixtoks + \global\matrixtoks = {} + \IfNoValueTF{#3} + {#2} + { + \IfNoValueTF{#4} + {\global\matrixtoks = \expandafter{#1&\mqty{#2}\\\mqty{#3}}} + { + \IfNoValueTF{#5} + {\global\matrixtoks = \expandafter{#1&\mqty{#2}\\#1&\mqty{#3}\\\mqty{#4}}} + { + \IfNoValueTF{#6} + {\global\matrixtoks = \expandafter{#1&\mqty{#2}\\#1&\mqty{#3}\\#1&\mqty{#4}\\\mqty{#5}}} + { + \IfNoValueTF{#7} + {\global\matrixtoks = \expandafter{#1&\mqty{#2}\\#1&\mqty{#3}\\#1&\mqty{#4}\\#1&\mqty{#5}\\\mqty{#6}}} + { + \IfNoValueTF{#8} + {\global\matrixtoks = \expandafter{#1&\mqty{#2}\\#1&\mqty{#3}\\#1&\mqty{#4}\\#1&\mqty{#5}\\#1&\mqty{#6}\\\mqty{#7}}} + { + \IfNoValueTF{#9} + {\global\matrixtoks = \expandafter{#1&\mqty{#2}\\#1&\mqty{#3}\\#1&\mqty{#4}\\#1&\mqty{#5}\\#1&\mqty{#6}\\#1&\mqty{#7}\\\mqty{#8}}} + {\global\matrixtoks = \expandafter{#1&\mqty{#2}\\#1&\mqty{#3}\\#1&\mqty{#4}\\#1&\mqty{#5}\\#1&\mqty{#6}\\#1&\mqty{#7}\\#1&\mqty{#8}\\\mqty{#9}}} + } + } + } + } + } + } + \the\matrixtoks +} +\DeclareDocumentCommand\admat{}{\antidiagonalmatrix} + % Misc -\DeclareDocumentCommand\varE{}{\mathcal{E}} % Curly 'E' +\DeclareDocumentCommand\flatfrac{ m m }{\left.#1\middle\slash#2\right.} \DeclareDocumentCommand\homework{}{ % You can try it \ensuremath{ \div{\vb{E}}=\frac{\rho}{\epsilon_0} \qc |