diff options
author | Karl Berry <karl@freefriends.org> | 2006-01-11 23:53:04 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-01-11 23:53:04 +0000 |
commit | a2bc3e518387aa30b4f7c0f5d95ad4c3eb584ee0 (patch) | |
tree | e13b08924be72930cdde934940d24e0fea07fc3a /Master/texmf-dist/source/latex/exercise | |
parent | 1548faa2c0d15b20f0d9473a06653ce688727b3a (diff) |
trunk/Master/texmf-dist/source/latex/exercise
git-svn-id: svn://tug.org/texlive/trunk@268 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/exercise')
-rw-r--r-- | Master/texmf-dist/source/latex/exercise/exercise.dtx | 1507 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/exercise/exercise.ins | 66 |
2 files changed, 1573 insertions, 0 deletions
diff --git a/Master/texmf-dist/source/latex/exercise/exercise.dtx b/Master/texmf-dist/source/latex/exercise/exercise.dtx new file mode 100644 index 00000000000..72d34436437 --- /dev/null +++ b/Master/texmf-dist/source/latex/exercise/exercise.dtx @@ -0,0 +1,1507 @@ +% \iffalse meta-comment +% +% Copyright (C) 2003 by Paul Pichaureau +% +% This program is free software; you can redistribute it and/or +% modify it under the terms of the GNU General Public License +% as published by the Free Software Foundation; either version 2 +% of the License, or (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +% Public LaTeX Project Public +% +% \fi + + +% \iffalse +%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] +%<package>\ProvidesPackage{exercise} +%<package> [2004/09/05 v1.1 Exercise package (P.Pichaureau)] +%<*driver> +\documentclass{ltxdoc} +\usepackage{exercise} +\usepackage[latin1]{inputenc} +\usepackage{xspace,fancyvrb} +%% \IfFileExists{hyperref.sty}{\usepackage[bookmarksopen]{hyperref}}{} +%% \def\PrintDescribeMacro#1{} +%% \def\PrintDescribeEnv#1{} +\newenvironment{decl}[1][]% + {\par\small\addvspace{4.5ex plus 1ex}% + \vskip -\parskip + \ifx\relax#1\relax + \def\@decl@date{}% + \else + \def\@decl@date{\NEWfeature{#1}}% + \fi + \noindent\hspace{-\leftmargini}% + \begin{tabular}{|l|}\hline\ignorespaces}% + {\\\hline\end{tabular}\nobreak\@decl@date\par\nobreak + \vspace{2.3ex}\vskip -\parskip} +\makeatletter + \EnableCrossrefs \PageIndex \RecordChanges +\makeatother +\begin{document} + \DocInput{exercise.dtx} +\end{document} +%</driver> +% \fi +%% \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 \~} +%% +% \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ } +% \DoNotIndex{\@ne,\@auxout,\@ifnextchar,\@ifstar,\@ifundefined,\@bsphack,\@esphack,\@fleqnfalse} +% \DoNotIndex{\advance,\begingroup,\begin,\bgroup,\catcode,\closein,\closeout} +% \DoNotIndex{\day,\def,\edef,\else,\empty,\endgroup,\end,\egroup,\errmessage} +% \DoNotIndex{\expandafter,\fi,\futurelet,\gdef,\global,\if,\ifeof} +% \DoNotIndex{\ifx,\immediate,\let,\loop,\m@ne,\message,\month} +% \DoNotIndex{\newcount} +% \DoNotIndex{\newif,\newlinechar,\newread,\newtoks,\newwrite} +% \DoNotIndex{\noexpand,\openin,\openout,\par,\quad,\read,\relax,\repeat} +% \DoNotIndex{\space,\the,\undefined,\write,\xdef,\year,\z@} +% \DoNotIndex{\item,\copy,\arabic,\addto,\addtolength,\alph} +% \DoNotIndex{\ref,\Roman,\rmdefault,\or,\number,\medskip,\makebox} +% \DoNotIndex{\fbox,\label,\ifcase,\ifnum,\ignorespaces,\newcommand} +% \DoNotIndex{\renewenvironment,\renewcommand,\refstepcounter,\newenvironment} +% \DoNotIndex{\setlength,\string,\textbf,\textsc,\emph,\whiledo,\vbox} +% \DoNotIndex{\unvbox,\usefont,\usecounter,\value,\vskip,\setbox,\setcounter} +% +%\CheckSum{1426} +% +% +% \GetFileInfo{exercise.sty} +% +% \makeatletter +% \IndexPrologue{\section*{Index}% +% \markboth{Index}{Index}% +% For entries in type-writer font, numbers written in italic +% refer to the page where the corresponding entry is +% described; numbers underlined refer to the +% \ifcodeline@index code line of the \fi definition; +% numbers in roman refer to the \ifcodeline@index code +% lines \else pages \fi where the entry is used. } +% \makeatother +%\title{\texttt{exercise.sty} : a package to typeset exercises} +% +%\date{\today} +% +%\author{Paul Pichaureau\\ \texttt{paul.pichaureau@nerim.net}} +% +%\maketitle +% +%\begin{abstract} +% This package offers a simple environment to typeset exercises, +% and their questions, sub-questions, indications, answers and so +% on. +% +% The layout of the exercises is fully customisable. Moreover, the +% answers of the exercise could be typeset immediately or +% later in the document. +%\end{abstract} +% +%\changes{v1.0}{2004/08/17}{Initial version} +%\changes{v1.01}{2004/08/18}{Many typos corrected, improved index.} +% +%\section{Simple usage} +% +%This package defines two environments. The environment |Exercise| +%is used to typeset one exercise. For example, the following +%output:\medskip\index{example} +% +%\noindent \fbox{\begin{minipage}[t]{.95\textwidth} +%\begin{Exercise}[title={Duhamel's Rule}, label={ex:one}] +% \label{exe:ex1} +% Assume that the series $\sum x_n$ satisfies +% $$ +% \frac{x_{n+1}}{x_n} = 1 - \frac{b}{n}+\frac{\varepsilon(n)}{n} +% $$ +% where $b$ is a real number and the function $\varepsilon$ satisfies +% $$ +% \lim_{n\rightarrow + \infty} \varepsilon(n) = 0. +% $$ +% +% \Question Show that if $b < 1$, then the series $\sum x_n$ is +% divergent. +% +% \Question Show that if $b > 1$, then the series $\sum x_n$ is +% convergent. +% +% \Question What happens to $\sum x_n$ if $b=1$? +% +% \end{Exercise} +% +%\end{minipage}} +% +%\medskip \noindent is obtained by the following code (the text has been cut to underscore +%the structure of the code): +%\begin{verbatim} +%\begin{Exercise}[title={Duhamel's Rule}] +% Assume... +% \Question Show that if $b < 1$... +% \Question Show that if $b > 1$... +% \Question What happens to if $b=1$? +%\end{Exercise} +%\end{verbatim} +% +%Up to three level of question are available, and a part level (between +%exercise and question) is implemented: +%\begin{verbatim} +%\begin{Exercise}[title={Example}] +% Assume... +% \ExePart +% \Question +% \subQuestion Show that... +% \subQuestion In this question... +% \subsubQuestion Show that... +% \subsubQuestion Conclude... +% \subQuestion Conclude. +% \Question Show that if $b > 1$... +% \ExePart +% \Question What happens to if $b=1$? +%\end{Exercise} +%\end{verbatim} +% +% +%The commands to typeset question, sub-question and sub-sub-question +%are |Question|, |subQuestion|, and +%|subsubQuestion|. The exercise is split in parts with the +%command |ExePart|. +% +%The environment \texttt{Exercise} can be stared (no number is +%typeset). The options of these commands are described in section +%\ref{sec:option}. The layout of exercises can be customised in many +%way: see section \ref{sec:custom}. +% +%It is common to have a long list of exercise to typeset, and the usage +%of the |Exercise| environment could be cumbersome. Another +%environment is available: the |ExerciseList| environment. +% +%\medskip +% +%\noindent \fbox{\begin{minipage}[t]{.95\textwidth} +%\begin{ExerciseList} +% \Exercise[label={ex:two}] Discuss the convergence or divergence of $ +% \left[1 + \sin \left(\frac1{an}\right)\right]^{bn}$ +% where $a$ and $b$ are two parameters. +% +% \Exercise Discuss the convergence or divergence of $ +% n^{\frac{(-1)^n}{n}} - 1$. +% +% \Exercise* Discuss the convergence or divergence of $ +% \frac{(-1)^n}{n+(-1)^n}$. +% +% \Answer[ref={ex:two}] $ \displaystyle \lim_{n\rightarrow +% +\infty} \left[1 + \sin \left(\frac1{an}\right)\right]^{bn}= {\mathrm{e}}^{\frac{b}{a}}$ +% +%\end{ExerciseList} +%\end{minipage}} +% +%\medskip +% +%\begin{verbatim} +%\begin{ExerciseList} +% \Exercise[label={ex:two}] Discuss... +% \Exercise Discuss... +% \Exercise* Discuss... +% \Answer[ref={ex:two}] $...$ +%\end{ExerciseList} +%\end{verbatim} +% +%This example show two new commands: |\Exercise*| (for an exercise +%without number) and |\Answer|. These commands are explained in detail +%later in this document. +% +%Of course, the |\Question|, |\subQuestion|, and |\subsubQuestion| +%hierarchy is also available in |ExerciseList|: +% +%\begin{verbatim} +%\begin{ExerciseList} +% \Exercise Discuss... +% \Exercise Let $u$... +% \Question ... +% \subQuestion ... +% \Question +% \Exercise What... +%\end{ExerciseList} +%\end{verbatim} +% +%\section{Options of the package} +% +%\index{package>options}\index{options>of the package} +% +%Here we list the options of the package |exercise.sty|: +% +%\begin{description} +% \item[|noexercise|] hide all the exercises +% of a document. +% +% \item[|noanswer|] hide all the answers +% of a document. The default behaviour is to show both the exercises +% and the answers. +% +% +% \item[|exerciseonly|] is a synonym of |noanswer|. +% +% \item[|answeronly|] is a synonym of |noexercise|. +% +% \item[|nothing|] hide answers and exercises (synonym of +% |noanswer| and |noexercise|). +% +% \item[|answerdelayed|] save the answers instead of typeset +% them. The answers can be included later in the document with the +% command |\shipoutAnswer|. More precisely, the answers are stored +% in a vertical box. When |\shipoutAnswer| is encountered, this box +% is emptied and its contents is placed in the main vertical +% list. The answers defined later are placed in this emptied +% vertical box. In this way, you can have many group of answers in +% the same document. +% +% \item[|exercisedelayed|] saves the exercises instead of +% typeset them. The exercises can be included later with the command +% |\shipoutExercise|. +% +% \item [|lastexercise|] if no references is given for an +% answer, then the answer is supposed to refer to the last +% exercise (see section \ref{sec:lastexercise}). +% +%\end{description} +% +% +%\section{Commands} +% +%\label{sec:option} +% +%\subsection{Exercises and answers} +% +% +%\begin{decl} +% |\begin{Exercise}| \oarg{key val list} ... |\end{Exercise}| \\ +% |\begin{Exercise*}| \oarg{key val list} ... |\end{Exercise*}| +%\end{decl} +% +%\DescribeEnv{Exercise}\DescribeEnv{Exercise*} +%The |Exercise| environment is used to typeset just one exercise. We +%use the \textsf{keyval} package to give different informations about +%an exercise. +% +%\vspace*{-\baselineskip} +% +%\index{options>of \texttt{Exercise}} +%\index{keys>of \texttt{Exercise}} +%\begin{decl} +%|label|=\marg{string}\\ +%|title|=\marg{string}\\ +%|difficulty|=\marg{number}\\ +%|origin|=\marg{string}\\ +%|name|=\marg{string}\\ +%|counter|=\marg{counter}\\ +%|number|=\marg{string} +%\end{decl} +%All these keys define commands that will be available later to typeset +%the exercise. They are all optional. +%\begin{description} +% \item[|label|] The label of the exercise. This label can be +% used later in cross-reference, or to link an answer to this +% exercise. +% \item[|title|] The title of the exercise. It will be available +% later with the command |\ExerciseTitle|. +% \item[|difficulty|] The difficulty of the exercise (a number). +% It will be available later with the counter +% |\ExerciseDifficulty|. +% \item[|origin|] The origin of the exercise. +% It will be available later with the command |\ExerciseOrigin|. +% \item[|name|] In document, exercises can have multiple +% denomination, like problem, exam, or even question. This key +% allows to change the denomination. +% \item[|counter|] Use the given counter to number this +% exercise. Here, \marg{counter} must be a pre-defined counter. +% \item[|number|] Use the given number for the exercise. In +% fact, this number is a string, so you can number the exercise +% with letters. +%\end{description} +% +%As an example, with the default definitions, the following code: +%\medskip +%\begin{verbatim} +%\begin{Exercise}[title={Euler's constant}, difficulty=2, +% origin={P.Paelw}] +%\end{Exercise} +%\end{verbatim} +%\noindent will give \par \medskip +%\index{example} +%\noindent \fbox{\begin{minipage}[t]{.95\textwidth} +%\begin{Exercise}[title={Euler's constant}, difficulty=2, +% origin={P.Paelw}] +%\end{Exercise} +%\end{minipage}} +% +%\DescribeEnv{Problem} +%It is possible to define different type of exercise. For example, +%you can define a |Problem| environment with the two lines: +%\begin{verbatim} +% \newcounter{Problem} +% \newenvironment{Problem}{\begin{Exercise}[name={Problem}, +% counter={Problem}]} +% {\end{Exercise}} +%\end{verbatim} +%Anyway, all type of exercise will have the same layout in the document. +% +%\begin{decl} +% |\begin{Answer}| \oarg{key val list} ... |\end{Answer}| +%\end{decl} +% +%\DescribeEnv{Answer} +%The |Answer| environment is used to typeset the answer of an +%exercise. To determine which the exercise this answer is attributed +%to, you can use the two following keys. +% +%\vspace*{-\baselineskip} +%\index{options>of \texttt{Answer}} +%\index{keys>of \texttt{Answer}} +%\begin{decl} +%|ref|=\marg{string}\\ +%|number|=\marg{string} +%\end{decl} +%This is the description of these keys: +%\begin{description} +% \item[|ref|] a \LaTeX\ reference. \emph{Must} correspond to the |label| +% key of an exercise. +% \item[|number|] if the answer refers to an exercise in +% another document, you can set the number of the exercise with this +% key. It is in fact a string. +%\end{description} +% +%\label{sec:lastexercise} If the package is loaded with the option +% |lastexercise| and if no |ref| and no |number| key is given, then +% the last exercise is taken as a reference for the answer. +% +%If no |ref| and no |number| key is given and the option |lastexercise| +%is not activated, a Package Warning is displayed. +% +%\begin{decl} +% |\begin{ExerciseList}| \\ +% \quad |\Exercise|\oarg{key val list} \\ +% \quad |\Answer|\oarg{key val list} \\ +% |\end{Exercise}| +%\end{decl} +% +%\DescribeEnv{ExerciseList} +%The |ExerciseList| environment is a convenience to typeset a list of +%small exercises. In |ExerciseList|, everything between two |\Exercise| +%or |\Answer| tags is interpreted as the body of an exercise (or an +%answer). +% +%\DescribeMacro{\Exercise} +%\DescribeMacro{\Exercise*} +%\DescribeMacro{\Answer} +%The command |\Exercise| inside |ExerciseList| accepts the same keys +%than the |Exercise| environment. The command |\Answer| inside +%|ExerciseList| accepts the same keys than the |Answer| environment and +%behaves in the same way. +% +%\subsection{Parts and questions} +% +%\begin{decl} +% |\ExePart|\oarg{key val list} \\ +% |\ExePart*|\oarg{key val list} +%\end{decl} +%\DescribeMacro{\ExePart} +%\DescribeMacro{\ExePart*} +%It is common to split large exercise in parts: it is the purpose of +%the |\ExePart| command. +%\index{options>of \texttt{\bslash ExePart}} +%\index{keys>of \texttt{\bslash ExePart}} +%The keys |title|, |name| and |difficulty| are +%available for this command. +% +%For example, a non-numbered preliminary part is obtained with +%\begin{verbatim} +% \ExePart*[name={Preliminary}] +%\end{verbatim} +% +%\begin{decl} +% |\Question|\oarg{key val list}\\ +% |\subQuestion|\oarg{key val list}\\ +% |\subsubQuestion|\oarg{key val list} +%\end{decl} +%\DescribeMacro{\Question} +%\DescribeMacro{\subQuestion} +%\DescribeMacro{\subsubQuestion} +%These three commands define the hierarchy of questions. A +%|\subsubQuestion| cannot be preceded by a |\Question| or a +%|\begin{Exercise}|. A |\subQuestion| cannot be preceded by a +% |\begin{Exercise}|. If one of these cases is detected, a Package +% Error is displayed. +% +%\index{options>of \texttt{\bslash Question}} +%\index{keys>of \texttt{\bslash Question}} +%\index{options>of \texttt{\bslash subQuestion}} +%\index{keys>of \texttt{\bslash subQuestion}} +%\index{options>of \texttt{\bslash subsubQuestion}} +%\index{keys>of \texttt{\bslash subsubQuestion}} +%Two keys are available for these commands: |title| and |difficulty|. +% +%\begin{decl} +% |\ExeText| +%\end{decl} +%\DescribeMacro{\ExeText} +%The text following this command has the same status that the first +%indications of the exercise. So, the next level of the hierarchy must +%be a |\ExePart| or a |\Question|. +% +% +%\subsection{Extra stuff} +%\DescribeMacro{\marker} +%\DescribeMacro{\DifficultyMarker} +%The difficulty of an exercise is represented by a certain amount of +%stars. The command |\marker| is used to typeset the difficulty of an +%exercise. +%\begin{verbatim} +% \marker<symbol><counter> +%\end{verbatim} +%displays |<symbol>| repeated |<counter>| times. For example |\marker*2| +% gives **, and |\marker+{14}| gives ++++++++++++++ +% +% By default, the difficulty is symbolized by star. You can customise +% this by redefining the command |\DifficultyMarker|. +% +%\section{Customisation} +% +%\label{sec:custom} +% +%\subsection{Internationalisation} +% +%\begin{decl} +%|\ExerciseName|\\ +%|\ExerciseListName|\\ +%|\AnswerName|\\ +%|\AnswerListName|\\ +%|\ExePartName|% +%\end{decl} +%\DescribeMacro{\ExerciseName} +%\DescribeMacro{\ExerciseListName} +%\DescribeMacro{\AnswerName} +%\DescribeMacro{\AnswerListName} +%\DescribeMacro{\ExePartName} +%\DescribeMacro{\ExePartListName} +%These commands store various hard-wired string. |\ExerciseListName| +%is used in the |ExerciseList| environment: it is possibly an +%abbreviation of the word ``Exercise". +% +%\textsf{Exercise.sty} automatically detects the usage of +% \textsf{babel} and translate these terms in the language loaded... +% if I (the author) know the translation! As my skills in foreign +% language are quite weak, only English and French are currently +% supported. +% +%If you sent me the translations in your language, I will be happy to +%add them in the package. Anyway, you can redefine these +%commands (with a |\renewcommand|). +% +%\subsection{Layout} +% +%\subsubsection{Exercises, answers and parts} +% +%For the layout of the exercises, two levels of customisation are +%available. First, you can customise the way the informations will be +%typeset, and then you can customise the way these pieces of +%informations are typeset together. +% +%\begin{decl} +% |\ExerciseHeaderTitle| \\ +% |\ExerciseHeaderDifficulty| \\ +% |\ExerciseHeaderOrigin|\\ +% |\ExerciseHeaderNB| +%\end{decl} +%\DescribeMacro{\ExerciseHeaderTitle} +%\DescribeMacro{\ExerciseHeaderDifficulty} +%\DescribeMacro{\ExerciseHeaderOrigin} +%\DescribeMacro{\ExerciseHeaderNB} +%These commands are used to typeset the corresponding information: +%\\ |\ExerciseHeaderTitle| corresponds to the |title| key, \\ +%|\ExerciseHeaderDifficulty| to the |difficulty| key, +%|\ExerciseHeaderOrigin| to the |origin| key and |\ExerciseHeaderNB| to +%the number of the exercise. +% +%In these commands, you specify the fonts to use, the space around the +%information, some symbols (like dash or dot) you want to put here, and +%so on. If the key is not present in the definition of the exercise, +%then the corresponding part of the header will be emptied by the package. +% +%For example the default definition of |\ExerciseHeaderTitle| is +%\begin{verbatim} +% \newcommand{\ExerciseHeaderTitle}{\quad---\quad\ExerciseTitle} +%\end{verbatim} +%If an exercise has a title, then this title will be displayed preceded +%by an emdash (as you can see in exercise \ref{exe:ex1} of this +%document). If an exercise doesn't have a title, then this command is +%set to nothing (precisely to |{}|) during the exercise. +% +%These commands can be redefined with a |\renewcommand|. You don't have +%to worry about the ``undefinition" mechanism: the package manages that +%by itself. +% +%\begin{decl} +% |\ExerciseHeader| \\ +% |\ExerciseListHeader| +%\end{decl} +%\DescribeMacro{\ExerciseHeader} +%\DescribeMacro{\ExerciseListHeader} +%When the layout of all the elements has been fixed, they are collected +%in the |\ExerciseHeader| command (or in |\ExerciseListHeader|). +%Here, you specify the way the different elements are mixed +%together. +% +%The default definition of |\ExerciseHeader| is +%\begin{verbatim} +% \newcommand{\ExerciseHeader}{\centerline{\textbf{\large +% \ExerciseName\ExerciseHeaderNB\ExerciseHeaderTitle +% \ExerciseHeaderOrigin\medskip}}} +%\end{verbatim} +%\noindent which displays all the informations in a centered line, using +%a large bold default font. +% +%\begin{decl} +% |\AnswerHeader| \\ +% |\AnswerListHeader| +%\end{decl} +%\DescribeMacro{\AnswerHeader} +%\DescribeMacro{\AnswerListHeader} +%The same mechanism is implemented for the answers. +%|\AnswerHeader| and |\AnswerListHeader| specifies the way the header +%of answers are typeset. In the definition of these commands, you can +%use freely the informations of the related exercise. For example, this +%is the default definition of |\AnswerHeader|: +% +%\begin{verbatim} +% \newcommand{\AnswerHeader}{\medskip\centerline{\textbf{ +% Answer of \ExerciseName\ \ExerciseHeaderNB}\smallskip}} +%\end{verbatim} +% +% +%\begin{decl} +% |\ExePartHeaderTitle| \\ +% |\ExePartHeaderDifficulty| \\ +% |\ExePartHeaderNB|\\ +% |\ExePartHeader|\\ +% |\ExePartListHeader| +%\end{decl} +%\DescribeMacro{\ExePartHeaderTitle} +%\DescribeMacro{\ExePartHeaderDifficulty} +%\DescribeMacro{\ExePartHeaderNB} +%\DescribeMacro{\ExePartHeader} +%\DescribeMacro{\ExePartListHeader} +%The same kind of customisation is available for the |\ExePart| +%command: |\ExePartHeaderTitle|, |\ExePartHeaderDifficulty| and +%|\ExePartHeaderNB| \\ control the way the title (|\ExePartTitle|), the +%difficulty (|\ExePartdifficulty|) and the number (|\theExePart|) of +%the part are displayed. +% +%These pieces are collected in the command |\ExePartHeader| or +%\\ |\ExePartListHeader|. +% +% +% +%\subsubsection{Questions, sub-questions and sub-sub-questions} +% +%The layout of the questions is a little more rigid. Somehow, it can be +%customised. +% +%\begin{decl} +% |\QuestionHeaderTitle| \\ +% |\QuestionHeaderDifficulty| \\ +% |\QuestionHeaderNB| +%\end{decl} +% +%\DescribeMacro{\QuestionHeaderTitle} +%\DescribeMacro{\QuestionHeaderDifficulty} +%\DescribeMacro{\QuestionHeaderNB} +%\DescribeMacro{\subQuestionHeaderTitle} +%\DescribeMacro{\subQuestionHeaderDifficulty} +%\DescribeMacro{\subQuestionHeaderNB} +%\DescribeMacro{\subsubQuestionHeaderTitle} +%\DescribeMacro{\subsubQuestionHeaderDifficulty} +%\DescribeMacro{\subsubQuestionHeaderNB} +%These commands plays the same role that the corresponding command +%relating to exercises. But here, no |\QuestionHeader| is defined. +% +%The |subQuestion| and |subsubQuestion| versions of these commands are +%also defined. +% +%All of these commands can be changed using |\renewcommand|. +% +% +%\subsection{Lengths} +% +%\begin{decl} +% \begin{tabular}{llll} +% |\Exesep| & |\Exetopsep| & |\Exeparsep| & +% |\Exepartopsep| \\ +% |\Exeleftmargin| & |\Exerightmargin| & |\Exelabelwidth| +% & |\Exelabelsep| +%\end{tabular} +%\end{decl} +%\DescribeMacro{Exesep} +%\DescribeMacro{Exetopsep} +%\DescribeMacro{Exeparsep} +%\DescribeMacro{Exepartopsep} +%\DescribeMacro{Exeleftmargin} +%\DescribeMacro{Exerightmargin} +%\DescribeMacro{Exelabelsep} +%The |ExerciseList| environment is nothing more than a |list| +%environment. All the parameters of \LaTeX's lists are +%available. Please consult your favourite source of information to have +%the exact definitions of these lengths. +% +%\begin{decl} +% \begin{tabular}{ll} +% |\QuestionBefore| & |\QuestionIndent| \\ +% |\subQuestionBefore| & |\subQuestionIndent| \\ +% |\subsubQuestionBefore| & |\subsubQuestionIndent| \\ +% \end{tabular} +%\end{decl} +%\DescribeMacro{QuestionBefore} +%\DescribeMacro{QuestionIndent} +%\DescribeMacro{subQuestionBefore} +%\DescribeMacro{subQuestionIndent} +%\DescribeMacro{subsubQuestionBefore} +%\DescribeMacro{subsubQuestionIndent} +%Here, |\QuestionBefore| is the vertical space above |\Question|, and\\ +%|\QuestionIndent| it the horizontal distance added to the margin in +%question. Same thing for |\subQuestion| and |\subsubQuestion|. +% +% \subsection{The \texttt{\textbackslash renewcounter} command} +% +%\changes{v1.1}{2004/09/05}{Added the 'renewcounter' command.} +% +% In a document, you will probably want to customise the way the +% |Exercise| counter will reseted. Strangely, it is impossible to +% redefined counter with \LaTeX. There is no equivalent of the +% |\renewcommand| command for the counters. +% +% We provide such an equivalent with the command |\renewcounter|. +%\DescribeMacro{\renewcounter} +% +%\begin{decl} +% |\newcounter|\marg{foo}\oarg{counter} +%\end{decl} +% The |\renewcounter| command defines a new counter named |foo|. The +% counter is initialized to zero. +% +% The optional argument \oarg{counter} causes the counter |foo| to be +% reset whenever the counter named in the optional argument is +% incremented. +% +% If the counter |foo| was not previously defined, an \LaTeX\ error +% occurs. +% +%\section{Known problems} +% +%The commands |\Question|, |\subQuestion|, etc. are heavily based +%on |list| environment. These lists are hidden (I know it's bad!) to +%simplify the syntax of the source file (I think it's nice!). +% +%In fact, every |\Question| is like the beginning of an environment, +%which is closed at the next |\Question| (the exact mechanism is a +%little bit more complicated). +% +%Consequently it's dangerous to put questions inside environment. +%The following code will lead to an error: +%\vspace*{-.5\baselineskip} +%\begin{verbatim} +% \begin{Exercise} +% \begin{multicols}{2} +% \Question ... +% \Question ... +% \end{multicols} +% \end{Exercise} +%\end{verbatim} +%Of course, you can put entire exercise inside other environment (like +%|minipage|). The following code will work: +%\vspace*{-.5\baselineskip} +%\begin{verbatim} +% \begin{multicols}{2} +% \begin{Exercise} +% \Question ... +% \Question ... +% \end{Exercise} +% \end{multicols} +%\end{verbatim} +% +%\begin{decl} +% |\EndCurrentQuestion| \\ +% |\EndCurrentsubQuestion| \\ +% |\EndCurrentsubsubQuestion| +%\end{decl} +%\DescribeMacro{\EndCurrentQuestion} +%\DescribeMacro{\EndCurrentsubQuestion} +%\DescribeMacro{\EndCurrentsubsubQuestion} +%If you really need to put some questions inside environment, you must +%use the command |\EndCurrentQuestion| just before ending the +%environment. This command ends the question's ``environment". So, +%this code will work: +%\vspace*{-.5\baselineskip} +%\begin{verbatim} +% \begin{Exercise} +% \begin{multicols}{2} +% \Question ... +% \Question ... +% \EndCurrentQuestion +% \end{multicols} +% \end{Exercise} +%\end{verbatim} +% +% +% +% +% +%In |ExerciseList| environment, the command |\Exercise| shouldn't be +%followed by an empty line. +% +% \PrintChanges +% +%\makeatletter\c@IndexColumns = 2\makeatother +% \StopEventually{\PrintIndex\newpage\tableofcontents } +% +% \section{Implementation} +% +% \subsection{Package options} +% This part deals with the package options. Nothing more than an +% affair of boolean. +% \begin{macrocode} +\newif\if@AnswerOutput \@AnswerOutputtrue +\newif\if@AnswerDelay \@AnswerDelayfalse +\newif\if@ExerciseOutput \@ExerciseOutputtrue +\newif\if@ExerciseDelay \@ExerciseDelayfalse +\newif\if@AswLastExe \@AswLastExefalse + +\DeclareOption{noanswer} {\@AnswerOutputfalse} +\DeclareOption{answeronly} {\@ExerciseOutputfalse} +\DeclareOption{noexercise} {\@ExerciseOutputfalse} +\DeclareOption{exerciseonly} {\@AnswerOutputfalse} +\DeclareOption{outputnothing}{\@ExerciseOutputfalse\@AnswerOutputfalse} +\DeclareOption{exercisedelayed}{\@ExerciseDelaytrue} +\DeclareOption{answerdelayed}{\@AnswerDelaytrue} +\DeclareOption{lastexercise} {\@AswLastExetrue} +% \end{macrocode} +% The following option, which displays the exercise label in margin, is +% not implemented yet. +% \begin{macrocode} +\newif\if@ShowLabel \@ShowLabelfalse +\DeclareOption{showlabel} {\@ShowLabeltrue} + +\ProcessOptions +% \end{macrocode} +% The only required package are \textsf{keyval} and \textsf{ifthen}. +% \begin{macrocode} +\RequirePackage{keyval, ifthen} +% \end{macrocode} +% +%\subsection{Customisation} +% +%\subsubsection{Internationalisation} +% \begin{macrocode} +\def\ExerciseName{Exercise}% +\def\AnswerName{Answer}% +\def\ExerciseListName{Ex.}% +\def\AnswerListName{Answer}% +\def\ExePartName{Part}% +\@ifpackageloaded{babel}{ +\addto{\captionsfrenchb}{ + \def\ExerciseName{Exercise}% + \def\AnswerName{Solution}% + \def\ExerciseListName{Ex.}% + \def\AnswerListName{Sol.}% + \def\ExePartName{Partie}% +}} +% \end{macrocode} +%\subsubsection{Layout} +% First a bunch of length definitions. +% \begin{macrocode} +\newlength{\Exesep} +\setlength{\Exesep}{1\baselineskip} +\newlength{\Exetopsep} +\setlength{\Exetopsep}\z@ +\newlength{\Exeparsep} +\setlength{\Exeparsep}\z@ +\newlength{\Exepartopsep} +\setlength{\Exepartopsep}\z@ +\newlength{\Exeleftmargin} +\setlength{\Exeleftmargin}\z@ +\newlength{\Exerightmargin} +\setlength{\Exerightmargin}\z@ +\newlength{\Exelabelwidth} +\setlength{\Exelabelwidth}\z@ +\newlength{\Exelabelsep} +\setlength{\Exelabelsep}\z@ +\newlength{\ExerciseBefore} +\setlength{\ExerciseBefore}{0em} +\newlength{\QuestionBefore} +\setlength{\QuestionBefore}{.25em} +\newlength{\subQuestionBefore} +\setlength{\subQuestionBefore}{0em} +\newlength{\subsubQuestionBefore} +\setlength{\subsubQuestionBefore}{0em} +\newlength{\QuestionIndent} +\setlength{\QuestionIndent}{3em} +\newlength{\subQuestionIndent} +\setlength{\subQuestionIndent}{2em} +\newlength{\subsubQuestionIndent} +\setlength{\subsubQuestionIndent}{1.5em} +% \end{macrocode} +% Now the counters +% \begin{macrocode} +\newcounter{Exercise} +\gdef\@ExerciseCounter{Exercise} %default exercise counter +\newcounter{ExePart}[Exercise] +\newcounter{Question}[Exercise] +\newcounter{subQuestion}[Question] +\newcounter{subsubQuestion}[subQuestion] +% \end{macrocode} +% Presentation of these labels in cross references +% \begin{macrocode} +\renewcommand{\theExercise}{\arabic{\@ExerciseCounter}} +\renewcommand{\theExePart}{\Roman{ExePart}} +\renewcommand{\theQuestion}{\arabic{Question}} +\renewcommand{\thesubQuestion}{\alph{subQuestion}} +\renewcommand{\thesubsubQuestion}{\arabic{subsubQuestion}} +% \end{macrocode} +% For internal purposes +% \begin{macrocode} +\newcounter{savedQuestion} +\newcounter{savedsubQuestion} +\newcounter{savedsubsubQuestion} +% \end{macrocode} +% The |\marker| command. +% \begin{macrocode} + \def\marker#1#2{\@tempcnta#2\whiledo{\@tempcnta>0}{#1\advance + \@tempcnta by -1 }} +% \end{macrocode} +% Symbol used to indicate the difficulty of an exercise or a question +% \begin{macrocode} +\def\DifficultyMarker{*} +% \end{macrocode} +% Presentation of informations in the header of exercises +% \begin{macrocode} +\newcommand{\ExerciseHeaderTitle}{\quad --- \quad \ExerciseTitle} +\newcommand{\ExerciseHeaderDifficulty}{\theExerciseDifficulty\ } +\newcommand{\ExerciseHeaderOrigin}{% +\ ({\usefont{\encodingdefault}{\rmdefault}{m}{it}\ExerciseOrigin})} +\newcommand{\ExerciseHeaderNB}{\ \theExercise} +\newcommand{\ExerciseHeaderLabel}{\fbox{\textsc{\ExerciseLabel}}} +% \end{macrocode} +% The header itself +% \begin{macrocode} +\newcommand{\ExerciseHeader}{\centerline{% +\textbf{\large\ExerciseHeaderDifficulty\ExerciseName% +\ExerciseHeaderNB\ExerciseHeaderTitle\ExerciseHeaderOrigin}}\medskip} +% \end{macrocode} +% The header of exercise in ExerciseList environment +% \begin{macrocode} +\newcommand{\ExerciseListHeader}{\ExerciseHeaderDifficulty% +\textbf{\ExerciseListName\ExerciseHeaderNB% +\ --- \ \ExerciseHeaderTitle}% +\ExerciseHeaderOrigin\ignorespaces} +% \end{macrocode} +% Presentation of informations in the header of ExePart +% \begin{macrocode} +\newcommand{\ExePartHeaderNB}{\ \theExePart} +\newcommand{\ExePartHeaderTitle}{\quad --- \quad {\ExePartTitle}} +\newcommand{\ExePartHeaderDifficulty}{\theExePartDifficulty\ } +% \end{macrocode} +% The header of |ExePart| +% \begin{macrocode} +\newcommand{\ExePartHeader}{% +\medskip\centerline{\emph{\large\ExePartHeaderDifficulty\ExePartName% +\ExePartHeaderNB\ExePartHeaderTitle}}} +% \end{macrocode} +% Presentation of Questions +% \begin{macrocode} +\newcommand{\QuestionNB}{\arabic{Question}.\ } +\newcommand{\QuestionHeaderTitle}{\emph{(\QuestionTitle)}\ } +\newcommand{\QuestionHeaderDifficulty}{\theQuestionDifficulty\ } +\newcommand{\theQuestionDifficulty}{\marker{\DifficultyMarker}% +{\QuestionDifficulty}} +\newcommand{\subQuestionNB}{\alph{subQuestion})} +\newcommand{\subQuestionHeaderTitle}{\emph{(\subQuestionTitle)}\ } +\newcommand{\subQuestionHeaderDifficulty}{\thesubQuestionDifficulty\ } +\newcommand{\subQuestionHeader}{\subQuestionHeaderDifficulty% + \subQuestionNB)\ \emph{\subQuestionHeaderTitle}} +\newcommand{\thesubQuestionDifficulty}{\marker{\DifficultyMarker}% +{\subQuestionDifficulty}} +\newcommand{\subsubQuestionNB}{\arabic{subsubQuestion} -- } +\newcommand{\subsubQuestionHeaderTitle}{\emph{(\subsubQuestionTitle)}\ } +\newcommand{\subsubQuestionHeaderDifficulty}{\thesubsubQuestionDifficulty\ } +\newcommand{\subsubQuestionHeader}{\subsubQuestionHeaderDifficulty% + \subsubQuestionNB \emph{\subsubQuestionHeaderTitle} --} +\newcommand{\thesubsubQuestionDifficulty}{% +\marker{\DifficultyMarker}{\subsubQuestionDifficulty}} +% \end{macrocode} +% \subsection{Macros definition} +% \begin{macrocode} +\newcount\@QuestionLevel \@QuestionLevel=0 +\newcommand{\the@QuestionLevel}{\number\@QuestionLevel} +\newbox\@Exercisebox +\newbox\all@Exercisebox +\newbox\temp@Exercisebox +\newbox\all@Answerbox +\newbox\temp@Answerbox +\newif\if@echapq \@echapqfalse +\newif\if@Answer \@Answerfalse +\def\termineliste#1{\global\@echapqfalse% +\whiledo{\@QuestionLevel>#1}% +{\ifnum\@QuestionLevel=\colonnesLevel\end{multicols}\colonnesLevel=-10\fi% +\end{list}\advance\@QuestionLevel by -1}% +\ifnum\@QuestionLevel=\colonnesLevel\end{multicols}\colonnesLevel=-10\fi} +% \end{macrocode} +% +% \subsubsection{Definition of \texttt{Exercise}} +% +% The keyval package is used to specify various information about an exercise. +% \begin{macrocode} +\newif\if@ExeTitle \@ExeTitlefalse +\newif\if@ExeReName \@ExeReNamefalse +\global\newcount\ExerciseDifficulty \ExerciseDifficulty=0 +\newif\if@ExeDifficulty \@ExeDifficultyfalse +\newif\if@ExeOrigin \@ExeOriginfalse +\newif\if@ExeLabel \@ExeLabelfalse +\newif\if@ExeNB \@ExeNBfalse +% +\def\theExerciseDifficulty{\marker{\DifficultyMarker}{\ExerciseDifficulty}} +% +\define@key{PPExercise}{title}% +{\global\@ExeTitletrue\gdef\ExerciseTitle{\string#1}} +\define@key{PPExercise}{difficulty}% +{\global\@ExeDifficultytrue\global\ExerciseDifficulty=\number#1} +\define@key{PPExercise}{name}% +{\global\@ExeReNametrue\gdef\@ExerciseName{\string#1}} +\define@key{PPExercise}{origin}% +{\global\@ExeOrigintrue\gdef\ExerciseOrigin{#1}} +\define@key{PPExercise}{counter}% +{\gdef\@ExerciseCounter{\string#1}} +\define@key{PPExercise}{label}% +{\global\@ExeLabeltrue\gdef\ExerciseLabel{\string#1}} +\define@key{PPExercise}{number}% +{\global\@ExeNBtrue\gdef\ExerciseLocalNB{\string#1}} +% +%% \define@key{PPExercise}{domain}{} +%% \define@key{PPExercise}{sdomain}{} +%% \define@key{PPExercise}{keyword}{} +% +\newif\if@ExeStared +\newif\if@staredpb +\newif\if@staredpart +\newif\if@renamepart +% +\@ExeStaredfalse +\@staredpbfalse +\@staredpartfalse +\@renamepartfalse +% +\def\@InitExe{\@savemathindent\global\@echapqfalse% +\gdef\ExerciseTitle{}% +\gdef\@ExerciseName{}% +\gdef\ExerciseOrigin{}% +\gdef\labelexe{}% +\global\ExerciseDifficulty=0% +\global\@ExeTitlefalse% +\global\@ExeReNamefalse% +\global\@ExeDifficultyfalse% +\global\@ExeOriginfalse% +\global\@ExeNBfalse% +\gdef\@ExerciseCounter{Exercise}% +\setcounter{Question}{0}% +\global\@ExeLabelfalse} +% +\def\@getExerciseInfo{% +\if@ExeReName\def\ExerciseName{\@ExerciseName}\fi% +\if@ExeTitle\else\def\ExerciseHeaderTitle{}\fi% +\if@ExeOrigin\else\def\ExerciseHeaderOrigin{}\fi% +\if@ExeLabel\else\def\ExerciseHeaderLabel{}\fi% +\if@ExeDifficulty\else\def\ExerciseHeaderDifficulty{}\fi% +\if@ExeStared\def\ExerciseHeaderNB{}\fi% +\if@ExeNB\def\theExercise{\ExerciseLocalNB}\fi% +\if@ExeLabel\label{\ExerciseLabel}\recordExerciseLabel{\ExerciseLabel}\fi% +} +% +\def\refstepExecounter{\if@ExeStared\else\if@ExeNB\else% +\refstepcounter{\@ExerciseCounter}\fi\fi} +% +\def\recordExerciseLabel#1{\@bsphack + \protected@write\@auxout{}% + {\string\newlabel{PP#1}{{\@AnswerHeaderRef}{\thepage}}}% + \@esphack} +% +\def\@BeginExeBox{\global\setbox\@Exercisebox\vbox\bgroup} +\def\@EndExeBox{\egroup\if@Answer\if@AnswerOutput\@DelayAnswerBox\fi% +\else\if@ExerciseOutput\@DelayExerciseBox\fi\fi} +% +\def\@DelayAnswerBox{% +\if@AnswerDelay\global\setbox\temp@Answerbox% +\vbox{\unvbox\all@Answerbox\vskip12pt\unvbox\@Exercisebox\vskip\z@}% +\global\setbox\all@Answerbox\copy\temp@Answerbox% +\else\unvbox\@Exercisebox\fi} +% +\def\@DelayExerciseBox{\if@ExerciseDelay% +\global\setbox\temp@Exercisebox% +\vbox{\unvbox\all@Exercisebox\vskip12pt\unvbox\@Exercisebox\vskip\z@}% +\global\setbox\all@Exercisebox\copy\temp@Exercisebox% +\else\unvbox\@Exercisebox\fi} +% +\newcommand{\shipoutAnswer}{\if@AnswerOutput\unvbox\all@Answerbox\fi} +\newcommand{\shipoutExercise}{\if@ExerciseOutput\unvbox\all@Exercisebox\fi} +% \end{macrocode} +% The commands for the \texttt{Exercise} environment. +% \begin{macrocode} +\def\beginExerciseEnv{\@InitExe\@ifnextchar[\@@ExeEnv{\@@ExeEnv[]}}%] +% +\def\@@ExeEnv[#1]{\setkeys{PPExercise}{#1}% +\global\@Answerfalse\@BeginExeBox\@@@ExeEnv} +% +\newcommand{\@@@ExeEnv}{% + \@QuestionLevel1 + \refstepExecounter + \begingroup\@getExerciseInfo\ExerciseHeader\endgroup} +% +% +\def\endExerciseEnv{\termineliste{1}\@EndExeBox} +% \end{macrocode} +% The commands for exercise within <ExerciseList> environment +% \begin{macrocode} +\def\ExerciseCmd{\@InitExe\@ifstar{\global\@ExeStaredtrue\@ExeCmd}% +{\global\@ExeStaredfalse\@ExeCmd}} +% +\def\@ExeCmd{\@ifnextchar[\@@ExeCmd{\@@ExeCmd[]}}%] for emacs +% +\def\@@ExeCmd[#1]{\setkeys{PPExercise}{#1}\@@@ExeCmd} +% +\newcommand{\@@@ExeCmd}{% + \ifnum\@QuestionLevel=0 + \advance \@QuestionLevel by 1 + \begin{list}{\@getExerciseInfo\ExerciseListHeader}% +{\partopsep\Exepartopsep \labelsep\Exelabelsep \itemsep \Exesep% +\parsep\Exeparsep \topsep\Exetopsep \labelwidth\Exelabelwidth% +\leftmargin\Exeleftmargin \rightmargin\Exerightmargin} + \else + \termineliste{1}\@EndExeBox + \fi + \global\@Answerfalse\@BeginExeBox\refstepExecounter% + \item\ignorespaces +} +% +\def\defineExerciseEnv{% + \renewenvironment{Exercise}{\global\@ExeStaredfalse\beginExerciseEnv}% +{\endExerciseEnv} + \renewenvironment{Exercise*}{\global\@ExeStaredtrue\beginExerciseEnv}% +{\endExerciseEnv} +} +\newenvironment{Exercise}{}{} +\newenvironment{Exercise*}{}{} +% +\def\defineExerciseCmd{\def\Exercise{\ExerciseCmd}} +% +\renewcommand{\Exercise}{} +% +\defineExerciseEnv +% +\def\beginExerciseListEnv{\defineExerciseCmd\defineAnswerCmd} +% +\def\endExerciseListEnv{\termineliste{1}\@EndExeBox\termineliste{0}% +\defineExerciseEnv\defineAnswerEnv} +% +\newenvironment{ExerciseList}{\beginExerciseListEnv}{\endExerciseListEnv} +% \end{macrocode} +% \subsubsection{Definition of \texttt{questions}} +% \begin{macrocode} +\def\QuestionTitle{} +\newif\if@QuestionTitle \@QuestionTitlefalse +\global\newcount\QuestionDifficulty \QuestionDifficulty=0 +\newif\if@QuestionDifficulty \@QuestionDifficultyfalse +% +\define@key{PPQuestion}{title}{% +\gdef\QuestionTitle{\string#1}\@QuestionTitletrue} +\define@key{PPQuestion}{difficulty}{% +\@QuestionDifficultytrue\global\QuestionDifficulty=\number#1} +% +\def\@InitQuestion{\gdef\QuestionTitle{}% +\global\QuestionDifficulty=0% +\global\@QuestionTitlefalse% +\global\@QuestionDifficultyfalse} +% +\def\@getQuestionInfo{% +\if@QuestionTitle\else\def\QuestionHeaderTitle{}\fi +\if@QuestionDifficulty\else\def\QuestionHeaderDifficulty{}\fi +} +% +\def\EndCurrentQuestion{\termineliste{1}} +% +\def\Question{\@InitQuestion\@ifnextchar[\@@Question{\@@Question[]}}%] +% +\def\@@Question[#1]{\setkeys{PPQuestion}{#1}\@@@Question} +% +\def\@QuestionHeader{\item[{\makebox[0cm][r]{\begingroup\@getQuestionInfo% +\QuestionHeaderDifficulty\QuestionNB\endgroup}}]% +\begingroup\@getQuestionInfo\QuestionHeaderTitle\endgroup\ignorespaces} +\newcommand{\@@@Question}{% + \ifnum\@QuestionLevel=1 + \advance \@QuestionLevel by 1 + \begin{list}{}{\leftmargin \QuestionIndent + \partopsep0pt \parsep0pt \topsep \QuestionBefore + \itemsep \QuestionBefore \labelwidth 2em + \usecounter{Question}} + \if@echapq + \setcounter{Question}{\value{savedQuestion}}\global\@echapqfalse + \fi + \refstepcounter{Question} + \@restoremathindent + \@decalemathindent{\QuestionIndent} + \@QuestionHeader + \else + \ifnum\@QuestionLevel=2 + \refstepcounter{Question} + \@QuestionHeader + \else + \ifnum\@QuestionLevel>2 + \termineliste{2} + \refstepcounter{Question} + \@QuestionHeader + \else + \PackageError{exercise}{You don't respect the hierarchy of + questions}{Verify the Question} + \fi + \fi + \fi +} +% \end{macrocode} +% \subsubsection{Definition of \texttt{sub-questions} and +%\texttt{sub-sub-questions}} +% Here a good factorization is possible, but I prefer readibility over +% efficacity. +% \begin{macrocode} +\def\subQuestionTitle{} +\newif\if@subQuestionTitle\@subQuestionTitlefalse +\global\newcount\subQuestionDifficulty\subQuestionDifficulty=0 +\newif\if@subQuestionDifficulty\@subQuestionDifficultyfalse +% +\define@key{PPsubQuestion}{title}{% +\gdef\subQuestionTitle{\string#1}\@subQuestionTitletrue} +\define@key{PPsubQuestion}{difficulty}{% +\@subQuestionDifficultytrue\global\subQuestionDifficulty=\number#1} +% +\def\@InitsubQuestion{\gdef\subQuestionTitle{}% +\global\subQuestionDifficulty=0% +\global\@subQuestionTitlefalse% +\global\@subQuestionDifficultyfalse} +% +\def\@getsubQuestionInfo{% +\if@subQuestionTitle\else\def\subQuestionHeaderTitle{}\fi +\if@subQuestionDifficulty\else\def\subQuestionHeaderDifficulty{}\fi +} +% +\def\EndCurrentsubQuestion{\termineliste{2}} +% +\def\subQuestion{\@InitsubQuestion% +\@ifnextchar[\@@subQuestion{\@@subQuestion[]}}%] +\def\@@subQuestion[#1]{\setkeys{PPsubQuestion}{#1}\@@@subQuestion} +% +\def\@subQuestionHeader{\item[{\makebox[0cm][r]% +{\begingroup\@getsubQuestionInfo\subQuestionHeaderDifficulty% +\subQuestionNB\endgroup}}]% +\begingroup\@getsubQuestionInfo\subQuestionHeaderTitle\endgroup% +\ignorespaces} +\newcommand{\@@@subQuestion}{% + \ifnum\@QuestionLevel=2 + \advance \@QuestionLevel by 1 + \begin{list}{}{\leftmargin \subQuestionIndent + \partopsep0pt \parsep0pt \topsep \subQuestionBefore + \itemsep \subQuestionBefore \labelwidth 2em + \usecounter{subQuestion}} + \if@echapq + \setcounter{subQuestion}{\value{savedsubQuestion}}% + \global\@echapqfalse + \fi + \refstepcounter{subQuestion} + \@restoremathindent + \@decalemathindent{\subQuestionIndent} + \@subQuestionHeader + \else + \ifnum\@QuestionLevel=3 + \refstepcounter{subQuestion} + \@subQuestionHeader + \else + \ifnum\@QuestionLevel>3 + \termineliste{3} + \refstepcounter{subQuestion} + \@subQuestionHeader + \else + \PackageError{exercise}{You don't respect the hierarchy of + subQuestion}{Verify the subQuestion} + \fi + \fi + \fi +} +% +\def\subsubQuestionTitle{} +\newif\if@subsubQuestionTitle\@subsubQuestionTitlefalse +\global\newcount\subsubQuestionDifficulty\subsubQuestionDifficulty=0 +\newif\if@subsubQuestionDifficulty\@subsubQuestionDifficultyfalse +% +\define@key{PPsubsubQuestion}{title}{% +\gdef\subsubQuestionTitle{\string#1}\@QuestionTitletrue} +\define@key{PPsubsubQuestion}{difficulty}{% +\@QuestionDifficultytrue\global\subsubQuestionDifficulty=\number#1} +% +\def\@InitsubsubQuestion{\gdef\subsubQuestionTitle{}% +\global\subsubQuestionDifficulty=0% +\global\@subsubQuestionTitlefalse% +\global\@subsubQuestionDifficultyfalse} +% +\def\@getsubsubQuestionInfo{% +\if@subsubQuestionTitle\else\def\subsubQuestionHeaderTitle{}\fi +\if@subsubQuestionDifficulty\else\def\subsubQuestionHeaderDifficulty{}\fi +} +% +\def\EndCurrentsubsubQuestion{\termineliste{3}} +\def\subsubQuestion{\@InitsubsubQuestion% +\@ifnextchar[\@@subsubQuestion{\@@subsubQuestion[]}}%] +\def\@@subsubQuestion[#1]{\setkeys{PPsubsubQuestion}{#1}\@@@subsubQuestion} +% +\def\@subsubQuestionHeader{\item[{\makebox[0cm][r]% +{\begingroup\@getsubsubQuestionInfo\subsubQuestionHeaderDifficulty% +\subsubQuestionNB\endgroup}}]% +\begingroup\@getsubsubQuestionInfo\subsubQuestionHeaderTitle\endgroup% +\ignorespaces} +\newcommand{\@@@subsubQuestion}{% + \ifnum\@QuestionLevel=3 + \advance \@QuestionLevel by 1 + \begin{list}{}{\leftmargin \subsubQuestionIndent + \partopsep0pt \parsep0pt \topsep \subsubQuestionBefore + \itemsep \subsubQuestionBefore \labelwidth 2em + \usecounter{subsubQuestion}} + \if@echapq + \setcounter{subsubQuestion}{\value{savedsubsubQuestion}}% + \global\@echapqfalse + \fi + \refstepcounter{subsubQuestion} + \@restoremathindent + \@decalemathindent{\subsubQuestionIndent} + \@subsubQuestionHeader + \else + \ifnum\@QuestionLevel=4 + \refstepcounter{subsubQuestion} + \@subsubQuestionHeader + \else + \ifnum\@QuestionLevel>4 + \termineliste{4} + \refstepcounter{subsubQuestion} + \@subsubQuestionHeader + \else + \PackageError{exercise}{You don't respect the hierarchy of + subsubQuestion}{Verify the subsubQuestion} + \fi + \fi + \fi +} +% \end{macrocode} +% \subsubsection{ Presentation of part (within an exercise)} +% \begin{macrocode} +\newif\if@ExePartStared \@ExePartStaredfalse +\newif\if@ExePartTitle \@ExePartTitlefalse +\newif\if@ExePartReName \@ExePartReNamefalse +\newif\if@ExePartDifficulty \@ExePartDifficultyfalse +\global\newcount\ExePartDifficulty \ExePartDifficulty=0 +% +\def\theExePartDifficulty{\marker{\DifficultyMarker}{\ExePartDifficulty}} +% +\def\@InitExePart{\global\@echapqfalse% +\gdef\ExePartTitle{}% +\gdef\@ExePartName{}% +\global\ExePartDifficulty=0% +\global\@ExePartTitlefalse% +\global\@ExePartReNamefalse% +\global\@ExePartDifficultyfalse% +\setcounter{Question}{0}} +% +\define@key{PPExePart}{title}{\gdef\ExePartTitle{\string#1}\@ExePartTitletrue} +\define@key{PPExePart}{name}{\gdef\@ExePartName{\string#1}\@ExePartReNametrue} +\define@key{PPExePart}{difficulty}{\@ExePartDifficultytrue% +\global\ExePartDifficulty=\number#1} +% +\def\@getExePartInfo{% +\if@ExePartReName\def\ExePartName{\@ExePartName}\fi +\if@ExePartTitle\else\def\ExePartHeaderTitle{}\fi +\if@ExePartDifficulty\else\def\ExePartHeaderDifficulty{}\fi +\if@ExePartStared\def\ExePartHeaderNB{}\fi +} +% +\def\ExePart{\@InitExePart\@ifstar{\global\@ExePartStaredtrue\@ExePart}% +{\global\@ExePartStaredfalse\@ExePart}} +% +\def\@ExePart{\@ifnextchar[\@@ExePart{\@@ExePart[]}}%] for emacs +% +\def\@@ExePart[#1]{\setkeys{PPExePart}{#1}\@@@ExePart} +% +\newcommand{\@@@ExePart}{% + \if@ExePartStared\else\refstepcounter{ExePart}\fi + \begingroup\@getExePartInfo\ExePartHeader\endgroup} +% +% \end{macrocode} +% \subsubsection{ Presentation of answers} +% \begin{macrocode} +\newbox\@Answerbox +% +%% \newcommand{\AnswerHeaderRef}{Answer of \ExerciseName\ \theExercise} +%% \newcommand{\AnswerListHeaderRef}{Answer (ex.\ \theExercise)\ ---\ } +% +\newcommand{\AnswerHeader}{\medskip\centerline{\textbf{Answer of + \ExerciseName \ExerciseHeaderNB}\smallskip}} +% +\newcommand{\AnswerListHeader}{\textbf{Answer (ex.\ + \ExerciseHeaderNB)\ ---\ }} +% +% The commands for <Exercise> environment +% +\def\@InitAnswer{\@savemathindent\global\@echapqfalse% +\gdef\AnswerRef{}% +\global\@AnswerReffalse% +\gdef\AnswerNB{}% +\global\@AnswerNBfalse% +\setcounter{Question}{0}} +% +\def\@getAnswerInfo{% +\if@AnswerRef% +\def\AnswerHeader{\ref{PP\AnswerRef}}% +\def\AnswerListHeader{\ref{PP\AnswerRef}}% +\else +\if@AnswerNB +\def\ExerciseTitle{} +\def\ExerciseName{} +\def\ExerciseOrigin{} +\ExerciseDifficulty=0 +\def\theExercise{\AnswerNB} +\else +\if@AswLastExe +\else +\PackageWarning{Exercise}% +{A answer has no reference and no number}{}% +\def\AnswerHeaderRef{\AnswerName\ ???}% +\def\AnswerListHeaderRef{\AnswerName\ ???}% +\fi\fi\fi} +% +\newif\if@AnswerRef \@AnswerReffalse +\newif\if@AnswerNB \@AnswerNBfalse +% +\define@key{PPAnswer}{ref}{\global\@AnswerReftrue\gdef\AnswerRef{\string#1}} +\define@key{PPAnswer}{number}{\global\@AnswerNBtrue\gdef\AnswerNB{\string#1}} +% +\def\beginAnswerEnv{\@InitAnswer\@ifnextchar[\@@AnswerEnv{\@@AnswerEnv[]}}%] +% +\def\@@AnswerEnv[#1]{\setkeys{PPAnswer}{#1}% +\global\@Answertrue\@BeginExeBox\@@@AnswerEnv} +% +\newcommand{\@@@AnswerEnv}{% + \@QuestionLevel1 + \begingroup\@getAnswerInfo\AnswerHeader\endgroup} +% +\def\endAnswerEnv{\termineliste{1}\@EndExeBox} +% +\newenvironment{Answer}{}{} +\def\defineAnswerEnv{ + \gdef\@AnswerHeaderRef{\AnswerHeader} + \renewenvironment{Answer}{\beginAnswerEnv}{\endAnswerEnv}} +% +\defineAnswerEnv +% +\def\AnswerCmd{\@InitAnswer\@ifnextchar[\@@AnswerCmd{\@@AnswerCmd[]}} +% +\def\@@AnswerCmd[#1]{\setkeys{PPAnswer}{#1}\@@@AnswerCmd} +% +\newcommand{\@@@AnswerCmd}{% + \ifnum\@QuestionLevel=0 + \advance \@QuestionLevel by 1 + \begin{list}{}{\partopsep\Exepartopsep \labelsep\Exelabelsep + \itemsep \Exesep \parsep\Exeparsep + \topsep\Exetopsep \labelwidth\Exelabelwidth + \leftmargin\Exeleftmargin + \rightmargin\Exerightmargin } + \refstepExecounter + \else + \termineliste{1}\@EndExeBox + \fi + \global\@Answertrue\@BeginExeBox% + \item[\bgroup\@getAnswerInfo\AnswerListHeader\egroup]\ignorespaces +} +% +\def\defineAnswerCmd{\gdef\@AnswerHeaderRef{\AnswerListHeader}% +\gdef\Answer{\AnswerCmd}} +% \end{macrocode} +% \subsubsection{ Some extra stuff} +% \begin{macrocode} +\newcommand{\ExeText}{\setcounter{savedQuestion}{\value{Question}}% +\termineliste{1}\@echapqtrue} +% \end{macrocode} +% \subsubsection{Secret stuff} +% \begin{macrocode} +% +% Il est possible de présenter un niveau de sectionnement sur +% deux colonnes avec la commande \colonnesLevel +% +\newcount\colonnesLevel \colonnesLevel=-10 +\newskip\tempskipa +\newskip\tempskipb +\def\deuxcolonnes{\tempskipa=\multicolsep\colonnesLevel=\@QuestionLevel +\ifcase\@QuestionLevel \multicolsep=\QuestionBefore % +\or +\multicolsep=\subQuestionBefore\or\multicolsep=\subsubQuestionBefore\fi% +\begin{multicols}{2}} +% +% Tenir compte de l'option fleqn +% +\@ifundefined{if@fleqn}{\newif\if@fleqn\@fleqnfalse}{} +% +\newcommand{\@savemathindent}{\relax} +\newcommand{\@decalemathindent}[1]{\relax} +\newcommand{\@restoremathindent}{\relax} +\if@fleqn % + \renewcommand{\@savemathindent}{\setlength{\@savedmathindent}{\mathindent}} + \renewcommand{\@decalemathindent}[1]{\addtolength{\mathindent}{#1}} + \renewcommand{\@restoremathindent}{\setlength{\mathindent}{\@savedmathindent}} +\else + \renewcommand{\@savemathindent}{\relax} + \renewcommand{\@decalemathindent}[1]{\relax} + \renewcommand{\@restoremathindent}{\relax} +\fi +% \end{macrocode} +% \subsection{The \texttt{\textbackslash renewcounter} command} +% This commands is the equivalent of the well--known |\renewcommand|, +% but for counter. It allows you to redefine the |Exercise| counter, +% in order to reset it at each chapter (for example). +% \begin{macrocode} +\def\renewcounter#1{% + \@ifundefined{c@#1} + {\@latex@error{counter #1 undefined}\@ehc}% + \relax + \let\@ifdefinable\@rc@ifdefinable + \@ifnextchar[{\@newctr{#1}}{}} +% \end{macrocode} +% \Finale +\endinput diff --git a/Master/texmf-dist/source/latex/exercise/exercise.ins b/Master/texmf-dist/source/latex/exercise/exercise.ins new file mode 100644 index 00000000000..57d5817637f --- /dev/null +++ b/Master/texmf-dist/source/latex/exercise/exercise.ins @@ -0,0 +1,66 @@ +%% Copyright (C) 2003 by Paul Pichaureau
+%%
+%% This program is free software; you can redistribute it and/or
+%% modify it under the terms of the GNU General Public License
+%% as published by the Free Software Foundation; either version 2
+%% of the License, or (at your option) any later version.
+%%
+%% This program is distributed in the hope that it will be useful,
+%% but WITHOUT ANY WARRANTY; without even the implied warranty of
+%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+%% GNU General Public License for more details.
+%%
+%% You should have received a copy of the GNU General Public License
+%% along with this program; if not, write to the Free Software
+%% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+%% Public LaTeX Project Public
+
+\input docstrip.tex
+
+%\keepsilent
+
+\usedir{tex/latex/exercise}
+
+\preamble
+
+This is a generated file.
+
+Copyright (C) 2003 by Paul Pichaureau
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+Public LaTeX Project Public
+
+\endpreamble
+
+\generate{\file{exercise.sty}{\from{exercise.dtx}{package}}}
+
+\Msg{*********************************************************}
+\Msg{*}
+\Msg{* To finish the installation you have to move the}
+\Msg{* following file into a directory searched by TeX:}
+\Msg{*}
+\Msg{* \space\space exercise.sty}
+\Msg{*}
+\Msg{* To produce the documentation run the file exercise.dtx}
+\Msg{* through LaTeX.}
+\Msg{*}
+\Msg{* Don't forget to produce Index and Change History with}
+\Msg{* makeindex -s gind.ist -o exercise.ind exercise.idx}
+\Msg{* makeindex -s gglo.ist -o exercise.gls exercise.glo}
+\Msg{*}
+\Msg{* Happy TeXing!}
+\Msg{*********************************************************}
+
+\endbatchfile
\ No newline at end of file |