\usepackage{listings}
%%% including some code
% \begin{lstlisting}[language=Python] ... \end{lstlisting}
%%% including a python file
% \lstinputlisting[language=Python]{source_filename.py}
% \lstinputlisting[language=Python, linerange={37-45,48-50}]{source_filename.py}

\lstset{ 
  backgroundcolor=\color{AW},  % background color
  basicstyle=\footnotesize,         % size of fonts used for the code 
  breakatwhitespace=false,          % automatic breaks should only happen at whitespace 
  breaklines=true,                  % automatic line breaking
  captionpos=b,                     % caption-position at bottom
  commentstyle=\color{DarkG},       % comment style
  deletekeywords={...},             % deletes keywords from the given language 
  escapeinside={\%*}{*)},           % to add LaTeX within the code 
  extendedchars=true,               % use non-ASCII characters;
                                    % for 8-bits encodings only,
                                    % does not work with UTF-8 
  firstnumber=1,                    % starts line enumeration with line 1 
  % frame=single,	            % adds a frame around the code
  keepspaces=true,                  % keeps spaces in text (indentation of code)
                                    % (possibly needs columns=flexible) 
  keywordstyle={\bf\color{DarkB}},  % keyword style
  language=Python,                  % sets language of the code
  % morekeywords={*,...},           % if you want to add more keywords to the set
  numbers=left,                     % where to put the line-numbers (none, left, right) 
  numbersep=1ex,                    % how far the line-numbers are from the code
  numberstyle=\tiny\color{BK},      % style used for the line-numbers
  % rulecolor=\color{BK},           % if not set, the frame-color may
                                    % be changed on line-breaks within
                                    % not-black text (e.g. comments (green here)) 
  showspaces=false,                 % shows spaces everywhere adding
                                    % particular underscores; it overrides 'showstringspaces'
  showstringspaces=false,           % underlines spaces within strings only
  showtabs=false,                   % shows tabs within strings adding particular underscores 
  stepnumber=1,                     % the step between two line-numbers
  stringstyle=\color{DarkR},        % string literal style
  tabsize=2,	                    % sets default tabsize to 2 spaces
  title=\lstname,                   % show the filename of files
                                    % included with \lstinputlisting; also
                                    % try caption instead of title
  belowskip=-1\thmsep %\baselineskip
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\usepackage{tcolorbox}
\tcbuselibrary{skins, breakable} %, hooks}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% varia elements

\newcommand{\abacktitlecolor}{white}  % {Sand}
\newcommand{\abackcolor}{white}  % {Sand!60!BGray!10}
\newcommand{\atextcolor}{black}
\newcommand{\acommandcolor}{DarkB!30!BK}  % {Eggplant}
\newcommand{\acommentcolor}{DarkR!20!RK}


\newenvironment{abox}[1]{%
  % the argument is the title of the algorithm
  \begin{tcolorbox}[%
    enhanced,
    breakable,
    float=h,
    title=#1,
    colbacktitle=\abacktitlecolor,
    coltitle=\acommandcolor,
    fonttitle=\bfseries,
    sharp corners,
    coltext=black,
    colback=\abackcolor,
    boxrule=0pt,
    frame hidden,
    left=2pt,
    top=5pt,
    bottom=5pt,
    boxsep=3pt,
    left skip=1\parindent,
    before skip=1.2\thmsep,
    after skip=1\thmsep,
    borderline north={1pt}{-1pt}{\acommandcolor},
    borderline south={1pt}{0pt}{\acommandcolor}]%
  }{\end{tcolorbox}}


\newenvironment{acommandbox}[2]{%
  \begin{tcolorbox}[%
    enhanced,
    title={\textsf{\color{\acommandcolor}\bfseries #1}\, #2},
    coltitle=black,
    colbacktitle=\abackcolor,
    boxrule=0pt,
    frame hidden,
    coltext=black,
    colback=\abackcolor,
    left=0pt,
    right=0pt,
    bottom=2pt,
    boxsep=0pt,
    leftupper=20pt,
    before skip=5pt,
    after skip=4pt,
    % borderline west={.4pt}{-2pt}{DarkB},
    overlay unbroken and last={%
      \draw[color=\acommandcolor, very thin]
      ($(frame.north west)+(-.5pt, -1\baselineskip+3pt)$) |-
      ($(frame.south west)+(15pt, 0)$);
      % ($(frame.north west)+(-2pt, -1pt)$) |- ++(4pt, 3pt)
      % ($(frame.south west)+(-2pt, 0)$) -- ++(4pt, 0);
    }]%
  }{\end{tcolorbox}}


\newcommand{\aelse}[1][]{%
  \par\vspace{1pt plus 1pt}\hspace{-20pt}%
  \ifthenelse{\equal{#1}{}}{\textsf{\color{\acommandcolor}\bfseries else}}{%
    \textsf{\color{\acommandcolor}\bfseries else if}\, #1}\par%
}


\newcommand{\areturn}{%
  \par\textsf{\color{\acommandcolor}\bfseries return\,~}%
}


\newcommand{\awhile}[2]{\begin{acommandbox}{while}{#1}#2\end{acommandbox}}
\newcommand{\afor}[2]{\begin{acommandbox}{for}{#1}#2\end{acommandbox}}
\newcommand{\aif}[2]{\begin{acommandbox}{if}{#1}#2\end{acommandbox}}
\newcommand{\acomment}[1]{\qquad\textsf{\color{\acommentcolor}\# \it #1}\par}
\newcommand{\adescription}[2]{\color{\acommentcolor}%
  Arguments\,: #1\par
  But\,: #2
  \tcblower
}

