texlive[74034] Master/texmf-dist: physics-patch (16feb25)

commits+karl at tug.org commits+karl at tug.org
Sun Feb 16 22:01:58 CET 2025


Revision: 74034
          https://tug.org/svn/texlive?view=revision&revision=74034
Author:   karl
Date:     2025-02-16 22:01:58 +0100 (Sun, 16 Feb 2025)
Log Message:
-----------
physics-patch (16feb25)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/physics-patch/physics-patch.pdf
    trunk/Master/texmf-dist/doc/latex/physics-patch/physics-patch.tex
    trunk/Master/texmf-dist/tex/latex/physics-patch/physics-patch.sty

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/latex/physics-patch/README.txt

Removed Paths:
-------------
    trunk/Master/texmf-dist/doc/latex/physics-patch/README.md

Deleted: trunk/Master/texmf-dist/doc/latex/physics-patch/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/physics-patch/README.md	2025-02-16 18:41:10 UTC (rev 74033)
+++ trunk/Master/texmf-dist/doc/latex/physics-patch/README.md	2025-02-16 21:01:58 UTC (rev 74034)
@@ -1,49 +0,0 @@
-# physics-patch
-
-Patches for physics package and integration of physics and siunitx packages
-
-* Author: **Willie Shen (Willie169)**
-* Repository: <https://github.com/Willie169/physics-patch>
-* Latest version: 1.0
-* Last update: Feb 13, 2025
-
-## Introduction
-
-The `physics-patch` package fixes issues in the `physics` package and improves compatibility between `physics` and `siunitx`.
-
-It provides improved versions of `\qty`, `\dv`, and `\pdv` and introduces new macros.
-
-## Usage
-
-This package requires the `xparse`, `etoolbox`, and `amsmath` packages.  
-Optionally, load `physics` and/or `siunitx` before this package.
-
-```latex
-\usepackage{physics} % Optional
-\usepackage{siunitx} % Optional
-\usepackage{physics-patch}
-```
-
-By default, `physics-patch` overrides `\qty` with an improved version. To disable this, use the `nooverride` option:
-
-```latex
-\usepackage<nooverride>{physics-patch}
-```
-
-## Communication Channels
-
-* **Bug tracker:** <https://github.com/Willie169/physics-patch/issues>
-* **Announcements:** <https://github.com/Willie169/physics-patch/releases>
-* **Repository:** <https://github.com/Willie169/physics-patch>
-
-## License and Credit
-
-This package is released under the **LaTeX Project Public License  1.3c**.  
-See <https://www.latex-project.org/lppl/lppl-1-3c> for the details of that license.
-
-Some parts of this package are modified from the `physics` package, created by **Sergio C. de la Barrera** and licensed under **LPPL 1.3**.  
-See <https://ctan.org/pkg/physics> for details on that package.
-
-## Documentation
-
-<**physics-patch.pdf**>
\ No newline at end of file

Added: trunk/Master/texmf-dist/doc/latex/physics-patch/README.txt
===================================================================
--- trunk/Master/texmf-dist/doc/latex/physics-patch/README.txt	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/physics-patch/README.txt	2025-02-16 21:01:58 UTC (rev 74034)
@@ -0,0 +1,21 @@
+physics-patch 2.1
+
+Improved version of the physics package
+
+This package is released under the LaTeX Project Public License (LPPL) 1.3c
+See https://www.latex-project.org/lppl/lppl-1-3c for the details of that license
+Many parts of this package are modified from the physics package, created by Sergio C. de la Barrera and licenced under LPPL 1.3
+See https://ctan.org/pkg/physics for the details of that package
+
+This package requires amsmath, etoolbox, xcolor, xparse, and xstring package.
+Commands that have different definitions come with PT in the beginning of their name (e.g. \PTmqty).
+physics-patch has covered all commands in physics since version 2.0, so there's no need to load physics.
+It is ok to load physics before this package. This package will silently overrides macros in physics with an improved version. To use the original version provided by physics, load physics before this package and use the nooverride option (not recommended).
+This package pretends that physics package is loaded so that this package won't be overriden if loading physics is called afterward and packages loaded afterward that checks whether physics is loaded to determine its behavior (e.g. siunitx) work correctly. To disable this, use the nopretend option (not recommended).
+If siuitx is loaded before this package, this package will define \ITquantity and \ITqty as the integration of the improved definition of physics's \qty (in \PHquantity and \PHqty) and siuitx's \SI. You can optionally set siintegrate option to override \PTquantity and \PTqty with \ITqty (not recommended).
+
+Author: Willie Shen (Willie169)
+Repository: https://github.com/Willie169/physics-patch
+Last update: Feb 16, 2025
+
+For documentation, see physics-patch.pdf
\ No newline at end of file


Property changes on: trunk/Master/texmf-dist/doc/latex/physics-patch/README.txt
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/doc/latex/physics-patch/physics-patch.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/physics-patch/physics-patch.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/physics-patch/physics-patch.tex	2025-02-16 18:41:10 UTC (rev 74033)
+++ trunk/Master/texmf-dist/doc/latex/physics-patch/physics-patch.tex	2025-02-16 21:01:58 UTC (rev 74034)
@@ -1,109 +1,15 @@
 \documentclass[a4paper,12pt]{article}
-\usepackage{fontspec,xparse,etoolbox,amsmath,physics,xcolor,array,longtable,multirow,needspace,setspace,titling}
+\usepackage[margin=1.27cm,foot=0.77cm]{geometry}
+\usepackage{amsmath,amssymb,array,etoolbox,fontspec,longtable,listings,multirow,needspace,parskip,setspace,titling,xcolor,xparse,xstring}
+\usepackage{physics-patch}
 \usepackage[colorlinks,urlcolor=blue]{hyperref}
 \setmainfont{TeX Gyre Termes}[Ligatures=TeX]
 \setsansfont{TeX Gyre Heros}[Ligatures=TeX]
 \setmonofont{TeX Gyre Cursor}[Ligatures=TeX]
-\DeclareDocumentCommand{\patchedphysicsquantity}{ t\big t\Big t\bigg t\Bigg o d() d|| g }
-{ % 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}
-      }
-    }
-  }
-  % Handles actual bracketing
-  \IfNoValueTF{#5}{
-    \IfNoValueTF{#6}{
-      \IfNoValueTF{#7}{
-        \IfNoValueTF{#8}{
-          \IfBooleanTF{#1}{\big}{
-            \IfBooleanTF{#2}{\Big}{
-              \IfBooleanTF{#3}{\bigg}{
-                \IfBooleanTF{#4}{\Bigg}{}
-              }
-            }
-          }
-        }
-        {\ltag\lbrace#8\rtag\rbrace}
-      }{
-        \ltag\lvert{#7}\rtag\rvert
-        \IfNoValueTF{#8}{}{#8}
-      }
-    }{
-        \ltag(#6\rtag)
-        \IfNoValueTF{#7}{}{|#7|}
-        \IfNoValueTF{#8}{}{#8}
-    }
-  }{
-    \ltag[#5\rtag]
-    \IfNoValueTF{#6}{}{(#6)}
-    \IfNoValueTF{#7}{}{|#7|}
-    \IfNoValueTF{#8}{}{#8}
-  }
-}
-\let\ppqty\patchedphysicsquantity
-\let\patchedquantity\patchedphysicsquantity
-\let\ptqty\patchedquantity
-\let\qty\patchedquantity
-\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(...)
-  \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}}}}
-  \IfNoValueTF{#5}{}{\argopen(#5\argclose)}
-}
-\let\dv\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(...)
-  \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}
-    {\fractype{\partial \IfNoValueTF{#2}{}{^{#2}} #3}{\partial #4\IfNoValueTF{#2}{}{^{#2}}}}
-    {\fractype{\partial^2 #3}{\partial #4 \partial #5}}
-    \IfNoValueTF{#6}{}{\argopen(#6\argclose)}
-  }
-}
-\let\pdv\partialderivative
-\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}}}}
+\everymath{\displaystyle}
+\everydisplay{\displaystyle}
+\newcolumntype{M}{>{$\displaystyle}c<{$}}
+\newcolumntype{L}{>{$\displaystyle}l<{$}}
 \renewcommand{\maketitle}{
 \begin{titlepage}
 \begin{center}
@@ -117,26 +23,53 @@
 \end{center}
 \end{titlepage}
 }
-\title{{\huge physics-patch}\\\mbox{}\\{\Large\textnormal{Patches for physics package and integration of physics and siunitx packages}}}
-\author{{\LARGE\mbox{}\\Willie Shen (Willie169)}\\\mbox{}\\{\Large https://github.com/Willie169/physics-patch}}
-\date{\Large\mbox{}\\Version 1.0, February 13, 2025}
+\renewcommand{\arraystretch}{2}
+\lstset{
+basicstyle=\ttfamily\scriptsize,
+keywordstyle=\color{blue},
+stringstyle=\color{red},
+commentstyle=\color{green!50!black},
+numbers=none,
+backgroundcolor=\color{white},
+showspaces=false,
+showstringspaces=false,
+showtabs=false,
+frame=none,
+tabsize=4,
+captionpos=b,
+breaklines=true,
+breakatwhitespace=false
+}
+\title{The \texttt{physics-patch} package\\\mbox{}\\\textnormal{\large Improved version of the physics package}}
+\author{\mbox{}\\Willie Shen (Willie169)}
+\date{Version 2.1\\\textnormal{Last update: Feb. 16, 2025}}
 \begin{document}
-\thispagestyle{empty}\Needspace{1\textheight}\maketitle\Needspace{1\textheight}\setcounter{page}{1}
-\section{Introduction}
-The \texttt{physics-patch} package fixes issues in the \texttt{physics} package and improves compatibility between \texttt{physics} and \texttt{siunitx}.\\
-It provides improved versions of \verb|\qty|, \verb|\dv|, and \verb|\pdv| and introduces new macros.
+\onehalfspacing\thispagestyle{empty}\Needspace{1\textheight}\maketitle\setcounter{page}{1}\Needspace{1\textheight}\tableofcontents\Needspace{1\textheight}\setcounter{page}{1}
+\section{Preface}
+Since version 2.0, the \texttt{physics-patch} package has evolved from merely patching the \texttt{physics} package to fully replacing it, covering all its commands. While preserving the original goal—simplifying mathematical and physics typesetting for greater readability and efficiency—this package refines the design by addressing unconventional behaviors, extending commands, and introducing additional macros.\\\\
+Like the original, this package provides commands with intuitive names and well-defined shorthands, ensuring both clarity and ease of recall.\\\\
+This package resolved the unintuitive definitions and behaviors in \texttt{physics} without changing the command names and intended behaviors. For instance, in the original package, suffix parentheses and their contents in expressions like \verb|\dv{f}{x}(\typical)| are ignored.\\\\
+Beyond refining existing functionality, this package extends commands for broader applicability—such as enabling \verb|\xmat| to support ellipses—and introduces entirely new macros, such as \verb|\omat|.
 \section{Usage}
-This package requires \texttt{xparse}, \texttt{etoolbox}, and \texttt{amsmath} package.\\
-Optionally, load \texttt{physics} and/or \texttt{siunitx} before this package.
-\begin{verbatim}
-\usepackage{physics} % Optional
-\usepackage{siunitx} % Optional
+\subsection{Required packages}
+The \texttt{physics-patch} package requires \texttt{amsmath}, \texttt{etoolbox}, \texttt{xcolor}, \texttt{xparse}, and \texttt{xstring} package to work properly in your \LaTeX~document. If you are unsure whether you've had them installed, you can either install it again using your local package manager (comes with most distributions) or by visiting the \href{http://www.ctan.org}{CTAN} online package database, or even just try to use \texttt{physics-patch} package without worrying about it. Many modern \LaTeX compilers will locate and offer to download missing required packages for you.
+\subsection{Using \texttt{physics-patch} in your \LaTeX~document}
+To use \texttt{physics-patch} in your \LaTeX~document, simply insert \verb|\usepackage{physics-patch}| in the preamble of your document, before \verb|\begin{document}| and after \verb|\documentclass{class}|:
+\begin{lstlisting}[language=TeX]
+\documentclass{class}
+...
 \usepackage{physics-patch}
-\end{verbatim}
-By default, \texttt{physics-patch} overrides \verb|\qty| with an improved version. To disable this, use the \texttt{nooverride} option:
-\begin{verbatim}
-\usepackage[nooverride]{physics-patch}
-\end{verbatim}
+...
+\begin{document}
+content...
+\end{document}
+\end{lstlisting}
+\begin{itemize}
+\item \texttt{physics-patch} has covered all commands in \texttt{physics} since version 2.0, so there's no need to load \texttt{physics}.
+\item It is ok to load \texttt{physics} before this package. This package will silently overrides macros in \texttt{physics} with an improved version. To use the original version provided by \texttt{physics}, load \texttt{physics} before this package and use the \texttt{nooverride} option (not recommended). \texttt{nooverride} falls back to \texttt{override} if physics is not loaded.
+\item This package pretends that \texttt{physics} package is loaded so that this package won't be overriden if loading \texttt{physics} is called afterward and packages loaded afterward that checks whether \texttt{physics} is loaded to determine its behavior (e.g. \texttt{siunitx}) work correctly. To disable this, use the \texttt{nopretend} option (not recommended).
+\item If \texttt{siuitx} is loaded before this package, this package will define \verb|\ITquantity| and \verb|\ITqty| as the integration of the improved definition of \texttt{physics}'s \verb|\qty| (in \verb|\PHquantity| and \verb|\PHqty|) and \texttt{siuitx}'s \verb|\SI|. You can optionally set \texttt{siintegrate} option to override \verb|\PTquantity| and \verb|\PTqty| with \verb|\ITqty| (not recommended). \texttt{siintegrate} falls back to \texttt{nosiintegrate} if \texttt{siunitx} is not loaded.
+\end{itemize}
 \section{Communication Channels}
 \begin{itemize}
 \item \textbf{Bug tracker:} \href{https://github.com/Willie169/physics-patch/issues}{https://github.com/Willie169/physics-patch/issues}.
@@ -148,46 +81,380 @@
 \item
 This package is released under the \textbf{LaTeX Project Public License (LPPL) 1.3c.}\\
 See \href{https://www.latex-project.org/lppl/lppl-1-3c}{https://www.latex-project.org/lppl/lppl-1-3c} for the details of that license.
-\item Some parts of this package are modified from the \texttt{physics} package, created by \textbf{Sergio C. de la Barrera} and licenced under \textbf{LPPL 1.3}.\\
+\item Many parts of this package are modified from the \texttt{physics} package, created by \textbf{Sergio C. de la Barrera} and licenced under \textbf{LPPL 1.3}.\\
 See \href{https://ctan.org/pkg/physics}{https://ctan.org/pkg/physics} for the details of that package.
 \end{itemize}
 \section{List of Commands}
-{\fontsize{6pt}{8pt}\selectfont
-\begin{longtable}[l]{ p{0.2\textwidth} l p{0.3\textwidth} l p{0.3\textwidth} }
-\verb|\patchedphysicsquantity| or \verb|\ppqty| & \verb|\ppqty(\typical)| $\displaystyle\rightarrow \ppqty(\typical)$ & automatic $\ppqty(\;)$ braces \\
-& \verb|\ppqty(\tall)| $\displaystyle\rightarrow \ppqty(\tall)$ & \\
-& \verb|\ppqty(\grande)| $\displaystyle\rightarrow \ppqty(\grande)$ & \\
-& \verb|\ppqty[\typical]| $\rightarrow \ppqty[\typical]$ & automatic $\ppqty[\;]$ braces \\
-& \verb+\ppqty|\typical|+ $\rightarrow \ppqty|\typical|$ & automatic $\ppqty|\;|$ braces \\
-& \verb|\ppqty{\typical}| $\rightarrow \ppqty{\typical}$ & automatic $\ppqty{\;}$ braces \\
-& \verb|\ppqty\big{}| $\rightarrow \ppqty\big{}$ & \multirow{2}{*}{\parbox{0.3\textwidth}{manual sizing (works with any of the above bracket types)}} \\
-& \verb|\ppqty\Big{}| $\rightarrow \ppqty\Big{}$ & \\
-& \verb|\ppqty\bigg{}| $\rightarrow \ppqty\bigg{}$ & \\
-& \verb|\ppqty\Bigg{}| $\rightarrow \ppqty\Bigg{}$ & \\
-\verb|\siqty| if \texttt{siunitx} loaded & & same as \verb|\SI| in \texttt{siunitx}\\
-\verb|\siqty| if \texttt{siunitx} not loaded & & not defined in this package\\
-\verb|\integratedquantity| or \verb|\iqty| if \texttt{siunitx} loaded & \verb|\iqty[]{}{}| & same as \verb|\SI| in \texttt{siunitx}\\
-& \verb|\iqty{}{}| & same as \verb|\SI| in \texttt{siunitx}\\
-& same as \verb|\patchedphysicsquantity| & same as \verb|\patchedphysicsquantity|\\
-\verb|\integratedquantity| or \verb|\iqty| if \texttt{siunitx} not loaded & & not defined in this package\\
-\verb|\patchedquantity| or \verb|\ptqty| if \texttt{siunitx} loaded & & same as \verb|\integratedquantity|\\
-\verb|\patchedquantity| or \verb|\ptqty| if \texttt{siunitx} not loaded & & same as \verb|\patchedphysicsquantity|\\
-\verb|\qty| if without \texttt{nooverride} option & & same as \verb|\patchedquantity|\\
-\verb|\qty| if with \texttt{nooverride} option & & not defined in this package\\
-\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}(\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|\dv{f}{x}(\grande)| $\displaystyle\rightarrow \dv{f}{x}(\grande)$ & note: in original \texttt{physics} package, \verb|\dv{f}{x}(\grande)| $\displaystyle\rightarrow \dv{f}{x}$\\
-\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}(\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|\pdv{f}{x}(\grande)| $\displaystyle\rightarrow \pdv{f}{x}(\grande)$ & note: in original \texttt{physics} package, \verb|\pdv{f}{x}(\grande)| $\displaystyle\rightarrow \pdv{f}{x}$
+In the commands listed below, the left column is long-form names with non-default alternate names (if any), the middle column is default shorthand commands with detailed syntaxes and explanations.\\
+Commands that have different definitions come with \texttt{PT} in the beginning of their name (e.g. \verb|\PTmqty|). If \texttt{nooverride} is not used or the \texttt{physics} package is not loaded before this package, the commands without \texttt{PT} will be silent overriden to be the same as the ones with \texttt{PT}.
+{\fontsize{6pt}{9pt}\selectfont
+\subsection{Automatic bracing}
+\begin{longtable}[l]{ p{6cm} l p{6cm} l p{6cm} }
+\verb|\PTquantity| or \verb|\PHquantity| or \verb|\PHqty| & \verb|\PTqty(\typical)| $\displaystyle\rightarrow \PTqty(\typical)$ & automatic $\PTqty(\;)$ braces \\
+& \verb|\PTqty(\tall)| $\displaystyle\rightarrow \PTqty(\tall)$ & \\
+& \verb|\PTqty(\grande)| $\displaystyle\rightarrow \PTqty(\grande)$ & \\
+& \verb|\PTqty[\typical]| $\rightarrow \PTqty[\typical]$ & automatic $\PTqty[\;]$ braces \\
+& \verb+\PTqty|\typical|+ $\rightarrow \PTqty|\typical|$ & automatic $\PTqty|\;|$ braces \\
+& \verb|\PTqty{\typical}| $\rightarrow \PTqty{\typical}$ & automatic $\PTqty{\;}$ braces \\
+& \verb|\PTqty\big{}| $\rightarrow \PTqty\big{}$ & \multirow{2}{*}{\parbox{6cm}{manual sizing (works with any of the above bracket types)}} \\
+& \verb|\PTqty\Big{}| $\rightarrow \PTqty\Big{}$ & \\
+& \verb|\PTqty\bigg{}| $\rightarrow \PTqty\bigg{}$ & \\
+& \verb|\PTqty\Bigg{}| $\rightarrow \PTqty\Bigg{}$ & \\
+& \verb|\pqty{}| $\leftrightarrow$ \verb|\PTqty()| & \multirow{2}{*}{\parbox{6cm}{alternative syntax; robust and more \LaTeX-friendly}} \\
+& \verb|\bqty{}| $\leftrightarrow$ \verb|\PTqty[]| & \\
+& \verb+\vqty{}+ $\leftrightarrow$ \verb+\PTqty||+ & \\
+& \verb|\Bqty{}| $\leftrightarrow$ \verb|\PTqty{}| & \\
+\verb|\absolutevalue| & \verb|\abs{a}| $\rightarrow \abs{a}$ & automatic sizing; equivalent to \verb|\PTqty| \!\!\texttt{|a|} \\
+& \verb|\abs\Big{a}| $\rightarrow \abs\Big{a}$ & inherits manual sizing syntax from \verb|\PTqty| \\
+& \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|\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| or \verb|\acommutator| & \verb|\acomm{A}{B}| $\rightarrow \acomm{A}{B}$ & same as \verb|\poissonbracket| \\
+\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-patch} vector notation can be switched to appear with an arrow $\vec{\vnabla}$ by including the option \texttt{arrowdel} in the document preamble:
+\begin{lstlisting}[language=TeX]
+\usepackage[arrowdel]{physics-patch}
+\end{lstlisting}
+\begin{longtable}[l]{ p{6cm} l p{6cm} 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 \\
+\verb|\vectorarrow| & \verb|\va{a}| $\rightarrow \va{a}$ & upright/no Greek \\
+& \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: \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+\tall)| $\displaystyle\rightarrow \grad(\Psi+\tall)$ & long-form (like \verb|\PTqty| but also handles spacing) \\
+& \verb|\grad[\Psi+\tall]| $\displaystyle\rightarrow \grad[\Psi+\tall]$ & \\
+\verb|\divergence| & \verb|\divg| $\rightarrow \divg$ & note: if \texttt{nooriginaldiv} option is used, \verb|\div| will be overriden as $\divg$ too (not recommended) \\
+\verb|\divisionsymbol| & \verb|\divisionsymbol| $\rightarrow \divisionsymbol$ &  \\
+& \verb|\divg{\vb{a}}| $\rightarrow \divg{\vb{a}}$ & default mode \\
+& \verb|\divg(\vb{a}+\tall)| $\displaystyle\rightarrow \divg(\vb{a}+\tall)$ & long-form \\
+& \verb|\divg[\vb{a}+\tall]| $\displaystyle\rightarrow \divg[\vb{a}+\tall]$ & \\
+\verb|\curl| & \verb|\curl| $\rightarrow \curl$ & \\
+& \verb|\curl{\vb{a}}| $\rightarrow \curl{\vb{a}}$ & default mode \\
+& \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+\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-patch} to provide automatic braces that behave like \verb|\PTqty()|. In addition, an optional power argument is provided. This behavior can be switched off by including the option \texttt{notrig} in the preamble:
+\begin{lstlisting}[language=TeX]
+\usepackage[notrig]{physics-patch}
+\end{lstlisting}
+\begin{longtable}[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|\sin x| $\rightarrow \sin x$ & can still use without an argument
+\end{longtable}
+The full set of available trig functions in \texttt{physics-patch} includes:
+\begin{longtable}{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{longtable}$\Rightarrow$
+\begin{longtable}{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{longtable}
+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{longtable}{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{longtable}
+Similar behavior has also been extended to the following functions:
+\begin{longtable}{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{longtable}
+\begin{longtable}[l]{ l l p{8cm} }
+\multicolumn{3}{l}{New operators:} \\
+\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|\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]{ p{6cm} l p{6cm} 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}
+\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]
+\end{longtable}
+\begin{longtable}[l]{ l }
+Similar to \verb|\qif|: \\
+\verb|\qthen|, \verb|\qelse|, \verb|\qotherwise|, \verb|\qunless|, \verb|\qgiven|, \verb|\qusing|, \verb|\qassume|, \verb|\qsince|, \\
+\verb|\qlet|, \verb|\qfor|, \verb|\qall|, \verb|\qeven|, \verb|\qodd|, \verb|\qinteger|, \verb|\qand|, \verb|\qor|, \verb|\qas|, \verb|\qin|
+\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:
+\begin{lstlisting}[language=TeX]
+\usepackage[italicdiff]{physics-patch}
+\end{lstlisting}
+\begin{longtable}[l]{ p{6cm} l p{6cm} l p{6cm} }
+\verb|\differential| & \verb|\dd| $\rightarrow \dd$ & \\
+& \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|\PTderivative| & \verb|\PTdv{x}| $\displaystyle\rightarrow \PTdv{x}$ & one argument \\
+& \verb|\PTdv{f}{x}| $\displaystyle\rightarrow \PTdv{f}{x}$ & two arguments \\
+& \verb|\PTdv[n]{f}{x}| $\displaystyle\rightarrow \PTdv[n]{f}{x}$ & optional power \\
+& \verb|\PTdv{x}(\grande)| $\displaystyle\rightarrow \PTdv{x}(\grande)$ & long-form; automatic braces, spacing \\
+& \verb|\PTdv*{f}{x}| $\displaystyle\rightarrow \PTdv*{f}{x}$ & inline form using \verb|\flatfrac| \\
+\verb|\PTpartialderivative| or \verb|\PTpderivative| & \verb|\PTdv{f}{x}(\grande)| $\displaystyle\rightarrow \PTdv{f}{x}(\grande)$ & note: in original \texttt{physics} package, \verb|\dv{f}{x}(\grande)| $\displaystyle\rightarrow \dv{f}{x}$\\
+& \verb|\PTpdv{x}| $\displaystyle\rightarrow \PTpdv{x}$ & shorthand name \\
+& \verb|\PTpdv{f}{x}| $\displaystyle\rightarrow \PTpdv{f}{x}$ & two arguments \\
+& \verb|\PTpdv[n]{f}{x}| $\displaystyle\rightarrow \PTpdv[n]{f}{x}$ & optional power \\
+& \verb|\PTpdv{x}(\grande)| $\displaystyle\rightarrow \PTpdv{x}(\grande)$ & long-form \\
+& \verb|\PTpdv{f}{x}{y}| $\displaystyle\rightarrow \PTpdv{f}{x}{y}$ & mixed partial \\
+& \verb|\PTpdv*{f}{x}| $\displaystyle\rightarrow \PTpdv*{f}{x}$ & inline form using \verb|\flatfrac| \\
+& \verb|\PTpdv{f}{x}(\grande)| $\displaystyle\rightarrow \PTpdv{f}{x}(\grande)$ & note: in original \texttt{physics} package, \verb|\pdv{f}{x}(\grande)| $\displaystyle\rightarrow \pdv{f}{x}$ \\
+\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|\PTdv|) \\
+& \verb|\fdv{F}{g}| $\displaystyle\rightarrow \fdv{F}{g}$ & \\
+& \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}
+The following collection of macros for Dirac notation contains two fundamental commands, \verb|\bra| and \verb|\ket|, along with a set of more specialized macros which are essentially combinations of the fundamental pair. The fundamental commands are designed to contract with one another algebraically when appropriate and are thus suggested for general use. For instance, the following code renders correctly\footnote{Note the lack of a space between the bra and ket commands. This is necessary in order for the bra to find the corresponding ket and form a contraction.}
+\begin{displaymath}
+\verb|\bra{\phi}\ket{\psi}| \rightarrow \bra{\phi}\ket{\psi} \qq{as opposed to} \bra{\phi} \ket{\psi}
+\end{displaymath}
+whereas a similar construction with higher-level macros will not contract in a robust manner
+\begin{displaymath}
+\verb|\bra{\phi}\dyad{\psi}{\xi}| \rightarrow \bra{\phi}\dyad{\psi}{\xi}.
+\end{displaymath}
+On the other hand, the correct output can be generated by sticking to the fundamental commands,
+\begin{displaymath}
+\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]{ p{6cm} l p{6cm} 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}
+{\fontsize{4pt}{6pt}\selectfont
+Note: \verb|\mqty| and \verb|\smqty| in \texttt{physics} uses \verb|\mathord|, while \verb|\PTmqty| and \verb|\PTsmqty| in \texttt{physics-patch} don't.\\\\
+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 $\PTsmqty{\imat{2}}$ without braces or grouping. This allows the command to also be used within another matrix, as in:
+\begin{minipage}{3cm}
+\begin{lstlisting}[language=TeX]
+\begin{pmatrix}
+\imat{2} \\ a & b
+\end{pmatrix}
+\end{lstlisting}
+\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|\PTmatrixquantity| or \verb|\PTmqty| to effectively convert \verb|\imat{2}| into a single matrix element of a larger matrix:
+\begin{minipage}{9cm}
+\begin{lstlisting}[language=TeX]
+\begin{pmatrix}
+\PTmqty{\imat{2}} & \PTmqty{a\\b} \\ \PTmqty{c & d} & e
+\end{pmatrix}
+\end{lstlisting}
+\end{minipage}
+\begin{minipage}{6cm}
+\begin{displaymath}
+\Rightarrow\qquad
+\begin{pmatrix}
+\PTmqty{\imat{2}} & \PTmqty{a\\b} \\ \PTmqty{c & d} & e
+\end{pmatrix}
+\end{displaymath}
+\end{minipage}
+The extra \verb|\PTmqty| groups were required in this case in order to get the $a$ and $b$ elements to behave as a single element, since \verb|\PTmqty{\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-patch} macro \verb|\PTmqty()|, allowing the above example to be written on one line:
+\begin{minipage}{9cm}
+\begin{lstlisting}[language=TeX]
+\PTmqty(\PTmqty{\imat{2}} & \PTmqty{a\\b} \\ \PTmqty{c & d} & e)
+\end{lstlisting}
+\end{minipage}
+\begin{minipage}{6cm}
+\begin{displaymath}
+\Rightarrow\qquad
+\PTmqty(\PTmqty{\imat{2}} & \PTmqty{a\\b} \\ \PTmqty{c & d} & e)
+\end{displaymath}
+\end{minipage}
+\begin{longtable}[l]{ p{6cm} l p{6cm} l p{6cm} }
+\verb|\PTmatrixquantity| & \verb|\PTmqty{a & b \\ c & d}| $\rightarrow \PTmqty{a & b \\ c & d}$ & groups a set of matrix elements into a single object \\
+& \verb|\PTmqty(a & b \\ c & d)| $\rightarrow {\PTmqty(a & b \\ c & d)}$ & parentheses \\
+& \verb|\PTmqty*(a & b \\ c & d)| $\rightarrow {\PTmqty*(a & b \\ c & d)}$ & alternate parentheses \\
+& \verb|\PTmqty[a & b \\ c & d]| $\rightarrow {\PTmqty[a & b \\ c & d]}$ & square brackets \\
+& \verb|\PTmqty| \texttt{|} \verb|a & b \\ c & d| \texttt{|} $\rightarrow {\PTmqty|a & b \\ c & d|}$ & vertical bars \\
+& \verb|\omqty{}| $\leftrightarrow$ \verb|\PTmqty{}| & \multirow{2}{*}{\parbox{6cm}{alternative syntax; robust and more \LaTeX-friendly}} \\
+& \verb|\pmqty{}| $\leftrightarrow$ \verb|\PTmqty()| & \\
+& \verb|\PTpmqty{}| $\leftrightarrow$ \verb|\PTmqty()| & \\
+& \verb|\PTpmqty*{}| $\leftrightarrow$ \verb|\PTmqty*{}| & \\
+& \verb|\Pmqty{}| $\leftrightarrow$ \verb|\PTmqty*()| & \\
+& \verb|\bmqty{}| $\leftrightarrow$ \verb|\PTmqty[]| & \\
+& \verb|\vmqty{}| $\leftrightarrow$ \verb+\PTmqty||+ & \\
+\verb|\PTsmallmatrixquantity| & \verb|\PTsmqty{a & b \\ c & d}| $\rightarrow \PTsmqty{a & b \\ c & d}$ & the \texttt{smallmatrix} form of \verb|\PTmqty| \\
+& \verb|\PTsmqty()| \qor \verb|\spmqty{}| \qor \verb|\PTspmqty{}| & small version of \verb|\PTmqty()| \\
+& \verb|\PTsmqty*()| \qor \verb|\sPmqty{}| \qor \verb|\PTspmqty*{}| & small version of \verb|\PTmqty*()|\\
+& \verb|\PTsmqty[]| \qor \verb|\sbmqty{}| & small version of \verb|\PTmqty[]| \\
+& \verb+\PTsmqty||+ \qor \verb|\svmqty{}| & small version of \verb+\PTmqty||+ \\
+\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|\PTmqty(\imat{3})| $\rightarrow \PTmqty(\imat{3})$ & formatted with \verb|\PTmqty| or \verb|\PTsmqty| \\
+\verb|\PTxmatrix| & \verb|\PTxmat{x}{n}{m}| & \multirow{4}{*}{\parbox{6cm}{elements of $n \times m$ matrix filled with $x$, if not provided, $1$ is used}} \\
+& \verb|\PTmqty(\PTxmat{x}{3}{3})| $\rightarrow \PTmqty(\PTxmat{x}{3}{3})$ & \\
+& \verb|\PTmqty(\PTxmat{x}{}{3})| $\rightarrow \PTmqty(\PTxmat{x}{}{3})$ & \\
+& \verb|\PTmqty(\PTxmat{x}{3}{})| $\rightarrow \PTmqty(\PTxmat{x}{3}{})$ & \\
+& \verb|\PTxmat*{x}{n}{m}| & \multirow{4}{*}{\parbox{6cm}{star for element indices, skip row/column indices $n=1$/$m=1$}} \\
+& \verb|\PTmqty(\PTxmat*{x}{3}{3})| $\rightarrow \PTmqty(\PTxmat*{x}{3}{3})$ & \\
+& \verb|\PTmqty(\PTxmat*{x}{1}{3})| $\rightarrow \PTmqty(\PTxmat*{x}{1}{3})$ & \\
+& \verb|\PTmqty(\PTxmat*{x}{3}{1})| $\rightarrow \PTmqty(\PTxmat*{x}{3}{1})$ & \\
+& \verb|\PTxmat{x}{n}{m}[p]| & \multirow{4}{*}{\parbox{6cm}{only show $p$ rows (including \texttt{\textbackslash vdots} row) with skipped rows indicated by \texttt{\textbackslash vdots}. If $n$ isn't provided, $p$ is used}} \\
+& \verb|\PTmqty(\PTxmat{x}{5}{3}[3])| $\rightarrow \PTmqty(\PTxmat{x}{5}{3}[3])$ & \\
+& \verb|\PTmqty(\PTxmat{x}{3}{3}[3])| $\rightarrow \PTmqty(\PTxmat{x}{3}{3}[3])$ & \\
+& \verb|\PTmqty(\PTxmat{x}{}{3}[3])| $\rightarrow \PTmqty(\PTxmat{x}{}{3}[3])$ & \\
+& \verb|\PTxmat{x}{n}{m}[p][q]| & \multirow{6}{*}{\parbox{6cm}{only show $p$ rows (including \texttt{\textbackslash vdots} row) and $q$ columns (including \texttt{\textbackslash ldots} column) with skipped rows indicated by \texttt{\textbackslash vdots}, skipped columns indicated by \texttt{\textbackslash ldots}, intersection of \texttt{\textbackslash vdots} row and \texttt{\textbackslash ldots} column being \texttt{\textbackslash ddots}. If $n$/$m$ isn't provided, $p$/$q$ is used. No indices will be added for ellipses even if star is given}} \\
+& \verb|\PTmqty(\PTxmat{x}{5}{5}[3][3])| $\rightarrow \PTmqty(\PTxmat{x}{5}{5}[3][3])$ & \\
+& \verb|\PTmqty(\PTxmat{x}{5}{3}[3][3])| $\rightarrow \PTmqty(\PTxmat{x}{5}{3}[3][3])$ & \\
+& \verb|\PTmqty(\PTxmat{x}{3}{3}[3][3])| $\rightarrow \PTmqty(\PTxmat{x}{3}{3}[3][3])$ & \\
+& \verb|\PTmqty(\PTxmat{x}{5}{}[3][3])| $\rightarrow \PTmqty(\PTxmat{x}{5}{}[3][3])$ & \\
+& \verb|\PTmqty(\PTxmat{x}{}{}[3][3])| $\rightarrow \PTmqty(\PTxmat{x}{}{}[3][3])$ & \\
+& \verb|\PTxmat*{x}{n}{m}{g}| & \multirow{3}{*}{\parbox{6cm}{customize last row's element indices to $g$}} \\
+& \verb|\PTmqty(\PTxmat*{x}{3}{3}{A})| $\rightarrow \PTmqty(\PTxmat*{x}{3}{3}{A})$ & \\
+& \verb|\PTmqty(\PTxmat*{x}{5}{5}[3][3]{A})| $\rightarrow \PTmqty(\PTxmat*{x}{5}{5}[3][3]{A})$ & \\
+& \verb|\PTxmat*{x}{n}{m}{g}{h}| & \multirow{3}{*}{\parbox{6cm}{customize last row's element indices to $g$ and last column's element indices to $h$}} \\
+& \verb|\PTmqty(\PTxmat*{x}{3}{3}{A}{B})| $\rightarrow \PTmqty(\PTxmat*{x}{3}{3}{A}{B})$ & \\
+& \verb|\PTmqty(\PTxmat*{x}{5}{5}[3][3]{A}{B})| $\rightarrow \PTmqty(\PTxmat*{x}{5}{5}[3][3]{A}{B})$ & \\
+& \verb|\PTxmat[0 or 1 or 2]{x}{n}{m}[p][q]| & \multirow{4}{*}{\parbox{6cm}{Change the \texttt{\textbackslash vdots} row/\texttt{\textbackslash ldots} column from the second last one to last one, 0 for both, 1 for row only, 2 for column only. Only work when corresponding $p$/$q$ is provided and do not change the behavior of element indices}} \\
+& \verb|\PTmqty(\PTxmat[0]{x}{5}{5}[3][3])| $\rightarrow \PTmqty(\PTxmat[0]{x}{5}{5}[3][3])$ & \\
+& \verb|\PTmqty(\PTxmat[1]{x}{5}{5}[3][3])| $\rightarrow \PTmqty(\PTxmat[1]{x}{5}{5}[3][3])$ & \\
+& \verb|\PTmqty(\PTxmat[2]{x}{5}{5}[3][3])| $\rightarrow \PTmqty(\PTxmat[2]{x}{5}{5}[3][3])$ & \\
+\verb|\zeromatrix| & \verb|\zmat{n}{m}| & \multirow{3}{*}{\parbox{6cm}{$n \times m$ matrix filled with zeros, equivalent to \texttt{\textbackslash xmat\{0\}\{n\}\{m\}}. If $m$ isn't provided, $n$ is used}} \\
+& \verb|\PTmqty(\zmat{2}{2})| $\rightarrow \PTmqty(\zmat{2}{2})$ & \\
+& \verb|\PTmqty(\zmat{2})| $\rightarrow \PTmqty(\zmat{2})$ & \\
+\verb|\paulimatrix| & \verb|\pmat{n}| & $n^\text{th}$ Pauli matrix \\
+& \verb|\PTmqty(\pmat{0})| $\rightarrow \PTmqty(\pmat{0})$ & $n\in \lbrace 0,1,2,3$ or $x,y,z \rbrace$ \\
+& \verb|\PTmqty(\pmat{1})| $\rightarrow \PTmqty(\pmat{1})$ & \\
+& \verb|\PTmqty(\pmat{2})| $\rightarrow \PTmqty(\pmat{2})$ & \\
+& \verb|\PTmqty(\pmat{3})| $\rightarrow \PTmqty(\pmat{3})$ & \\
+\verb|\diagonalmatrix| & \verb|\dmat{a,b,c,...}| & \multirow{2}{*}{\parbox{6cm}{specify up to eight diagonal or block diagonal elements}} \\
+& \verb|\PTmqty(\dmat{1,2,3})| $\rightarrow \PTmqty(\dmat{1,2,3})$ & \\
+& \verb|\PTmqty(\dmat[0]{1,2})| $\rightarrow \PTmqty(\dmat[0]{1,2})$ & optional argument to fill spaces \\
+& \verb|\PTmqty(\dmat{1,2&3\\4&5})| $\rightarrow \PTmqty(\dmat{1,2&3\\4&5})$ & 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|\PTmqty(\admat{1,2,3})| $\rightarrow \PTmqty(\admat{1,2,3})$ & \\
+\end{longtable}
+\subsection{Symbols}
+\begin{longtable}[l]{ p{0.5\textwidth} l p{0.5\textwidth} }
+\verb|\lparen| $\rightarrow ($ &\\
+\verb|\rparen| $\rightarrow )$ &\\
+\verb|\ordersymbol| $\rightarrow \ordersymbol$ & \\
+\verb|\typical| $\rightarrow \typical$ & \\
+\verb|\tall| $\rightarrow \tall$ & \\
+\verb|\grande| $\rightarrow \grande$ & \\
+\verb|\venti| $\rightarrow \venti$ & \\
+\verb|\Vtextvisiblespace[width]| $\rightarrow$ \Vtextvisiblespace & a visible space character, where the optional argument (defaulting to \texttt{.3em}) sets the width of the horizontal rule
+\end{longtable}
 }
+\subsection{Shorthands for Greek letters}
+If option \texttt{shortgreek} is used, the following shorthands will be defined for every Greeks letter:
+\begin{lstlisting}[language=TeX]
+\DeclareDocumentCommand{\tgAlpha}{O{}}{\text{\textAlpha}}
+\DeclareDocumentCommand{\tgalpha}{O{}}{\text{\textalpha}}
+\DeclareDocumentCommand{\vAlpha}{}{\varAlpha}
+\DeclareDocumentCommand{\valpha}{}{\varalpha}
+\DeclareDocumentCommand{\uAlpha}{}{\upAlpha}
+\DeclareDocumentCommand{\ualpha}{}{\upalpha}
+\DeclareDocumentCommand{\uvAlpha}{}{\upvarAlpha}
+\DeclareDocumentCommand{\uvalpha}{}{\upvaralpha}
+\end{lstlisting}
+\subsection{Others}
+\begin{longtable}[l]{ p{6cm} l p{6cm} l p{6cm} }
+\verb|\autommode| & \verb|\amm{content}| & \verb|\relax\ifmmode #1\else\(#1\)\fi| \\
+\verb|\mathcolorbox| & \verb|\mcbox{color}{content}| & \multirow{2}{*}{\parbox{6cm}{\texttt{\textbackslash colorbox} for math environment, applying to all four levels of math styles}} \\
+& \verb|\mcbox{cyan}{\phantom{A}}| $\rightarrow \mcbox{cyan}{\phantom{A}}$ & \\
+\verb|\autocolorbox| or \verb|\acbox| & \verb|\cbox{color}{content}| & samw as \verb|\colorbox| in text environment, same as \verb|\mathcolorbox| in math environment \\
+\verb|\tentothepowerof| & \verb|\tenpow{n}| $\rightarrow \tenpow{n}$ & work in both math mode and text mode \\
+\verb|\scientificnotation| & \verb|\scinote{3.00}{8}| $\rightarrow \scinote{3.00}{8}$ & \parbox{6cm}{work in both math mode and text mode}
+\end{longtable}
+}
 \end{document}
\ No newline at end of file

Modified: trunk/Master/texmf-dist/tex/latex/physics-patch/physics-patch.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/physics-patch/physics-patch.sty	2025-02-16 18:41:10 UTC (rev 74033)
+++ trunk/Master/texmf-dist/tex/latex/physics-patch/physics-patch.sty	2025-02-16 21:01:58 UTC (rev 74034)
@@ -1,35 +1,299 @@
 \ProvidesPackage{physics-patch}
-% physics-patch 1.0
-% Patches for physics package and integration of physics and siunitx packages
-% Author: Willie Shen (Willie169)
-% Repository: https://github.com/Willie169/physics-patch
-% Last update: Feb 13, 2025
+% physics-patch 2.1
 %
-% The physics-patch package fixes issues in the physics package and improves compatibility between physics and siunitx
-% It provides improved versions of \qty, \dv, and \pdv and introduces new macros
+% Improved version of the physics package
 %
-% This package requires xparse, etoolbox, and amsmath package
-% Optionally, load physics and/or siunitx optionally before this package
-% By default, physics-patch overrides \qty with an improved version. To disable this, use the nooverride option
-%
 % This package is released under the LaTeX Project Public License (LPPL) 1.3c
 % See https://www.latex-project.org/lppl/lppl-1-3c for the details of that license
-% Some parts of this package are modified from the physics package, created by Sergio C. de la Barrera and licenced under LPPL 1.3
+% Many parts of this package are modified from the physics package, created by Sergio C. de la Barrera and licenced under LPPL 1.3
 % See https://ctan.org/pkg/physics for the details of that package
+%
+% This package requires amsmath, etoolbox, xcolor, xparse, and xstring package.
+% Commands that have different definitions come with PT in the beginning of their name (e.g. \PTmqty).
+% physics-patch has covered all commands in physics since version 2.0, so there's no need to load physics.
+% It is ok to load physics before this package. This package will silently overrides macros in physics with an improved version. To use the original version provided by physics, load physics before this package and use the nooverride option (not recommended).
+% This package pretends that physics package is loaded so that this package won't be overriden if loading physics is called afterward and packages loaded afterward that checks whether physics is loaded to determine its behavior (e.g. siunitx) work correctly. To disable this, use the nopretend option (not recommended).
+% If siuitx is loaded before this package, this package will define \ITquantity and \ITqty as the integration of the improved definition of physics's \qty (in \PHquantity and \PHqty) and siuitx's \SI. You can optionally set siintegrate option to override \PTquantity and \PTqty with \ITqty (not recommended).
+%
+% Author: Willie Shen (Willie169)
+% Repository: https://github.com/Willie169/physics-patch
+% Last update: Feb 16, 2025
+%
+% For documentation, see physics-patch.pdf
 
+\RequirePackage{amsmath}
+\RequirePackage{etoolbox}
+\RequirePackage{xcolor}
 \RequirePackage{xparse}
-\RequirePackage{etoolbox}
-\RequirePackage{amsmath}
+\RequirePackage{xstring}
 
-% override: override \qty to \patchedqty (default)
-% nooverride: not override \qty to \patchedqty
+% Options
 \newif\ifoverride
-\DeclareOption{override}{\overridetrue}
-\DeclareOption{nooverride}{\overridefalse}
-\ExecuteOptions{override}
+\DeclareOption{override}{\overridetrue} % Override macros in physics to patched ones. (default) This option can be set no matter whether physics is loaded
+\DeclareOption{nooverride}{\overridefalse} % Not override macros in physics to patched ones. (not recommended) Fall back to override if physics is not loaded
+\newif\ifpretend
+\DeclareOption{pretend}{\pretendtrue} % Pretend that physics package is loaded so that this package won't be overriden if \@onefilewithoptions{physics} is called afterward (e.g. \usepackage{physics}) and packages loaded afterward that checks whether physics is loaded to determine its behavior (e.g. siunitx) work correctly (default)
+\DeclareOption{nopretend}{\pretendfalse} % Not pretend that physics package is loaded
+\newif\ifsiintegrate
+\DeclareOption{siintegrate}{\siintegratetrue} % Override \PTquantity and \PTqty with \ITqty (not recommended). Fall back to nosiintegrate if siunitx is not loaded
+\DeclareOption{nosiintegrate}{\siintegratefalse} % Not override \PTquantity and \PTqty with \ITqty (default)
+\newif\iforiginaldiv
+\DeclareOption{originaldiv}{\originaldivtrue} % Let \div be division symbol (default)
+\DeclareOption{nooriginaldiv}{\originaldivfalse} % Let \div be \divergence
+\DeclareOption{trig}{\let\trigopt = 1} % Redefine trig function and operator (default)
+\DeclareOption{notrig}{\let\trigopt = 0} % Not redefine trig function and operator
+\DeclareOption{uprightdiff}{\def\diffd{\mathrm{d}}} % Upright differentials (default)
+\DeclareOption{italicdiff}{\def\diffd{d}} % Italic differentials
+\DeclareOption{bolddel}{\DeclareDocumentCommand\vnabla{}{\boldsymbol\nabla}} % Vector bold \nabla symbol (default)
+\DeclareOption{arrowdel}{\DeclareDocumentCommand\vnabla{}{\vec{\boldsymbol\nabla}}} % Vector arrow \nabla symbol
+\newif\ifshortgreek
+\DeclareOption{shortgreek}{\shortgreektrue} % Define shorthands for Greek letters
+\DeclareOption{noshortgreek}{\shortgreekfalse} % Not define shorthands for Greek letters (default)
+\DeclareOption*{}
+\ExecuteOptions{override,pretend,nosiintegrate,originaldiv,trig,uprightdiff,bolddel,noshortgreek,noshortalphabet}
 \ProcessOptions\relax
 
-\DeclareDocumentCommand{\patchedphysicsquantity}{ t\big t\Big t\bigg t\Bigg o d() d|| g }
+\newif\ifphysics
+\IfPackageLoadedTF{physics}{\physicstrue}{\overridetrue\physicsfalse}
+
+\ifpretend
+  \makeatletter
+  \@namedef{ver at physics.sty}{9999/99/99}
+  \makeatother
+\fi
+
+% Shorthands for Greek letters
+\ifshortgreek
+\DeclareDocumentCommand{\tgAlpha}{O{}}{\text{\textAlpha}}
+\DeclareDocumentCommand{\tgBeta}{O{}}{\text{\textBeta}}
+\DeclareDocumentCommand{\tgGamma}{O{}}{\text{\textGamma}}
+\DeclareDocumentCommand{\tgDelta}{O{}}{\text{\textDelta}}
+\DeclareDocumentCommand{\tgEpsilon}{O{}}{\text{\textEpsilon}}
+\DeclareDocumentCommand{\tgZeta}{O{}}{\text{\textZeta}}
+\DeclareDocumentCommand{\tgEta}{O{}}{\text{\textEta}}
+\DeclareDocumentCommand{\tgTheta}{O{}}{\text{\textTheta}}
+\DeclareDocumentCommand{\tgIota}{O{}}{\text{\textIota}}
+\DeclareDocumentCommand{\tgKappa}{O{}}{\text{\textKappa}}
+\DeclareDocumentCommand{\tgLambda}{O{}}{\text{\textLambda}}
+\DeclareDocumentCommand{\tgMu}{O{}}{\text{\textMu}}
+\DeclareDocumentCommand{\tgNu}{O{}}{\text{\textNu}}
+\DeclareDocumentCommand{\tgXi}{O{}}{\text{\textXi}}
+\DeclareDocumentCommand{\tgOmicron}{O{}}{\text{\textOmicron}}
+\DeclareDocumentCommand{\tgPi}{O{}}{\text{\textPi}}
+\DeclareDocumentCommand{\tgRho}{O{}}{\text{\textRho}}
+\DeclareDocumentCommand{\tgSigma}{O{}}{\text{\textSigma}}
+\DeclareDocumentCommand{\tgTau}{O{}}{\text{\textTau}}
+\DeclareDocumentCommand{\tgUpsilon}{O{}}{\text{\textUpsilon}}
+\DeclareDocumentCommand{\tgPhi}{O{}}{\text{\textPhi}}
+\DeclareDocumentCommand{\tgChi}{O{}}{\text{\textChi}}
+\DeclareDocumentCommand{\tgPsi}{O{}}{\text{\textPsi}}
+\DeclareDocumentCommand{\tgOmega}{O{}}{\text{\textOmega}}
+\DeclareDocumentCommand{\tgalpha}{O{}}{\text{\textalpha}}
+\DeclareDocumentCommand{\tgbeta}{O{}}{\text{\textbeta}}
+\DeclareDocumentCommand{\tggamma}{O{}}{\text{\textgamma}}
+\DeclareDocumentCommand{\tgdelta}{O{}}{\text{\textdelta}}
+\DeclareDocumentCommand{\tgepsilon}{O{}}{\text{\textepsilon}}
+\DeclareDocumentCommand{\tgzeta}{O{}}{\text{\textzeta}}
+\DeclareDocumentCommand{\tgeta}{O{}}{\text{\texteta}}
+\DeclareDocumentCommand{\tgtheta}{O{}}{\text{\texttheta}}
+\DeclareDocumentCommand{\tgiota}{O{}}{\text{\textiota}}
+\DeclareDocumentCommand{\tgkappa}{O{}}{\text{\textkappa}}
+\DeclareDocumentCommand{\tglambda}{O{}}{\text{\textlambda}}
+\DeclareDocumentCommand{\tgmu}{O{}}{\text{\textmu}}
+\DeclareDocumentCommand{\tgnu}{O{}}{\text{\textnu}}
+\DeclareDocumentCommand{\tgxi}{O{}}{\text{\textxi}}
+\DeclareDocumentCommand{\tgomicron}{O{}}{\text{\textomicron}}
+\DeclareDocumentCommand{\tgpi}{O{}}{\text{\textpi}}
+\DeclareDocumentCommand{\tgrho}{O{}}{\text{\textrho}}
+\DeclareDocumentCommand{\tgsigma}{O{}}{\text{\textsigma}}
+\DeclareDocumentCommand{\tgtau}{O{}}{\text{\texttau}}
+\DeclareDocumentCommand{\tgupsilon}{O{}}{\text{\textupsilon}}
+\DeclareDocumentCommand{\tgphi}{O{}}{\text{\textphi}}
+\DeclareDocumentCommand{\tgchi}{O{}}{\text{\textchi}}
+\DeclareDocumentCommand{\tgpsi}{O{}}{\text{\textpsi}}
+\DeclareDocumentCommand{\tgomega}{O{}}{\text{\textomega}}
+\DeclareDocumentCommand{\vAlpha}{}{\varAlpha}
+\DeclareDocumentCommand{\vBeta}{}{\varBeta}
+\DeclareDocumentCommand{\vGamma}{}{\varGamma}
+\DeclareDocumentCommand{\vDelta}{}{\varDelta}
+\DeclareDocumentCommand{\vEpsilon}{}{\varEpsilon}
+\DeclareDocumentCommand{\vZeta}{}{\varZeta}
+\DeclareDocumentCommand{\vEta}{}{\varEta}
+\DeclareDocumentCommand{\vTheta}{}{\varTheta}
+\DeclareDocumentCommand{\vIota}{}{\varIota}
+\DeclareDocumentCommand{\vKappa}{}{\varKappa}
+\DeclareDocumentCommand{\vLambda}{}{\varLambda}
+\DeclareDocumentCommand{\vMu}{}{\varMu}
+\DeclareDocumentCommand{\vNu}{}{\varNu}
+\DeclareDocumentCommand{\vXi}{}{\varXi}
+\DeclareDocumentCommand{\vOmicron}{}{\varOmicron}
+\DeclareDocumentCommand{\vPi}{}{\varPi}
+\DeclareDocumentCommand{\vRho}{}{\varRho}
+\DeclareDocumentCommand{\vSigma}{}{\varSigma}
+\DeclareDocumentCommand{\vTau}{}{\varTau}
+\DeclareDocumentCommand{\vUpsilon}{}{\varUpsilon}
+\DeclareDocumentCommand{\vPhi}{}{\varPhi}
+\DeclareDocumentCommand{\vChi}{}{\varChi}
+\DeclareDocumentCommand{\vPsi}{}{\varPsi}
+\DeclareDocumentCommand{\vOmega}{}{\varOmega}
+\DeclareDocumentCommand{\valpha}{}{\varalpha}
+\DeclareDocumentCommand{\vbeta}{}{\varbeta}
+\DeclareDocumentCommand{\vgamma}{}{\vargamma}
+\DeclareDocumentCommand{\vdelta}{}{\vardelta}
+\DeclareDocumentCommand{\vepsilon}{}{\varepsilon}
+\DeclareDocumentCommand{\vzeta}{}{\varzeta}
+\DeclareDocumentCommand{\veta}{}{\vareta}
+\DeclareDocumentCommand{\vtheta}{}{\vartheta}
+\DeclareDocumentCommand{\viota}{}{\variota}
+\DeclareDocumentCommand{\vkappa}{}{\varkappa}
+\DeclareDocumentCommand{\vlambda}{}{\varlambda}
+\DeclareDocumentCommand{\vmu}{}{\varmu}
+\DeclareDocumentCommand{\vnu}{}{\varnu}
+\DeclareDocumentCommand{\vxi}{}{\varxi}
+\DeclareDocumentCommand{\vomicron}{}{\varomicron}
+\DeclareDocumentCommand{\vpi}{}{\varpi}
+\DeclareDocumentCommand{\vrho}{}{\varrho}
+\DeclareDocumentCommand{\vsigma}{}{\varsigma}
+\DeclareDocumentCommand{\vtau}{}{\vartau}
+\DeclareDocumentCommand{\vupsilon}{}{\varupsilon}
+\DeclareDocumentCommand{\vphi}{}{\varphi}
+\DeclareDocumentCommand{\vchi}{}{\varchi}
+\DeclareDocumentCommand{\vpsi}{}{\varpsi}
+\DeclareDocumentCommand{\vomega}{}{\varomega}
+\DeclareDocumentCommand{\uAlpha}{}{\upAlpha}
+\DeclareDocumentCommand{\uBeta}{}{\upBeta}
+\DeclareDocumentCommand{\uGamma}{}{\upGamma}
+\DeclareDocumentCommand{\uDelta}{}{\upDelta}
+\DeclareDocumentCommand{\uEpsilon}{}{\upEpsilon}
+\DeclareDocumentCommand{\uZeta}{}{\upZeta}
+\DeclareDocumentCommand{\uEta}{}{\upEta}
+\DeclareDocumentCommand{\uTheta}{}{\upTheta}
+\DeclareDocumentCommand{\uIota}{}{\upIota}
+\DeclareDocumentCommand{\uKappa}{}{\upKappa}
+\DeclareDocumentCommand{\uLambda}{}{\upLambda}
+\DeclareDocumentCommand{\uMu}{}{\upMu}
+\DeclareDocumentCommand{\uNu}{}{\upNu}
+\DeclareDocumentCommand{\uXi}{}{\upXi}
+\DeclareDocumentCommand{\uOmicron}{}{\upOmicron}
+\DeclareDocumentCommand{\uPi}{}{\upPi}
+\DeclareDocumentCommand{\uRho}{}{\upRho}
+\DeclareDocumentCommand{\uSigma}{}{\upSigma}
+\DeclareDocumentCommand{\uTau}{}{\upTau}
+\DeclareDocumentCommand{\uUpsilon}{}{\upUpsilon}
+\DeclareDocumentCommand{\uPhi}{}{\upPhi}
+\DeclareDocumentCommand{\uChi}{}{\upChi}
+\DeclareDocumentCommand{\uPsi}{}{\upPsi}
+\DeclareDocumentCommand{\uOmega}{}{\upOmega}
+\DeclareDocumentCommand{\ualpha}{}{\upalpha}
+\DeclareDocumentCommand{\ubeta}{}{\upbeta}
+\DeclareDocumentCommand{\ugamma}{}{\upgamma}
+\DeclareDocumentCommand{\udelta}{}{\updelta}
+\DeclareDocumentCommand{\uepsilon}{}{\upepsilon}
+\DeclareDocumentCommand{\uzeta}{}{\upzeta}
+\DeclareDocumentCommand{\ueta}{}{\upeta}
+\DeclareDocumentCommand{\utheta}{}{\uptheta}
+\DeclareDocumentCommand{\uiota}{}{\upiota}
+\DeclareDocumentCommand{\ukappa}{}{\upkappa}
+\DeclareDocumentCommand{\ulambda}{}{\uplambda}
+\DeclareDocumentCommand{\umu}{}{\upmu}
+\DeclareDocumentCommand{\unu}{}{\upnu}
+\DeclareDocumentCommand{\uxi}{}{\upxi}
+\DeclareDocumentCommand{\uomicron}{}{\upomicron}
+\DeclareDocumentCommand{\upi}{}{\uppi}
+\DeclareDocumentCommand{\urho}{}{\uprho}
+\DeclareDocumentCommand{\usigma}{}{\upsigma}
+\DeclareDocumentCommand{\utau}{}{\uptau}
+\DeclareDocumentCommand{\uupsilon}{}{\upupsilon}
+\DeclareDocumentCommand{\uphi}{}{\upphi}
+\DeclareDocumentCommand{\uchi}{}{\upchi}
+\DeclareDocumentCommand{\upsi}{}{\uppsi}
+\DeclareDocumentCommand{\uomega}{}{\upomega}
+\DeclareDocumentCommand{\uvAlpha}{}{\upvarAlpha}
+\DeclareDocumentCommand{\uvBeta}{}{\upvarBeta}
+\DeclareDocumentCommand{\uvGamma}{}{\upvarGamma}
+\DeclareDocumentCommand{\uvDelta}{}{\upvarDelta}
+\DeclareDocumentCommand{\uvEpsilon}{}{\upvarEpsilon}
+\DeclareDocumentCommand{\uvZeta}{}{\upvarZeta}
+\DeclareDocumentCommand{\uvEta}{}{\upvarEta}
+\DeclareDocumentCommand{\uvTheta}{}{\upvarTheta}
+\DeclareDocumentCommand{\uvIota}{}{\upvarIota}
+\DeclareDocumentCommand{\uvKappa}{}{\upvarKappa}
+\DeclareDocumentCommand{\uvLambda}{}{\upvarLambda}
+\DeclareDocumentCommand{\uvMu}{}{\upvarMu}
+\DeclareDocumentCommand{\uvNu}{}{\upvarNu}
+\DeclareDocumentCommand{\uvXi}{}{\upvarXi}
+\DeclareDocumentCommand{\uvOmicron}{}{\upvarOmicron}
+\DeclareDocumentCommand{\uvPi}{}{\upvarPi}
+\DeclareDocumentCommand{\uvRho}{}{\upvarRho}
+\DeclareDocumentCommand{\uvSigma}{}{\upvarSigma}
+\DeclareDocumentCommand{\uvTau}{}{\upvarTau}
+\DeclareDocumentCommand{\uvUpsilon}{}{\upvarUpsilon}
+\DeclareDocumentCommand{\uvPhi}{}{\upvarPhi}
+\DeclareDocumentCommand{\uvChi}{}{\upvarChi}
+\DeclareDocumentCommand{\uvPsi}{}{\upvarPsi}
+\DeclareDocumentCommand{\uvOmega}{}{\upvarOmega}
+\DeclareDocumentCommand{\uvalpha}{}{\upvaralpha}
+\DeclareDocumentCommand{\uvbeta}{}{\upvarbeta}
+\DeclareDocumentCommand{\uvgamma}{}{\upvargamma}
+\DeclareDocumentCommand{\uvdelta}{}{\upvardelta}
+\DeclareDocumentCommand{\uvepsilon}{}{\upvarepsilon}
+\DeclareDocumentCommand{\uvzeta}{}{\upvarzeta}
+\DeclareDocumentCommand{\uveta}{}{\upvareta}
+\DeclareDocumentCommand{\uvtheta}{}{\upvartheta}
+\DeclareDocumentCommand{\uviota}{}{\upvariota}
+\DeclareDocumentCommand{\uvkappa}{}{\upvarkappa}
+\DeclareDocumentCommand{\uvlambda}{}{\upvarlambda}
+\DeclareDocumentCommand{\uvmu}{}{\upvarmu}
+\DeclareDocumentCommand{\uvnu}{}{\upvarnu}
+\DeclareDocumentCommand{\uvxi}{}{\upvarxi}
+\DeclareDocumentCommand{\uvomicron}{}{\upvaromicron}
+\DeclareDocumentCommand{\uvpi}{}{\upvarpi}
+\DeclareDocumentCommand{\uvrho}{}{\upvarrho}
+\DeclareDocumentCommand{\uvsigma}{}{\upvarsigma}
+\DeclareDocumentCommand{\uvtau}{}{\upvartau}
+\DeclareDocumentCommand{\uvupsilon}{}{\upvarupsilon}
+\DeclareDocumentCommand{\uvphi}{}{\upvarphi}
+\DeclareDocumentCommand{\uvchi}{}{\upvarchi}
+\DeclareDocumentCommand{\uvpsi}{}{\upvarpsi}
+\DeclareDocumentCommand{\uvomega}{}{\upvaromega}
+\fi
+
+% Others
+\DeclareDocumentCommand{\autommode}{m}{\relax\ifmmode #1\else\(#1\)\fi}
+\let\amm\autommode
+\DeclareDocumentCommand{\mathcolorbox}{ m m }{
+  \begingroup
+  \setlength{\fboxsep}{0pt}
+  \mathchoice
+    {\colorbox{#1}{$\displaystyle#2$}}
+    {\colorbox{#1}{$\textstyle#2$}}
+    {\colorbox{#1}{$\scriptstyle#2$}}
+    {\colorbox{#1}{$\scriptscriptstyle#2$}}
+  \endgroup
+}
+\let\mcbox\mathcolorbox
+\DeclareDocumentCommand{\autocolorbox}{m m}{
+  \relax\ifmmode \mathcolorbox{#1}{#2}\else\colorbox{#1}{#2}\fi
+}
+\let\acbox\autocolorbox
+\let\cbox\autocolorbox
+\DeclareDocumentCommand{\tentothepowerof}{m}{\relax\ifmmode 10^{#1}\else\(10^{#1}\)\fi}
+\let\tenpow\tentothepowerof
+\DeclareDocumentCommand{\scientificnotation}{m m}{\relax\ifmmode #1\times 10^{#2}\else\(#1\times 10^{#2}\)\fi}
+\let\scinote\scientificnotation
+
+% Symbols
+\DeclareDocumentCommand\lparen{}{(} % Left parenthesis
+\DeclareDocumentCommand\rparen{}{)} % Right parenthesis
+\DeclareDocumentCommand\ordersymbol{}{\mathcal{O}} % Order symbol --> O(x^2)
+\DeclareDocumentCommand{\typical}{}{\cbox{cyan}{\phantom{A}}}
+\DeclareDocumentCommand{\tall}{}{\cbox{cyan}{\phantom{A^{\vphantom{x^x}}_x}}}
+\DeclareDocumentCommand{\grande}{}{\cbox{cyan}{\phantom{\frac{1}{xx}}}}
+\DeclareDocumentCommand{\venti}{}{\cbox{cyan}{\phantom{\sum_x^x}}}
+\DeclareDocumentCommand\Vtextvisiblespace{O{.3em}}{\mbox{\kern.06em\vrule height.3ex}\vbox{\hrule width#1}\hbox{\vrule height.3ex}}
+
+% Brackets and braces
+\DeclareDocumentCommand{\PHquantity}{ t\big t\Big t\bigg t\Bigg o d() d|| g }
 { % Flexible automatic bracketing of an expression in () or [] or {} or ||
   % Handles manual override of sizing
   \IfBooleanTF{#1}{\let\ltag\bigl \let\rtag\bigr}{
@@ -42,94 +306,487 @@
   % Handles actual bracketing
   \IfNoValueTF{#5}{
     \IfNoValueTF{#6}{
-      \IfNoValueTF{#7}{
-        \IfNoValueTF{#8}{
-          \IfBooleanTF{#1}{\big}{
-            \IfBooleanTF{#2}{\Big}{
-              \IfBooleanTF{#3}{\bigg}{
-                \IfBooleanTF{#4}{\Bigg}{}
-              }
-            }
-          }
+    \IfNoValueTF{#7}{
+    \IfNoValueTF{#8}{
+      \IfBooleanTF{#1}{\big}{
+      \IfBooleanTF{#2}{\Big}{
+        \IfBooleanTF{#3}{\bigg}{
+        \IfBooleanTF{#4}{\Bigg}{}
         }
-        {\ltag\lbrace#8\rtag\rbrace}
-      }{
-        \ltag\lvert{#7}\rtag\rvert
-        \IfNoValueTF{#8}{}{#8}
       }
+      }
+    }
+    {\ltag\lbrace#8\rtag\rbrace}
     }{
-        \ltag(#6\rtag)
-        \IfNoValueTF{#7}{}{|#7|}
-        \IfNoValueTF{#8}{}{#8}
+    \ltag\lvert{#7}\rtag\rvert
+    \IfNoValueTF{#8}{}{#8}
     }
   }{
-    \ltag[#5\rtag]
-    \IfNoValueTF{#6}{}{(#6)}
+    \ltag(#6\rtag)
     \IfNoValueTF{#7}{}{|#7|}
     \IfNoValueTF{#8}{}{#8}
   }
+  }{
+  \ltag[#5\rtag]
+  \IfNoValueTF{#6}{}{(#6)}
+  \IfNoValueTF{#7}{}{|#7|}
+  \IfNoValueTF{#8}{}{#8}
+  }
 }
-\let\ppqty\patchedphysicsquantity
+\let\PHqty\PHquantity
 \IfPackageLoadedTF{siunitx}
 {
-  \DeclareDocumentCommand\siqty{o m m}{
-    \IfValueTF{#1}{\SI[#1]{#2}{#3}}{\SI{#2}{#3}}
-  }
-  \DeclareDocumentCommand{\integratedquantity}{ t\big t\Big t\bigg t\Bigg o d() d|| g g }
-  { % integrate \qty from physics and \qty from siunitx
+  \DeclareDocumentCommand{\ITquantity}{ t\big t\Big t\bigg t\Bigg o d() d|| g g }
+  { % integrate \qty from siunitx into \qty
     \IfValueTF{#9}
     { % \qty from siunitx
-      \IfValueTF{#5}
-      {\siqty[#5]{#8}{#9}}
-      {\siqty{#8}{#9}}
+    \IfValueTF{#5}
+    {\SI[#5]{#8}{#9}}
+    {\SI{#8}{#9}}
     }{ % \qty from physics
-      % 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}
-          }
-        }
+    % 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}
       }
-      % Handles actual bracketing
-      \IfNoValueTF{#5}{
-        \IfNoValueTF{#6}{
-          \IfNoValueTF{#7}{
-            \IfNoValueTF{#8}{
-              \IfBooleanTF{#1}{\big}{
-                \IfBooleanTF{#2}{\Big}{
-                  \IfBooleanTF{#3}{\bigg}{
-                    \IfBooleanTF{#4}{\Bigg}{}
-                  }
-                }
-              }
-            }
-            {\ltag\lbrace#8\rtag\rbrace}
-          }{
-            \ltag\lvert{#7}\rtag\rvert
-            \IfNoValueTF{#8}{}{#8}
+      }
+    }
+    % Handles actual bracketing
+    \IfNoValueTF{#5}{
+      \IfNoValueTF{#6}{
+      \IfNoValueTF{#7}{
+        \IfNoValueTF{#8}{
+        \IfBooleanTF{#1}{\big}{
+          \IfBooleanTF{#2}{\Big}{
+          \IfBooleanTF{#3}{\bigg}{
+            \IfBooleanTF{#4}{\Bigg}{}
           }
-        }{
-            \ltag(#6\rtag)
-            \IfNoValueTF{#7}{}{|#7|}
-            \IfNoValueTF{#8}{}{#8}
+          }
         }
+        }
+        {\ltag\lbrace#8\rtag\rbrace}
       }{
-        \ltag[#5\rtag]
-        \IfNoValueTF{#6}{}{(#6)}
-        \IfNoValueTF{#7}{}{|#7|}
+        \ltag\lvert{#7}\rtag\rvert
         \IfNoValueTF{#8}{}{#8}
       }
+      }{
+      \ltag(#6\rtag)
+      \IfNoValueTF{#7}{}{|#7|}
+      \IfNoValueTF{#8}{}{#8}
+      }
+    }{
+      \ltag[#5\rtag]
+      \IfNoValueTF{#6}{}{(#6)}
+      \IfNoValueTF{#7}{}{|#7|}
+      \IfNoValueTF{#8}{}{#8}
     }
+    }
   }
-  \let\patchedquantity\integratedquantity
-  \let\iqty\integratedquantity
-}{
-  \let\patchedquantity\patchedphysicsquantity
+  \let\ITqty\ITquantity
+  \ifsiintegrate
+    \let\PTquantity\ITquantity
+  \else
+    \let\PTquantity\PHquantity
+  \fi
+}{\let\PTquantity\PHquantity}
+\let\PTqty\PTquantity
+\ifoverride
+  \let\qty\PTquantity
+  \let\quantity\PTquantity
+\fi
+\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\omqty{m}{\begin{matrix}#1\end{matrix}}
+\DeclareDocumentCommand\pmqty{m}{\begin{pmatrix}#1\end{pmatrix}}
+\DeclareDocumentCommand\PTpmqty{s m}{\IfNoValueTF{#1}{\begin{pmatrix}#2\end{pmatrix}}{\left\lgroup\begin{matrix}#2\end{matrix}\right\rgroup}}
+\ifoverride\let\pmqty\PTpmqty\fi
+\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\PTmatrixquantity{ s g o d() d|| }
+{
+  \IfNoValueTF{#2}
+  {
+    \IfNoValueTF{#3}
+    {
+      \IfNoValueTF{#4}
+      {
+        \vmqty{#5}
+      }
+      {
+        \IfBooleanTF{#1}
+        {\Pmqty{#4}}
+        {\pmqty{#4}}
+        \IfNoValueTF{#5}{}{|#5|}
+      }
+    }
+    {
+      \bmqty{#3}
+      \IfNoValueTF{#4}{}{(#4)}
+      \IfNoValueTF{#5}{}{|#5|}}
+    }
+  {
+    \omqty{#2}
+    \IfNoValueTF{#3}{}{[#3]}
+    \IfNoValueTF{#4}{}{(#4)}
+    \IfNoValueTF{#5}{}{|#5|}
+  }
 }
-\let\ptqty\patchedquantity
-\ifoverride\let\qty\patchedquantity\fi
-\DeclareDocumentCommand\derivative{ s o m g d() }
+\let\PTmqty\PTmatrixquantity
+\ifoverride\let\mqty\PTmatrixquantity\fi
+\DeclareDocumentCommand\matrixdeterminant{m}{\vmqty{#1}} % Matrix determinant
+\DeclareDocumentCommand\mdet{}{\matrixdeterminant} % Shorthand for matrix determinant
+
+\DeclareDocumentCommand\somqty{m}{\begin{smallmatrix}#1\end{smallmatrix}}
+\DeclareDocumentCommand\spmqty{m}{\pqty{\begin{smallmatrix}#1\end{smallmatrix}}}
+\DeclareDocumentCommand\PTspmqty{s m}{\IfNoValueTF{#1}{\pqty{\begin{smallmatrix}#2\end{smallmatrix}}}{\left\lgroup\begin{smallmatrix}#2\end{smallmatrix}\right\rgroup}}
+\ifoverride\let\spmqty\PTspmqty\fi
+\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\PTsmallmatrixquantity{ s g o d() d|| }
+{
+  \IfNoValueTF{#2}
+  {
+    \IfNoValueTF{#3}
+    {
+      \IfNoValueTF{#4}
+      {
+        \svmqty{#5}
+      }
+      {
+        \IfBooleanTF{#1}
+        {\sPmqty{#4}}
+        {\spmqty{#4}}
+        \IfNoValueTF{#5}{}{|#5|}
+      }
+    }
+    {
+      \sbmqty{#3}
+      \IfNoValueTF{#4}{}{(#4)}
+      \IfNoValueTF{#5}{}{|#5|}}
+    }
+  {
+    \somqty{#2}
+    \IfNoValueTF{#3}{}{[#3]}
+    \IfNoValueTF{#4}{}{(#4)}
+    \IfNoValueTF{#5}{}{|#5|}
+  }
+}
+\let\PTsmqty\PTsmallmatrixquantity
+\ifoverride\let\smqty\PTsmallmatrixquantity\fi
+\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{ 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}
+    }
+    }
+  }
+  }
+}
+
+\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}
+    }
+    }
+  }
+  }
+}
+
+\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{ l m m }{\braces#1{\lbrace}{\rbrace}{#2,#3}} % Poisson bracket [same as anti-commutator]
+\DeclareDocumentCommand\pb{}{\poissonbracket} % Shorthand for \poissonbracket
+
+% Commutators
+\DeclareDocumentCommand\commutator{ l m m }{\braces#1{\lbrack}{\rbrack}{#2,#3}} % Commutator
+\DeclareDocumentCommand\comm{}{\commutator} % Shorthand for \commutator
+\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
+
+% Vector notation
+\DeclareDocumentCommand\vectorbold{ s m }{\IfBooleanTF{#1}{\boldsymbol{#2}}{\mathbf{#2}}} % Vector bold [star for Greek and italic Roman]
+\DeclareDocumentCommand\vb{}{\vectorbold} % Shorthand for \vectorbold
+
+\DeclareDocumentCommand\vectorarrow{ s m }{\IfBooleanTF{#1}{\vec{\boldsymbol{#2}}}{\vec{\mathbf{#2}}}} % Vector arrow + bold [star for Greek and italic Roman]
+\DeclareDocumentCommand\va{}{\vectorarrow} % Shorthand for \vectorarrow
+
+\DeclareDocumentCommand\vectorunit{ s m }{\IfBooleanTF{#1}{\boldsymbol{\hat{#2}}}{\mathbf{\hat{#2}}}} % Unit vector [star for Greek and italic Roman]
+\DeclareDocumentCommand\vu{}{\vectorunit} % Shorthand for \vectorunit
+
+\DeclareDocumentCommand\dotproduct{}{\boldsymbol\cdot} % Vector dot product symbol
+\DeclareDocumentCommand\vdot{}{\dotproduct} % Shorthand for \dotproduct [note that the command sequence \dp is protected]
+
+\DeclareDocumentCommand\crossproduct{}{\boldsymbol\times} % Vector cross product symbol
+\DeclareDocumentCommand\cross{}{\crossproduct} % Shorthand for \crossproduct
+\DeclareDocumentCommand\cp{}{\crossproduct} % Shorthand for \crossproduct
+
+\DeclareDocumentCommand\gradient{ g o d() }{ % Gradient
+  \IfNoValueTF{#1}{
+  \IfNoValueTF{#2}{
+    \IfNoValueTF{#3}{\vnabla}{\fbraces{\lparen}{\rparen}{\vnabla}{#3}}
+  }
+  {\fbraces{\lbrack}{\rbrack}{\vnabla}{#2} \IfNoValueTF{#3}{}{(#3)}}
+  }
+  {\vnabla #1 \IfNoValueTF{#2}{}{[#2]} \IfNoValueTF{#3}{}{(#3)}}
+}
+\DeclareDocumentCommand\grad{}{\gradient} % Shorthand for \gradient
+
+\DeclareDocumentCommand\divergence{ g o d() }{ % Divergence
+  \IfNoValueTF{#1}{
+  \IfNoValueTF{#2}{
+    \IfNoValueTF{#3}{\vnabla \vdot}{\vnabla \vdot \quantity(#3)}
+  }
+  {\vnabla \vdot \quantity[#2] \IfNoValueTF{#3}{}{(#3)}}
+  }
+  {\vnabla \vdot #1 \IfNoValueTF{#2}{}{[#2]} \IfNoValueTF{#3}{}{(#3)}}
+}
+\let\divg\divergence
+\iforiginaldiv
+  \ifphysics
+    \let\div\divisionsymbol
+    \let\divg\divergence
+  \else
+    \let\divisionsymbol\div
+  \fi
+\else
+  \ifphysics
+    \let\div\divergence
+  \else
+    \let\divisionsymbol\div % Rename \div [division symbol] in order to free up control sequence for \divergence
+    \let\div\divergence
+  \fi
+\fi
+
+\DeclareDocumentCommand\curl{ g o d() }{ % Curl
+  \IfNoValueTF{#1}{
+  \IfNoValueTF{#2}{
+    \IfNoValueTF{#3}{\vnabla \cross}{\vnabla \cross \quantity(#3)}
+  }
+  {\vnabla \cross \quantity[#2] \IfNoValueTF{#3}{}{(#3)}}
+  }
+  {\vnabla \cross #1 \IfNoValueTF{#2}{}{[#2]} \IfNoValueTF{#3}{}{(#3)}}
+}
+
+\DeclareDocumentCommand\laplacian{ g o d() }{ % Laplacian
+  \IfNoValueTF{#1}{
+  \IfNoValueTF{#2}{
+    \IfNoValueTF{#3}{\nabla^2}{\fbraces{\lparen}{\rparen}{\nabla^2}{#3}}
+  }
+  {\fbraces{\lbrack}{\rbrack}{\nabla^2}{#2} \IfNoValueTF{#3}{}{(#3)}}
+  }
+  {\nabla^2 #1 \IfNoValueTF{#2}{}{[#2]} \IfNoValueTF{#3}{}{(#3)}}
+}
+
+% Operators
+\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}
+\DeclareDocumentCommand\qq{}{\qqtext}
+
+\DeclareDocumentCommand\qcomma{}{,\quad}
+\DeclareDocumentCommand\qc{}{\qcomma}
+
+\DeclareDocumentCommand\qif{s}{\IfBooleanTF{#1}{}{\quad}\text{if}\quad}
+\DeclareDocumentCommand\qthen{s}{\IfBooleanTF{#1}{}{\quad}\text{then}\quad}
+\DeclareDocumentCommand\qelse{s}{\IfBooleanTF{#1}{}{\quad}\text{else}\quad}
+\DeclareDocumentCommand\qotherwise{s}{\IfBooleanTF{#1}{}{\quad}\text{otherwise}\quad}
+\DeclareDocumentCommand\qunless{s}{\IfBooleanTF{#1}{}{\quad}\text{unless}\quad}
+\DeclareDocumentCommand\qgiven{s}{\IfBooleanTF{#1}{}{\quad}\text{given}\quad}
+\DeclareDocumentCommand\qusing{s}{\IfBooleanTF{#1}{}{\quad}\text{using}\quad}
+\DeclareDocumentCommand\qassume{s}{\IfBooleanTF{#1}{}{\quad}\text{assume}\quad}
+\DeclareDocumentCommand\qsince{s}{\IfBooleanTF{#1}{}{\quad}\text{since}\quad}
+\DeclareDocumentCommand\qlet{s}{\IfBooleanTF{#1}{}{\quad}\text{let}\quad}
+\DeclareDocumentCommand\qfor{s}{\IfBooleanTF{#1}{}{\quad}\text{for}\quad}
+\DeclareDocumentCommand\qall{s}{\IfBooleanTF{#1}{}{\quad}\text{all}\quad}
+\DeclareDocumentCommand\qeven{s}{\IfBooleanTF{#1}{}{\quad}\text{even}\quad}
+\DeclareDocumentCommand\qodd{s}{\IfBooleanTF{#1}{}{\quad}\text{odd}\quad}
+\DeclareDocumentCommand\qinteger{s}{\IfBooleanTF{#1}{}{\quad}\text{integer}\quad}
+\DeclareDocumentCommand\qand{s}{\IfBooleanTF{#1}{}{\quad}\text{and}\quad}
+\DeclareDocumentCommand\qor{s}{\IfBooleanTF{#1}{}{\quad}\text{or}\quad}
+\DeclareDocumentCommand\qas{s}{\IfBooleanTF{#1}{}{\quad}\text{as}\quad}
+\DeclareDocumentCommand\qin{s}{\IfBooleanTF{#1}{}{\quad}\text{in}\quad}
+\DeclareDocumentCommand\qcc{s}{\IfBooleanTF{#1}{}{\quad}\text{c.c.}\quad}
+
+% Derivatives
+\DeclareDocumentCommand\differential{ o g d() }{ % Differential 'd'
+  % o: optional n for nth differential
+  % g: optional argument for readability and to control spacing
+  % d: long-form as in d(cos x)
+  \IfNoValueTF{#2}{
+  \IfNoValueTF{#3}
+  {\diffd\IfNoValueTF{#1}{}{^{#1}}}
+  {\mathinner{\diffd\IfNoValueTF{#1}{}{^{#1}}\argopen(#3\argclose)}}
+  }
+  {\mathinner{\diffd\IfNoValueTF{#1}{}{^{#1}}#2} \IfNoValueTF{#3}{}{(#3)}}
+}
+\DeclareDocumentCommand\dd{}{\differential} % Shorthand for \differential
+
+\DeclareDocumentCommand\PTderivative{ s o m g d() }
 { % Total derivative
   % s: star for \flatfrac flat derivative
   % o: optional n for nth derivative
@@ -141,15 +798,16 @@
   {\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)}
+  \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}}}}
   \IfNoValueTF{#5}{}{\argopen(#5\argclose)}
 }
-\let\dv\derivative
-\DeclareDocumentCommand\partialderivative{ s o m g g d() }
+\let\PTdv\PTderivative
+\ifoverride\let\dv\PTderivative\fi
+\DeclareDocumentCommand\PTpartialderivative{ s o m g g d() }
 { % Partial derivative
   % s: star for \flatfrac flat derivative
   % o: optional n for nth derivative
@@ -162,15 +820,422 @@
   {\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{#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}
+  {\fractype{\partial \IfNoValueTF{#2}{}{^{#2}} #3}{\partial #4\IfNoValueTF{#2}{}{^{#2}}}}
+  {\fractype{\partial^2 #3}{\partial #4 \partial #5}}
+  \IfNoValueTF{#6}{}{\argopen(#6\argclose)}
+  }
+}
+\let\PTpdv\PTpartialderivative
+\let\PTpderivative\PTpartialderivative
+\ifoverride
+  \let\pderivative\PTpartialderivative
+  \let\pdv\PTpartialderivative
+\fi
+
+\DeclareDocumentCommand\variation{ o g d() }{ % Functional variation
+  % o: optional n for nth differential
+  % g: optional argument for readability and to control spacing
+  % d: long-form as in d(F(g))
+  \IfNoValueTF{#2}{
+  \IfNoValueTF{#3}
+  {\delta \IfNoValueTF{#1}{}{^{#1}}}
+  {\mathinner{\delta \IfNoValueTF{#1}{}{^{#1}}\argopen(#3\argclose)}}
+  }
+  {\mathinner{\delta \IfNoValueTF{#1}{}{^{#1}}#2} \IfNoValueTF{#3}{}{(#3)}}
+}
+\DeclareDocumentCommand\var{}{\variation} % Shorthand for \variation
+
+\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(...)
+  \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 s g }
+{ % Bra
+  \IfBooleanTF{#3}
+  { % Contraction
+  \IfBooleanTF{#1}
+  { % Bra has a star: no resize
     \IfNoValueTF{#5}
-    {\fractype{\partial \IfNoValueTF{#2}{}{^{#2}} #3}{\partial #4\IfNoValueTF{#2}{}{^{#2}}}}
-    {\fractype{\partial^2 #3}{\partial #4 \partial #5}}
-    \IfNoValueTF{#6}{}{\argopen(#6\argclose)}
+    {\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
+  }
+  }
+  { % No contraction
+  \IfBooleanTF{#1}
+  {\vphantom{#2}\left\langle\smash{#2}\right\rvert}
+  {\left\langle{#2}\right\rvert}
+  \IfBooleanTF{#4}{*}{}
+  \IfNoValueTF{#5}{}{#5}
+  }
 }
-\let\pdv\partialderivative
\ No newline at end of file
+
+\DeclareDocumentCommand\ket{ s m }
+{ % Ket
+  \IfBooleanTF{#1}
+  {\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}
+  }
+  { % Auto resize
+  \IfNoValueTF{#3}
+  {\left\langle{#2}\middle\vert{#2}\right\rangle}
+  {\left\langle{#2}\middle\vert{#3}\right\rangle}
+  }
+}
+\DeclareDocumentCommand\braket{}{\innerproduct} % Alternative for \innerproduct
+\DeclareDocumentCommand\ip{}{\innerproduct} % Shorthand for \innerproduct
+
+\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}
+  {\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{ 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{ 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\PTxmatrix{ s o m m m o o g g }
+{
+  {
+    \newtoks\matrixtoks
+    \global\matrixtoks = {}
+
+    \newcount\rowcount
+    \newcount\actualrow
+    \newcount\rowdots
+    \IfValueTF{#6}{
+      \actualrow = #6
+      \IfValueTF{#2}{
+        \IfStrEq{#2}{1}{\rowdots = \numexpr\actualrow\relax}{
+          \IfStrEq{#2}{0}{\rowdots = \numexpr\actualrow\relax}{\rowdots = \numexpr\actualrow-1\relax}
+        }
+      }{
+        \IfBlankTF{#4}
+        {\rowdots = \numexpr\actualrow-1\relax}
+        {
+          \ifnum\actualrow = #4
+            \rowdots = 0
+          \else
+            \rowdots = \numexpr\actualrow-1\relax
+          \fi
+        }
+      }
+    }{
+      \IfBlankTF{#4}{
+        \actualrow = 1
+      }{
+        \actualrow = #4
+      }
+      \rowdots = 0
+    }
+
+    \newcount\colcount
+    \newcount\actualcol
+    \newcount\coldots
+    \IfValueTF{#7}{
+      \actualcol = #7
+      \IfValueTF{#2}{
+        \IfStrEq{#2}{2}{\coldots = \numexpr\actualcol\relax}{
+          \IfStrEq{#2}{0}{\coldots = \numexpr\actualcol\relax}{\coldots = \numexpr\actualcol-1\relax}
+        }
+      }{
+        \IfBlankTF{#5}
+        {\coldots = \numexpr\actualcol-1\relax}
+        {
+          \ifnum\actualcol = #5
+            \coldots = 0
+          \else
+            \coldots = \numexpr\actualcol-1\relax
+          \fi
+        }
+      }
+    }{
+      \IfBlankTF{#5}{
+        \actualcol = 1
+      }{
+        \actualcol = #5
+      }
+      \coldots = 0
+    }
+    
+    \loop
+      \colcount = 0
+      \advance \rowcount by 1
+      {
+        \loop
+          \advance \colcount by 1
+          \edef\addtoks{
+            \ifnum\colcount = 1
+            \else
+              &
+            \fi
+            \ifnum\colcount = \coldots
+              \ifnum\rowcount = \rowdots
+                \ddots
+              \else
+                \ldots
+              \fi
+            \else
+              \ifnum\rowcount = \rowdots
+                \vdots
+              \else
+                #3
+                \IfBooleanTF{#1}{_{
+                  \ifnum\actualrow = \rowcount
+                    \IfValueTF{#8}{#8}{
+                      \IfBlankTF{#4}{}{
+                        \ifnum #4 > 1
+                          #4
+                        \fi
+                      }
+                    }
+                  \else
+                    \the\rowcount
+                  \fi
+                  \ifnum\actualcol = \colcount
+                    \IfValueTF{#9}{#9}{
+                      \IfBlankTF{#5}{}{
+                        \ifnum #5 > 1
+                          #5
+                        \fi
+                      }
+                    }
+                  \else
+                    \the\colcount
+                  \fi
+                }}{}
+              \fi
+            \fi
+          }
+        \global\matrixtoks = \expandafter{\the\expandafter\matrixtoks\addtoks}
+        \ifnum \colcount < \actualcol
+          \repeat
+      }
+    \ifnum \rowcount < \actualrow
+      \global\matrixtoks = \expandafter{\the\expandafter\matrixtoks \\}
+      \repeat
+  }
+  \the\matrixtoks
+}
+\let\PTxmat\PTxmatrix
+\ifoverride\let\xmat\PTxmatrix\fi
+
+\DeclareDocumentCommand\zeromatrix{ m g }{\IfNoValueTF{#2}{\PTxmatrix{0}{#1}{#1}}{\PTxmatrix{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\PTdmat{ m m g g g g g g g }
+{
+\newtoks\matrixtoks
+\global\matrixtoks = {}
+\IfNoValueTF{#3}
+{#2}
+{
+  \IfNoValueTF{#4}
+  {\global\matrixtoks = \expandafter{\PTmqty{#2}&#1\\#1&\PTmqty{#3}}}
+  {
+  \IfNoValueTF{#5}
+  {\global\matrixtoks = \expandafter{\PTmqty{#2}&#1&#1\\#1&\PTmqty{#3}&#1\\#1&#1&\PTmqty{#4}}}
+  {
+    \IfNoValueTF{#6}
+    {\global\matrixtoks = \expandafter{\PTmqty{#2}&#1&#1&#1\\#1&\PTmqty{#3}&#1&#1\\#1&#1&\PTmqty{#4}&#1\\#1&#1&#1&\PTmqty{#5}}}
+    {
+    \IfNoValueTF{#7}
+    {\global\matrixtoks = \expandafter{\PTmqty{#2}&#1&#1&#1&#1\\#1&\PTmqty{#3}&#1&#1&#1\\#1&#1&\PTmqty{#4}&#1&#1\\#1&#1&#1&\PTmqty{#5}&#1\\#1&#1&#1&#1&\PTmqty{#6}}}
+    {
+      \IfNoValueTF{#8}
+      {\global\matrixtoks = \expandafter{\PTmqty{#2}&#1&#1&#1&#1&#1\\#1&\PTmqty{#3}&#1&#1&#1&#1\\#1&#1&\PTmqty{#4}&#1&#1&#1\\#1&#1&#1&\PTmqty{#5}&#1&#1\\#1&#1&#1&#1&\PTmqty{#6}&#1\\#1&#1&#1&#1&#1&\PTmqty{#7}}}
+      {
+      \IfNoValueTF{#9}
+      {\global\matrixtoks = \expandafter{\PTmqty{#2}&#1&#1&#1&#1&#1&#1\\#1&\PTmqty{#3}&#1&#1&#1&#1&#1\\#1&#1&\PTmqty{#4}&#1&#1&#1&#1\\#1&#1&#1&\PTmqty{#5}&#1&#1&#1\\#1&#1&#1&#1&\PTmqty{#6}&#1&#1\\#1&#1&#1&#1&#1&\PTmqty{#7}&#1\\#1&#1&#1&#1&#1&#1&\PTmqty{#8}}}
+      {\global\matrixtoks = \expandafter{\PTmqty{#2}&#1&#1&#1&#1&#1&#1&#1\\#1&\PTmqty{#3}&#1&#1&#1&#1&#1&#1\\#1&#1&\PTmqty{#4}&#1&#1&#1&#1&#1\\#1&#1&#1&\PTmqty{#5}&#1&#1&#1&#1\\#1&#1&#1&#1&\PTmqty{#6}&#1&#1&#1\\#1&#1&#1&#1&#1&\PTmqty{#7}&#1&#1\\#1&#1&#1&#1&#1&#1&\PTmqty{#8}&#1\\#1&#1&#1&#1&#1&#1&#1&\PTmqty{#9}}}
+      }
+    }
+    }
+  }
+  }
+}
+\the\matrixtoks
+}
+\DeclareDocumentCommand\diagonalmatrix{O{} >{\SplitList{,}}m }{\PTdmat{#1}#2}
+\DeclareDocumentCommand\dmat{}{\diagonalmatrix}
+
+\DeclareDocumentCommand\PTadmat{mmggggggg}
+{
+\newtoks\matrixtoks
+\global\matrixtoks = {}
+\IfNoValueTF{#3}
+{#2}
+{
+  \IfNoValueTF{#4}
+  {\global\matrixtoks = \expandafter{#1&\PTmqty{#2}\\\PTmqty{#3}&#1}}
+  {
+  \IfNoValueTF{#5}
+  {\global\matrixtoks = \expandafter{#1&#1&\PTmqty{#2}\\#1&\PTmqty{#3}&#1\\\PTmqty{#4}&#1&#1}}
+  {
+    \IfNoValueTF{#6}
+    {\global\matrixtoks = \expandafter{#1&#1&#1&\PTmqty{#2}\\#1&#1&\PTmqty{#3}&#1\\#1&\PTmqty{#4}&#1&#1\\\PTmqty{#5}&#1&#1&#1}}
+    {
+    \IfNoValueTF{#7}
+    {\global\matrixtoks = \expandafter{#1&#1&#1&#1&\PTmqty{#2}\\#1&#1&#1&\PTmqty{#3}&#1\\#1&#1&\PTmqty{#4}&#1&#1\\#1&\PTmqty{#5}&#1&#1&#1\\\PTmqty{#6}&#1&#1&#1&#1}}
+    {
+      \IfNoValueTF{#8}
+      {\global\matrixtoks = \expandafter{#1&#1&#1&#1&#1&\PTmqty{#2}\\#1&#1&#1&#1&\PTmqty{#3}&#1\\#1&#1&#1&\PTmqty{#4}&#1&#1\\#1&#1&\PTmqty{#5}&#1&#1&#1\\#1&\PTmqty{#6}&#1&#1&#1&#1\\\PTmqty{#7}&#1&#1&#1&#1&#1}}
+      {
+      \IfNoValueTF{#9}
+      {\global\matrixtoks = \expandafter{#1&#1&#1&#1&#1&#1&\PTmqty{#2}\\#1&#1&#1&#1&#1&\PTmqty{#3}&#1\\#1&#1&#1&#1&\PTmqty{#4}&#1&#1\\#1&#1&#1&\PTmqty{#5}&#1&#1&#1\\#1&#1&\PTmqty{#6}&#1&#1&#1&#1\\#1&\PTmqty{#7}&#1&#1&#1&#1&#1\\\PTmqty{#8}&#1&#1&#1&#1&#1&#1}}
+      {\global\matrixtoks = \expandafter{#1&#1&#1&#1&#1&#1&#1&\PTmqty{#2}\\#1&#1&#1&#1&#1&#1&\PTmqty{#3}&#1\\#1&#1&#1&#1&#1&\PTmqty{#4}&#1&#1\\#1&#1&#1&#1&\PTmqty{#5}&#1&#1&#1\\#1&#1&#1&\PTmqty{#6}&#1&#1&#1&#1\\#1&#1&\PTmqty{#7}&#1&#1&#1&#1&#1\\#1&\PTmqty{#8}&#1&#1&#1&#1&#1&#1\\\PTmqty{#9}&#1&#1&#1&#1&#1&#1&#1}}
+      }
+    }
+    }
+  }
+  }
+}
+\the\matrixtoks
+}
+\DeclareDocumentCommand\antidiagonalmatrix{O{} >{\SplitList{,}}m }{\PTadmat{#1}#2}
+\DeclareDocumentCommand\admat{}{\antidiagonalmatrix}
+
+% Misc
+\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
+  \div{\vb{B}}=0 \qc
+  \curl{\vb{E}}=-\pdv{\vb{B}}{t}\qc
+  \curl{\vb{B}}=\mu_0\vb{J}+\frac{1}{c^2}\pdv{\vb{E}}{t}\qc
+  H\ket{\Psi}=i\hbar\pdv{}{t}\ket{\Psi},
+  \qq{all else follows.}
+  }
+}
\ No newline at end of file



More information about the tex-live-commits mailing list.