\ProvidesPackage{physics-ng}
% physics-ng 1.0
% This material is subject to the LaTeX Project Public License.
% See http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html for the details of that license.
%
% Personal substitute to the obselete physics package, might not be adapted to every one
% The derivative part and the Dirac brakets are respectively taken of by the
% diffcoeff and braket packages.
% It depends on asm ecosystem, siunitx, and esvect (for black board vector notation)
% Designed for Fourier mathtype-font with sloped setting, following ISO 80000-2 notations
% If you do not want to use the Fourier math font, or follow this ISO norm, this package
% is not yet ready for you
%
% Created by Alexis Draussin
% Updated on December 8, 2022
% Uploaded on December 20, 2022

\RequirePackage{xparse} % only for \dd and \nqty commands, copied from the old physics, to be replaced
\RequirePackage{amsmath}
\RequirePackage{fourier, bm}
\RequirePackage{esvect}
\RequirePackage{siunitx}

\DeclareOption{bb}{\let\arrowopt = 1}
\DeclareOption{nobb}{\let\arrowopt = 0} % default
\ExecuteOptions{nobb}
\ProcessOptions\relax

% incertitude command, using siunitx
\newcommand{\incert}[3]{\left(\num{#1}\pm\num{#2}\right)~\si{#3}}

% text between elements of equation
\newcommand{\qq}[1]{\ensuremath{\quad\text{#1}\quad}}

% transforms: Laplace, Fourier and Z
\DeclareMathAlphabet{\pazocal}{OMS}{zplm}{m}{n} % fourier overwrite the mathcal alpabet
\newcommand{\LT}[1]{\ensuremath{\pazocal{L}\left\lbrace#1\right\rbrace}}
\newcommand{\FT}[1]{\ensuremath{\pazocal{F}\left\lbrace#1\right\rbrace}}
\newcommand{\ZT}[1]{\ensuremath{\pazocal{Z}\left\lbrace#1\right\rbrace}}

% math constants
\newcommand{\e}{\ensuremath{\mathrm{e}}}
\newcommand{\im}{\ensuremath{\mathrm{i}}}
\newcommand{\jm}{\ensuremath{\mathrm{j}}}

% derivative
\DeclareDocumentCommand\dd{ 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}
            {\mathrm{d}\IfNoValueTF{#1}{}{^{#1}}}
            {\mathinner{\mathrm{d}\IfNoValueTF{#1}{}{^{#1}}\argopen(#3\argclose)}}
	    }
        {\mathinner{\mathrm{d}\IfNoValueTF{#1}{}{^{#1}}#2} \IfNoValueTF{#3}{}{(#3)}}
	}

% vectors, bb arrows with \vv or \vv* (for indexes)
\ifx\arrowopt 1 % just use esvect at this point
    \newcommand{\vect}[1]{\ensuremath{\vv{#1}}} % italic arrowed
    \newcommand{\mat}[1]{\ensuremath{{\mathrm{#1}}} % roman
    \newcommand{\tensor}[1]{\ensuremath{\vv{\vv{\mathsf{#1}}}}} % arrow and sans-serif
\else
    \newcommand{\vect}[1]{\ensuremath{\bm{#1}}} % bold and italic
    \newcommand{\mat}[1]{\ensuremath{\bm{\mathbf{#1}}}} % bold and roman
    \newcommand{\tensor}[1]{\ensuremath{\bm{\mathsf{#1}}}} % bold and sans-serif
\fi
\newcommand{\vecu}[1]{\ensuremath{\hat{\vect{#1}}}} % vector unit
\newcommand{\vecui}[1]{\ensuremath{\hat{\vect{e}}_{\bm{#1}}}} % vector unit wth index

\newcommand{\abs}[1]{\ensuremath{\left|#1\right|}}
\newcommand{\norm}[1]{\ensuremath{\left\|#1\right\|}}

% Note on vectors:
% - vec v = (v_i) = (v)_i
% - product by scalar, no dot xv = x(v)_i
% - |v| or bb with ||v||
% - hat e_a = a / |a|
% - scalar product, dot a . b = sum_i a_ib_i
% - vector product, cross a x b = sum_j sum_k LeviCivita_ijk a_j b_k
% - nabla roman, arrow in bb
% - grad, rot and div with nable notation, letter in bb
% - laplacian := nabla^2 only
% - D'Alembertian := square only

% Note on matrices:
% - mat A = (a_ij) = (A)_ij
% - scalar product, no dot xA = x(A)_ij
% - matrix product, no dot AB = sum_j (A)ij(B)jk
% - unit matrix I = (I)_ij = Krodelta_ij
% - det A, rank A, tr A, ||A||

% Note on tensors:
% - dyatic product, between 2 vectors: a otimes b = (ab)_ij = a_ib_j
% - tensor product, between 2 tensors: T otimes S = T_ij S_kl
% - inner product, between 2 tensors: T . S = sum_j T_ij S_jk
% - inner product with a vector: T . a = sum_j T_ij a_j
% - scalar product, column:  T:S = sum_i sum_j T_ij S_ji

% bunch functions not base-declared
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator{\sinc}{sinc}
\DeclareMathOperator{\Ei}{Ei}
\DeclareMathOperator{\Li}{Li}
\DeclareMathOperator{\Si}{Si}
\DeclareMathOperator{\erf}{erf}
\DeclareMathOperator{\erfc}{erfc}
\DeclareMathOperator{\arccot}{arccot}
\DeclareMathOperator{\arcsec}{arcsec}
\DeclareMathOperator{\arccsc}{arccsc}
\DeclareMathOperator{\sech}{sech}
\DeclareMathOperator{\csch}{csch}
\DeclareMathOperator{\arsinh}{arsinh}
\DeclareMathOperator{\arcosh}{arcosh}
\DeclareMathOperator{\artanh}{artanh}
\DeclareMathOperator{\arcoth}{arcoth}
\DeclareMathOperator{\arsech}{arsech}
\DeclareMathOperator{\arcsch}{arcsch}

\DeclareDocumentCommand\nqty{}{{\ifnum\z@=`}\fi\@nqty}
\DeclareDocumentCommand\@nqty{ t\big t\Big t\bigg t\Bigg g o d() d|| }
{ % Flexible automatic bracketing of an expression in () or [] or {} or ||
	% Handles manual override of sizing
	\IfBooleanTF{#1}{\let\ltag\bigl \let\rtag\bigr}{
		\IfBooleanTF{#2}{\let\ltag\Bigl \let\rtag\Bigr}{
			\IfBooleanTF{#3}{\let\ltag\biggl \let\rtag\biggr}{
				\IfBooleanTF{#4}
				{\let\ltag\Biggl \let\rtag\Biggr}
				{\let\ltag\left \let\rtag\right}
			}
		}
	}
	% Handles actual bracketing
	\IfNoValueTF{#5}{
		\IfNoValueTF{#6}{
			\IfNoValueTF{#7}{
				\IfNoValueTF{#8}
				{()}
				{\ltag\lvert{#8}\rtag\rvert}
			}
			{\ltag(#7\rtag) \IfNoValueTF{#8}{}{|#8|}}
		}
		{\ltag[#6\rtag] \IfNoValueTF{#7}{}{(#7)} \IfNoValueTF{#8}{}{|#8|}}
	}
	{\ltag\lbrace#5\rtag\rbrace  \IfNoValueTF{#6}{}{[#6]} \IfNoValueTF{#7}{}{(#7)} \IfNoValueTF{#8}{}{|#8|}}
	\ifnum\z@=`{\fi}
}

\newcommand{\comm}[2]{\ensuremath{\nqty[#1,#2]}}
\newcommand{\acomm}[2]{\ensuremath{\nqty{#1,#2}}}
