%% hgbalgo.sty

%% Toward better looking algorithms ...
%% This package imports and pre-configures the 'algorithmicx'/'algpseudocodex' packages
%% (see https://ctan.org/pkg/algpseudocodex), fixes some problems and adds new functionality
%% and colors. It relies on the 'algorithm' package for typesetting float-type algorithms
%% with captions.

%% This file is part of the Hagenberg Thesis package for creating bachelors's and masters's theses
%% Author: Wilhelm Burger (wilbur@ieee.org)
%% GitHub: https://github.com/Digital-Media/HagenbergThesis
%% File encoding: ASCII

\ProvidesPackage{hgbalgo}[2023/11/06]%%AUTO

\RequirePackage[noEnd=true,indLines=true,italicComments=false]{algpseudocodex}	% https://ctan.org/pkg/algpseudocodex
\RequirePackage{calc}				% for numeric calculations
\RequirePackage{xcolor}

% Colors to be used in algorithms (can be redefined locally if desired)
\definecolor{AlgKeywordColor}{rgb}{0.00, 0.00, 0.666}	% = Dark Blue
\definecolor{AlgProcedureColor}{rgb}{0.00, 0.5, 0.20}	% = Dark Green
%\definecolor{AlgCommentColor}{gray}{0.40} 				% = Gray (40% black)

\algrenewcommand\algorithmicend{\textbf{\color{AlgKeywordColor}end}}
\algrenewcommand\algorithmicdo{\textbf{\color{AlgKeywordColor}do}}
\algrenewcommand\algorithmicwhile{\textbf{\color{AlgKeywordColor}while}}
\algrenewcommand\algorithmicfor{\textbf{\color{AlgKeywordColor}for}}
\algrenewcommand\algorithmicforall{\textbf{\color{AlgKeywordColor}for all}}
\algrenewcommand\algorithmicloop{\textbf{\color{AlgKeywordColor}loop}}
\algrenewcommand\algorithmicrepeat{\textbf{\color{AlgKeywordColor}repeat}}
\algrenewcommand\algorithmicuntil{\textbf{\color{AlgKeywordColor}until}}
\algrenewcommand\algorithmicprocedure{\textbf{\color{AlgKeywordColor}procedure}}
\algrenewcommand\algorithmicfunction{\textbf{\color{AlgKeywordColor}function}}
\algrenewcommand\algorithmicif{\textbf{\color{AlgKeywordColor}if}}
\algrenewcommand\algorithmicthen{\textbf{\color{AlgKeywordColor}then}}
\algrenewcommand\algorithmicelse{\textbf{\color{AlgKeywordColor}else}}
\algrenewcommand\algorithmicrequire{\textbf{\color{AlgKeywordColor}Require:}}
\algrenewcommand\algorithmicensure{\textbf{\color{AlgKeywordColor}Ensure:}}
\algrenewcommand\algorithmicreturn{\textbf{\color{AlgKeywordColor}return}}

% Use SF font and color for procedure and function names:
\newcommand{\@AlgTextProc}[1]{\textcolor{AlgProcedureColor}{\textsf{#1}}}
\algrenewcommand\textproc{\@AlgTextProc}			
\algrenewcommand\Call[2]{\textproc{#1}\hskip0.75pt(#2)}%

%% -----------------------------------------------------------------

\newlength{\@AlgTmpIndent}

%% Additional public macros:

% This macro is obsolete and will eventually dissappear:
\algnewcommand{\StateL}[1]{\State #1%
	\PackageWarning{hgbalgo}{Macro \protect\StateL\space is obsolete, use \protect\State\space instead}}%

% \StateNN[<nesting>]{<text>} creates non-numbered statements like algorithmicx's \Statex 
% command but provides consistent indentation inside nested constructs and over multiple lines.
% The optional integer argument [<nesting>] can be used to specify the nesting depth
% to counteract a bug in algorithmicx (nesting level is not set properly before the first \State
% command inside a nested construct.
\algnewcommand{\StateNN}[2][\numexpr\theALG@nested-1]{% default indentation = nesting - 1
  \setlength\@AlgTmpIndent{\algorithmicindent*#1}% requires calc package
	\Statex\hskip\@AlgTmpIndent\parbox[t]{\linewidth-\@AlgTmpIndent}{#2\strut}%
}%

% Macros for describing input and output of procedures and functions:
\algnewcommand\Input[1]{\StateNN[1]{\textbf{Input:} #1}}%			use to describe input parameters: \Input{<description>}
\algrenewcommand\Output[1]{\StateNN[1]{\textbf{Output:} #1}}%		use to describe output values: \Output{<description>} (already defined in algpseudocodex.sty) 
\algnewcommand\Returns[1]{\StateNN[1]{\textbf{Returns} #1}}%	use to describe what a procedure/function returns: \Returns{<description}

% The following macros insert additional vertical space after a statement.
% They only work in horizontal mode and are supposed
% to be used inside (at the end of) statements, e.g.,
%     \State $x \gets x + 1$ \algsmallskip
\algnewcommand{\algsmallskip}[0]{\raisebox{-3pt}{\strut}}
\algnewcommand{\algmedskip}[0]{\raisebox{-6pt}{\strut}}
\algnewcommand{\algbigskip}[0]{\raisebox{-12pt}{\strut}}

% 'algorithm' creates a floating environment for algorithms: \begin{algorithm}...\end{algorithm}
\@ifundefined{chapter}%
  {\RequirePackage[ruled]{algorithm}}%
	{\RequirePackage[ruled,chapter]{algorithm}}

\ifthenelse{\equal{\bbl@main@language}{german} \or \equal{\bbl@main@language}{ngerman}}%
	{\floatname{algorithm}{Algorithmus}}{}%
	
\ifthenelse{\equal{\bbl@main@language}{english}}%
	{\floatname{algorithm}{Algorithm}}{}%
