%%
%% This is file `exsol.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% exsol.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2014 by Walter Daems <walter.daems@ieee.org>
%% 
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3 of this license
%% or (at your option) any later version.  The latest version of this
%% license is in:
%% 
%%    http://www.latex-project.org/lppl.txt
%% 
%% and version 1.3 or later is part of all distributions of LaTeX version
%% 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{exsol}
  [2013/05/12 v0.6 ExSol - Exercises and Solutions package (DMW)]
\RequirePackage{fancyvrb}
\RequirePackage{ifthen}
\RequirePackage{kvoptions}
\DeclareStringOption[normalsize]{exercisesfontsize}
\DeclareBoolOption[false]{exerciseaslist}
\DeclareBoolOption[false]{copyexercisesinsolutions}
\ProcessKeyvalOptions*
\newcommand{\exercisesfontsize}{\csname \exsol@exercisesfontsize\endcsname}
\AtBeginDocument{
  \newwrite\solutionstream
  \immediate\openout\solutionstream=\jobname.sol.tex
  \newwrite\exercisestream
}
\AtEndDocument{
  \immediate\closeout\solutionstream
}
\newcounter{exercise}[subsection]
\setcounter{exercise}{0}
\renewcommand{\theexercise}{%
  \@ifundefined{c@chapter}{}{\if0\arabic{chapter}\else\arabic{chapter}.\fi}%
  \if0\arabic{section}\else\arabic{section}\fi%
  \if0\arabic{subsection}\else.\arabic{subsection}\fi%
  \if0\arabic{subsubsection}\else.\arabic{subsubsection}\fi%
  \if0\arabic{exercise}\else%
    \@ifundefined{c@chapter}%
                 {\if0\arabic{section}\else-\fi}%
                 {-}%
    \arabic{exercise}%
  \fi
}
\newcommand{\GPES@write@detok}[1]{%
  \immediate\write\exercisestream{\detokenize{#1}}}%
\newcommand{\GPSS@write@detok}[1]{%
  \immediate\write\solutionstream{\detokenize{#1}}}%
\newcommand{\GPESS@write@detok}[1]{%
  \GPES@write@detok{#1}%
  \GPSS@write@detok{#1}}%
\def\exercise{\FV@Environment{}{exercise}}
\def\FVB@exercise{%
  \refstepcounter{exercise}%
  \immediate\openout\exercisestream=\jobname.exc.tex
  \ifexsol@copyexercisesinsolutions
    \typeout{Writing exercise to \jobname.sol.tex}
    \immediate\write\solutionstream{\string\par---\string\newline
      \string\textbf\string{\exercisename{} \theexercise \string}}
  \else
    \immediate\write\solutionstream{\string\par---\string\newline}
  \fi
  \immediate\write\exercisestream{\string\begin{exsol@exercise}}
  \@bsphack
  \begingroup
    \FV@UseKeyValues
    \FV@DefineWhiteSpace
    \def\FV@Space{\space}%
    \FV@DefineTabOut
    \ifexsol@copyexercisesinsolutions
      \let\FV@ProcessLine\GPESS@write@detok %
    \else
      \let\FV@ProcessLine\GPES@write@detok %
    \fi
    \relax
    \let\FV@FontScanPrep\relax
    \let\@noligs\relax
    \FV@Scan
  }
\def\FVE@exercise{
  \endgroup\@esphack
  \immediate\write\exercisestream{\string\end{exsol@exercise}}
  \ifexsol@copyexercisesinsolutions
    \immediate\write\solutionstream{\string~\string\newline}
  \fi
  \immediate\closeout\exercisestream
  \input{\jobname.exc.tex}
}
\DefineVerbatimEnvironment{exercise}{exercise}{}
\newenvironment{exsol@exercise}[0]
{%
  \begin{minipage}[t]{\textwidth}%
    \ifthenelse{\boolean{exsol@exerciseaslist}}
               {\begin{list}%
                   {%
                   }%
                   {%
                     \setlength{\topsep}{0pt}%
                     \setlength{\leftmargin}{1em}%
                     \setlength{\rightmargin}{1em}%
                     \setlength{\listparindent}{0em}%
                     \setlength{\itemindent}{0em}%
                     \setlength{\parsep}{\parskip}}%
                 \item[\hspace*{\leftmargin}\textit{\exercisename{}
                                                    \theexercise:}]
               }%
               {
                 \textit{\exercisename{} \theexercise:}~
               }
}
{%
  \ifthenelse{\boolean{exsol@exerciseaslist}}
             {\end{list}}{}
  \end{minipage}
  \vspace{1ex}\par
}
\def\solution{\FV@Environment{}{solution}}
\def\FVB@solution{%
  \typeout{Writing solution to \jobname.sol.tex}
  \immediate\write\solutionstream{\string\textbf\string{\solutionname{}\string}}
  \ifexsol@copyexercisesinsolutions
    \immediate\write\solutionstream{\string\newline}
  \else
    \immediate\write\solutionstream{\string\textbf\string{\theexercise\string}%
                                    \string\newline}
  \fi
  \@bsphack
  \begingroup
    \FV@UseKeyValues
    \FV@DefineWhiteSpace
    \def\FV@Space{\space}%
    \FV@DefineTabOut
    \let\FV@ProcessLine\GPSS@write@detok %
    \relax
    \let\FV@FontScanPrep\relax
    \let\@noligs\relax
    \FV@Scan
  }
\def\FVE@solution{\endgroup\@esphack}
\DefineVerbatimEnvironment{solution}{solution}{}
\newenvironment{exercises}
{\par\exercisesfontsize\rule{.25\linewidth}{0.15mm}\\*~\\*%
 \textbf{\normalsize \exercisesname}\vspace*{1ex}\\}
{~\\*\rule{.25\linewidth}{0.15mm}\par}
\newcommand{\exercisename}{Exercise}
\newcommand{\exercisesname}{Exercises}
\newcommand{\solutionname}{Solution}
\newcommand{\solutionsname}{Solutions}
\addto\captionsdutch{%
  \renewcommand{\exercisename}{Oefening}%
  \renewcommand{\exercisesname}{Oefeningen}%
  \renewcommand{\solutionname}{Oplossing}%
  \renewcommand{\solutionsname}{Oplossingen}%
}
\addto\captionsgerman{%
  \renewcommand{\exercisename}{Aufgabe}%
  \renewcommand{\exercisesname}{Aufgaben}%
  \renewcommand{\solutionname}{L\"osung}%
  \renewcommand{\solutionsname}{L\"osungen}%
}
\addto\captionsfrench{%
  \renewcommand{\exercisename}{Exercice}%
  \renewcommand{\exercisesname}{Exercices}%
  \renewcommand{\solutionname}{Solution}%
  \renewcommand{\solutionsname}{Solutions}%
}
\addto\captionsfinnish{
  \renewcommand{\exercisename}{Teht\"av\"a}%
  \renewcommand{\exercisesname}{Teht\"avi\"a}%
  \renewcommand{\solutionname}{Ratkaisu}%
  \renewcommand{\solutionsname}{Ratkaisut}%
}
\let\exsol@@makechapterhead\@makechapterhead
\def\@makechapterhead#1{%
  \immediate\write\solutionstream{\string\chapter{#1}}%
  \exsol@@makechapterhead{#1}
}
\ifdefined\frontmatter
  \let\exsol@@frontmatter\frontmatter
  \def\frontmatter{%
    \immediate\write\solutionstream{\string\frontmatter}%
    \exsol@@frontmatter
  }
\fi
\ifdefined\frontmatter
  \let\exsol@@mainmatter\mainmatter
  \def\mainmatter{%
    \immediate\write\solutionstream{\string\mainmatter}%
    \exsol@@mainmatter
  }
\fi
\ifdefined\backmatter
  \let\exsol@@backmatter\backmatter
  \def\backmatter{%
    \immediate\write\solutionstream{\string\backmatter}%
    \exsol@@backmatter
  }
\fi
\newcommand{\noexercisesinchapter}
{
  \immediate\write\solutionstream{No exercises in this chapter}
}
\endinput
%%
%% End of file `exsol.sty'.
