% \iffalse meta-comment % % Copyright (C) 2000 by Roger Jud <rogerjud@outlook.com> % ------------------------------------------------------- % % This file may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either version 1.2 % 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.2 or later is part of all distributions of LaTeX % version 1999/12/01 or later. % % \fi % % \iffalse %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] %<package>\ProvidesPackage{exercises}[2000/05/17 v1.1 .dtx exercises file] % %<*driver> \documentclass[a4paper]{ltxdoc} \usepackage{doctools} \usepackage{hyperref} \hypersetup{colorlinks,% citecolor=black,% filecolor=black,% linkcolor=black,% urlcolor=black,% } \usepackage[printsolution=true]{exercises}[2000/05/17] \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{amsmath} \usepackage{units} \usepackage{xcolor} \usepackage[toc]{multitoc} \usepackage[T1]{fontenc} \usepackage[mono=false]{libertine} \usepackage[scaled=0.8]{DejaVuSansMono} \setlength{\parindent}{0pt} \setlength{\parskip}{1ex plus 0.5ex minus 0.2ex} \EnableCrossrefs \CodelineIndex \RecordChanges \begin{document} \DocInput{exercises.dtx} \end{document} %</driver> % \fi % % \CheckSum{0} % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z % Digits \0\1\2\3\4\5\6\7\8\9 % Exclamation \! Double quote \" Hash (number) \# % Dollar \$ Percent \% Ampersand \& % Acute accent \' Left paren \( Right paren \) % Asterisk \* Plus \+ Comma \, % Minus \- Point \. Solidus \/ % Colon \: Semicolon \; Less than \< % Equals \= Greater than \> Question mark \? % Commercial at \@ Left bracket \[ Backslash \\ % Right bracket \] Circumflex \^ Underscore \_ % Grave accent \` Left brace \{ Vertical bar \| % Right brace \} Tilde \~} % % % % \changes{v1.0}{2015/09/19}{Initial version} % \changes{v1.1}{2000/05/17}{Add the command ifsolutionthenelse} % % \GetFileInfo{exercises.sty} % % \DoNotIndex{\newcommand,\newenvironment} % % % \title{The \textsf{exercises} package\thanks{This document % corresponds to \textsf{exercises}~\fileversion, dated \filedate.}} % \author{Roger Jud \\ \texttt{rogerjud@outlook.com}} % % \maketitle % % % % % % \begin{abstract} % The package |exercises| defines the environments |exercise| and |solution|. They can be used to typeset exercices and solutions. The package allows you to customize the layout of those environments. The optional points in exercises can be added automatically. In addition you're able to hide the solutions. % \end{abstract} % % \tableofcontents % % % \newpage % % % \section{Usage} % Install the package and put |\usepackage{exercises}| in your preamble. Notice that |exercises| loads |verbatim|, |ifthen|, |kvoptions| and |xparse|. If you have already loaded these packages using |\usepackage{verbatim, ifthen, ...}|, you should unload these therefore. % % Now you are able to use the environments |exercise| and |solution|. The two following sections show some code examples and the corresponding output. This is followed by some explanations and a list of all the options. % % % \subsection{Basic example} % % The following example shows the basic usage of the two environmets. There are two exercises and two solutions. Notice that the exercises and the solutions are automatically numbered. % % It is important to put |printsolution=true| as an option of the package, because otherwise the solutions won't be printed. (The default value is |false|.) % % \iffalse %<*example> % \fi \begin{latexcode} \usepackage[printsolution=true]{exercises} \begin{exercise} Calculate $1 + 1 =$ \end{exercise} \begin{solution} The result is $1 + 1 = 2$ \end{solution} \begin{exercise} Is this $2 + 3 = 6$ true or false. Give a reason why. \end{exercise} \begin{solution} It is false, because $2 + 3 = 5$ \end{solution} \end{latexcode} % \iffalse %</example> % \fi % % \emph{produces} % % \begin{exercise} % Calculate $1 + 1 =$ % % % \end{exercise} % % \begin{solution} % The result is $1 + 1 = 2$ % % % \end{solution} % % \begin{exercise} % Is this $2 + 3 = 6$ true or false. Give a reason why. % \end{exercise} % % \begin{solution} % It is false, because $2 + 3 = 5$ % \end{solution} % % % % \subsection{Optional arguments} % % The |exercise|-environment has a optional argument -- the points. The |solution|-environment has also a optional argument -- the space which is left blank, if the solutions are hidden. % % \iffalse %<*example> % \fi \begin{latexcode} \usepackage[printsolution=true]{exercises} \begin{exercise}[2] Calculate $1 + 1 =$ \end{exercise} \begin{solution}[3cm] The result is $1 + 1 = 2$ \end{solution} \begin{exercise}[2] Is this $2 + 3 = 6$ true or false. Give a reason why. \end{exercise} \begin{solution}[2cm] It is false, because $2 + 3 = 5$ \end{solution} \end{latexcode} % \iffalse %</example> % \fi % % \emph{produces} % % \begin{exercise}[1] % Calculate $1 + 1 =$ % \end{exercise} % % \begin{solution}[3cm] % The result is $1 + 1 = 2$ % \end{solution} % % % \begin{exercise}[2] % Is this $2 + 3 = 6$ true or false. Give a reason why. % \end{exercise} % % \begin{solution}[2cm] % It is false, because $2 + 3 = 5$ % \end{solution} % % % % \subsection{Sum of points} % % The points of all exercises are added. The command \cs{totalpoints} can be used to print the sum of the points. The word |Pt.| will be added automatically. You can customize it using the package option |totalpointsname=|\meta{string}. (See also the following section.) % % \iffalse %<*example> % \fi \begin{latexcode} Sum of points: \totalpoints \end{latexcode} % \iffalse %</example> % \fi % % \emph{produces} % % Sum of points: \totalpoints % % % % % % % % % \section{Options} % This package uses the key-value-format for the package options. You can choose them while loading the package. % % \cs{usepackage}\oarg{option}|{exercises}| % % The following options are available: % \begin{itemize} % \item |printsolution=|\meta{boolean}: % \begin{itemize} % \item |printsolution=false| \emph{(default)}\hspace{0.5em} The content between |\begin{solution}| and |\end{solution}| is not printed. % \item |printsolution=true|\hspace{2ex} The solutions are printed. % \end{itemize} % \item |exercisespaceabove=|\meta{length} \hspace{0.5em} Space above the |exercise|-environment. \newline \hspace*{0.5em} \emph{default value:} \unit[2.0]{ex} plus \unit[1.0]{ex} minus \unit[0.5]{ex} % \item |exercisespacebelow=|\meta{length} \hspace{0.5em} Space below the |exercise|-environment. \newline \hspace*{0.5em} \emph{default value:} \unit[1.5]{ex} plus \unit[1.0]{ex} minus \unit[0.5]{ex} % \item |solutionspaceabove=|\meta{length} \hspace{0.5em} Space above the |solution|-environment. \newline \hspace*{0.5em} \emph{default value:} \unit[2.0]{ex} plus \unit[1.0]{ex} minus \unit[0.5]{ex} % \item |solutionspacebelow=|\meta{length} \hspace{0.5em} Space below the |solution|-environment. \newline \hspace*{0.5em} \emph{default value:} \unit[1.5]{ex} plus \unit[1.0]{ex} minus \unit[0.5]{ex} % \item |blockspace=|\meta{length} \hspace{0.5em} Space below |exercisename| respectively |solutionname|, if |exercisenameposition| respectively |solutionnameposition| is set to |block|. \newline \hspace*{0.5em} \emph{default value:} \unit[0.25]{ex} % \item |inlinespace=|\meta{length} \hspace{0.5em} Space after |exercisename| respectively |solutionname|, if |exercisenameposition| respectively |solutionnameposition| is set to |inline|. \newline \hspace*{0.5em} \emph{default value:} \unit[0.5]{em} % \item |exercisenumberformat=|\meta{string} \hspace{0.5em} It defines the number format for the numbering of the exercises and the solutions. You can choose from the following: % \begin{itemize} % \item |exercisenumberformat=arabic| \emph{(default)}\hspace{0.5em} arabic numbers % \item |exercisenumberformat=roman| \hspace{0.5em} small roman numbers % \item |exercisenumberformat=Roman| \hspace{0.5em} large roman numbers % \item |exercisenumberformat=alph| \hspace{0.5em} small latin letters % \item |exercisenumberformat=Alph| \hspace{0.5em} large latin letters % \end{itemize} % \item |pointsposition=|\meta{string}\hspace{0.5em} If you use points for the |exercise|-Environment, you can tell the package where to put them. You can choose from the following: % \begin{itemize} % \item |pointsposition=aftername| \emph{(default)} \hspace{0.5em} after the double point (Exercise 1: (3 Pt.)) % \item |pointsposition=margin| \hspace{0.5em} at the right margin % \end{itemize} % \item |pointsfontsize=|\meta{string} \hspace{0.5em} You can shoose between two fontsizes for the points: % \begin{itemize} % \item |pointsfontsize=normalsize| \emph{(default)} \hspace{0.5em} normal fontsize (like \cs{normalsize}) % \item |pointsfontsize=footnotesize| \hspace{0.5em} smaller fontsize (like \cs{footnotesize}) % \end{itemize} % \item |pointsname=|\meta{string} \hspace{0.5em} You can select which text is displayed after the points of an exercise. \emph{(default: Pt.)} % \item |exercisename=|\meta{string} \hspace{0.5em} You can select which text is displayed at the beginning of an exercise. \emph{(default: Exercise)} % \item |exercisenameposition=|\meta{string} \hspace{0.5em} There are two ways to position the |exercisename|: % \begin{itemize} % \item |exercisenameposition=block| \emph{(default)} \hspace{0.5em} There is a line break after |exercisename| and optionally an additional vertical space (|blockspace|). % \item |exercisenameposition=inline| \hspace{0.5em} There is only a horizontal space (|inlinespace|) after |exercisename|. % \end{itemize} % \item |solutionname=|\meta{string} \hspace{0.5em} You can select which text is displayed at the beginning of a solution. \emph{(default: Solution)} % \item |solutionnameposition=|\meta{string} \hspace{0.5em} There are two ways to position the |solutionname|: % \begin{itemize} % \item |solutionnameposition=block|: \emph{(default)} \hspace{0.5em} There is a line break after |solutionname| and optionally an additional vertical space (|blockspace|). % \item |solutionnameposition=inline| \hspace{0.5em} There is only a horizontal space (|inlinespace|) after |solutionname|. % \end{itemize} % \item |totalpointsname=|\meta{string} \hspace{0.5em} You can select which text is displayed after the points using the command \cs{totalpoints}. \emph{(default: Pt.)} % \item |braces=|\meta{string} \hspace{0.5em} You can choose between three types of braces embracing the points of an exercise: % \begin{itemize} % \item |braces=nobraces| \hspace{0.5em} no braces % \item |braces=round| \emph{(default)} \hspace{0.5em} round braces like (1 Pt.) % \item |braces=square| \hspace{0.5em} square braces like [1 Pt.] % \end{itemize} % \item |starpoints=|\meta{boolean}: % \begin{itemize} % \item |starpoints=false| \emph{(default)} \hspace{0.5em} The points are printed as normal arabic numbers. % \item |starpoints=true| \hspace{0.5em} Stars (for exmaple **** for five points) are printed instead of numbers. % \end{itemize} % \end{itemize} % % % \section{Special commands} % % \subsection{Sum of points} % You can print the sum of points anywhere in the document using \cs{totalpoints}. \LaTeX{} needs two runs to calculate the sum. % % % \subsection{Special page breaks} % Custom page breaks using \cs{newpage} will move depending on wether or not to print the solutions. Because of that two new commands are available. % % \cs{exercisenewpage} inserts only a page break if |printsolution=false|, so if the solutions are \emph{not} printed. \cs{solutionnewpage} -- on the other hand -- inserts a page break if |printsolution=true|, so if the solutions are printed. % % % % \subsection{Print text depending on wether the solution is printed or not} % With the command |\ifsolutionthenelse{}{}| you can print text depending on wether the solution is printed or not. % % \iffalse %<*example> % \fi \begin{latexcode} \usepackage[printsolution=true]{exercises} \ifsolutionthenelse{% \subsection*{This is the header for the solutions}% }% {% \subsection*{This is the header for the exercises}% } \end{latexcode} % \iffalse %</example> % \fi % % \emph{produces} % % \subsection*{This is the header for the solutions} % % % \emph{while} % % % % % \iffalse %<*example> % \fi \begin{latexcode} \usepackage[printsolution=false]{exercises} \ifsolutionthenelse{% \subsection*{This is the header for the solutions}% }% {% \subsection*{This is the header for the exercises}% } \end{latexcode} % \iffalse %</example> % \fi % % \emph{produces} % % \subsection*{This is the header for the exercises} % % \StopEventually{\PrintChanges} % % \section[Implementation]{Implementation -- how I've done it (only in German)} % % \subsection{Ben��tigte Pakete} % % Zuerst lade ich alle ben��tigten Pakete. Das Paket |verbatim| benutze ich, um die L��sungen mit den Befehlen |\comment| und |\endcomment| auszukommentieren. % \begin{macrocode} \RequirePackage{verbatim} % \end{macrocode} % Das Paket |ifthen| hilft mit Befehlen wie |\ifthenelse|, |\equal|, |\boolean| und anderen. % \begin{macrocode} \RequirePackage{ifthen} % \end{macrocode} % Um eine Komma-separierte Liste von \meta{key}=\meta{value}-Optionen erstellen zu k��nnen, ben��tige ich das Paket |kvoptions|. % \begin{macrocode} \RequirePackage{kvoptions} % \end{macrocode} % Das Paket |xparse| erlaubt mir das erstellen von Befehlen und Umgebungen mit mehreren (optionalen) Argumenten. % \begin{macrocode} \RequirePackage{xparse} % \end{macrocode} % Das Paket |marginnote| erlaubt mir die Erstellung von Bemerkungen am Rand. Ich benutze dieses Pakte anstelle des Befehls |marginpar|, weil |marginpar| die Notiz manchmal auf einer Seite platziert. (Paket-Warnung: marginpar on page xy moved.) % \begin{macrocode} \RequirePackage{marginnote} % \end{macrocode} % % In einem ersten Schritt weise ich den Wert \meta{family} (am besten der Name des Pakets) sowie \meta{prefix} (das Pr��fix, welches vor jeden Variabelnnamen gesetzt wird) zu. Weitere Informationen k��nnen der Dokumentation von |kvoptions| entnommen werden. % \begin{macrocode} \SetupKeyvalOptions{ family=exercises, prefix=exercises@} % \end{macrocode} % % % % % % % % % % % % % % % % % % % % % % % \subsection{Paket-Optionen definieren} % % Jetzt definiere und initialisiere ich alle Paket-Optionen. Wenn der Benutzer keine Option w��hlt, wir der Standard-Wert (in eckigen Klammern) benutzt. Dann benutze ich den Befehl |\ProcessKeyvalOptions| um die Optionen dem Paket |exercises| zug��nglich zu machen. % \begin{macrocode} \DeclareBoolOption{printsolution} \DeclareStringOption[2.0ex plus 1.0ex minus 0.5ex]{exercisespaceabove} \DeclareStringOption[1.5ex plus 1.0ex minus 0.5ex]{exercisespacebelow} \DeclareStringOption[2.0ex plus 1.0ex minus 0.5ex]{solutionspaceabove} \DeclareStringOption[1.5ex plus 1.0ex minus 0.5ex]{solutionspacebelow} \DeclareStringOption[0.25ex]{blockspace} \DeclareStringOption[0.5em]{inlinespace} \DeclareStringOption[arabic]{exercisenumberformat} \DeclareStringOption[aftername]{pointsposition} \DeclareStringOption[normalsize]{pointsfontsize} \DeclareStringOption[Pt.]{pointsname} \DeclareStringOption[Exercise]{exercisename} \DeclareStringOption[block]{exercisenameposition} \DeclareStringOption[Solution]{solutionname} \DeclareStringOption[block]{solutionnameposition} \DeclareStringOption[Pt.]{totalpointsname} \DeclareStringOption[round]{braces} \DeclareBoolOption[false]{starpoints} \ProcessKeyvalOptions{exercises} % \end{macrocode} % % % % % % % % % % % % % % % % % % % % % % % \subsection{Formatierung der Nummerierung} % % Ich \DescribeMacro{\exercises@formatnumbers}\ definiere einen Befehl um die Nummerierung der ��bungen zu formatieren. % % Wird f��r die Option \meta{exercisenumberformat} \meta{arabic} verwendet, so wird |\exercises@formatnumbers| so definiert, dass die Nummerierung als arabische Ziffern ausgegeben wird. % \begin{macrocode} \ifthenelse{\equal{\exercises@exercisenumberformat}{arabic}}% {\newcommand{\exercises@formatnumbers}[1]{\arabic{#1}}}{}% % \end{macrocode} % % Wird f��r die Option \meta{exercisenumberformat} \meta{roman} verwendet, so wird |\exercises@formatnumbers| so definiert, dass die Nummerierung als kleine r��mische Ziffern ausgegeben wird. % \begin{macrocode} \ifthenelse{\equal{\exercises@exercisenumberformat}{roman}}% {\newcommand{\exercises@formatnumbers}[1]{\roman{#1}}}{}% % \end{macrocode} % % Wird f��r die Option \meta{exercisenumberformat} \meta{Roman} verwendet, so wird |\exercises@formatnumbers| so definiert, dass die Nummerierung als grosse r��mische Ziffern ausgegeben wird. % \begin{macrocode} \ifthenelse{\equal{\exercises@exercisenumberformat}{Roman}}% {\newcommand{\exercises@formatnumbers}[1]{\Roman{#1}}}{}% % \end{macrocode} % % Wird f��r die Option \meta{exercisenumberformat} \meta{alph} verwendet, so wird |\exercises@formatnumbers| so definiert, dass die Nummerierung als Buchstaben ausgegeben wird. % \begin{macrocode} \ifthenelse{\equal{\exercises@exercisenumberformat}{alph}}% {\newcommand{\exercises@formatnumbers}[1]{\alph{#1}}}{}% % \end{macrocode} % % Wird f��r die Option \meta{exercisenumberformat} \meta{Alph} verwendet, so wird |\exercises@formatnumbers| so definiert, dass die Nummerierung als grosse Buchstaben ausgegeben wird. % \begin{macrocode} \ifthenelse{\equal{\exercises@exercisenumberformat}{Alph}}% {\newcommand{\exercises@formatnumbers}[1]{\Alph{#1}}}{}% % \end{macrocode} % % Wird f��r die Option \meta{exercisenumberformat} weder \meta{arabic} noch \meta{roman} noch \meta{Roman} noch \meta{alph} noch \meta{Alph} verwendet, so wird eine Fehlermeldung ausgegeben und \meta{exercisenumberformat} auf \meta{arabic} gesetzt. % \begin{macrocode} \ifthenelse{\not\equal{\exercises@exercisenumberformat}{arabic}% \and \not\equal{\exercises@exercisenumberformat}{roman}% \and \not\equal{\exercises@exercisenumberformat}{Roman}% \and \not\equal{\exercises@exercisenumberformat}{alph}% \and \not\equal{\exercises@exercisenumberformat}{Alph}}% {\PackageError{exercises}% {"\exercises@exercisenumberformat" ist als Option von "exercisenumberformat" nicht erlaubt. % Stattdessen wurde "arabic" verwendet.}% {"\exercises@exercisenumberformat" ist als Option von "exercisenumberformat" nicht erlaubt. % Stattdessen wurde "arabic" verwendet.}% \newcommand{\exercises@formatnumbers}[1]{\arabic{#1}}}{}% % \end{macrocode} % % % % % % % % % % % % % % % % % % % % % % % \subsection{Positionierung der ��berschriften} % % \begin{macrocode} \ifthenelse{\equal{\exercises@exercisenameposition}{block}}% {\newcommand{\exercises@placeexercise}{\noindent\par\vspace{\exercises@blockspace}}}{}% % \end{macrocode} % % % % \begin{macrocode} \ifthenelse{\equal{\exercises@exercisenameposition}{inline}}% {\newcommand{\exercises@placeexercise}{\hspace{\exercises@inlinespace}}}{}% % \end{macrocode} % % % % \begin{macrocode} \ifthenelse{\not\equal{\exercises@exercisenameposition}{block}% \and \not\equal{\exercises@exercisenameposition}{inline}}% {\PackageError{exercises}% {"\exercises@exercisenameposition" ist als Option von "exercisenameposition" nicht erlaubt. % Stattdessen wurde "block" verwendet.}% {"\exercises@exercisenameposition" ist als Option von "exercisenameposition" nicht erlaubt. % Stattdessen wurde "block" verwendet.} \newcommand{\exercises@placeexercise}{\noindent\par\vspace{\exercises@blockspace}}}{}% % \end{macrocode} % % % % \begin{macrocode} \ifthenelse{\equal{\exercises@solutionnameposition}{block}}% {\newcommand{\exercises@placesolution}{\noindent\par\vspace{\exercises@blockspace}}}{}% % \end{macrocode} % % % % \begin{macrocode} \ifthenelse{\equal{\exercises@solutionnameposition}{inline}}% {\newcommand{\exercises@placesolution}{\hspace{\exercises@inlinespace}}}{}% % \end{macrocode} % % % % \begin{macrocode} \ifthenelse{\not\equal{\exercises@solutionnameposition}{block}% \and \not\equal{\exercises@solutionnameposition}{inline}}% {\PackageError{exercises}% {"\exercises@solutionnameposition" ist als Option von "solutionnameposition" nicht erlaubt. % Stattdessen wurde "block" verwendet.}% {"\exercises@solutionnameposition" ist als Option von "solutionnameposition" nicht erlaubt. % Stattdessen wurde "block" verwendet.}% \newcommand{\exercises@placesolution}{\noindent\par\vspace{\exercises@blockspace}}}{}% % \end{macrocode} % % % % % % % % % % % % % \subsection{Positionierung der Punktzahlen} % % Nun\DescribeMacro{\exercises@placepoints}\ werden die Befehle zur Positionierung der Punkte (falls vorhanden) definiert. Falls f��r die Option \meta{pointsplace} keine der Werte \meta{aftername} (Position der Punkte rechts des Doppelpunktes nach \emph{Exercise}) oder \meta{margin} (am rechten Rand) verwendet wird, gibt das Paket eine Fehlermeldung aus und verwendet die Option \meta{aftername}. % % Wird f��r die Option \meta{aftername} verwendet, so wird |\exercises@placepoints| so definiert, dass lediglich die Punktzahl ausgegeben wird. % \begin{macrocode} \ifthenelse{\equal{\exercises@pointsposition}{aftername}}% {\newcommand{\exercises@placepoints}[1]{ #1}}{}% % \end{macrocode} % % Wird f��r die Option \meta{margin} verwendet, so wird |\exercises@placepoints| so definiert, dass die Punktzahl mit Hilfe von |\marginnote| am rechten Rand ausgegeben wird. % \begin{macrocode} \ifthenelse{\equal{\exercises@pointsposition}{margin}}% {\newcommand{\exercises@placepoints}[1]% {\marginnote{#1}}}{}% % \end{macrocode} % % Wird f��r die Option \meta{pointsposition} weder \meta{aftername} noch \meta{margin} verwendet, so wird eine Fehlermeldung ausgegeben und \meta{pointsposition} auf \meta{aftername} gesetzt. % \begin{macrocode} \ifthenelse{\not\equal{\exercises@pointsposition}{aftername}% \and \not\equal{\exercises@pointsposition}{margin}}% {\PackageError{exercises}% {"\exercises@pointsposition" ist als Option von "pointsposition" nicht erlaubt. % Stattdessen wurde "aftername" verwendet.}% {"\exercises@pointsposition" ist als Option von "pointsposition" nicht erlaubt. % Stattdessen wurde "aftername" verwendet.}% \newcommand{\exercises@placepoints}[1]{ #1}}{}% % \end{macrocode} % % % % % % % % % % % \subsection{Formatierung der Punktzahlen} % % \begin{macrocode} \ifthenelse{\equal{\exercises@pointsfontsize}{normalsize}}% {\newcommand{\exercises@formatpoints}[1]{\normalsize #1}}{}% % \end{macrocode} % % \begin{macrocode} \ifthenelse{\equal{\exercises@pointsfontsize}{footnotesize}}% {\newcommand{\exercises@formatpoints}[1]{\footnotesize #1 \normalsize}}{}% % \end{macrocode} %% % \begin{macrocode} \ifthenelse{\not\equal{\exercises@pointsfontsize}{normalsize}% \and \not\equal{\exercises@pointsfontsize}{footnotesize}}% {\PackageError{exercises}% {"\exercises@pointsfontsize" ist als Option von "pointsfontsize" nicht erlaubt. % Stattdessen wurde "normalsize" verwendet.}% {"\exercises@pointsfontsize" ist als Option von "pointsfontsize" nicht erlaubt. % Stattdessen wurde "normalsize" verwendet.}% \newcommand{\exercises@formatpoints}[1]{\normalsize #1}}{}% % \end{macrocode} % % % % % % % % % % % % % % % % \subsection{Klammern formatieren} % % Nun\DescribeMacro{\exercises@braces}\ werden die Befehle zur Ausgabe der Klammern (falls vorhanden) definiert. Falls f��r die Option \meta{braces} keine der Werte \meta{nobraces}, \meta{round} oder \meta{square} verwendet wird, gibt das Paket eine Fehlermeldung aus und verwendet die Option \meta{round}. % % Wird f��r die Option \meta{braces} \meta{nobraces} verwendet, so wird |\exercises@braces| so definiert, dass keine Klammern ausgegeben werden. % \begin{macrocode} \ifthenelse{\equal{\exercises@braces}{nobraces}}% {\newcommand{\exercises@openbrace}{}% \newcommand{\exercises@closebrace}{}}{}% % \end{macrocode} % % Wird f��r die Option \meta{braces} \meta{round} verwendet, so wird |\exercises@braces| so definiert, dass runde Klammern ausgegeben werden. % \begin{macrocode} \ifthenelse{\equal{\exercises@braces}{round}}% {\newcommand{\exercises@openbrace}{(}% \newcommand{\exercises@closebrace}{)}}{}% % \end{macrocode} % % Wird f��r die Option \meta{braces} \meta{square} verwendet, so wird |\exercises@braces| so definiert, dass eckige Klammern ausgegeben werden. % \begin{macrocode} \ifthenelse{\equal{\exercises@braces}{square}}% {\newcommand{\exercises@openbrace}{[}% \newcommand{\exercises@closebrace}{]}}{}% % \end{macrocode} % % Wird f��r die Option \meta{braces} weder \meta{nobraces} noch \meta{round} noch \meta{square} verwendet, so wird eine Fehlermeldung ausgegeben und \meta{braces} auf \meta{round} gesetzt. % \begin{macrocode} \ifthenelse{\not\equal{\exercises@braces}{nobraces}% \and \not\equal{\exercises@braces}{round}% \and \not\equal{\exercises@braces}{square}}% {% \PackageError{exercises}% {"\exercises@braces" ist als Option von "braces" nicht erlaubt. % Stattdessen wurde "round" verwendet.}% {"\exercises@braces" ist als Option von "braces" nicht erlaubt. % Stattdessen wurde "round" verwendet.}% \newcommand{\exercises@openbrace}{(}% \newcommand{\exercises@closebrace}{)}% }{}% % \end{macrocode} % % % % % % % % % % % % % % % % % % % % % % % % % \subsection{Definition von Z��hlern} % % Nun werden die Z��hler zur Nummerierung der Aufgaben (\meta{exercises@exercisenumber}) und L��sungen (\meta{exercises@solutionnumber}) sowie zur Z��hlung der Punkte (\meta{exercises@totalpoints} und \meta{exercises@finaltotalpoints}) definiert und initialisiert. % \begin{macrocode} \newcounter{exercises@totalpoints} \setcounter{exercises@totalpoints}{0} \newcounter{exercises@finaltotalpoints} \newcounter{exercises@exercisenumber} \setcounter{exercises@exercisenumber}{1} \newcounter{exercises@solutionnumber} \setcounter{exercises@solutionnumber}{1} \newcounter{i} \newlength{\exercises@parskipsave} % \end{macrocode} % % % % % % % % % % % % % % % % % % % % % % % % % % % \subsection{Umgebung \texttt{exercise}} % %\begin{macro}{exercise} % Der eigentliche Code folgt nun. Die Umgebung |exercise| definiert ein optionales Argument (die Punktzahl). % \begin{macrocode} \DeclareDocumentEnvironment{exercise}{o}{% \setlength{\exercises@parskipsave}{0cm} \setlength{\exercises@parskipsave}{\parskip} \setlength{\parskip}{0cm} % \end{macrocode} % % Der obere Abstand wird eingef��gt. % \begin{macrocode} \vspace{\exercises@exercisespaceabove}% % \end{macrocode} % % Ist das optionale Argument leer (|\IfNoValueTF| also wahr), wird lediglich \meta{exercisename} (standarm��ssig Exercise) sowie \meta{exercisenumber} ausgegeben. % \begin{macrocode} \IfNoValueTF{#1}% {\textbf{\exercises@exercisename\ \exercises@formatnumbers{exercises@exercisenumber}:}\exercises@placeexercise}% % \end{macrocode} % % Ist das optionale Argument vorhanden (|\IfNoValueTF| also nicht wahr), wird zuerst \meta{totalpoints} um die Punktzahel erh��ht und anschliessend \meta{exercisename} sowie \meta{exercisenumber} ausgegeben. % \begin{macrocode} {\addtocounter{exercises@totalpoints}{#1}% \textbf{\exercises@exercisename\ \exercises@formatnumbers{exercises@exercisenumber}:}% % \end{macrocode} % % Falls \meta{starpoints} wahr ist, wird eine Schleife zur Ausgabe der Sterne -- entsprechend der Anzahl Punkt -- gestartet. % \begin{macrocode} \ifthenelse{\boolean{exercises@starpoints}}% {\exercises@placepoints{\exercises@openbrace% \setcounter{i}{0}\whiledo{#1>\thei}{*\stepcounter{i}}% \exercises@closebrace}}% % \end{macrocode} % % Ist \meta{starpoints} nicht wahr ist, wird die Punktzahl ausgegeben. % \begin{macrocode} {\exercises@placepoints{\exercises@formatpoints{\exercises@openbrace#1 \exercises@pointsname\exercises@closebrace}}}\exercises@placeexercise% }% \setlength{\parskip}{\exercises@parskipsave}% }{% \setlength{\parskip}{0cm}% % \end{macrocode} % \end{macro} % % Der Z��hler \meta{exercisenumber} wird um 1 hochgez��hlt und der untere Abstand wird eingef��gt. % \begin{macrocode} \stepcounter{exercises@exercisenumber}% \vspace{\exercises@exercisespacebelow}% \setlength{\parskip}{\exercises@parskipsave}% }% % \end{macrocode} % % % % % % % % % % % % % % % % % % % % % % % % % \subsection{Berechnung und Ausgabe der Gesamtpunktzahl} % % \begin{macro}{\totalpoints} % Der Befehle |\totalpoints| zur Ausgabe der Gesamtpunktzahl im Dokument wird definiert. Es wird eine Referenz auf den Z��hler \meta{exercises@finaltotalpoints} erstellt, welcher am Ende des Dokuments mit Hilfe von |\AtEndDocument| in die |aux|-Datei geschrieben wird. % \begin{macrocode} \newcommand\totalpoints{\theexercises@finaltotalpoints\ \exercises@totalpointsname}% % \end{macrocode} % % |\immediate\write\@auxout| sorgt daf��r, dass der String |\setcounter{exercises@finaltotalpoints}{\theexercises@totalpoints}| in die |aux|-Datei geschrieben wird. So wird dem Z��hler \meta{exercises@finaltotalpoints} der Wert von \meta{exercises@totalpoints} ��bergeben. Die direkte Speicherung von \meta{exercises@totalpoints} in der |aux|-Datei ist nicht m��glich, denn dann w��rde bei einem \LaTeX\-Lauf folgendes passieren: % \begin{enumerate} % \item Das Paket |exercises| wird geladen und \meta{exercises@totalpoints} wird mit 0 initialisiert. % \item Bei |\begin{document}| wird die |aux|-Datei gelesen. Beim ersten Lauf ��ndert sich \meta{exercises@totalpoints} nicht. % \item Zu \meta{exercises@totalpoints} werden die Punktzahlen der einzelnen Aufgaben addiert. % \item Am Ende des Dokumentes wird mit |\AtEndDocument| bzw. |\immediate\write\@auxout| der aktuelle Wert von \meta{exercises@totalpoints} in die |aux|-Datei geschreiben. % \item Beim zweiten \LaTeX\-Lauf w��rde wiederum das Paket |exercises| geladen und \meta{exercises@totalpoints} mit 0 initialisiert werden. % \item Bei |\begin{document}| wird wiederum die |aux|-Datei gelesen. Beim diesem zweiten \LaTeX\-Lauf w��rde \meta{exercises@totalpoints} nun den Wert der Gesamtpunktzahl aus dem ersten Lauf bekommen. % \item Zu \meta{exercises@totalpoints} werden die Punktzahlen der einzelnen Aufgaben addiert. % \item usw. % \end{enumerate} % Man erkennt, dass sich so die Gesamtpunktzahl bei jedem \LaTeX\-Lauf verdoppeln, verdreifachen usw. w��rde. Entsprechend wird \meta{exercises@totalpoints} jeweils am Schluss des Dokuments an \meta{exercises@finaltotalpoints} ��bergeben. % \begin{macrocode} \AtEndDocument{\immediate\write\@auxout% {\string\setcounter{exercises@finaltotalpoints}{\theexercises@totalpoints}}}% % \end{macrocode} % \end{macro} % % % % % % % % % % % % % % % % % % % % % % % % % % \subsection{Umgebung \texttt{solution}} % % \begin{macro}{solution} % Die Umgebung |solution| definiert ein optionales Argument: der Abstand, welcher freigelassen werden soll, falls die L��sung nicht ausgegeben wird. % \begin{macrocode} \DeclareDocumentEnvironment{solution}{o}{% \setlength{\exercises@parskipsave}{0cm} \setlength{\exercises@parskipsave}{\parskip} \setlength{\parskip}{0cm} % \end{macrocode} % % Der obere Abstand wird eingef��gt, falls die L��sungen ausgegeben werden. % \begin{macrocode} \ifthenelse{\boolean{exercises@printsolution}}% {\vspace{\exercises@solutionspaceabove}}{}% % \end{macrocode} % % \meta{solutionname} und die L��sungsnummer werden ausgegeben, sofern die L��sungen ��berhaupt ausgegeben. Andernfalls wird der Leerraum (das optionale Argument) sowie |\comment| ausgegeben. % \begin{macrocode} \ifthenelse{\boolean{exercises@printsolution}}% {\textbf{\exercises@solutionname\ \exercises@formatnumbers{exercises@solutionnumber}:\exercises@placesolution}}% {\IfNoValueTF{#1}{}{\vspace{#1}}\comment}% \setlength{\parskip}{\exercises@parskipsave}% }% % \end{macrocode} % Werden die L��sungen ausgegeben, so wird \meta{solutionspacebelow} ausgegeben. Andern falls folgt die Ausgabe von |\endcomment|. Zu guter Letzt wird der Z��hler \meta{solutionnumber} eins hochgez��hlt. % \begin{macrocode} {% \setlength{\parskip}{0cm}% \ifthenelse{\boolean{exercises@printsolution}}{\vspace{\exercises@solutionspacebelow}}% {\endcomment}\stepcounter{exercises@solutionnumber}\setlength{\parskip}{\exercises@parskipsave}% \setlength{\parskip}{\exercises@parskipsave}% }% % \end{macrocode} % \end{macro} % % % % % % % % % % % % % % % % % % % % % % % % % \subsection{Befehle f��r die Seitenumbr��che} % % \begin{macro}{\exercisenewpage} % \begin{macro}{\solutionnewpage} % Die Befehle |exercisenewpage| und |solutionnewpage| erlauben es, einen Seitenumbruch in Abh��ngigkeit der L��sungsausgabe einzuf��gen. % \begin{macrocode} \newcommand{\exercisenewpage}{\ifthenelse{\boolean{exercises@printsolution}}{}{\newpage}} % \end{macrocode} % % \begin{macrocode} \newcommand{\solutionnewpage}{\ifthenelse{\boolean{exercises@printsolution}}{\newpage}{}} % \end{macrocode} % \end{macro} % \end{macro} % % % % \subsection{Befehl f��r die bedingte Textausgabe} % % \begin{macro}{\ifsolutionthenelse} % Der Befehl |ifsolutionthenelse{}{}| erlaubt es, Text in Abh��ngigkeit der L��sungsausgabe auszugeben. % \begin{macrocode} \newcommand{\ifsolutionthenelse}[2]{\ifthenelse{\boolean{exercises@printsolution}}{#1}{#2}} % \end{macrocode} % % \end{macro} % % \Finale \endinput