% !TEX root = ../HSRTReport.cls
% ==============================================================================
% Equations Configuration Module
% ==============================================================================
% Description: Configuration for equation lists and equation formatting
% Author: Frederik Beimgraben
% License: Creative Commons CC BY 4.0
% ==============================================================================

% ==============================================================================
% List of Equations Configuration
% ==============================================================================
% Define custom list for equations
\newcommand{\listequationsname}{List of Equations}
\newlistof{myequations}{equ}{\listequationsname}

% Define equation name for references
\newcommand{\equationname}{Equation}

% ==============================================================================
% Equation List Commands
% ==============================================================================
% Command to add equations to the list
\newfloat{Formel}{htbp}{}
\newcommand\numbereq{\addtocounter{equation}{1}\tag{\theequation}}

\newcommand{\myequations}[1]{
	% Add Floating (N) #1 below (This function is called after the equation environment)
	\captionof{Formel}{#1}\vspace{1em}

	% Add to list of equations
	\cftaddtitleline{equ}{myequations}{\quad\blenderfont(\theequation)\quad #1}{\blenderfont\thepage}\par
}

% ==============================================================================
% Equation Counter Configuration
% ==============================================================================
% Remove chapter dependency from equation counter
% (This allows continuous equation numbering throughout the document)
\counterwithout{equation}{chapter}

% ==============================================================================
% Equation Formatting Configuration
% ==============================================================================
% Set equation indentation to 1cm from margin
% We redefine the equation environment to add left margin

% Configure vertical spacing around equations
% Two lines spacing before and after equations as per requirements
\setlength{\abovedisplayskip}{24pt plus 6pt minus 6pt}
\setlength{\belowdisplayskip}{24pt plus 6pt minus 6pt}
\setlength{\abovedisplayshortskip}{12pt plus 3pt minus 3pt}
\setlength{\belowdisplayshortskip}{12pt plus 3pt minus 3pt}

% Save original equation environments
\let\originalequation\equation
\let\endoriginalequation\endequation
\let\originalequationstar\[
	\let\endoriginalequationstar\]

% Redefine equation environment with 1cm left indent
\renewenvironment{equation}{%
	\vspace{\abovedisplayskip}%
	\noindent\hspace{1cm}\begin{minipage}{\dimexpr\textwidth-1cm\relax}%
		\originalequation%
		}{%
		\endoriginalequation%
	\end{minipage}%
	\vspace{\belowdisplayskip}%
}

% Redefine displaymath with 1cm left indent
\renewenvironment{displaymath}{%
	\vspace{\abovedisplayskip}%
	\noindent\hspace{1cm}\begin{minipage}{\dimexpr\textwidth-1cm\relax}%
		\[%
			}{%
		\]%
	\end{minipage}%
	\vspace{\belowdisplayskip}%
}

% ==============================================================================
% Alternative Indented Equation Environments
% ==============================================================================
% These can be used when you don't want global indentation
\newenvironment{indentedequation}{%
	\vspace{\abovedisplayskip}%
	\noindent\hspace{1cm}\begin{minipage}{\dimexpr\textwidth-1cm\relax}%
		\originalequation%
		}{%
		\endoriginalequation%
	\end{minipage}%
	\vspace{\belowdisplayskip}%
}

% Define unnumbered version
\newenvironment{indentedequation*}{%
	\vspace{\abovedisplayskip}%
	\noindent\hspace{1cm}\begin{minipage}{\dimexpr\textwidth-1cm\relax}%
		\[%
			}{%
		\]%
	\end{minipage}%
	\vspace{\belowdisplayskip}%
}

% ==============================================================================
% End of Equations Configuration Module
% ==============================================================================
