%%
%% This is file `hep-math.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% hep-math-implementation.dtx  (with options: `package')
%% This is a generated file.
%% Copyright (C) 2019-2023 by Jan Hajer
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. The latest version of this license is in:
%% http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.

\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{hep-math}[2024/11/01 v1.3 Math and physics macros]

\RequirePackage{mathtools}
\mathtoolsset{centercolon}
\allowdisplaybreaks[1]
\thickmuskip=5mu plus 3mu minus 1mu
\medmuskip=4mu plus 2mu minus 3mu
\RequirePackage{xparse}
\DeclareDocumentCommand{\mathdef}{mO{0}om}{%
  \expandafter\let\csname hep@text\string#1\endcsname=#1
  \expandafter\newcommand\csname hep@math\string#1%
  \IfNoValueTF{#3}{\endcsname[#2]}{\endcsname[#2][#3]}{#4}
  \DeclareRobustCommand#1{%
    \ifmmode
      \expandafter\let\expandafter\next\csname%
      hep@math\string#1\endcsname%
    \else
      \expandafter\let\expandafter\next\csname%
      hep@text\string#1\endcsname%
    \fi
    \next
  }%
}
\newcommand{\imaginaryunit}{\text{i}}
\AtBeginDocument{\mathdef{\i}{\imaginaryunit}}
\RequirePackage{soul}
\newcommand\textoverline[1]{{\setul{-1.9ex}{}\ul{#1}}}
\let\overline\textoverline
\DeclareRobustCommand{\over@line}[1]{\@@overline{#1}}
\mathdef{\overline}{\over@line}
\newcommand\hep@widebar[1]{%
  \mkern2.5mu\overline{\mkern-2.5mu#1\mkern-.5mu}\mkern.5mu%
}
\newcommand\widebar[1]{%
  \settowidth{\dimen0}{\ensuremath{#1}}%
  \ifdim\dimen0>.475em\hep@widebar{#1}\else\bar{#1}\fi%
}
\newcommand{\oset}[3][-1pt]{%
  \text{\raisebox{.2ex}{$\mathop{#3}\limits^{%
    \vbox to#1{\kern-2\ex@\hbox{$\scriptscriptstyle#2$}\vss}%
  }$}}%
}
\newcommand{\overleft}[1]{\oset{\leftarrow}{#1}}
\newcommand{\overright}[1]{\oset{\rightarrow}{#1}}
\newcommand{\overleftright}[1]{\oset{\leftrightarrow}{#1}}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\Tr}{Tr}
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator{\erf}{erf}
\DeclareMathOperator{\Res}{Res}
\DeclareMathOperator{\sgn}{sgn}
\DeclareMathOperator{\diag}{diag}
\let\det\relax\DeclareMathOperator{\det}{det}

\let\Re\relax\DeclareMathOperator{\Re}{Re}
\let\Im\relax\DeclareMathOperator{\Im}{Im}

\RequirePackage{amssymb}
\newcommand*{\hep@transpose}[2]{\raisebox{\depth}{$\m@th#1\intercal$}}
\newcommand*{\transpose}{{\mathpalette\hep@transpose{}}}
\let\trans\transpose

\let\cos\undefined\DeclareMathOperator{\cos}{cos\vphantom{i}}
\let\tan\undefined\DeclareMathOperator{\tan}{tan\vphantom{i}}
\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}
\RequirePackage{units}
\let\oldunit\unit
\renewcommand{\unit}[2][]{%
  \ifthenelse{\boolean{mmode}}{%
    \mathinner{\oldunit[#1]{#2}}%
  }{%
     \oldunit[#1]{#2}%
  }%
}
\let\oldunitfrac\unitfrac
\renewcommand{\unitfrac}[3][]{%
  \ifthenelse{\boolean{mmode}}{%
    \mathinner{\oldunitfrac[#1]{#2}{#3}}%
  }{%
    \oldunitfrac[#1]{#2}{#3}%
  }%
}
\newcommand{\inv}[2][1]{#2\ensuremath{^{-#1}}}
\newcommand{\textfrac}[2]{\ensuremath{\nicefrac{\text{#1}}{\text{#2}}}}
\DeclarePairedDelimiterX{\hep@flatfrac}[2]{.}{.}{%
  \kern-\nulldelimiterspace#1\delimsize/%
  \hep@left@delim#2\kern-\nulldelimiterspace%
}
\NewDocumentCommand{\flatfrac}{somm}{%
  \mathinner{%
    \IfBooleanTF{#1}{%
      \hep@flatfrac*{#3}{#4}%
    }{%
      \IfNoValueTF{#2}{\hep@left@delim#3/\hep@left@delim#4%
      }{%
       \hep@flatfrac[#2]{#3}{#4}%
      }%
    }%
  }%
}
\newcommand{\differential}[1]{\mathop{}\!#1}
\newcommand\newderivative[2]{
  \NewDocumentCommand{#1}{somse{^}}{%
    \IfBooleanTF{##4}{%
      \IfBooleanTF{##1}{\nicefrac}{\frac}%
    }{%
      \IfBooleanTF{##1}{\flatfrac}{\dfrac}%
    }{%
      \differential#2\IfValueT{##5}{^{##5\!}}\IfValueT{##2}{##2}%
    }{%
      \differential#2{{}##3}\IfValueT{##5}{^{##5}}%
    }%
  }
}
\newcommand\newpartialderivative[2]{
  \NewDocumentCommand{#1}{somsE{^}{1}oE{^}{1}oE{^}{1}}{%
    \def\hep@one{\IfValueTF{##6}{##7}{0}}
    \def\hep@two{\IfValueTF{##8}{##9}{0}}
    \def\hep@sum{\the\numexpr##5+\hep@one+\hep@two\relax}
    \IfBooleanTF{##4}{%
      \IfBooleanTF{##1}{\nicefrac}{\frac}%
    }{%
      \IfBooleanTF{##1}{\flatfrac}{\dfrac}%
    }{%
      \differential#2\ifnum\hep@sum=1\relax\else{^{\hep@sum\!}}\fi
      \IfValueT{##2}{##2}%
    }{%
      \differential#2{{}##3}\ifnum##5=1\relax\else{^{##5}}\fi%
      \IfValueT{##6}{#2##6\ifnum##7=1\relax\else{^{##7}}\fi}%
      \IfValueT{##8}{#2##8\ifnum##9=1\relax\else{^{##9}}\fi}%
    }%
  }
}
\providecommand{\diffsymbol}{d}
\newcommand{\diff}{\differential\diffsymbol}
\AtBeginDocument{\mathdef{\d}{\diff}}
\newderivative{\derivative}{\diffsymbol}
\newcommand\dv{\derivative}
\newcommand\partialdifferential{\differential\partial}
\newcommand\slashedpartialdifferential{\differential{\slashed\partial}}
\newcommand\spd{\slashedpartialdifferential}
\newcommand\pd{\partialdifferential}
\newpartialderivative{\partialderivative}{\partial}
\newcommand\pdv{\partialderivative}
\providecommand{\gaugediffsymbol}{D}
\newcommand{\gaugediff}{\differential\gaugediffsymbol}
\newcommand{\D}{\gaugediff}
\newcommand{\covariantdiff}{\differential\nabla}
\newcommand{\cd}{\covariantdiff}
\newcommand\variation{\differential\delta}
\newcommand\var{\variation}
\newpartialderivative{\functionalderivative}{\delta}
\newcommand\fdv{\functionalderivative}
\RequirePackage{cancel}
\RequirePackage{slashed}
\declareslashed{}{/}{.14}{0}{L}
\declareslashed{}{/}{.055}{0}{\partial}
\declareslashed{}{/}{.06}{0}{\gaugediff}
\declareslashed{}{/}{.055}{0}{\partialdifferential}
\RequirePackage{mleftright}
\mleftright
\RequirePackage{etoolbox}
\newcommand{\noargumentsymbol}{\:\cdot\:}
\newcommand{\optionalargument}[1]{\ifblank{#1}{\noargumentsymbol}{#1}}
\DeclarePairedDelimiterX\abs[1]\lvert\rvert{\optionalargument{#1}}
\DeclarePairedDelimiterX\hep@norm[1]\lVert\rVert{\optionalargument{#1}}
\DeclarePairedDelimiterXPP\hep@pnorm[2]{}\lVert\rVert{_{#1}}{#2}
\NewDocumentCommand{\norm}{som}{%
  \IfValueTF{#2}{%
    \IfBooleanTF{#1}{\hep@pnorm*}{\hep@pnorm}{#2}%
  }{%
    \IfBooleanTF{#1}{\hep@norm*}{\hep@norm}%
  }{\optionalargument{#3}}%
}

\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}

\providecommand{\ordersymbol}{\mathcal{O}}
\DeclarePairedDelimiterXPP\order[1]{\ordersymbol}(){}{#1}

\DeclarePairedDelimiter{\hep@evaluated}{.}{\rvert}
\NewDocumentCommand{\evaluated}{som}{%
  \IfBooleanTF{#1}{%
    \hep@evaluated*{#3}%
  }{%
    \IfNoValueTF{#2}{#3\rvert}{\hep@evaluated[#2]{#3}}%
  }%
}
\newcommand\eval{\evaluated}

\newcommand*{\rowseperator}{,\,}
\ExplSyntaxOn
\newcommand*{\hep@row}[1]{
 \seq_set_split:Nnn\hep@seq{,}{#1}
 \begin{matrix}\seq_use:Nn\hep@seq{\rowseperator}\end{matrix}
}
\newcommand*{\hep@column}[1]{%
 \seq_set_split:Nnn\hep@seq{,}{#1}%
 \begin{matrix}\seq_use:Nn\hep@seq{\\}\end{matrix}%
}
\ExplSyntaxOff
\DeclarePairedDelimiterX{\hep@row@}[1]{(}{)}{\hep@row{#1}}
\NewDocumentCommand{\hep@column@}{me{^}e{_}}{%
  \left(\hep@column{#1}\right)%
  \IfValueT{#2}{^{\!\!\!#2}}\IfValueT{#3}{_{\!\!\!#3}}%
}
\providecommand{\column}{}
\providecommand{\row}{}
\mathdef{\column}{\hep@column@}
\providecommand{\row}{}
\mathdef{\row}{\hep@row@}

\newcommand\hep@left@delim{\mathopen{}}
\providecommand{\midbar}[1][]{%
  \nonscript\:#1\vert\allowbreak\nonscript\:\hep@left@delim%
}

\RequirePackage{xpatch}
\@ifundefined{exfs@merge@families}{}{%
  \xpatchcmd{\exfs@merge@families}{\set}{\cfr@set}{}{}%
  \xpatchcmd{\exfs@merge@families}{\set}{\cfr@set}{}{}%
  \xpatchcmd{\exfs@merge@families}{\set}{\cfr@set}{}{}%
}%
\providecommand\suchthat{\midbar}
\DeclarePairedDelimiterX\set[1]\{\}{%
  \renewcommand\suchthat{\midbar[\delimsize]}#1%
}

\providecommand{\probabilitysymbol}{\operatorname{Pr}}
\providecommand\given{\midbar}
\DeclarePairedDelimiterXPP\hep@Pr[1]{%
  \probabilitysymbol}(){}{%
  \renewcommand\given{\midbar[\delimsize]}#1%
}
\let\Pr\relax
\NewDocumentCommand{\Pr}{so}{%
  \IfValueTF{#2}{%
    \IfBooleanTF{#1}{\hep@Pr*}{\hep@Pr}{#2}%
  }{%
    \probabilitysymbol%
  }%
}

\NewDocumentCommand{\newpair}{mmme{_}e{^}}{%
  \IfNoValueTF{#4}{%
    \IfNoValueTF{#5}{%
      \DeclarePairedDelimiterX{#1}[2]{#2}{#3}%
    }{%
      \DeclarePairedDelimiterXPP{#1}[2]{}{#2}{#3}{^{#5}}%
    }%
  }{%
    \DeclarePairedDelimiterXPP{#1}[2]{}{#2}{#3}{_{#4}}%
  }{%
    \optionalargument{##1},\optionalargument{##2}%
  }%
}
\newpair\innerproduct\langle\rangle
\newpair\poissonbracket\lbrace\rbrace
\newpair\commutator\lbrack\rbrack
\newcommand\pb{\poissonbracket}
\newcommand\comm{\commutator}
\newcommand\acomm{\poissonbracket}
\providecommand\braketouterspace{\mskip1mu}
\providecommand\braketinnerspace{\mskip3mu}
\newcommand\hep@midvert{%
  \braketinnerspace\delimsize\vert\braketinnerspace\hep@left@delim%
}
\DeclarePairedDelimiterX\braket[2]{\langle}{\rangle}{%
  \braketouterspace#1\hep@midvert#2\braketouterspace%
}

\DeclarePairedDelimiterXPP\hep@bra[1]{%
  }{\langle}{\rvert}{\braketinnerspace%
  }{\braketouterspace#1\braketinnerspace%
}
\NewDocumentCommand{\bra}{smt\ket sgt\ketbra sgg}{%
  \IfBooleanTF{#6}{%
    \IfBooleanTF{#1}{\braket*{#2}{#8}}{\braket{#2}{#8}}%
    \IfBooleanTF{#7}{\bra*{#9}}{\bra{#9}}%
  }{
    \IfBooleanTF{#3}{%
      \IfBooleanTF{#1}{\braket*}{%
        \IfBooleanTF{#4}{\braket*}{\braket}}{#2}{#5%
      }%
    }{%
      \IfBooleanTF{#1}{\hep@bra*}{\hep@bra}{#2}%
    }%
  }%
}

\DeclarePairedDelimiterXPP\ket[1]{%
  \braketinnerspace}{\lvert}{\rangle}{%
}{%
  \braketinnerspace\hep@left@delim#1\braketouterspace%
}

\NewDocumentCommand{\ketbra}{smm}{%
  \IfBooleanTF{#1}{%
    \ket*{#2}\bra*{#3}%
  }{%
    \ket{#2}\bra{#3}%
  }%
}

\DeclarePairedDelimiterX\matrixelement[3]{%
  \langle}{\rangle
}{%
  \braketouterspace#1\hep@midvert#2\hep@midvert#3\braketouterspace%
}
\newcommand\matrixel{\matrixelement}
\newcommand\mel{\matrixelement}

\DeclarePairedDelimiterX\hep@expvalue[1]{\langle}{\rangle}{%
  \braketouterspace#1\braketouterspace%
}
\NewDocumentCommand{\expectationvalue}{som}{%
  \IfNoValueTF{#2}{%
    \IfBooleanTF{#1}{\hep@expvalue*}{\hep@expvalue}{#3}%
  }{%
    \IfBooleanTF{#1}{\matrixelement*}{\matrixelement}{#2}{#3}{#2}%
  }%
}
\newcommand\ev{\expectationvalue}
\newcommand\vev[1]{\expectationvalue[0]{#1}}

\endinput
%%
%% End of file `hep-math.sty'.