% \input{exercisee.sty}
% this files differs from exercise.sty only in that \exercise is
% called \exerciseee, because latex2e has already taken \exercise,
% and \example, and \solution likewise
%
% also the within chapter part has been removed.
%
% environments for making examples, exercises, solutions to exercises,
% continuations of examples.
%
% the following options:
%  with rat / without  (global)                            see ratfull
%    or with pointer to where the solution is
%  indented / not indented                             choose exercis or Exercis
%  exercises numbered with pages when refered to       see \exerciseref
%
% usage: 
% \exercisa{ Text of exercise }  
%  (obsolete, widely used in 97)
%  makes an indented exercise which doesn't get labelled.
%  recommended alternative:
%
% \exercis{label}{ Text of exercise }
%  makes an indented exercise with a label.
% \Exercis{label}{ Text of exercise }
%  makes an NON-indented exercise with a label.
% \exercinr{label}{ Text of exercise }
%  same, no rat
% \exerciss{label}{ Text of exercise }
%  same, with margin giving pointer to soln (the pointer can be an arrow or rat)
%
% how to refer to an exercise: 
% \exerciseref{#1}
%
% to make a global change use 
% perl -pi -e 's/\\exercis\{/\\exerciss\{/' tex/_l1.tex
%
% \solutiona{ Text }
%  OBSOLETE -- makes use of the solution_number counter
%  recommended alternative
% \soln{ref}{ Text }
% \solution.
%  OBSOLETE -- starts a non-indented solution.
%  recommended alternative
% \Soln{ref}{ Text } 
%
% \exampl{label}{ Text }
%  an indented example
% \cexampl{ref}{ Text }
%  continuation, indented, of example
% \Exampl{label}{ Text }
%  a non-indented example
% \Cexampl{ref}{ Text }
%  continuation, non-indented, of example
% \exampla{text}
%  for use where you don't want to bother with a ref
%
% \exerciseref{ref} makes ``exercise 32 (p. 10)''
% \exerciserefrange{refa}{refb} makes ``exercises 32-36 (pp. 10-12)''
% \exerciserefshort{ref} makes ``32 (p. 10)''
% \exerciserefrangeshort{refa}{refb} makes ``32-36 (pp. 10-12)''
%
% The above commands all work by invoking the following environments
%
% \begin{examplee} blah blah \end{examplee}     equivalent to \exampl{}{}
% \begin{Examplee} blah blah \end{Examplee}     equivalent to \Exampl{}{}
% The other environments are {sexercise} Sexercise
% exercisee Exercisee exercisenr exercises Exercises
% cexamplee Cexamplee
%
% NB, the indented environments don't work perfectly because the 
% \label{} does not get the right number. To fix this use the 
% \exercisehack command immediately before the label, or just use
% the convenient forms.
% A correct solution to this would replace the {description}\item[...]
% by a new trivlist, I suppose.

% silly auxiliary things
\newcommand{\dorat}{\raisebox{-0.3in}[0in][0in]{\psfig{figure=figs/myrat1b.eps,width=0.4in}}}% was ratbert4 % was raise  -0.45in . width 1.37cm
\newcommand{\ratfull}{\makebox[0in][r]{\dorat}}% change to {} to get no rats
%
% The counters and their invokers -- \exercise just spits out `exercise 1'
%   with no punctuation
\newcounter{exercisenumber}
\def\theexercisenumber {\arabic{exercisenumber}}
\newcommand{\exerciseee}{\refstepcounter{exercisenumber}%
{\ratfull\sf{Exercise}~\theexercisenumber}}
\newcommand{\exercisenorat}{\refstepcounter{exercisenumber}%
{\sf{Exercise}~\theexercisenumber}}
\newcommand{\exercisesol}[1]{\refstepcounter{exercisenumber}%
{\solref{#1}\sf{Exercise}~\theexercisenumber}}
\newcommand{\solref}[1]{%
\makebox[0in][r]{\raisebox{0in}[0in][0in]{\parbox{0in}%
%{\small\sf{\makebox[0in][r]{Soln.\ on}\\%
{\tiny\sf{\makebox[0in][r]{Solutions}\\%
\makebox[0in][r]{\mbox{on p.}~\pageref{#1}}%
}}\dorat}}}
%}}$\rightarrow$}}}
%
\newcounter{solution_number} % an obsolete object, useful for hacks but not for the book.
\setcounter{solution_number}{1}
\newcommand{\solutione}{{\sf{Solution to exercise}
 \arabic{solution_number}}\addtocounter{solution_number}{1}}
%
\newcounter{examplenumber}
\def\theexamplenumber {\arabic{examplenumber}}
\newcommand{\exampleee}{\refstepcounter{examplenumber}%
{\sf{Example}~\theexamplenumber}}
%
\newcommand{\exercisehack}{%
\addtocounter{exercisenumber}{-1}\refstepcounter{exercisenumber}}
\newcommand{\examplehack}{%
\addtocounter{examplenumber}{-1}\refstepcounter{examplenumber}}
%
% obsolete counters
\newcounter{exercise_number}[section]
\newcounter{example_number}[section]
%

%
%   			examples
%
%                 example environment , NOT indented
\newenvironment{Examplee}% 
{\begin{trivlist}\item[]\exampleee: }% 
{\end{trivlist}}
%		 continuation of example , NOT indented
\newenvironment{Cexamplee}[1]%
{\begin{trivlist}\item[]%
{\sf Example~\ref{#1} (continued): }}%
{\end{trivlist}}
%		 example environment , indented
\newenvironment{examplee}% 
{\begin{description}\item[\exampleee:] %
\ifnum \@enumdepth >3 \@toodeep\else\advance\@enumdepth \@ne \fi}%
{\end{description}}
%		 continuation of example , indented
\newenvironment{cexamplee}[1]%
{\begin{description}\item[{\sf{Example~\ref{#1} (continued):}}] %
\ifnum \@enumdepth >3 \@toodeep\else\advance\@enumdepth \@ne \fi}%
{\end{description}}
% 
%			exercises and solutions
%
%		 exercise  , NOT indented
\newenvironment{Exercisee}%
{\begin{trivlist}\item[]\exerciseee: }%
{\end{trivlist}}
%		 exercise  ,  indented
\newenvironment{exercisee}%
{\begin{description}%
\item[\exerciseee:] %% make depth one greater, since we are indenting
\ifnum \@enumdepth >3 \@toodeep\else\advance\@enumdepth \@ne \fi}%
{\end{description}}
%		 exercise  ,  indented , no rat
\newenvironment{exercisenr}%
{\begin{description}%
\item[\exercisenorat:] %% make depth one greater, since we are indenting
\ifnum \@enumdepth >3 \@toodeep\else\advance\@enumdepth \@ne \fi}%
{\end{description}}
%		exercise with soln page pointer in margin
%		 exercise  , NOT indented
\newenvironment{Exercises}[1]%
{\begin{trivlist}\item[]\exercisesol{#1}: }%
{\end{trivlist}}
\newenvironment{exercises}[1]%
{\begin{description}%
\item[\exercisesol{#1}:] %% make depth one greater, since we are indenting
\ifnum \@enumdepth >3 \@toodeep\else\advance\@enumdepth \@ne \fi}%
{\end{description}}
\newcommand{\exref}[1]{ex~\ref{#1}\typeout{exercise or example?}}
\newcommand{\exerciseref}[1]{exercise~\handle\ref{#1} (p.\ \pageref{#1})}
\newcommand{\exercisebref}[1]{(exercise~\ref{#1}, p.\ \pageref{#1})}
\newcommand{\Exerciseref}[1]{Exercise~\ref{#1} (p.\ \pageref{#1})}
\newcommand{\exerciseonlyref}[1]{exercise~\ref{#1}}
\newcommand{\Exerciseonlyref}[1]{Exercise~\ref{#1}}
\newcommand{\exerciserefrange}[2]{exercises~\ref{#1}--\ref{#2} (pp.\ \pageref{#1}--\pageref{#2})}
\newcommand{\Exerciserefrange}[2]{Exercises~\ref{#1}--\ref{#2} (pp.\ \pageref{#1}--\pageref{#2})}
\newcommand{\exerciseonlyrange}[2]{exercises~\ref{#1}--\ref{#2}}
\newcommand{\Exerciseonlyrange}[2]{Exercises~\ref{#1}--\ref{#2}}
\newcommand{\pagerange}[2]{(pp.\ \pageref{#1}--\pageref{#2})}
\newcommand{\exerciserefshort}[1]{\ref{#1} (p.\ \pageref{#1})}
\newcommand{\exerciseonlyrangeshort}[2]{\ref{#1}--\ref{#2}}
\newcommand{\exerciserefrangeshort}[2]{\ref{#1}--\ref{#2} (pp.\ \pageref{#1}--\pageref{#2})}
\newcommand{\exampleref}[1]{example~\ref{#1} (p.\ \pageref{#1})}
\newcommand{\Exampleref}[1]{Example~\ref{#1} (p.\ \pageref{#1})}
%		 solution to exercise  , NOT indented
\newenvironment{Sexercise}[1]%
{\begin{trivlist}\item[]%
{\sf Solution to \exerciseref{#1}:} 
\label{#1.sol}% this makes it possible to point to where the soln is
\ifnum \@enumdepth >3 \@toodeep\else\advance\@enumdepth \@ne \fi}%
{\end{trivlist}}
%		 solution to exercise  , indented
% CUP recommend not using indented form.
%
\newenvironment{sexercise}[1]%
{\begin{description}%
\item[{\sf Solution to \exerciseref{#1}:}] 
\label{#1.sol}% this makes it possible to point to where the soln is
\ifnum \@enumdepth >3 \@toodeep\else\advance\@enumdepth \@ne \fi}%
{\end{description}}

% 
% Defns of Convenient forms:
%
% \exercisa is obsolete
\newcommand{\exercisa}[1]{\begin{exercisee} #1 \end{exercisee}}
% \exampl{label}{ Text }
\newcommand{\exampl}[2]{\begin{examplee}\examplehack\label{#1} #2 \end{examplee}}
% \cexampl{label}{ Text }
\newcommand{\cexampl}[2]{\begin{cexamplee}{#1} #2 \end{cexamplee}}
% \Exampl{label}{ Text }
\newcommand{\Exampl}[2]{\begin{Examplee}\label{#1} #2 \end{Examplee}}
% \Cexampl{label}{ Text }
\newcommand{\Cexampl}[2]{\begin{Cexamplee}{#1} #2 \end{Cexamplee}}
% \exercis{label}{ Text }
\newcommand{\exercis}[2]{\begin{exercisee}\exercisehack\label{#1} #2 \end{exercisee}}
% \exercinr{label}{ Text }
\newcommand{\exercinr}[2]{\begin{exercisenr}\exercisehack\label{#1} #2 \end{exercisenr}}
% \exerciss{label}{ Text }
\newcommand{\exerciss}[2]{\begin{exercises}{#1.sol}\exercisehack\label{#1} #2 \end{exercises}}
% \Exercis{label}{ Text }
\newcommand{\Exercis}[2]{\begin{Exercisee}\label{#1} #2 \end{Exercisee}}
% \Exerciss{label}{ Text }
\newcommand{\Exerciss}[2]{\begin{Exercises}{#1.sol}\label{#1} #2 \end{Exercises}}
% my intention was that soln would be indented, and Soln not, 
% but now I want all solns not to be indented.
% \soln{label}{ Text } 
% \newcommand{\soln}[2]{\begin{sexercise}{#1} #2 \end{sexercise}}
% \Soln{label}{ Text }
\newcommand{\Soln}[2]{\begin{Sexercise}{#1} #2 \end{Sexercise}}
\newcommand{\soln}[2]{\begin{Sexercise}{#1} #2 \end{Sexercise}}
%
% OBSOLETE
% problema is just the same as an old exercisa -- no rat, no clever depth change
\newcommand{\problema}[1]{\begin{description}\item[\exerciseee:] #1 \end{description}}
\newcommand{\exercisnr}[1]{\begin{description}\item[\exerciseee:]
\ifnum \@enumdepth >3 \@toodeep\else
% this advances the enum depth. I don't know what causes it to get unadvanced.
\advance\@enumdepth \@ne 
 #1 \end{description}}
\newcommand{\exampla}[1]{\begin{examplee} #1 \end{examplee}}
\newcommand{\solutiona}[1]{\begin{description}\item[\solutione:] \ifnum \@enumdepth >3 \@toodeep\else
% this from chapternotes.sty
\advance\@enumdepth \@ne 
\fi
{#1} \end{description}}

% old stuff... see  exercise.sty.old
%%%%%%%%%%%%%%%%%%%%%%5
%%%%%%%%
%            Used in exercise sheets
%%%%
%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\handle}{}
\newcounter{qno}

\newenvironment{Ex}[1]%\addtocounter{qno}{1}
{\begin{trivlist}\item[]\refstepcounter{qno}{\large\bf{\handle\arabic{qno}}}$\;\;${\label{#1}}\ifnum \@enumdepth >3 \@toodeep\else\advance\@enumdepth \@ne \fi}%
{\end{trivlist}}

\newcommand{\newq}{\vspace*{-\baselineskip}\subsubsection*{}
\noindent{\addtocounter{qno}{1}}{\large\bf{\handle\arabic{qno}}}$\;\;$}
