%% Generic commands macros

% Functions
\newcommand{\area}{\mathsf{area}}
\newcommand{\dinv}{\mathsf{dinv}}
\newcommand{\inv}{\mathsf{inv}}
\newcommand{\bounce}{\mathsf{bounce}}
\newcommand{\pbounce}{\mathsf{pbounce}}
\newcommand{\pmaj}{\mathsf{pmaj}}
\newcommand{\maj}{\mathsf{maj}}
\newcommand{\ides}{\mathsf{ides}}

\newcommand{\Val}{\mathsf{Val}}
\newcommand{\Rise}{\mathsf{Rise}}
\newcommand{\Peak}{\mathsf{Peak}}
\newcommand{\ZVal}{\mathsf{ZVal}}
\newcommand{\DRise}{\mathsf{DRise}}
\newcommand{\DPeak}{\mathsf{DPeak}}

\newcommand{\DP}{\mathsf{DP}} % Dyck paths
\newcommand{\D}{\mathsf{D}} % Dyck paths (new)
\newcommand{\LD}{\mathsf{LD}} % Labelled Dyck paths
\newcommand{\DD}{\mathsf{DD}} % Decorated Dyck paths
\newcommand{\LDD}{\mathsf{LDD}} % Labelled decorated Dyck paths
\newcommand{\PDD}{\mathsf{PDD}} % parking decorated Dyck paths
\newcommand{\DDd}{\mathsf{DDd}} % Decorated Dyck paths dinv set
\newcommand{\DDb}{\mathsf{DDb}} % Decorated Dyck paths bounce set
\newcommand{\DDp}{\mathsf{DDp}} % Decorated Dyck paths pbounce set
\newcommand{\SQE}{\mathsf{SQ^{E}}} % square paths ending east
\newcommand{\SQN}{\mathsf{SQ^{N}}} % square paths ending north
\newcommand{\PLSQE}{\mathsf{PLSQ^{E}}} 
\newcommand{\PLSQN}{\mathsf{PLSQ^{N}}} 
\newcommand{\PF}{\mathsf{PF}} % Parking functions
\newcommand{\PLD}{\mathsf{PLD}} % Partially labelled Dyck paths
\newcommand{\PLDd}{\mathsf{PLDd}} % Partially labelled Dyck paths
\newcommand{\PLDb}{\mathsf{PLDb}} % Partially labelled Dyck paths

\newcommand{\PP}{\mathsf{PP}} % Parallelogram polyominoes
\newcommand{\RP}{\mathsf{RP}} % Reduced parallelogram polyominoes
\newcommand{\LPP}{\mathsf{LPP}} % Labelled parallelogram polyominoes

\newcommand{\gendelta}{\mathsf{PLD}_{\underline x,q,t}(m,n)^{\ast k}} % the combinatorial def of generalized delta conjecture.
\newcommand{\gensquare}{\mathsf{PLSQ^E}_{\underline x,q,t}(m,n)^{\ast k}} % the combinatorial def of the generalized square conjecture. 
\newcommand{\OP}{\mathsf{OP}} % ordered set partitions 
\newcommand{\OPi}{\mathsf{OPi} } % ordered set partitions with inv
\newcommand{\OPd}{\mathsf{OPd} } % ordered set partitions with dinv
\newcommand{\OPm}{\mathsf{OPm} } % ordered set partitions with maj
\newcommand{\SOP}{\mathsf{SOP}} % standard ordered set partitions 
\newcommand{\SOPi}{\mathsf{SOPi} } % standard ordered set partitions with inv
\newcommand{\SOPd}{\mathsf{SOPd} } % standard ordered set partitions with dinv
\newcommand{\SOPm}{\mathsf{SOPm} } % standard ordered set partitions with maj


% q-binomials
\newcommand{\qbinom}[2]{\genfrac{[}{]}{0pt}{}{#1}{#2}}
\newcommand{\dqbinom}[2]{\genfrac{[}{]}{0pt}{0}{#1}{#2}}

% Dominoes
\newcommand*{\mystrut}{\rule[-0.4\baselineskip]{0pt}{1.2\baselineskip}}
\renewcommand*{\boxed}[1]{\framebox{\mystrut $#1$}}
\newcommand{\domino}[2]{\boxed{\genfrac{}{}{0pt}{}{#1}{#2}}}
\newcommand{\ddomino}[2]{\boxed{\genfrac{}{}{0pt}{0}{#1}{#2}}}

% Tikz keys for lines of different colours
\makeatletter

% First
\pgfkeys{
	/tikz/sharp angle/.code={%
		\pgfsetarrowoptions{sharp >}{#1}%
		\pgfsetarrowoptions{sharp <}{-#1}%
	},
	/tikz/sharp > angle/.code={%
		\pgfsetarrowoptions{sharp >}{#1}%
	},
	/tikz/sharp < angle/.code={%
		\pgfsetarrowoptions{sharp <}{#1}%
	},
	/tikz/sharp protrude/.code=\csname if#1\endcsname\qrr@tikz@sharp@z@-0.05\p@\else\qrr@tikz@sharp@z@\z@\fi,
	/tikz/sharp protrude/.default=true
}

\newdimen\qrr@tikz@sharp@z@
\qrr@tikz@sharp@z@\z@
\pgfarrowsdeclare{sharp >}{sharp >}{%
	\edef\pgf@marshal{\noexpand\pgfutil@in@{and}{\pgfgetarrowoptions{sharp >}}}%
	\pgf@marshal
	\ifpgfutil@in@
	\edef\pgf@tempa{\pgfgetarrowoptions{sharp >}}
	\expandafter\qrr@tikz@sharp@parse\pgf@tempa\@qrr@tikz@sharp@parse
	\else
	\qrr@tikz@sharp@parse\pgfgetarrowoptions{sharp >}and-\pgfgetarrowoptions{sharp >}\@qrr@tikz@sharp@parse
	\fi
	% 
	\pgfmathparse{max(\pgf@tempa,\pgf@tempb,0)}%
	\let\qrr@tikz@sharp@max\pgfmathresult
	\pgfmathsetlength\pgf@xa{.5*\pgflinewidth * tan(\qrr@tikz@sharp@max)}%
	\pgfarrowsleftextend{+\pgf@xa}%
	\pgfarrowsrightextend{+\pgf@xa}%
}{%
	\edef\pgf@marshal{\noexpand\pgfutil@in@{and}{\pgfgetarrowoptions{sharp >}}}%
	\pgf@marshal
	\ifpgfutil@in@
	\edef\pgf@tempa{\pgfgetarrowoptions{sharp >}}
	\expandafter\qrr@tikz@sharp@parse\pgf@tempa\@qrr@tikz@sharp@parse
	\else
	\qrr@tikz@sharp@parse\pgfgetarrowoptions{sharp >}and-\pgfgetarrowoptions{sharp >}\@qrr@tikz@sharp@parse
	\fi
	% 
	\pgfmathsetlength\pgf@ya{.5*\pgflinewidth * tan(max(\pgf@tempa,\pgf@tempb,0))}%
	\pgfmathsetlength\pgf@xa{-.5*\pgflinewidth * tan(\pgf@tempa)}%
	\pgfmathsetlength\pgf@xb{-.5*\pgflinewidth * tan(\pgf@tempb)}%
	\advance\pgf@xa\pgf@ya
	\advance\pgf@xb\pgf@ya
	\ifdim\pgf@xa>\pgf@xb
	\pgftransformyscale{-1}%
	\pgf@xc\pgf@xb
	\pgf@xb\pgf@xa
	\pgf@xa\pgf@xc
	\fi
	\pgfpathmoveto{\pgfqpoint{\qrr@tikz@sharp@z@}{.5\pgflinewidth}}%
	\pgfpathlineto{\pgfqpoint{\pgf@xa}{.5\pgflinewidth}}%
	\pgfpathlineto{\pgfqpoint{\pgf@ya}{+0pt}}%
	\pgfpathlineto{\pgfqpoint{\pgf@xb}{-.5\pgflinewidth}}%
	\pgfpathlineto{\pgfqpoint{\qrr@tikz@sharp@z@}{-.5\pgflinewidth}}%
	\pgfusepathqfill
}
\pgfarrowsdeclare{sharp <}{sharp <}{%
	\edef\pgf@marshal{\noexpand\pgfutil@in@{and}{\pgfgetarrowoptions{sharp <}}}%
	\pgf@marshal
	\ifpgfutil@in@
	\edef\pgf@tempa{\pgfgetarrowoptions{sharp <}}
	\expandafter\qrr@tikz@sharp@parse\pgf@tempa\@qrr@tikz@sharp@parse
	\else
	\expandafter\qrr@tikz@sharp@parse\pgfgetarrowoptions{sharp <}and-\pgfgetarrowoptions{sharp <}\@qrr@tikz@sharp@parse
	\fi
	% 
	\pgfmathparse{max(\pgf@tempa,\pgf@tempb,0)}%
	\let\qrr@tikz@sharp@max\pgfmathresult
	\pgfmathsetlength\pgf@xa{.5*\pgflinewidth * tan(\qrr@tikz@sharp@max)}%
	\pgfarrowsleftextend{+\pgf@xa}%
	\pgfarrowsrightextend{+\pgf@xa}%
}{%
	\edef\pgf@marshal{\noexpand\pgfutil@in@{and}{\pgfgetarrowoptions{sharp <}}}%
	\pgf@marshal
	\ifpgfutil@in@
	\edef\pgf@tempa{\pgfgetarrowoptions{sharp <}}
	\expandafter\qrr@tikz@sharp@parse\pgf@tempa\@qrr@tikz@sharp@parse
	\else
	\expandafter\qrr@tikz@sharp@parse\pgfgetarrowoptions{sharp <}and-\pgfgetarrowoptions{sharp <}\@qrr@tikz@sharp@parse
	\fi
	% 
	\pgfmathsetlength\pgf@ya{.5*\pgflinewidth * tan(max(\pgf@tempa,\pgf@tempb,0))}%
	% 
	\pgfmathsetlength\pgf@xa{-.5*\pgflinewidth * tan(\pgf@tempa)}%
	\pgfmathsetlength\pgf@xb{-.5*\pgflinewidth * tan(\pgf@tempb)}%
	\advance\pgf@xa\pgf@ya
	\advance\pgf@xb\pgf@ya
	\ifdim\pgf@xa>\pgf@xb
	\pgftransformyscale{-1}%
	\pgf@xc\pgf@xb
	\pgf@xb\pgf@xa
	\pgf@xa\pgf@xc
	\fi
	\pgfpathmoveto{\pgfqpoint{\qrr@tikz@sharp@z@}{.5\pgflinewidth}}%
	\pgfpathlineto{\pgfqpoint{\pgf@xa}{.5\pgflinewidth}}%
	\pgfpathlineto{\pgfqpoint{\pgf@ya}{+0pt}}%
	\pgfpathlineto{\pgfqpoint{\pgf@xb}{-.5\pgflinewidth}}%
	\pgfpathlineto{\pgfqpoint{\qrr@tikz@sharp@z@}{-.5\pgflinewidth}}%
	\pgfusepathqfill
}
\def\qrr@tikz@sharp@parse#1and#2\@qrr@tikz@sharp@parse{\def\pgf@tempa{#1}\def\pgf@tempb{#2}}

\makeatother

% Multisets
\newcommand\multiset[2]%
{\mathchoice{\left(\kern-0.4em{\binom{#1}{#2}}\kern-0.4em\right)}
            {\bigl(\kern-0.2em{\binom{#1}{#2}}\kern-0.2em\bigr)}
            {\bigl(\kern-0.2em{\binom{#1}{#2}}\kern-0.2em\bigr)}
            {\bigl(\kern-0.2em{\binom{#1}{#2}}\kern-0.2em\bigr)}}
        
% Properly spaced \exists and \forall
\let\existstemp\exists \renewcommand*{\exists}{\mathop \existstemp}
\let\foralltemp\forall \renewcommand*{\forall}{\mathop \foralltemp}

% Quotients
%\def\quotient#1#2{\raise.0ex\hbox{$#1$}/\lower.0ex\hbox{$#2$}}
\def\quotient#1#2{\raise1ex\hbox{$#1$}\Big/\lower1ex\hbox{$#2$}}

% Scalar products
\newcommand{\<}{\langle}
\renewcommand{\>}{\rangle}

% Duck QED's
%\renewcommand{\qedsymbol}{\begin{tikzpicture}[scale=0.1] \duck[graduate=gray!20!black, tassel=red!70!black] \end{tikzpicture}}