exercises either here, at end of chapter or at end of script

This commit is contained in:
Jan Benda 2019-12-01 17:35:42 +01:00
parent 1e3ec8944e
commit e0b6ca4f33
18 changed files with 104 additions and 53 deletions

View File

@ -38,7 +38,7 @@ watchscript :
clean : clean :
rm -f *~ $(BASENAME).aux $(BASENAME).log $(BASENAME).out $(BASENAME).toc $(BASENAME).lo? $(BASENAME).idx $(BASENAME)-term.i* $(BASENAME)-enterm.i* $(BASENAME)-code.i* rm -f *~ $(BASENAME).aux $(BASENAME).log $(BASENAME).out $(BASENAME)-solutions.tex $(BASENAME).toc $(BASENAME).lo? $(BASENAME).idx $(BASENAME)-term.i* $(BASENAME)-enterm.i* $(BASENAME)-code.i*
for sd in $(SUBDIRS); do $(MAKE) -C $$sd/lecture clean; done for sd in $(SUBDIRS); do $(MAKE) -C $$sd/lecture clean; done
cleanall : clean cleanall : clean

View File

@ -14,7 +14,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} \begin{document}
\input{bootstrap} \include{bootstrap}
\section{TODO} \section{TODO}
\begin{itemize} \begin{itemize}

View File

@ -46,7 +46,7 @@ watchchapter :
cleanchapter : cleanpythonplots cleangnuplots cleanchapter : cleanpythonplots cleangnuplots
rm -f *~ rm -f *~
rm -f $(BASENAME).aux $(BASENAME).log rm -f $(BASENAME).aux $(BASENAME).log
rm -f $(BASENAME)-chapter.aux $(BASENAME)-chapter.log $(BASENAME)-chapter.out $(BASENAME)-chapter.idx $(BASENAME)-chapter-solutions.tex rm -f $(BASENAME)-chapter.aux $(BASENAME)-chapter.log $(BASENAME)-chapter.out $(BASENAME)-chapter.idx $(BASENAME)-chapter-solutions.tex $(BASENAME)-solutions.tex
cleanallchapter : cleanchapter cleanallchapter : cleanchapter

View File

@ -15,7 +15,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} \begin{document}
\input{debugging} \include{debugging}
\end{document} \end{document}

View File

@ -14,7 +14,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} \begin{document}
\input{designpattern} \include{designpattern}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Sortieren von Vektoren} \section{Sortieren von Vektoren}

View File

@ -282,6 +282,22 @@
% %
% The boolean showexercisesolutions controls whether solutions for the exercises % The boolean showexercisesolutions controls whether solutions for the exercises
% are actually included. % are actually included.
%
% \exercisesolutions controls where the solutions of the exercises are placed:
% - 'here': solutions are printed right after the exercises in the same box
% - 'chapter': solutions are printed at the end of each chapter
% - 'end': all solutions are printed at the end of the script
%
\newboolean{showexercisesolutions}
\setboolean{showexercisesolutions}{true}
\newcommand{\exercisesolutions}{chapter} % 0: here, 1: chapter, 2: end
% we need this also as numbers:
\ifthenelse{\equal{\exercisesolutions}{end}}{\newcommand{\exercisesolutionsnum}{2}}{%
\ifthenelse{\equal{\exercisesolutions}{chapter}}{\newcommand{\exercisesolutionsnum}{1}}{%
\newcommand{\exercisesolutionsnum}{0}}}
\newcommand{\codepath}{}
\newcommand{\setcodepath}[1]{\ifthenelse{\not\equal{\exercisesolutions}{here}}{\renewcommand{\codepath}{#1/}}{}\lstset{inputpath=#1}}
\newcommand{\exercisesection}[1]{}
\usepackage{mdframed} \usepackage{mdframed}
\usepackage{xstring} \usepackage{xstring}
\newlistof{exercisef}{loe}{\tr{Exercises}{\"Ubungen}} \newlistof{exercisef}{loe}{\tr{Exercises}{\"Ubungen}}
@ -291,16 +307,16 @@
placement=t, placement=t,
chapterlistsgaps=on, chapterlistsgaps=on,
]{exercisef} ]{exercisef}
\newboolean{showexercisesolutions}
\setboolean{showexercisesolutions}{true}
\newwrite\solutions % file descriptor for writing solutions \newwrite\solutions % file descriptor for writing solutions
% we need to know the name of the included file as \currentjobname: % we need to know the name of the included file as \currentjobname:
\usepackage{xpatch} \usepackage{xpatch}
\makeatletter % the following does not work with \ifthenelse
\def\currentjobname{\jobname}% \ifnum\exercisesolutionsnum=1
\xpretocmd{\include}{\def\currentjobname{#1}\immediate\openout\solutions=\currentjobname-solutions}{}{} \def\currentjobname{\jobname}
\makeatother \xpretocmd{\include}{\def\currentjobname{#1}\immediate\openout\solutions=\currentjobname-solutions}{}{}\fi%
\usepackage{needspace} \ifnum\exercisesolutionsnum=2
\def\currentjobname{\jobname}
\immediate\openout\solutions=\currentjobname-solutions\fi
\newenvironment{exercise}[2]% \newenvironment{exercise}[2]%
{ \setlength{\fboxsep}{2mm}% { \setlength{\fboxsep}{2mm}%
\newcommand{\saveenumi}{\theenumi}\renewcommand{\labelenumi}{(\alph{enumi})}% \newcommand{\saveenumi}{\theenumi}\renewcommand{\labelenumi}{(\alph{enumi})}%
@ -309,27 +325,59 @@
\begin{mdframed}[linewidth=0pt,backgroundcolor=exerciseback]% \begin{mdframed}[linewidth=0pt,backgroundcolor=exerciseback]%
\captionof{exercisef}[\protect\StrSubstitute{#1}{_}{\_}]{}% \captionof{exercisef}[\protect\StrSubstitute{#1}{_}{\_}]{}%
\captionsetup{font={normal,sf,it}}% \captionsetup{font={normal,sf,it}}%
\immediate\write\solutions{\unexpanded{% \ifthenelse{\equal{\exercisesolutions}{here}}{%
\subsection}[Exercise \thechapter.\arabic{exercisef}]% \newcommand{\exercisesource}{#1}%
{\unexpanded{\needspace{4\baselineskip}}Exercise \thechapter.\arabic{exercisef}}}% \newcommand{\exercisefile}{\protect\StrSubstitute{#1}{_}{\_}}%
\immediate\write\solutions{\unexpanded{\label}{solution\arabic{exercisef}}}% \newcommand{\exerciseoutput}{#2}%
}{%
\immediate\write\solutions{\unexpanded{\exercisesection}{Exercise \thechapter.\arabic{exercisef}}}%
\immediate\write\solutions{\unexpanded{\label}{solution\arabic{chapter}-\arabic{exercisef}}}%
\immediate\write\solutions{\unexpanded{\lstinputlisting[belowskip=0ex,aboveskip=0ex,% \immediate\write\solutions{\unexpanded{\lstinputlisting[belowskip=0ex,aboveskip=0ex,%
nolol=true, title={\textbf{Source code:} \protect\StrSubstitute{#1}{_}{\_}}]}{#1}}% nolol=true, title={\textbf{Source code:} \protect\StrSubstitute{#1}{_}{\_}}]}{\codepath#1}}%
\ifthenelse{\equal{#2}{}}{}% \ifthenelse{\equal{#2}{}}{}%
{\immediate\write\solutions{\unexpanded{\lstinputlisting[language={},% {\immediate\write\solutions{\unexpanded{\lstinputlisting[language={},%
nolol=true, title={\textbf{Output:}}, belowskip=0ex, aboveskip=1ex]}{#2}}}% nolol=true, title={\textbf{Output:}}, belowskip=0ex, aboveskip=1ex]}{\codepath#2}}}%
\immediate\write\solutions{}% \immediate\write\solutions{}%
}% }%
{ \ifthenelse{\boolean{showexercisesolutions}}% }%
{\hspace*{\fill}\hyperref[solution\arabic{exercisef}]{Solution}}{}% { \ifthenelse{\equal{\exercisesolutions}{here}}{%
\ifthenelse{\boolean{showexercisesolutions}}%
{ \hypersetup{hypertexnames=false}%
\ifthenelse{\equal{\exercisesource}{}}{}%
{ \addtocounter{lstlisting}{-1}%
\lstinputlisting[belowskip=0pt,aboveskip=1ex,nolol=true,%
title={\textbf{Solution:} \exercisefile}]%
{\exercisesource}%
\ifthenelse{\equal{\exerciseoutput}{}}{}%
{ \addtocounter{lstlisting}{-1}%
\lstinputlisting[language={},title={\textbf{Output:}},%
nolol=true,belowskip=0pt]%
{\exerciseoutput}%
}%
}%
\hypersetup{hypertexnames=true}%
}{}}{%
\ifthenelse{\boolean{showexercisesolutions}}%
{\hspace*{\fill}\hyperref[solution\arabic{chapter}-\arabic{exercisef}]{\mbox{$\rightarrow$ solution}}}{}}%
\renewcommand{\theenumi}{\saveenumi}% \renewcommand{\theenumi}{\saveenumi}%
\end{mdframed}% \end{mdframed}%
} }
} }
\newcommand{\printsolutions}{\immediate\closeout\solutions% \newcommand{\printsolutions}{\ifthenelse{\equal{\exercisesolutions}{chapter}%
\or\(\equal{\exercisesolutions}{end}\and\not\isundefined{\chapternumber}\)}{%
\immediate\closeout\solutions%
\ifthenelse{\boolean{showexercisesolutions}}{% \ifthenelse{\boolean{showexercisesolutions}}{%
\clearpage\section{Solutions to the exercises}% \clearpage\section{Solutions to the exercises}%
\input{\currentjobname-solutions}}{}} \renewcommand{\exercisesection}[1]{\subsection{#1}}%
\ifthenelse{\isundefined{\chapternumber}}{\lstset{inputpath=}}{}%
\input{\currentjobname-solutions} }{}}{}}
\newcommand{\printallsolutions}{\ifthenelse{\equal{\exercisesolutions}{end}}{%
\immediate\closeout\solutions%
\ifthenelse{\boolean{showexercisesolutions}}{%
\setcounter{secnumdepth}{0}\lstset{inputpath=}%
\clearpage\chapter{Solutions to the exercises}%
\renewcommand{\exercisesection}[1]{\section{#1}}%
\input{\currentjobname-solutions} }{}}{}}
\setlength{\cftexercisefindent}{1.2em} \setlength{\cftexercisefindent}{1.2em}
\setlength{\cftexercisefnumwidth}{2.6em} \setlength{\cftexercisefnumwidth}{2.6em}

View File

@ -14,7 +14,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} \begin{document}
\input{likelihood} \include{likelihood}
\section{TODO} \section{TODO}
\begin{itemize} \begin{itemize}

View File

@ -14,7 +14,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} \begin{document}
\input{plotting} \include{plotting}
\subsection{Heatmaps} \subsection{Heatmaps}

View File

@ -14,7 +14,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} \begin{document}
\input{pointprocesses} \include{pointprocesses}
\section{TODO} \section{TODO}
\begin{itemize} \begin{itemize}

View File

@ -1,7 +1,7 @@
%!PS-Adobe-2.0 EPSF-2.0 %!PS-Adobe-2.0 EPSF-2.0
%%Title: pointprocessscetchA.tex %%Title: pointprocessscetchA.tex
%%Creator: gnuplot 4.6 patchlevel 4 %%Creator: gnuplot 4.6 patchlevel 4
%%CreationDate: Sat Nov 30 23:19:23 2019 %%CreationDate: Sun Dec 1 14:45:38 2019
%%DocumentFonts: %%DocumentFonts:
%%BoundingBox: 50 50 373 135 %%BoundingBox: 50 50 373 135
%%EndComments %%EndComments
@ -433,7 +433,7 @@ SDict begin [
/Author (jan) /Author (jan)
% /Producer (gnuplot) % /Producer (gnuplot)
% /Keywords () % /Keywords ()
/CreationDate (Sat Nov 30 23:19:23 2019) /CreationDate (Sun Dec 1 14:45:38 2019)
/DOCINFO pdfmark /DOCINFO pdfmark
end end
} ifelse } ifelse

View File

@ -1,7 +1,7 @@
%!PS-Adobe-2.0 EPSF-2.0 %!PS-Adobe-2.0 EPSF-2.0
%%Title: pointprocessscetchB.tex %%Title: pointprocessscetchB.tex
%%Creator: gnuplot 4.6 patchlevel 4 %%Creator: gnuplot 4.6 patchlevel 4
%%CreationDate: Sat Nov 30 23:19:23 2019 %%CreationDate: Sun Dec 1 14:45:38 2019
%%DocumentFonts: %%DocumentFonts:
%%BoundingBox: 50 50 373 237 %%BoundingBox: 50 50 373 237
%%EndComments %%EndComments
@ -433,7 +433,7 @@ SDict begin [
/Author (jan) /Author (jan)
% /Producer (gnuplot) % /Producer (gnuplot)
% /Keywords () % /Keywords ()
/CreationDate (Sat Nov 30 23:19:23 2019) /CreationDate (Sun Dec 1 14:45:38 2019)
/DOCINFO pdfmark /DOCINFO pdfmark
end end
} ifelse } ifelse

View File

@ -14,7 +14,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} \begin{document}
\input{programming} \include{programming}
\section{TODO} \section{TODO}
\begin{itemize} \begin{itemize}

View File

@ -14,7 +14,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} \begin{document}
\input{programmingstyle} \include{programmingstyle}
\end{document} \end{document}

View File

@ -14,7 +14,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} \begin{document}
\input{regression} \include{regression}
\section{Improvements} \section{Improvements}
Adapt function arguments to matlabs polyfit. That is: first the data Adapt function arguments to matlabs polyfit. That is: first the data

View File

@ -32,23 +32,23 @@
\part{Programming basics} \part{Programming basics}
\graphicspath{{programming/lecture/}{programming/images/}} \graphicspath{{programming/lecture/}{programming/images/}}
\lstset{inputpath=programming/code} \setcodepath{programming/code}
\include{programming/lecture/programming} \include{programming/lecture/programming}
\graphicspath{{debugging/lecture/}{debugging/lecture/figures/}} \graphicspath{{debugging/lecture/}{debugging/lecture/figures/}}
\lstset{inputpath=debugging/code} \setcodepath{debugging/code}
\include{debugging/lecture/debugging} \include{debugging/lecture/debugging}
\graphicspath{{plotting/lecture/}{plotting/lecture/images/}} \graphicspath{{plotting/lecture/}{plotting/lecture/images/}}
\lstset{inputpath=plotting/code/} \setcodepath{plotting/code}
\include{plotting/lecture/plotting} \include{plotting/lecture/plotting}
\graphicspath{{programmingstyle/lecture/}{programmingstyle/lecture/figures/}} \graphicspath{{programmingstyle/lecture/}{programmingstyle/lecture/figures/}}
\lstset{inputpath=programmingstyle/code/} \setcodepath{programmingstyle/code}
\include{programmingstyle/lecture/programmingstyle} \include{programmingstyle/lecture/programmingstyle}
\graphicspath{{designpattern/lecture/}{designpattern/lecture/figures/}} \graphicspath{{designpattern/lecture/}{designpattern/lecture/figures/}}
\lstset{inputpath=designpattern/code} \setcodepath{designpattern/code}
\include{designpattern/lecture/designpattern} \include{designpattern/lecture/designpattern}
@ -56,29 +56,29 @@
\part{Data analysis} \part{Data analysis}
\graphicspath{{statistics/lecture/}{statistics/lecture/figures/}} \graphicspath{{statistics/lecture/}{statistics/lecture/figures/}}
\lstset{inputpath=statistics/code} \setcodepath{statistics/code}
\include{statistics/lecture/statistics} \include{statistics/lecture/statistics}
\graphicspath{{bootstrap/lecture/}{bootstrap/lecture/figures/}} \graphicspath{{bootstrap/lecture/}{bootstrap/lecture/figures/}}
\lstset{inputpath=bootstrap/code} \setcodepath{bootstrap/code}
\include{bootstrap/lecture/bootstrap} \include{bootstrap/lecture/bootstrap}
\graphicspath{{regression/lecture/}{regression/lecture/figures/}} \graphicspath{{regression/lecture/}{regression/lecture/figures/}}
\lstset{inputpath=regression/code} \setcodepath{regression/code}
\include{regression/lecture/regression} \include{regression/lecture/regression}
\graphicspath{{likelihood/lecture/}{likelihood/lecture/figures/}} \graphicspath{{likelihood/lecture/}{likelihood/lecture/figures/}}
\lstset{inputpath=likelihood/code} \setcodepath{likelihood/code}
\include{likelihood/lecture/likelihood} \include{likelihood/lecture/likelihood}
\graphicspath{{pointprocesses/lecture/}{pointprocesses/lecture/figures/}} \graphicspath{{pointprocesses/lecture/}{pointprocesses/lecture/figures/}}
\lstset{inputpath=pointprocesses/code/} \setcodepath{pointprocesses/code}
\renewcommand{\texinputpath}{pointprocesses/lecture/} \renewcommand{\texinputpath}{pointprocesses/lecture/}
\include{pointprocesses/lecture/pointprocesses} \include{pointprocesses/lecture/pointprocesses}
\graphicspath{{spectral/lecture/}{spectral/lecture/figures/}} %\graphicspath{{spectral/lecture/}{spectral/lecture/figures/}}
\lstset{inputpath=spectral/code/} %\setcodepath{spectral/code/}
\renewcommand{\texinputpath}{spectral/lecture/} %\renewcommand{\texinputpath}{spectral/lecture/}
%\include{spectral/lecture/spectral} %\include{spectral/lecture/spectral}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -99,6 +99,9 @@
\backmatter \backmatter
%%%% solutions: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\printallsolutions
%%%% indices: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% indices: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\printindex[term] \printindex[term]

View File

@ -14,7 +14,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} \begin{document}
\input{statistics} \include{statistics}
\end{document} \end{document}