
% baabaas environment for definition boxes
\usepackage[dvipsnames]{pstricks}
\usepackage{pst-eucl,pst-text,pst-tree,pst-tools,pstricks-add}
\usepackage{calc,pifont,fontawesome}

\newlength{\margedef}
\newlength{\marge}
\setlength{\marge}{0.75cm}
\newcounter{definition}
\newsavebox{\defbox}
\newcommand{\defboxtext}{\raisebox{-0.5ex}{\Large \faBook} \textsf{Definition \thedefinition}}
\newlength{\deftextlength}
\setlength{\deftextlength}{\widthof{\textbf{\defboxtext}}+\widthof{\textsf{\textbf{8}}}+0.66cm+1cm}
\newlength{\defboxheight}
\newenvironment{boxdef}{
   %\par\noindent                        % No indentation
   \begin{flushleft}
   \refstepcounter{definition}             % Counter for this environment
   \begin{lrbox}{\defbox}           % Name of box to contain text
   \begin{minipage}{0.95\linewidth-0.5cm}
}
{
  \end{minipage}
  \end{lrbox}%
  \setlength{\defboxheight}{\totalheightof{\usebox{\defbox}}+20.5pt}
  \rput[tl](0,0){   % Choose colours of framebox
    \psframebox[opacity=0.8,fillstyle=solid,fillcolor=blue!10,framearc=0,framesep=10pt,linecolor=blue,linestyle=none]{%
      \usebox{\defbox}
    }
  }
  \rput[l](1cm,0){      % Patch white line
    \psline[linewidth=2.1\pslinewidth,linecolor=white](-0.25em,0)(\deftextlength,0)%
  }%
  \rput[l](1cm,0.5ex){  % Place text
    %\textcolor{Blue}{\parbox[m]{0.66cm}{\includegraphics[width=0.66cm]{./include/books8_Blue.eps}} \textbf{\defboxtext}}%
    \color{Blue} \textbf{\defboxtext}
  }
  \psline[linewidth=3pt,linecolor=Blue](0.22,0)(0.22,-\defboxheight)
  \par
  \setlength{\margedef}{\ht\defbox+\dp\defbox+\marge}
  \vspace{\margedef}
  \end{flushleft}
}


% theorembox

\usepackage[tikz]{mdframed}
\usepackage{xcolor,comment}
\newmdenv[backgroundcolor=exampleboxcolor]{examplebox}
\colorlet{exampleboxcolor}{green!30}

%try

\newmdenv[backgroundcolor=answerboxcolor,roundcorner=12pt,linewidth=2pt]{answerbox}
\newmdenv[backgroundcolor=clarboxcolor,roundcorner=12pt,linewidth=2pt]{clarbox}
\newmdenv[backgroundcolor=hintboxcolor]{hintbox}
\newmdenv[backgroundcolor=exerciseboxcolor]{exercisebox}

\colorlet{answerboxcolor}{blue!20}
\colorlet{hintboxcolor}{green!20}
\colorlet{clarboxcolor}{yellow!20}
\colorlet{exerciseboxcolor}{red!20}


%takes in number and spits out that many dotted lines
\newcommand{\mdots}[1]{%
  \ifnum#1>0
    \begin{doublespace}
    \begin{center}
      \foreach \i in {1,...,#1}{%
        \dotfill\\
      }
    \end{center}
    \end{doublespace}
  \fi
  \vspace{-0.5cm}
}

% algebraic expansion demonstration

\newcounter{source}
\newcommand\source[1]{%
    \tikz[remember picture,baseline,inner sep=0pt] {%
        \node [name=source-\thesource,anchor=base]{$#1$};
    }%
    \setcounter{target}{0}
    \stepcounter{source}
}

\newcounter{target}
\newcommand\target[1]{%
    \tikz[remember picture,baseline,inner xsep=0pt] {%
        \node [name=target-\thetarget,anchor=base]{$#1$};
    }%
    \setcounter{source}{0}
    \stepcounter{target}%
}
\newcommand\drawarrows{
    \tikz[remember picture, overlay, bend left=45, -latex] {
    \foreach \j [evaluate=\j as \m using int(\j)] in {1,...,\thesource}{
        \foreach \i [evaluate=\i as \n using int(\i-1)] in {1,...,\thetarget} {
            \draw [red](source-0.north) to (target-\n.north) ;
              \node [red] at ([xshift=-5mm]target-\n.north) [above=2mm] {\i};
          }

    }
}

 \tikz[remember picture, overlay, bend left=-45, -latex] {
    \foreach \j [evaluate=\j as \m using int(\j)] in {1,...,\thesource}{
        \foreach \i [evaluate=\i as \n using int(\i-1)] in {1,...,\thetarget} {
            \draw [blue](source-1.south) to (target-\n.south)  ;
      \pgfmathsetmacro{\ii}{\i+2)};
         \node [blue] at ([xshift=-2mm]target-\n.south) [below=2mm] {\pgfmathprintnumber \ii};
    }
}
}}

