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 :
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
cleanall : clean

View File

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

View File

@ -46,7 +46,7 @@ watchchapter :
cleanchapter : cleanpythonplots cleangnuplots
rm -f *~
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

View File

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

View File

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

View File

@ -282,6 +282,22 @@
%
% The boolean showexercisesolutions controls whether solutions for the exercises
% 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{xstring}
\newlistof{exercisef}{loe}{\tr{Exercises}{\"Ubungen}}
@ -291,16 +307,16 @@
placement=t,
chapterlistsgaps=on,
]{exercisef}
\newboolean{showexercisesolutions}
\setboolean{showexercisesolutions}{true}
\newwrite\solutions % file descriptor for writing solutions
% we need to know the name of the included file as \currentjobname:
\usepackage{xpatch}
\makeatletter
\def\currentjobname{\jobname}%
\xpretocmd{\include}{\def\currentjobname{#1}\immediate\openout\solutions=\currentjobname-solutions}{}{}
\makeatother
\usepackage{needspace}
% the following does not work with \ifthenelse
\ifnum\exercisesolutionsnum=1
\def\currentjobname{\jobname}
\xpretocmd{\include}{\def\currentjobname{#1}\immediate\openout\solutions=\currentjobname-solutions}{}{}\fi%
\ifnum\exercisesolutionsnum=2
\def\currentjobname{\jobname}
\immediate\openout\solutions=\currentjobname-solutions\fi
\newenvironment{exercise}[2]%
{ \setlength{\fboxsep}{2mm}%
\newcommand{\saveenumi}{\theenumi}\renewcommand{\labelenumi}{(\alph{enumi})}%
@ -309,27 +325,59 @@
\begin{mdframed}[linewidth=0pt,backgroundcolor=exerciseback]%
\captionof{exercisef}[\protect\StrSubstitute{#1}{_}{\_}]{}%
\captionsetup{font={normal,sf,it}}%
\immediate\write\solutions{\unexpanded{%
\subsection}[Exercise \thechapter.\arabic{exercisef}]%
{\unexpanded{\needspace{4\baselineskip}}Exercise \thechapter.\arabic{exercisef}}}%
\immediate\write\solutions{\unexpanded{\label}{solution\arabic{exercisef}}}%
\immediate\write\solutions{\unexpanded{\lstinputlisting[belowskip=0ex,aboveskip=0ex,%
nolol=true, title={\textbf{Source code:} \protect\StrSubstitute{#1}{_}{\_}}]}{#1}}%
\ifthenelse{\equal{#2}{}}{}%
{\immediate\write\solutions{\unexpanded{\lstinputlisting[language={},%
nolol=true, title={\textbf{Output:}}, belowskip=0ex, aboveskip=1ex]}{#2}}}%
\immediate\write\solutions{}%
\ifthenelse{\equal{\exercisesolutions}{here}}{%
\newcommand{\exercisesource}{#1}%
\newcommand{\exercisefile}{\protect\StrSubstitute{#1}{_}{\_}}%
\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,%
nolol=true, title={\textbf{Source code:} \protect\StrSubstitute{#1}{_}{\_}}]}{\codepath#1}}%
\ifthenelse{\equal{#2}{}}{}%
{\immediate\write\solutions{\unexpanded{\lstinputlisting[language={},%
nolol=true, title={\textbf{Output:}}, belowskip=0ex, aboveskip=1ex]}{\codepath#2}}}%
\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}%
\end{mdframed}%
}
}
\newcommand{\printsolutions}{\immediate\closeout\solutions%
\ifthenelse{\boolean{showexercisesolutions}}{%
\clearpage\section{Solutions to the exercises}%
\input{\currentjobname-solutions}}{}}
\newcommand{\printsolutions}{\ifthenelse{\equal{\exercisesolutions}{chapter}%
\or\(\equal{\exercisesolutions}{end}\and\not\isundefined{\chapternumber}\)}{%
\immediate\closeout\solutions%
\ifthenelse{\boolean{showexercisesolutions}}{%
\clearpage\section{Solutions to the exercises}%
\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{\cftexercisefnumwidth}{2.6em}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -32,23 +32,23 @@
\part{Programming basics}
\graphicspath{{programming/lecture/}{programming/images/}}
\lstset{inputpath=programming/code}
\setcodepath{programming/code}
\include{programming/lecture/programming}
\graphicspath{{debugging/lecture/}{debugging/lecture/figures/}}
\lstset{inputpath=debugging/code}
\setcodepath{debugging/code}
\include{debugging/lecture/debugging}
\graphicspath{{plotting/lecture/}{plotting/lecture/images/}}
\lstset{inputpath=plotting/code/}
\setcodepath{plotting/code}
\include{plotting/lecture/plotting}
\graphicspath{{programmingstyle/lecture/}{programmingstyle/lecture/figures/}}
\lstset{inputpath=programmingstyle/code/}
\setcodepath{programmingstyle/code}
\include{programmingstyle/lecture/programmingstyle}
\graphicspath{{designpattern/lecture/}{designpattern/lecture/figures/}}
\lstset{inputpath=designpattern/code}
\setcodepath{designpattern/code}
\include{designpattern/lecture/designpattern}
@ -56,29 +56,29 @@
\part{Data analysis}
\graphicspath{{statistics/lecture/}{statistics/lecture/figures/}}
\lstset{inputpath=statistics/code}
\setcodepath{statistics/code}
\include{statistics/lecture/statistics}
\graphicspath{{bootstrap/lecture/}{bootstrap/lecture/figures/}}
\lstset{inputpath=bootstrap/code}
\setcodepath{bootstrap/code}
\include{bootstrap/lecture/bootstrap}
\graphicspath{{regression/lecture/}{regression/lecture/figures/}}
\lstset{inputpath=regression/code}
\setcodepath{regression/code}
\include{regression/lecture/regression}
\graphicspath{{likelihood/lecture/}{likelihood/lecture/figures/}}
\lstset{inputpath=likelihood/code}
\setcodepath{likelihood/code}
\include{likelihood/lecture/likelihood}
\graphicspath{{pointprocesses/lecture/}{pointprocesses/lecture/figures/}}
\lstset{inputpath=pointprocesses/code/}
\setcodepath{pointprocesses/code}
\renewcommand{\texinputpath}{pointprocesses/lecture/}
\include{pointprocesses/lecture/pointprocesses}
\graphicspath{{spectral/lecture/}{spectral/lecture/figures/}}
\lstset{inputpath=spectral/code/}
\renewcommand{\texinputpath}{spectral/lecture/}
%\graphicspath{{spectral/lecture/}{spectral/lecture/figures/}}
%\setcodepath{spectral/code/}
%\renewcommand{\texinputpath}{spectral/lecture/}
%\include{spectral/lecture/spectral}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -99,10 +99,13 @@
\backmatter
%%%% solutions: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\printallsolutions
%%%% indices: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\printindex[term]
\printindex[determ] % for english text
\printindex[determ] % for english text
% \printindex[enterm] % for german text
%\setindexprenote{Some explanations.}

View File

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