% \iffalse meta-comment
%
% Copyright (C) 2020-2021 by Antoine Missier <antoine.missier@ac-toulouse.fr>
% ----------------------------------------------------------------------
% 
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% 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.3 or later is part of all distributions of LaTeX 
% version 2005/12/01 or later.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{exesheet.dtx}
%</driver>
%<class|package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
%<class>\ProvidesClass{exesheet}
%<package>\ProvidesPackage{exesheet}
%<*class|package>
[2023/01/16 v2.0 .dtx exesheet file]
%</class|package>
%<*driver>
\documentclass{ltxdoc}
%
% uncomment the following lines if you want to use the exesheet class instead of ltxdoc
%\usepackage{doc}
%\AtBeginDocument{\MakeShortVerb{\|}}
%\providecommand\marg[1]{{\ttfamily\{}\meta{#1}{\ttfamily\}}}
%\providecommand\oarg[1]{{\ttfamily[}\meta{#1}{\ttfamily]}}
\usepackage[exetoc=false,marginwidth=unset,display=notes]{exesheet}
\usepackage{schooldocs}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{lmodern}
\usepackage{multicol}
\usepackage{hyperref}
\usepackage{sectsty}
\usepackage{pstricks}
\usepackage{array}
\usepackage{spacingtricks}
\usepackage{centeredline}
%
\psset{unit=1cm}
\geometry{textwidth=355pt,vmarginratio=1:1,hmarginratio=3:2}
% altered by schoodocs, now very close from the default geometry used by ltxdoc.
% The following instruction gives the same margin width
% as with display=notes without altering the margin ratio
\leftnotemarginwidth{0.55} % special setting here
\newcommand{\ds}{\displaystyle}
\newcommand{\bs}{\textbackslash}
\definecolor{darkbrown}{rgb}{0.5,0.1,0.1}
\allsectionsfont{\sffamily\color{darkbrown}}
\renewcommand{\labelexercisestyle}{\rmfamily\color{black}}
\renewcommand{\labelsubpartstyle}{\rmfamily\color{black}}
\renewcommand{\annexstyle}{\rmfamily\color{black}\MakeUppercase}
\renewcommand{\correctionstyle}{\rmfamily\color{correctioncolor}}
\renewcommand{\titlestyle}{\LARGE\sffamily\bfseries}
%
\DisableCrossrefs
%\CodelineIndex
%\RecordChanges
\title{The \textsf{exesheet} class and package}
\subject{Antoine Missier \\
    \texttt{antoine.missier@ac-toulouse.fr}}
\date{\filedate, \fileversion}
\hypersetup{%
    colorlinks,
    linkcolor=blue,
    pdftitle={exesheet},
    pdfsubject={LaTeX class and package},
    pdfauthor={Antoine Missier}
}

\begin{document}
\DocInput{exesheet.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{1118}
%
% \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{v0.0}{2010/09/01}{Initial personal version}
% \changes{v0.9}{2020/01/02}{Initial documentation in french}
% \changes{v1.0}{2020/07/22}{Initial public version with documentation in english}
% \changes{v1.1}{2021/08/30}{
%    Macro tablenum (also used by siunitx) replaced by tablenum1, 
%    small modifications due to changes in tasks package}
%
% \changes{v1.2}{2021/09/18}{
%    Bug correction in macros tablenum1 and tablenuma, 
%    using the translations package for internationalization}
%
% \changes{v1.3}{2021/11/15}{
%    Bad spacing in the exe macro and bug correction in the starred version of this macro}
%
% \changes{v2.0}{2022/12/28}{
%    options toc and setlist with kvoptions (instead of notoc and nosetlist),
%    introducing the key 'output' instead of old commands questionsonly, answersonly,
%    introducing the key 'display' instead of old command displaypts, displaypoints,
%        displaynotes,
%    introducing the keys 'margin' and 'noteragged' to set how the notes are displayed,
%    introducing the key 'correct'}
% \changes{v2.0}{2023/01/02}{
%    documentation update,
%    new option checkpts}
% \changes{v2.0}{2023/01/09}{
%    new option 'marginwidth', 
%    modifying hmarginratio from 5:1 to 3:1 when display=notes,
%    correct management of two side mode documents}
% \changes{v2.0}{2023/01/16}{
%    \enskip between titles and their optional argument,
%    simplifying macros markingstyle and notestyle,
%    use of ragged2e package,
%    code revision and simplification,
%    documentation update}
%
% \GetFileInfo{exesheet.dtx}
%
% \maketitle
% \tableofcontents
% \enlargethispage{1ex}
%
% \section{Introduction}
%
% The \textsf{exesheet} \emph{package} is used for typesetting exercise or exam sheets.
% In addition, the \textsf{exesheet} \emph{class} loads the \textsf{schooldocs} package.
% This one makes adjustments for margins and title and defines various layout styles 
% with particular header and footer, appropriate for exercise sheets (among others).
% See the \textsf{schooldocs} documentation for more details.
% The \textsf{exesheet} \emph{class} is based on \textsf{article} 
% and passes to it its unknown options.
%
% Many other packages are dedicated to exercise sheets.
% Most propose to encapsulate each exercise in an environment
% whereas \textsf{exesheet} begins each exercise with |\exercise|, 
% which works like a subsection (with the same features)
% and is suitable for documents consisting exclusively of exercises.
% The package provides also alternative formatting, 
% more relevant for short exercises.
%
% Another specificity of the \textsf{exesheet} package is the particular settings
% for enumeration lists, 
% useful for the numbering of questions or answers inside an exercise.
%
% Other packages provide often more or less elaborate mechanisms
% to manage the placement of answers.
% \textsf{exesheet} has no such ambitions, however,
% for all exercises of the sheet, you can display questions only, 
% answers only or both, but always at the place they are inserted
% in the source file. On the other hand this choice may be very flexible:
% you can do a correct version for all exercises together, or a correction per exercise,
% per part (subpart of exercise), per question, per sub-question.
%
% Finally this package enables to display 
% a detailed marking scheme in the margin,
% with optional explanations or remarks, 
% and with consistency control.
%
% Many settings can be changed and several options manage the output document.
% These options are based on the keyval mechanism: \texttt{key=value}
% (thanks to Maxime Chupin and Denis Bitouzé for their wise ideas to improve this package).
% The options can be passed to class or package, \eg
% \begin{center}
% |\documentclass[a4paper,11pt,output=answers,display=pts]{exesheet}|
% \end{center}
% or later with the |\exesheetset|\marg{options} command.
% In the example above, \texttt{a4paper,11pt} are options
% passed to the underlying class \textsf{article}.
%
%\medskip
% \emph{In the current document, a frame is used to highlight 
% examples output.}
%
% \section{Titles}
%
% \subsection{The \texttt{\bs exercise} command}
%
% \DescribeMacro{\exercise}
% Each exercise begins with the |\exercise|\oarg{opt} command. 
% This command typesets \textbf{\exercisename}, as a document
% subsection, followed by automatic numbering,
% unique for the whole document.
% The optional parameter \meta{opt} is used to put additional text
% on the same title line, for example to precise a subject or a marking scheme.
% |\exercise[(to begin)]| yields:
%
% \exercise[(to begin)]
% \psframe(-0.25,1.3)(12.75,-0.3)
% Try to use this first command now, it's easy.
%
% \bigskip
% To bring additional text closer to the exercise number, 
% we can use |\unskip| which eliminates preceding space, 
% and also |\hrulefill| can be put in the optional argument 
% to produce an horizontal rule.
% See the following example, obtained with \\
% |\exercise[\unskip*** (difficult)]|:
% \exercise[\unskip*** (difficult)]
% \psframe(-0.25,1.3)(12.75,-0.3)
% Calculate $1+1$.
%
% \bigskip
% Several settings can be changed by refining the following commands.
%
% \medskip
% \DescribeMacro{\exercisename}
% The word ``\exercisename'' has automatic translation in a few languages
% \footnote{Translation is currently integrated into the package 
% for the following languages: French, German, Spanish, Italian, Portuges.}
% according to the loaded language (by \textsf{babel} or \textsf{polyglossia}).
% It can be redefined, with |\renewcommand|,
% or better you can use (in the preamble) macros from the \textsf{translations} 
% package (allowing dynamic language change), \eg \\
% |\DeclareTranslation{Swedish}{exesheet-exercise}{\"Ovning}}|.
%
% \DescribeMacro{\labelexercise}
% This command calls |\exercisename| following by the exercise number.
% It can be redefined. For example, to add a period after the exercise number:
% |\renewcommand{\labelexercise}{\exercisename~\theexercise.}|
%
% \DescribeMacro{\theexercise}
% To change only the numbering type, redefine
% the |\theexercise| command, based on the |exercise| counter.
%
% \DescribeMacro{\labelexercisestyle}
% This macro (which is empty by default) allows to define a particular style
% for exercise titles. In the present document, we defined in the preamble:
% |\renewcommand{\labelexercisestyle}{\rmfamily\color{black}}|
% \footnote{In the present document, to highlight real sections and subsections titles,
% their color and font have been modified with the
% \texttt{\bs allsectionsfont} macro from the \textsf{sectsty} package.}.
%
% \medskip
% \DescribeMacro{\exercise*}
% The starred version |\exercise*|\oarg{opt}\marg{label}
% allows to choose another \meta{label} for a particular exercise
% and removes the numbering. For instance:
% |\exercise*[(Fermat's theorem)]{Problem}| yields:
%
% \exercise*[(Fermat's theorem)]{Problem}
% \psframe(-0.25,1.3)(12.75,-0.7)
% Prove that there are no positive integers $x, y, z$ such that $x^n+y^n=z^n$
% for any integer $n$ greater than 2.
%
% \subsection{The \texttt{\bs subpart} command}
%
% \DescribeMacro{\subpart}
% An exercise may contain several parts that we obtain 
% with the |\subpart|\oarg{opt} command, typeset like a sub-subsection.
% \exercise
% \subpart[(preliminary)]
% \psframe(-0.25,1.95)(12.75,-1.85)
% First of all, prepare your cup of tea.
% \subpart
% Now you are ready to make the current exercise.
%
% \bigskip
% The following macros manage formatting in the same way as for |\exercise|.
%
% \medskip
% \DescribeMacro{\thesubpart}
% By default, the subpart numbering uses letters : A, B, C, etc.
% This numbering type can be redefined with the |\thesubpart| command based on
% the |subpart| counter, for instance |\renewcommand\thesubpart{\arabic{subpart}}|.
%
% \DescribeMacro{\subpartname} \DescribeMacro{\labelsubpart} 
% \DescribeMacro{\labelsubpartstyle}
% The |\subpart| command
% uses |\subpartname| (with automatic translation in a few languages 
% according to the selected language),
% |\labelsubpart| and |\labelsubpartstyle|, which can be changed.
%
% \medskip
% \DescribeMacro{\subpart*}
% Like |\exercise*|, the starred version |\subpart*|\oarg{opt}\marg{label}
% allows to freely typeset the subpart \marg{label}, for instance
% |\subpart*{First part}|.
%
% \subsection{The \texttt{\bs annex} command}
% \DescribeMacro{\annex}
% The |\annex|\oarg{opt} command typesets the title \textbf{ANNEX}, 
% in uppercase letters, centered
% and in the subsection style,
% with an optional parameter, added on the same line.
%
% \vspace{-\baselineskip}
% \noindent\psframe(-0.25,-0.3)(12.75,-1.3)
% \annex[(to return)]
%
% \bigskip
% \DescribeMacro{\annexname}
% The word ``\annexname'' has automatic translation in a few languages.
% It can be extended to other languages or modified by redefining |\annexname|
% or with macros from the \textsf{translations} package.
%
% \DescribeMacro{\annexstyle}
% The annex title style is set by the |\annexstyle| macro,
% defined as follows: |\newcommand\annexstyle{\MakeUppercase}|.
% This command may be redefined as one wants.
%
% \subsection{Exercise titles in table of contents} \label{toc}
% \DescribeMacro{[exetoc=\meta{bool}]}
% By default, the titles \textbf{\exercisename}, \textbf{\subpartname} 
% or \textbf{\annexname}, appear in the table of contents
% (or in the pdf file summary when \textsf{hyperref} package is used). 
% To avoid this, you can set the option \texttt{exetoc=false} (default is \texttt{true}).
% But notice that title optional arguments will always be ignored in the table of contents.
%
% \subsection{Short exercises: the \texttt{\bs exe} command}
% \DescribeMacro{\exe}
% The |\exe| command starts an exercise by the abbreviation \textbf{\exname}.\ 
% followed by the exercise number,
% without using sectioning commands, and the exercise body begins on the same
% line. An exercise starts a new paragraph without indentation.
%
% \exe This is a short exercise who
% can contain several paragraphs or questions however.
%
% \noindent\psframe(-0.25,1.4)(12.75,-1.2)
% \indent Here for example starts a new paragraph.
% \exe This is another short exercise.
%
% \bigskip
% \DescribeMacro{\exname} \DescribeMacro{\exlabel} \DescribeMacro{\exsepmark}
% The abbreviation \textbf{\exname} may be changed by
% redefining |\exname| or with macros from the \textsf{translations} package.
% The |\exlabel| macro calls |\exname| following by a period then the exercise number,
% and |\exsepmark| typesets a long dash.
% One can change these features by redefining these commands.
%
% \medskip
% \DescribeMacro{\exe*}
% The starred version prints no separator as shown below:
%
% \vspace{-\baselineskip}
% \noindent\psframe(-0.25,-0.35)(12.75,-1.1) 
% \exe* Another short exercise without separator.
% 
% \section{Enumerations and lists}
%
% \subsection{List settings} \label{setlist}
% \DescribeEnv{enumerate} \DescribeMacro{\item}
% Enumeration lists are intended to represent questions and sub-questions
% inside exercises. For a good highlight,
% labels are typeset in bold. 
% Moreover, they are left aligned, at the start of the line, 
% without indentation, and the vertical space between items
% is increased compared with \LaTeX\ standard lists.
% These settings are done by the |\setlist| command
% \footnote{Labels may also be changed occasionally in an optional argument 
% \eg \texttt{\bs begin\{enumerate\}[A.]},
% or globally thanks to \texttt{\bs labelenumi} 
% and \texttt{\bs labelenumii} commands.}
% from the \textsf{enumitem} package of Javier Bezos.
% Lists with \texttt{itemize} environment are kept in their default 
% configuration
% \footnote{The \texttt{french} option of the \textsf{babel} package
% alters \texttt{itemize} lists behavior and uses long dashes
% as labels for each list level.
% This behavior is problematic when mathematics follows the dash
% symbol because the latter may be confused with the minus sign.
% Default \texttt{itemize} lists are restored.}.
%
% \vspace{-\baselineskip}
% \noindent\psframe(-0.25,-0.35)(12.75,-3.6) 
% \exercise
% \begin{enumerate}
% \item First question
% \begin{enumerate}
% \item First sub-question
% \item Second sub-question
% \end{enumerate}
% \item Second question
% \end{enumerate}
%
% \smallskip
% \DescribeMacro{[setlist=\meta{bool}]}
% One can avoid enumeration list alterations and restore \LaTeX\ 
% default settings with the option |[setlist=false]| 
% (default value is \texttt{true} of course).
%
% \subsection{List of exercises : the \texttt{exenumerate} environment}
% \DescribeEnv{exenumerate}
% When an exercise sheet is made of short independent questions,
% it would be ill-advised to display the complete title \textbf{\exercisename} for each. 
% In addition to the |\exe| command, previously presented,
% we provide an even lighter solution with the |exenumerate| environment.
% It's only an enumeration list in which
% spaces between items are further increased compared to those of \texttt{enumerate}.
% Below is an example (the main list is an \texttt{exenumerate} environment but the
% sub-list is produced with common \texttt{enumerate} environments):
%
% \vspace{-\baselineskip}
% \noindent\psframe(-0.25,-0.3)(12.75,-5.3) 
% \begin{exenumerate}
% \item Translate the following sentences in English: 
% \begin{enumerate}
% \item Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi.
% \item Nam lacus libero, pretium at, lobortis vitae, ultricies et, tellus.
% \end{enumerate}
% \item  Translate the following sentence in German:
% \par Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna,
% vitae ornare odio metus a mi. 
% \item  Translate the following sentences in French: 
% Cum sociis natoque penatibus 
% et magnis dis parturient montes, nascetur ridiculus mus.
% \end{exenumerate}
%
% \medskip
% The environment takes an optional parameter, like \texttt{enumerate}, 
% which enables, among others, 
% to typeset alternative list labels, \eg
% |\begin{exenumerate}[A.]|.
% There are many other options (see the \textsf{enumitem} package documentation).
%
% \subsection{Items aligned by row: \texttt{tablenum1$\mid$a}, \texttt{tablitem}}
% \DescribeEnv{tablenum1} 
% \DescribeEnv{tablenuma}
% \DescribeEnv{tablitem}
% These three environments are used to typeset short questions (\texttt{tablenum1}),
% sub-questions (\texttt{tablenuma}) or \texttt{itemize} lists (\texttt{tablitem})
% on the same line. They have the same syntax:
% |\begin{tablenum1}|\oarg{opt}|(|\meta{cols}|)|.
% The \meta{cols} parameter is the number of columns used by the environment. It must be
% \emph{in parentheses}. This parameter can be omitted, then its value is 2.
% As for classic lists, each item begins with the |\item| command.
%
% These three environments are defined by the
% |\NewTasksEnvironment| macro, from the \textsf{tasks} package by Clemens Niederberger.
% They take an optional argument \meta{opt}
% explained in the documentation of this package, 
% \eg |label=\arabic*)| produces an Arabic numbering
% following by a closing parenthesis (like in \texttt{enumitem} package).
% There are also many possibilities to place items in an original way,
% for instance, the |\item*| command allows to
% specify the number of columns the item is supposed to span.
% In the following example,
% the five |\item| are placed in order between
% |\begin{tablenum1}(3)| and |\end{tablenum1}|.
% Notice that numbering is made line by line.
%
% \exercise
% \psframe(-0.25,1.3)(12.75,-2.7)
% Give the derivative of the following functions:
% \begin{tablenum1}(3)
% \item $\ds f(x) = \frac{1-x^2}{\mathrm{e}^x +\mathrm{e}^{-x}}$,
% \item $\ds g(x) = \ln \left( \frac{1-x}{1+x^2}\right)$,
% \item $\ds h(x) = \int_{0}^{1}\mathrm{e}^{xy}\, \mathrm{d}y$,
% \item $\ds k(x) = \sum_{i=1}^{\infty}\frac{1}{x^i}$,
% \item $\ds l(x) = \int_{\frac{1}{x}}^{x}\frac{1}{\ln t}\, \mathrm{d}t$.
% \end{tablenum1}
%
% \smallskip
% For \texttt{tablenuma}, labels are
% letters (a, b, c, \ldots) surrounded
% by parentheses. This cannot be modified globally,
% except by redefining the environment with |\RenewTasksEnvironment|.
% If the \textsf{exesheet} package is called with the option \texttt{setlist=false},
% labels of \texttt{tablenum1} and \texttt{tablenuma} environments
% are displayed with indentation and in normal font instead of bold.
%
% \subsection{Items aligned by column: \texttt{colsenum}, \texttt{colsitem}}
% \DescribeEnv{colsenum}    
% To get numbering of items by column, we provide the
% \texttt{colsenum} environment: |\begin{colsenum}|\oarg{opt}\marg{cols}.
% The mandatory parameter is the number of columns
% and the optional one will be passed to \texttt{enumerate},
% allowing, for example, to change the type of numbering (a, A, etc.).
% To use this environment, we have to load the
% \textsf{multicol} package in the preamble.
% Here an example with |\begin{colsenum}{3}|:
%
% \exercise
% \psframe(-0.25,1.3)(12.75,-2.65)
% Give the derivative of the following functions:
% \begin{colsenum}{3}
% \item $\ds f(x) = \frac{1-x^2}{\mathrm{e}^x +\mathrm{e}^{-x}}$,
% \item $\ds g(x) = \ln \left( \frac{1-x}{1+x^2}\right)$,
% \item $\ds h(x) = \int_{0}^{1}\mathrm{e}^{xy}\, \mathrm{d}y$,
% \item $\ds k(x) = \sum_{i=1}^{\infty}\frac{1}{x^i}$,
% \item $\ds l(x) = \int_{\frac{1}{x}}^{x}\frac{1}{\ln t}\, \mathrm{d}t$.
% \end{colsenum}
%
% \medskip
% \DescribeEnv{colsenum*}
% We will notice that, on each line, items are not necessarily well
% aligned, which can produce inelegant effects. 
% On the other hand, the \texttt{colsenum} environment doesn't try to align columns 
% from the bottom by adjusting space between items.
% If we want to get this
% (which is the default option in \textsf{multicol}), we have the
% \texttt{colsenum*} environment (same syntax than \texttt{colsenum}).
% Here what we get in that case, with the same exercise:
%
% \exercise
% \psframe(-0.25,1.3)(12.75,-2.65)
% Give the derivative of the following functions:
% \begin{colsenum*}{3}
% \item $\ds f(x) = \frac{1-x^2}{\mathrm{e}^x +\mathrm{e}^{-x}}$,
% \item $\ds g(x) = \ln \left( \frac{1-x}{1+x^2}\right)$,
% \item $\ds h(x) = \int_{0}^{1}\mathrm{e}^{xy}\, \mathrm{d}y$,
% \item $\ds k(x) = \sum_{i=1}^{\infty}\frac{1}{x^i}$,
% \item $\ds l(x) = \int_{\frac{1}{x}}^{x}\frac{1}{\ln t}\, \mathrm{d}t$.
% \end{colsenum*}
%
% \medskip
% We can see that these alignments are less good than those
% obtained by row numbering. The column numbering
% may nevertheless be preferable when there are many items with variable heights,
% and a number of items which can be different from one column to the other.
% Moreover, an advantage of \texttt{colsenum} is that the choice of labels 
% is automatic depending on the list level (and the language),
% unlike \texttt{tablenum1} or \texttt{tablenuma}. 
%
% \bigskip
% \DescribeEnv{colsitem} 
% \DescribeEnv{colsitem*}
% For \texttt{itemize} lists, the environment \texttt{colsitem}
% produces items aligned by column rather than by lines as for
% \texttt{tablitem}:
% |\begin{colsitem}|\oarg{opt}\marg{cols}. The optional parameter,
% which is passed to the underlying \texttt{itemize} environment, 
% allows to change the item label (bullet by default).
% And, as for \texttt{colsenum*}, the \texttt{colsitem*} environment
% produces an alignment of columns from the bottom.
%
% \section{Questions and solutions}
%
% \subsection{Environments \texttt{questions} and \texttt{answers}}
% \label{output}
%
% \DescribeEnv{questions} \DescribeEnv{answers}
% The package provides the two environments \texttt{questions} and \texttt{answers}
% to make optionally appear or disappear questions and answers of exercises.
%
% \bigskip
% \DescribeMacro{[output=\meta{opt}]}
% The output is controlled by the \texttt{output} key option: it takes three
% recognized values: \texttt{questions}, \texttt{answers}, \texttt{both}.
% The \texttt{questions} value allows to display questions without answers,
% \texttt{answers} displays answers without questions,
% \texttt{both} (the default option) displays  both.
% 
% \bigskip
% \DescribeMacro{\correctionstyle} \DescribeMacro{correctioncolor}
% \DescribeMacro{\correctionname}
% In the case (by default) where questions and answers are displayed both,
% answers are then typeset in the style
% |\correctionstyle|, which uses the color \texttt{correctioncolor}.
% This color may be changed with the |\definecolor| macro
% \footnote{from the \textsf{xcolor} package by Uwe Kern 
% which is loaded by \textsf{exesheet}.}
% (by default |\definecolor{correctioncolor}{rgb}{0,0.2,0.6}| = kind of dark blue).
% Moreover, with \texttt{output=both}
% the title \textbf{\correctionname} is displayed at the beginning
% of \texttt{answers} environments.
% It is defined by the |\correctionname| macro (with translation in a few languages
% and that can changed:
% for example you may prefer ``Solution''
% than ``\correctionname'').
% The style defined by |\correctionstyle| will apply to the title
% as for the whole environment.
% Here an example.
%
% \vspace{-\baselineskip}
% \noindent\psframe(-0.25,-0.25)(12.75,-6.7) 
% \exercise
% \begin{questions}
% \begin{enumerate}
% \item Is the \textsf{exesheet} package useful ? 
% \item Isn't there any other packages that deal with exercises ?
% \end{enumerate}
% \end{questions}
% \begin{answers}
% \begin{enumerate}
% \item Yes, the \textsf{exesheet} package is useful for teachers.
% \item There are many other packages that deal with exercises, and
% give the ability to produce separately questions and solutions, for example
% \textsf{exercise} by Paul Pichaureau, \textsf{exercises} by Roger Jud,
% \textsf{exsheets} (superseded by \textsf{xsim}) by Clemens Niederberger,
% \textsf{exframe} by Niklas Beisert,
% \textsf{exam} by Philip Hirschhorn,
% \textsf{answers} by Mike Piff and Joseph Wright,
% \textsf{probsoln} by Nicola Talbot, etc.
% \end{enumerate}
% \end{answers}
%
% \medskip
% When only answers are displayed, the text color remains black and
% the word ``\correctionname'' is not displayed.
%
% \subsection{About the title ``\correctionname'' in \texttt{answers} environments}
% Internally, we have used the |\comment| and |\endcomment| macros
% from the \textsf{versions} package by Uwe Lück.
% Other excellent packages allow to manage
% selectively piece of code. Let us mention 
% \textsf{verbatim} by Rainer Schöpf, \textsf{comment} by Victor Eijkhout, 
% \textsf{version} by Donald Arseneau and Stephen Bellantoni,
% \textsf{optional} by Donald Arseneau
% and \textsf{codesection} by Matthias Pospiech.
%
% The \textsf{versions} package provides furthermore 
% the |\includeversion|\marg{env} and
% |\excludeversion|\marg{env} macros who allow to make appear or disappear
% any environment \meta{env} and these optional environments
% may be nested
% \footnote{The \textsf{codesection} package also allows
% such nesting, including in the preamble, as well as 
% the \textsf{optional} package, but the latter manages only short optional code.}.
%
% However the \texttt{questions} and \texttt{answers} environments
% perform another task, not only making appear or disappear piece of text.
% In what format should the output yield the title \textbf{\correctionname} 
% and at which level should it be put in the table of contents
% (or in the summary of the pdf file)?
% In fact it depends on which level the environment has been nested.
% We can make a single \texttt{answers} environment for the whole
% sheet or an \texttt{answers} environment
% for each exercise, for each exercise part, for each question or sub-question.
% In fact, the typeset of the title \textbf{\correctionname}
% and his level in the table of contents will be computed by the environment.
%
% \medskip
% \DescribeEnv{answers\oarg{level}}
% Nevertheless, one can imagine twisted situations in which 
% the title level will not be correct.
% Moreover, the user may want to change the level of the title.
% It is then possible to force the level of the title ``\correctionname''
% with |\begin{answers}|\oarg{level}.
% The optional \meta{level} parameter is defined as follows:
% 1 for section level titles,
% 2 for subsections (like \textbf{\exercisename}), 
% 3 for sub-subsections (like \textbf{\partname}),
% another number for lower levels
% (that will not appear in the table of contents).
%
% \pagebreak
% \DescribeMacro{answers*}
% The starred version \texttt{answers*} makes the title
% \textbf{\correctionname} completely disappear.
%
% \subsection{Commands \texttt{\bs question}, \texttt{\bs answer} and \texttt{\bs answerspace}}
% \label{answerspace}
% \DescribeMacro{\question}\DescribeMacro{\answer}
% Instead of \texttt{questions} and \texttt{answers} environments,
% we can also use simple |\question|\marg{ques} and |\answer|\marg{ans} macros
% in which display of \meta{ques} and \meta{ans} arguments 
% are controlled by the same previous key option \texttt{output=\meta{opt}}.
% It may be more suitable when questions and answers are short, for instance
% if you want to display the answer after each question item.
% The title ``\correctionname'' will not appear on the beginning
% of each answer; answers are typeset with |\correctionstyle|
% if \texttt{output=both}.
% But these commands don't work with \texttt{verbatim} text inside,
% whereas \texttt{questions} and \texttt{answers} environments allow that.
%
% \bigskip
% \DescribeMacro{\answerspace}
% Some teachers are used to give to their students documents in which questions are typeset
% but instead of answers you have blank space, so that the paper is intended to be
% fulfilled by the students. 
% For this purpose, thanks to a suggestion of Maxime Chupin,
% we provide the macro |\answerspace|\oarg{height},
% in which the parameter height is a valid length, \eg |\answerspace{3cm}|.
%
% \DescribeMacro{[answerspace=\meta{bool}]}
% This vertical space display is optional and is controlled by the key
% \texttt{answerspace} which can be \texttt{true} or \texttt{false} (by default).
% Of course this macro is not intended to be placed inside \texttt{answers}
% environments, but anywhere else.
%
% \section{Marginal notes for marking scheme} 
%
% The \textsf{exesheet} package allows to display in margins a marking
% scheme with comments and explanations about answers.
%
% \subsection{The \texttt{\bs points} command}\label{points}
% \DescribeMacro{\points}
% The |\points|\marg{pts} command displays the number of points awarded for an exercise.
% It is intended to be entered in the optional argument of the 
% |\exercise| command
% \footnote{Using this command in the optional argument of 
% \texttt{\bs exercise} is incompatible with
% the \textsf{memoir} class which redefines section commands.}.
% For instance
% |\exercise[\points{5}]| yields:
% \exercise[\points{5}]
% \psframe(-0.25,1.3)(12.75,-0.4)
% Try to read this document to the end without drinking tea and you get five points.
%
% \bigskip
% When only correction is displayed in an exercise, the |\points| macro is patched 
% to suppress the display of points.
% An extended solution for printing answers with the scale will be presented
% in section \ref{totalpoints}, including a new |\totalpoints| macro.
%
% \bigskip
% \DescribeMacro{\pointsname} \DescribeMacro{\pointname}
% The word ``\pointsname'' (or in the singular ``\pointname''
% if \meta{pts} is inferior to 2), is added and, like before,
% gets automatic translation in a few languages
% (and can be changed).
% 
% \DescribeMacro{\pointsstyle} \DescribeMacro{pointscolor}
% The style used by the |\points| command may be redefined with |\pointsstyle|. 
% The color is set by |pointscolor| with the |\definecolor| command,
% and you can change it, 
% \eg: |\definecolor{pointscolor}{named}{blue}|.
%
% \subsection{The \texttt{\bs pts} command} \label{pts}
% \DescribeMacro{\pts}
% When exercises are typeset with the |\exe| macro,
% or as a list with the \texttt{exenumerate} environment,
% the marking scheme can be displayed in the margin, on the line where
% we put the |\pts|\marg{num} command (in general the first line of the exercise).
% The \meta{num} parameter is the number of points assigned to the exercise.
% Below what we obtain with with |\exe\pts{3}... \exe\pts{1.5}...|
%
% \vspace{-\baselineskip}
% \noindent\psframe(-3.0,-0.25)(12.75,-1.95)
% \exe \pts{3} The first exercise with a marking scheme.
% \exe \pts{1.5} The second one.
% 
% \bigskip
% \DescribeMacro{\ptsname} \DescribeMacro{\ptname} 
% \DescribeMacro{ptscolor} \DescribeMacro{\ptsstyle}
% The abbreviation ``\ptsname'' (or ``\ptname''
% when the number of points is inferior to 2)
% is automatically added with macros |\ptsname| or |\ptname| 
% (translated in a few languages if \textsf{babel} ore \textsf{polyglossia} are loaded).
% The display color of the points is defined by \texttt{ptscolor}, which can be changed
% with |\definecolor|: by default |\definecolor{ptscolor}{named}{red}|.
% The display style is defined by |\ptsstyle|: among other things, it adds parenthesis around.
%
% \bigskip
% \DescribeMacro{[display=\meta{opt}]} 
% The display of the marking scheme is controlled by the
% option key \texttt{display}.
% By default |display=none| and the marking scheme will not be displayed.
% Use |display=pts| to make it appear.
% More details about this key are given in \ref{margin}.
%
% \medskip
% \DescribeMacro{[marginpos=\meta{opt}]} 
% The side where to place the scale is controlled by the |marginpos| key option
% whose possible values are (first) \texttt{left} or \texttt{right}.
% The default is \texttt{left}
% (although the default behavior of \LaTeX{} is to place marginal notes on the right side). 
% This option has no effect when
% |display=none|.
%
% For a \emph{two side} document, the default behavior is to typeset text in the outer margin
% which will be enlarged relatively to the inner margin (that contains the binding).
% The outer margin is on the right hand side for odd pages and on the left hand side
% for even pages. So the \texttt{marginpos} key option can take those two additional 
% values.
% When you give a \texttt{left} or \texttt{right} value with a two side document,
% it will be converted to default value, \texttt{outer}, with a warning message.
%
% \medskip
% \DescribeMacro{twoside mode}
% For a document is in twoside mode, marginal notes sometimes appear on the wrong 
% side of a page. This is a known bug of \LaTeX\ for which the solution
% is to call the package \textsf{mparhack} (what is done by \textsf{exesheet}
% for a twoside mode document) and to \emph{run \LaTeX\ twice}. 
% If necessary you get a warning message to rerun.
% 
% \subsection{Commands \texttt{\bs totalexe}, \texttt{\bs note*} and \texttt{\bs note}}
%
% \label{note}
% To give a more detailed marking scheme, we get
% the following commands.
%
% \medskip
% \DescribeMacro{\totalexe}
% |\totalexe|\marg{num} displays the total number of points of an exercise,
% by default inside an oval box, with the word ``\ptsname'' (or ``\ptname'') 
% added and in bold red.
% In the next example, the exercise title has been obtained with |\exercise[\totalexe{4}]|.
%
% \medskip
% \DescribeMacro{\note*} 
% For each answer or solution in the correct version, the command
% |\note*|\marg{num} states the number of points of that question.
% The appearance is somewhat different from the one obtained with |\pts|:
% by default the number is displayed without being followed by ``\ptsname'' or ``\ptname'',
% without parenthesis, and in bold. 
% In the answer 3 of the next example, just after |\item|, we used: |\note*{1.5}|.
%
% \medskip
% \DescribeMacro{\note}
% The |\note|\marg{comment} macro is used to give details about the marking scheme
% and to indicate how points are awarded.
% In a comment argument you can use |\\| to get a line break,
% or even |\\[|\meta{height}|]| to increase the line break from \meta{height}.
%
% \DescribeMacro{\note\oarg{num}}
% It is often convenient to put |\note*|\marg{num}|\note|\marg{comment} 
% at the beginning of an answer. In that case \LaTeX\ will place the margin
% notes one under the other and will protest with: 
% \texttt{LaTeX Warning: Marginpar on page \ldots\@ moved.} \\
% This is not a real problem because generally \LaTeX\ is able to
% manage the placement of these
% marginal notes, one below the other. Nevertheless, one can avoid unnecessary protests by 
% compacting both commands in a single one and typing the number of points
% as an optional argument of note:
% |\note|\oarg{num}\marg{comment}.
%
% The first comment on the following example is obtained (just after |\item|) with\\
% |\note[1]{0.5 for the anti-derivative\\0.5 for simplifying}|.
%
% \exercise[\totalexe{4}] \label{totalexe}
% \begin{questions}
% \psframe(-3.5,1.3)(12.75,-14)
% For each following question, say if the assertion is true or false.
% Justify the answer carefully.
% \begin{tablenum1}
% \item $\ds \int_{0}^{\sqrt{3}}\frac{1}{x+\sqrt{3}} \,\mathrm{d}x = \ln 2$,
% \item $\ds \int_{2}^{\mathrm{e}} \frac{1}{x\ln x} \,\mathrm{d}x = -\ln 2$,
% \item* The function $F$ defined on $\mathbf{R}$ by 
% $F(x) = \ds \int_{0}^{x}\frac{1}{t^2+t+1}\,\mathrm{d} t$ is increasing on $\mathbf{R}$.
% \end{tablenum1}
% \end{questions}
% 
% \begin{answers}
% \begin{enumerate}
%    \item \note[1]{0.5 for the anti-derivative\\0.5 for simplifying}
%    We calculate:
%    \[ \int_{0}^{\sqrt{3}}\frac{1}{x+\sqrt{3}}\,\mathrm{d}x
%        = \bigg[ \ln\left(x+\sqrt{3}\right) \bigg]_0^{\sqrt{3}}
%        = \ln\left(2\sqrt{3}\right)-\ln \sqrt{3}
%        = \ln\left(\frac{2 \sqrt{3}}{\sqrt{3}}\right)
%        =\ln 2.
%    \]
%    \textbf{TRUE}.
%
%    \item \note[1.5]{1 for the anti-derivative \\0.5 for final value \\[2ex]
%        other method: $\frac{1}{x \ln x} >0$ on $[2, \mathrm{e}]$ 
%        whereas $-\ln2<0$
%    }
%    We have $\ds\frac{1}{x \ln x}= \frac{\frac{1}{x}}{\ln x}= \frac{u'(x)}{u(x)}$
%    with $u(x)=\ln x$, which is positive on $[2, \mathrm{e}]$. Hence
%
%    \[ \int_{2}^{\mathrm{e}}\frac{1}{x \ln x}\,\mathrm{d}x
%        = \Big[ \ln(\ln x) \Big]_2^\mathrm{e}
%        = \ln(\ln \mathrm{e})-\ln(\ln2)= \ln1 -\ln(\ln2)=-\ln(\ln2).
%    \]
%    \textbf{FALSE}.
%
%    \item \note*{1.5}
%    The function $F$ defined on $\mathbf{R}$ by
%    \[ F(x)= \int_{0}^{x}\frac{1}{t^2+t+1}\, \mathrm{d}t \]
%    is derivable on $\mathbf{R}$ and its derivative is such that
%    $F'(x)=\frac{1}{x^2+x+1}$.
%    \note{0.5 for $F'$\\1 for the sign of $F'$ and conclusion}
%    The denominator is a quadratic polynomial, always positive because its discriminant is
%    $\Delta=-3 <0$.
%    Thus $F$ is increasing on $\mathbf{R}$. \\
%    \textbf{TRUE}.
% \end{enumerate}
% \end{answers}
% In the comment of answer 2, a wider vertical space is produced at line break
% with the optional argument |\\[2ex]|.
% The last comment, not placed beside the number of points of answer 3,
% has been produced by placing on the first line after the formula:
% |\note{0.5 for $F'$\\1 for the sign of $F'$ and conclusion}|.
%
% \medskip
% \DescribeMacro{markingcolor} \DescribeMacro{\markingstyle} \DescribeMacro{\ptsboxlength}
% The points display color, in |\totalexe| and |\note*|,
% is defined by \texttt{markingcolor}
% and the style by |\markingstyle|, which are modifiable.
% The oval box produced by |\totalexe| is obtained with the |\ovalbox| command
% of the \textsf{fancybox} package (by Timothy Van Zandt),
% with corner arcs set by |\cornersize{1}|.
% The length of the box is not adjusted to content but depends on the value
% of |\ptsboxlength| in order to keep uniform appearance
% from one exercise to the other.
%
% \medskip
% \DescribeMacro{notecolor} \DescribeMacro{\notestyle} 
% Comment notes are typeset by default in a dark green color
% defined by |\definecolor{notecolor}{rgb}{0.0,0.4,0.0}|.
% The style of the comment is set by the |\notestyle| macro.
%
% \subsection{Margin notes options} \label{margin}
%
% \DescribeMacro{[display=\meta{opt}]}
% The \texttt{display} key option controls how the marking scheme
% will be displayed: as seen previously (subsection \ref{pts}), 
% \texttt{display=none} displays nothing. With \texttt{display=pts}
% the numbers passed as argument to |\pts|, |\totalexe|, |\note*|
% or as optional argument of |\note|\oarg{num}\texttt{\{...\}} will be displayed.
% The last possible value is \texttt{display=notes} which displays the full marginal
% notes with points and comments (the mandatory argument of |\note|)
% as seen in the previous example.
%
% \medskip
% \DescribeMacro{[marginpos=\meta{opt}]}
% As seen previously in subsection \ref{pts}, the side where to place the scale is controlled 
% by the \texttt{marginpos} key option
% whose possible values are \texttt{left} and \texttt{right} 
% (or \texttt{inner} and \texttt{outer} if the document is in two side mode).
%
% \medskip
% \DescribeMacro{[marginwidth=\meta{opt}]}
% The key option \texttt{marginwidth} controls margins layout. 
% The possible values are
% \texttt{standard}, \texttt{expand} or \texttt{unset}.
%
% This option has no effect when \texttt{display=none}.
% In that case, left and right margins have same width,
% except for a two side mode document for which the ratio between left and right
% margin is 2:3. 
% Otherwise the key \texttt{marginwidth} acts as follow:
% \begin{description}
% \item[\texttt{standard}] 
% The left margin is enlarged and the 
% right one is reduced, with a ratio of 3:2 (or 2:3 if \texttt{marginpos=left}).
% The text body is shifted without altering the text width.
% The margin paragraph width remains relatively short; it depends also on page geometry.
% This option is not suitable for verbose comments.
% 
% \item[\texttt{expand}] It is the default value.
% The behavior is the same than with the
% \texttt{standard} value if \texttt{display=pts}, but if \texttt{display=notes}
% the margin is expanded with a ratio of 3:1 (or 1:3) and margin paragraph width
% is increased.
%
% \item[\texttt{unset}] The previous settings may not suit to anyone, 
% so you have this other option.
% In that case, no setting will be proceeded on the margin width and you
% can make your own setting. For that, you have the convenient macro |\geometry|
% from the \textsf{geometry} package (by Hideo Umeki).
% For example you can put in the preamble 
% \centeredline{|\geometry{hmarginratio=2:1,marginparwidth=2.5cm}|.}
%
% If \texttt{marginpos=right}, you must invert the ratio, \eg 1:2 instead of 2:1.
% If \texttt{marginwidth} is not set to \texttt{unset}, 
% such a command will have no effect.
% \end{description}

% The margin settings are valid
% for the whole document and must be set in the preamble.
%
% \medskip
% \DescribeMacro{[noteragged=\meta{opt}]}
% For the mandatory argument of |\note|, text alignment in margins 
% is controlled by the package option \texttt{noteragged},
% which can take the following values: 
% \texttt{left}, \texttt{right}, \texttt{center}, \texttt{justify} or \texttt{twoside}.
% The default value is \texttt{noteragged=left}. It means that the text 
% is right aligned, which is a common behavior for text in the left margin;
% \texttt{noteragged=right} yields a left aligned text;
% \texttt{justify} means that the text is justified, which is the default setting
% of \LaTeX\ marginal notes. 
% Finally \texttt{noteragged=twoside} is equivalent to \texttt{noteragged=left} for odd pages
% and \texttt{noteragged=right} for even pages, if the document is in two side mode.
% It has no effect otherwise (the default value \texttt{noteragged=left} will be taken
% and a warning message appears in the shell).
%
% When \texttt{display} is not set to \texttt{notes}, the \texttt{noteragged} option
% has no effect because it concerns only text put in mandatory argument of |\note|.
% 
% \subsection{The \texttt{\bs totalpoints} command} \label{totalpoints}
%
% \DescribeMacro{\totalpoints}
% The |\totalpoints|\marg{num} macro is intended
% to replace |\points| when using a detailed marking scheme.
% When the scale is not displayed,
% it is equivalent to |\points| and when the scale is displayed,
% it is equivalent to |\totalexe|.
% For example, in the exercise \ref{totalexe}, we should use
% |\totalpoints| rather than |\totalexe|,
% because, when the detailed marking scheme is not displayed, the total points will be typeset
% as in the exercise \ref{points} rather than in the margin.
%
% \subsection{Marking scheme consistency checking}\label{scale}
%
% \DescribeMacro{[checkpts=\meta{bool}]}
% The marking scheme can be checked
% \footnote{Thanks to Denis Bitouzé for his suggestion about this feature.}
% with the keyval option \texttt{[checkpts=true]},
% the default value is \texttt{false}.
%
% \medskip
% For each exercise, the sum of points awarded for each question (with |\pts|, |\note*|
% or |\note[ ]| is compared to the total of the exercise given in 
% |\points|, |\totalexe| or |totalpoints|.
% A warning message appear in the shell to indicate if the scale is valid or not
% for the exercise. For example:
% \begin{center}
% \texttt{Package exesheet warning: Exercise 3: sum of points is 4.5pt instead of 5pt.}
% \end{center}
% Depending on your language, you can use comma notation numbers (4,5 as well as 4.5).
% The checking takes place at the beginning of the next exercise. If no points are specified
% for the questions, no warning message will be displayed at this level.
%
% \medskip
% \DescribeMacro{\totalsheet}
% At the end of the sheet, the last exercise is checked, then a global checking
% is made on the whole sheet. For that, the total points of the sheet must be specified
% in the preamble with the |\totalsheet|\marg{total} macro
% (else you get a warning message).
% If subtotal points have been awarded for exercises, the global comparison
% is between the sum of these subtotals and the total of points recorded
% with the |\totalsheet| macro.
% If not, the audit covers the sum of points awarded for each individual question.
% A warning message indicates the result of this last checking.
% Finally a last message indicate if all the scale controls have been successfully
% passed or not.
%
% \section{Options} \label{options}
%
% \subsection{Summary of available options}
%
% Here we present a summary table of available options. Explanations of use
% are given in the corresponding sections.
% The default value is typeset in bold.
%
% \begin{center} \ttfamily
% \setlength{\extrarowheight}{1pt}
% \begin{tabular}{llc}
% \hline
% \textsf{Key} & \textsf{Possible values} & \textsf{See section} \\
% \hline
% exetoc & \textbf{true}, false & \ref{toc} \\
% setlist & \textbf{true}, false & \ref{setlist} \\
% output & questions, answers, \textbf{both} & \ref{output} \\
% answerspace & true, \textbf{false} & \ref{answerspace}\\
% display & \textbf{none}, pts, notes & \ref{pts}, \ref{margin} \\
% marginpos & \textbf{left} (inner), right (\textbf{outer}) & \ref{pts}, \ref{margin} \\
% marginwidth & standard, \textbf{expand}, unset &  \ref{margin} \\
% noteragged & \textbf{left}, right, center, justify, twoside & \ref{margin} \\
% checkpts & true, \textbf{false} & \ref{scale} \\
% correct & true, \textbf{false}, conditional & \hyperlink{correct}{see below} \\
% \hline
% \end{tabular}
% \end{center}
%
% When an invalid key is passed, an error is produced, but
% when a value is not recognized, a warning message occur:\\
% \texttt{Value `\meta{value}'\ is not supported by option `\meta{key}'\ 
% on input line \ldots} \\
% For each option, you can set them with class or package calling: \eg \\
% |\usepackage[output=answers,display=notes,noteragged=right]{exesheet}|
%
% \bigskip
% \DescribeMacro{\exesheetset}
% You can also use the |\exesheetset|\{list of \meta{key}=\meta{value} options\}
% command.
% Nevertheless, only the options \texttt{output}, \texttt{answerspace}, \texttt{display}, 
% and \texttt{noteragged}, 
% can be changed dynamically, even in the document body, although this is not really expected.
% The others are usable in the preamble only.
% Dynamic options are processed at each call, the others will be processed once,
% at begin document.
% \hypertarget{correct}{}
%
% \bigskip
% \DescribeMacro{[correct=\meta{opt}]} 
% A special option, \texttt{correct}, can be used only when calling the \textsf{exesheet}
% class or in combination with the \textsf{schooldocs} package.
% Its effect is to add ``\correctname'' (or its translation)
% in the document title and headers.
% Possible values are: \texttt{true}, \texttt{false} (by default) or \texttt{conditional}.
% The value \texttt{correct=conditional}, means \texttt{true} if answers are displayed,
% \texttt{false} otherwise.
%
% \subsection{Alternative (deprecated) commands}
% 
% Previously to version 2.0, we used some special commands to set output and display options.
% Thanks to a suggestion of Maxime Chupin, keyval options have been implemented 
% in the package.
% Although the latter is more convenient,
% the old commands will be presented here
% and maintained for now, for compatibility reasons.
% When using them, a warning message will appear, but these commands still work.
% However previous options \texttt{nosetlist} and \texttt{notoc}
% are no longer supported.
%
% \bigskip
% \DescribeMacro{\questionsonly} \DescribeMacro{\answersonly}
% These two commands are equivalent to respectively \texttt{output=questions} 
% and \texttt{output=answers}.
%
% \medskip
% \DescribeMacro{\displaypts} \DescribeMacro{\displaypoints} 
% These two commands are now equivalent to \texttt{display=pts}.
%
% \medskip
% \DescribeMacro{\displaynotes}\DescribeMacro{\displaynotesright}
% These two commands mean \texttt{display=notes}
% and moreover \texttt{marginpos=right} for the latter.
%
% \StopEventually{}
%
% \section{Implementation}
%
% \subsection{Options and required packages}
% The \texttt{exesheet} class is based on the \texttt{article} class
% and passes to it all its unknown options.
% |\ProcessKeyvalOptions*| is useless in class, will be done by the package.
%    \begin{macrocode}
%<*class>
\RequirePackage{kvoptions}
\DeclareBoolOption[true]{exetoc}
\DeclareBoolOption[true]{setlist}
\DeclareStringOption[both]{output}
\DeclareStringOption[none]{display}
\DeclareBoolOption[false]{answerspace}
\DeclareStringOption[left]{marginpos}
\DeclareStringOption[expand]{marginwidth}
\DeclareStringOption[left]{noteragged}
\DeclareBoolOption[false]{checkpts}
\DeclareStringOption[false]{correct}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions \relax
\LoadClass{article}
\RequirePackage{exesheet}
\RequirePackage{schooldocs}
%</class>
%    \end{macrocode}
%
% Then options are defined thanks to \textsf{kvoptions} package (based on \textsf{keyval}).
% String options are processed in separate macros 
% defined in the corresponding sections of each.
% These process macros will be executed when package is loaded
% (at end of package because |\exs@process...| aren't recognized at the beginning),
% or at begin document for options whose
% effect cannot be changed dynamically
% and must be set in the preamble
% (they will be processed once).
%
% A special case is \texttt{setlist} when used with \textsf{babel-french}.
% It will then be processed immediately and disabled (see below for explanations).
% 
%    \begin{macrocode}
%<*package>
\@ifclassloaded{exesheet}{}{
    \RequirePackage{kvoptions}
    \DeclareBoolOption[true]{exetoc}
    \DeclareBoolOption[true]{setlist} 
    \DeclareStringOption[both]{output}
    \DeclareStringOption[none]{display}
    \DeclareBoolOption[false]{answerspace}
    \DeclareStringOption[left]{marginpos}
    \DeclareStringOption[expand]{marginwidth}
    \DeclareStringOption[left]{noteragged}
    \DeclareBoolOption[false]{checkpts}
    \DeclareStringOption[false]{correct}
}

\ProcessKeyvalOptions*

\def\exs@process@dynoptions{
    \exs@process@output
    \exs@process@display 
    \exs@process@noteragged
}

\AtEndOfPackage{\exs@process@dynoptions}
\AtBeginDocument{
    \newif\ifexesheet@multicol
    \@ifpackageloaded{multicol}{
        \exesheet@multicoltrue}{\exesheet@multicolfalse}
        % to set the rule to the right color in answers environments
    \exs@process@setlist
    \exs@process@marginpos
    \exs@process@marginwidth
    \exs@process@checkpts
    \exs@process@correct
    \DisableKeyvalOption[action=warning,package=exesheet]{exesheet}{setlist}
    \DisableKeyvalOption[action=warning,package=exesheet]{exesheet}{marginpos}
    \DisableKeyvalOption[action=warning,package=exesheet]{exesheet}{marginwidth}
    \DisableKeyvalOption[action=warning,package=exesheet]{exesheet}{checkpts}
    \DisableKeyvalOption[action=warning,package=exesheet]{exesheet}{correct}
}

%    \end{macrocode}
% \begin{macro}{\exesheetset}
% The macro |\exesheetset| can receive keyval options.
% It can be used anywhere in the document to modify some settings,
% but has no effect on non dynamic options if called outside the preamble;
% thanks to |\DisableKeyValOption| a warning message occur in that case.
%    \begin{macrocode}  
\def\exesheetset#1{\setkeys{exesheet}{#1}\exs@process@dynoptions}

%    \end{macrocode}
% \end{macro}
% Now we load several packages.
% The \texttt{shortlabel} option in the \textsf{enumitem} package allows to use labels like in 
% the \textsf{enumerate} package \eg 1., a), A. etc.
% The \textsf{mparhack} package (by Tom Sgouros and Stefan Ulrich)
% is loaded only for two side mode documents.
%    \begin{macrocode}
\RequirePackage{ifthen}
\RequirePackage{geometry}
\RequirePackage{xcolor}
\RequirePackage[shortlabels]{enumitem}
\RequirePackage{tasks}
\RequirePackage{versions}
\RequirePackage{fancybox}
\RequirePackage{translations}
\RequirePackage{ragged2e}
\ifthenelse{\boolean{@twoside}}{\RequirePackage{mparhack}}{}

%    \end{macrocode}
%
% \subsection{Internationalization}
% Here we define keywords and their translation in French, German, Spanish
% Italian, Portuguese, thanks to macros of the \textsf{translations} package 
% by Clemens Niederberger. It detects the used language 
% loaded by \textsf{babel} or \textsf{polyglossia}.
%
% Accented characters cannot be used here because they are not recognized 
% if \textsf{inputenc} is loaded after \textsf{exesheet}.
% So we have used basic \LaTeX\ control sequences to produce them.
%
%    \begin{macrocode}
\DeclareTranslationFallback{exesheet-exercise}{Exercise}
\DeclareTranslationFallback{exesheet-subpart}{Part}
\DeclareTranslationFallback{exesheet-annex}{Annex}
\DeclareTranslationFallback{exesheet-ex}{Ex}
\DeclareTranslationFallback{exesheet-points}{points}
\DeclareTranslationFallback{exesheet-point}{point}
\DeclareTranslationFallback{exesheet-correction}{Correction}
\DeclareTranslationFallback{exesheet-pts}{pts}
\DeclareTranslationFallback{exesheet-pt}{pt}

\DeclareTranslation{English}{exesheet-exercise}{Exercise}
\DeclareTranslation{English}{exesheet-subpart}{Part}
\DeclareTranslation{English}{exesheet-annex}{Annex}
\DeclareTranslation{English}{exesheet-ex}{Ex}
\DeclareTranslation{English}{exesheet-points}{points}
\DeclareTranslation{English}{exesheet-point}{point}
\DeclareTranslation{English}{exesheet-correction}{Correction}
\DeclareTranslation{English}{exesheet-pts}{pts}
\DeclareTranslation{English}{exesheet-pt}{pt}

\DeclareTranslation{French}{exesheet-exercise}{Exercice}
\DeclareTranslation{French}{exesheet-subpart}{Partie}
\DeclareTranslation{French}{exesheet-annex}{Annexe}
\DeclareTranslation{French}{exesheet-ex}{Ex}
\DeclareTranslation{French}{exesheet-points}{points}
\DeclareTranslation{French}{exesheet-point}{point}
\DeclareTranslation{French}{exesheet-correction}{Correction}
\DeclareTranslation{French}{exesheet-pts}{pts}
\DeclareTranslation{French}{exesheet-pt}{pt}

\DeclareTranslation{German}{exesheet-exercise}{\"Ubung}
\DeclareTranslation{German}{exesheet-subpart}{Teil}
\DeclareTranslation{German}{exesheet-annex}{Anhang}
\DeclareTranslation{German}{exesheet-ex}{\"Ub}
\DeclareTranslation{German}{exesheet-points}{Punkte}
\DeclareTranslation{German}{exesheet-point}{Punkt}
\DeclareTranslation{German}{exesheet-correction}{Verbesserung}
\DeclareTranslation{German}{exesheet-pts}{P.}
\DeclareTranslation{German}{exesheet-pt}{P.}

\DeclareTranslation{Spanish}{exesheet-exercise}{Ejercicio}
\DeclareTranslation{Spanish}{exesheet-subpart}{Parte}
\DeclareTranslation{Spanish}{exesheet-annex}{Anexo}
\DeclareTranslation{Spanish}{exesheet-ex}{Ej}
\DeclareTranslation{Spanish}{exesheet-points}{puntos}
\DeclareTranslation{Spanish}{exesheet-point}{punto}
\DeclareTranslation{Spanish}{exesheet-correction}{Correcci\'on}
\DeclareTranslation{Spanish}{exesheet-pts}{ptos}
\DeclareTranslation{Spanish}{exesheet-pt}{pto}

\DeclareTranslation{Italian}{exesheet-exercise}{Esercizio}
\DeclareTranslation{Italian}{exesheet-subpart}{Parte}
\DeclareTranslation{Italian}{exesheet-annex}{Annesso}
\DeclareTranslation{Italian}{exesheet-ex}{Es}
\DeclareTranslation{Italian}{exesheet-points}{punti}
\DeclareTranslation{Italian}{exesheet-point}{punto}
\DeclareTranslation{Italian}{exesheet-correction}{correzione}
\DeclareTranslation{Italian}{exesheet-pts}{pti}
\DeclareTranslation{Italian}{exesheet-pt}{pt}

\DeclareTranslation{Portuges}{exesheet-exercise}{Exerc\'icio}
\DeclareTranslation{Portuges}{exesheet-subpart}{Parte}
\DeclareTranslation{Portuges}{exesheet-annex}{Anexo}
\DeclareTranslation{Portuges}{exesheet-ex}{Ex}
\DeclareTranslation{Portuges}{exesheet-points}{pontos}
\DeclareTranslation{Portuges}{exesheet-point}{ponto}
\DeclareTranslation{Portuges}{exesheet-correction}{Corre\c c\~ao}
\DeclareTranslation{Portuges}{exesheet-pts}{pts}
\DeclareTranslation{Portuges}{exesheet-pt}{pt}

\newcommand*\exercisename{\GetTranslation{exesheet-exercise}}
\newcommand*\subpartname{\GetTranslation{exesheet-subpart}}
\newcommand*\annexname{\GetTranslation{exesheet-annex}}
\newcommand*\exname{\GetTranslation{exesheet-ex}}
\newcommand*\pointsname{\GetTranslation{exesheet-points}}
\newcommand*\pointname{\GetTranslation{exesheet-point}}
\newcommand*\correctionname{\GetTranslation{exesheet-correction}}
\newcommand*\ptsname{\GetTranslation{exesheet-pts}}
\newcommand*\ptname{\GetTranslation{exesheet-pt}}

%    \end{macrocode}
%
% \subsection{Titles}
%
% The \texttt{exercise} counter numbers exercises for the whole document 
% regardless of any section.
% To reset the counter at some point, just write |\setcounter{exercise}{0}|
% and for an automatic reset at each section,
% add in the preamble \\
% |\makeatletter \@addtoreset{exercise}{section} \makeatother|.
%
% The parts counter depends on \texttt{exercise} and is reset
% at each new exercise.
%
% Commands |\labelexercisestyle| and |\labelsubpartstyle|
% are empty, but allow to personalize the style, for instance:\\
% |\renewcommand\labelexercisestyle{\sffamily}|.
%
% The |\exe@check| macro checks the marking scheme, it will be defined
% in section \ref{MSoptions}.
% By default, the table of contents displays the titles of exercises and parts,
% |\ifexesheet@exetoc| is \texttt{true}.
% To display in it only exercise titles but not parts,
% place in the preamble |\setcounter{tocdepth}{2}|.
%
% \begin{macro}{\exercise}
%    \begin{macrocode}
\newcounter{exercise}

\newcommand{\labelexercise}{\exercisename\space \theexercise}
\newcommand{\labelexercisestyle}{}
\newcommand*{\@exercise}[1][]{%
    \ifexesheet@checkpts \exe@check{\labelexercise} \fi
    % curiously the \execheck must be done before \refstepcounter !
    \refstepcounter{exercise}
    \subsection*{\labelexercisestyle\labelexercise\enskip #1}
    \ifexesheet@exetoc
        \addcontentsline{toc}{subsection}{\labelexercise}
    \fi
}
\newcommand*{\@@exercise}[2][]{%
    \ifexesheet@checkpts \exe@check{#2} \fi
    \subsection*{\labelexercisestyle #2\enskip #1}
    \setcounter{subpart}{0} % resets the parts counter
    \ifexesheet@exetoc
        \addcontentsline{toc}{subsection}{#2}
    \fi
}
\newcommand{\exercise}{\@ifstar{\@@exercise}{\@exercise}}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\subpart}
%    \begin{macrocode}
\newcounter{subpart}[exercise] %
\renewcommand{\thesubpart}{\Alph{subpart}}

\newcommand{\labelsubpart}{\subpartname~\thesubpart}
\newcommand{\labelsubpartstyle}{}
\newcommand*{\@subpart}[1][]{%
    \refstepcounter{subpart}%
    \subsubsection*{\labelsubpartstyle\labelsubpart\enskip #1}
    \ifexesheet@exetoc
        \addcontentsline{toc}{subsubsection}{\labelsubpart}
    \fi
}
\newcommand*{\@@subpart}[2][]{%
    \subsubsection*{\labelsubpartstyle #2\enskip #1}
    \ifexesheet@exetoc
        \addcontentsline{toc}{subsubsection}{#2}
    \fi
}
\newcommand{\subpart}{\@ifstar{\@@subpart}{\@subpart}}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\annex}
%    \begin{macrocode}
\newcommand{\annexstyle}{\MakeUppercase}
\newcommand*{\annex}[1][]{%
    \subsection*{\mbox{}\hfill\annexstyle{\annexname} #1\hfill\mbox{}}
    \ifexesheet@exetoc
        \addcontentsline{toc}{subsection}{\annexname}
    \fi
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\exe}
%    \begin{macrocode}
\newcommand{\exlabel}{\exname.~\theexercise}
\newcommand{\exsepmark}{---}
\newcommand{\@exe}{\bigskip\refstepcounter{exercise}
    \par\noindent\textbf{\exlabel~\exsepmark}~}
\newcommand{\@@exe}{\bigskip\refstepcounter{exercise}
    \par\noindent\textbf{\exlabel}~}
\newcommand{\exe}{\@ifstar{\@@exe}{\@exe}}

%    \end{macrocode}
% \end{macro}
%
% \subsection{Enumerations and lists}
%
% \begin{macro}{\exenumerate}
% The |\setlist| command comes from the \textsf{enumitem} package
% (|\setenumerate| is obsolete). By default |itemsep=1ex| for lists of first level,
% and |leftmargin=1.5em| allows to align labels on the start of lines.
%    \begin{macrocode}
\newenvironment{exenumerate}[1][]{%
    \setlist[enumerate]{font=\bfseries}
    \setlist[enumerate,1]{leftmargin=1.5em,
        itemsep=3ex plus 1ex minus 1ex,topsep=3ex plus 1ex minus 1ex}
    \setlist[enumerate,3]{noitemsep,nolistsep}
    \setlist[itemize]{noitemsep,nolistsep}
    \begin{enumerate}[#1]
        }{\end{enumerate}}

%    \end{macrocode}
% \end{macro}
% When using \textsf{babel} with the option \texttt{french},
% \texttt{itemize} lists are modified with the same dash label for each list level. 
% These modifications are canceled here to restore default 
% \LaTeX\ \texttt{itemize} lists (labels and spaces).
% We have create the |\standardfrenchlists| command which must be called into
% |AtBeginDocument| or not, depending on whether
% \textsf{exesheet} is loaded before \textsf{babel} or after.
%    \begin{macrocode}
\newcommand\standardfrenchlists{%
    \@ifpackagewith{babel}{french}{
        \frenchsetup{StandardLists=true}
    }{}
}
\ifexesheet@setlist
    \standardfrenchlists % necessary when exesheet is loaded after babel
    \DisableKeyvalOption[action=warning,package=exesheet]{exesheet}{setlist}
\fi

\def\exs@process@setlist{% must be executed at begin document
  \ifexesheet@setlist
    \standardfrenchlists % if exesheet is loaded before babel package
    \setlist[enumerate]{font=\bfseries}
    \setlist[enumerate,1]{topsep=1.5ex plus 1ex minus 1ex,leftmargin=1.5em}
  \fi
%    \end{macrocode}

% \DescribeEnv{tablenum1} \DescribeEnv{tablenuma}
% The |\NewTasks| command comes from the \textsf{tasks} package.
% It allows to define environments \texttt{tablenum1}, \texttt{tablenuma}
% and \texttt{tablitem}.
% Horizontal spaces are adjusted to get good alignments with
% items of other \texttt{enumerate} (or \texttt{itemize}) environments.
%    \begin{macrocode}
  \ifexesheet@setlist
    \NewTasksEnvironment[label=\arabic*.,label-format=\bfseries,
        column-sep=1em,label-align=right,
        item-indent=1.5em,label-width=1em,label-offset=0.5em,
        after-item-skip=0.5ex plus 0.5ex minus 0.5ex]{tablenum1}[\item](2)
    \NewTasksEnvironment[label=(\alph*),label-format=\bfseries,
        column-sep=1em,label-align=right,
        item-indent=2.15em,label-width=1.6em,label-offset=0.5em,
        after-item-skip=0.5ex plus 0.5ex minus 0.5ex]{tablenuma}[\item](2)
  \else
    \NewTasksEnvironment[label=\arabic*.,
        column-sep=1em,
        after-item-skip=0.5ex plus 0.5ex minus 0.5ex]{tablenum1}[\item](2)
    \NewTasksEnvironment[label=(\alph*),
        column-sep=1em,label-align=right,
        item-indent=2.15em,label-width=1.6em,label-offset=0.5em,
        after-item-skip=0.5ex plus 0.5ex minus 0.5ex]{tablenuma}[\item](2)
  \fi
} % end of macro \exs@process@setlist

%    \end{macrocode}
% \DescribeEnv{tablitem}
%    \begin{macrocode}
\NewTasksEnvironment[label=\labelitemi,
    label-align=right,
    item-indent=2.3333em,label-offset=0.5em,
    after-item-skip=0.5ex plus 0.5ex minus 0.5ex]{tablitem}[\item](2)

%    \end{macrocode}
% \DescribeEnv{colsenum}
%    \begin{macrocode}
\newenvironment{colsenum}[2][]{%
    \setlength{\multicolsep}{2ex}
    \raggedcolumns % default is \flushcolumns
    \begin{multicols}{#2} % #2 = number of columns
    \begin{enumerate}[#1] % #1 = options of enumerate
    }{
    \end{enumerate}
    \end{multicols}
}

%    \end{macrocode}
% \DescribeEnv{colsenum*}
%    \begin{macrocode}
\newenvironment{colsenum*}[2][]{%
    \setlength{\multicolsep}{2ex}
    \begin{multicols}{#2} % #2 = number of columns
    \begin{enumerate}[#1] % #1 = options of enumerate
    }{
    \end{enumerate}
    \end{multicols}
}

%    \end{macrocode}
% \DescribeEnv{colsitem}
%    \begin{macrocode}
\newenvironment{colsitem}[2][]{%
    \setlength{\multicolsep}{2ex}
    \raggedcolumns
    \begin{multicols}{#2}
    \begin{itemize}[#1]
    }{
    \end{itemize}
    \end{multicols}
}

%    \end{macrocode}
% \DescribeEnv{colsitem*}
%    \begin{macrocode}
\newenvironment{colsitem*}[2][]{%
    \setlength{\multicolsep}{2ex}
    \begin{multicols}{#2}
    \begin{itemize}[#1]
    }{
    \end{itemize}
    \end{multicols}
}

%    \end{macrocode}
%
% \subsection{Questions and answers}
%
% \begin{macro}{\exs@process@output}
% |exesheet@questions| and |exesheet@answers| booleans
% control the display of corresponding environments.
% They are set by the \texttt{output} key option in the
% |\exs@process@output| macro.
%    \begin{macrocode}
\newboolean{exesheet@questions}\setboolean{exesheet@questions}{true}
\newboolean{exesheet@answers}\setboolean{exesheet@answers}{true}

\def\exs@process@output{
    \ifthenelse{\equal{\exesheet@output}{questions}}{
        \setboolean{exesheet@questions}{true}
        \setboolean{exesheet@answers}{false}
    }{% else if
    \ifthenelse{\equal{\exesheet@output}{answers}}{
        \setboolean{exesheet@questions}{false}
        \setboolean{exesheet@answers}{true}
    }{% else if
    \ifthenelse{\equal{\exesheet@output}{both}}{
        \setboolean{exesheet@questions}{true}
        \setboolean{exesheet@answers}{true}
    }{% else
    \PackageWarning{exesheet}{Value `\exesheet@output'
         is not supported by option `output'}
    }}}
}

%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{questions}
% We use the \textsf{versions} package  by Uwe Lück
% who provides |\comment| and |\endcomment| macros, 
% that allow the magic of conditional displays (we can also find them 
% in \textsf{verbatim} or \textsf{version} packages).
% The noteworthy \textsf{codesection} package, allows to encapsulate 
% optional code between the macros |\BeginCodeSection|\marg{skip} 
% and |\EndCodeSection|\marg{skip},
% both in the text body and in the preamble,
% but these macros cannot be used inside an environment 
% as we did here for |\comment| and |\endcomment|.
%
% Some tests are made by |\ifthenelse{\bolean{...}}|
% because |\comment| and |\endcomment| causes some hassle 
% with the \TeX\ structure |\if| \ldots |\else| \ldots |\fi|.
% The two counters |exe@ini| and |subpart@ini| are used in
% the following |\set@toclevel| macro.
%    \begin{macrocode}
\newcounter{exe@ini}
\newcounter{subpart@ini}

\newenvironment{questions}{
    \ifthenelse{\boolean{exesheet@questions}}{%
        \setcounter{exe@ini}{\value{exercise}}
        \setcounter{subpart@ini}{\value{subpart}}
    }{\comment}
}{\ifthenelse{\boolean{exesheet@questions}}{}{\endcomment}}

%    \end{macrocode}
% \end{environment}
% \begin{environment}{answers}
% The internal macro |\set@toclevel| calculates the title level (counter |toc@level|)
% to get a correct typesetting of the word ``\correctionname'' at the start of an
% \texttt{answers} environment (when \texttt{questions} and \texttt{answers} are
% displayed together). The principle is to compare the state of counters
% \texttt{exercise} and \texttt{subpart} with those saved at the time of
% the call of the \texttt{questions} environment. The |\@enumdepth| counter indicates the 
% \texttt{enumerate} list level in which we are (0 = out of lists).
% The optional parameter of the \texttt{answers} environment allows to force this title level.
%    \begin{macrocode}
\newcounter{@toclevel}
\newcommand{\set@toclevel}[1][]{
    \ifthenelse{\equal{#1}{}}{
        \ifthenelse{\value{exercise} > \value{exe@ini}}{
            \setcounter{@toclevel}{1}
        }{% else
        \ifthenelse{\equal{\the\@enumdepth}{0}}{
            % we're not in an enumerate environment
            \ifthenelse{\(\value{subpart} > \value{subpart@ini}\)
                \or \(\value{subpart} = 0\)}{
              \setcounter{@toclevel}{2}
            }{\setcounter{@toclevel}{3}}
        }{\setcounter{@toclevel}{4}}}
    }{\setcounter{@toclevel}{#1}}}

%    \end{macrocode}
% The internal macro |\typeset@correctionname|,
% typesets the word ``\correctionname'' at the right level.
%    \begin{macrocode}
\definecolor{correctioncolor}{rgb}{0,0.2,0.6} % kind of dark blue
\newcommand{\correctionstyle}{\color{correctioncolor}}

\newcommand{\typeset@correctionname}{
    \ifthenelse{\value{@toclevel} = 1}{
        \section*{\correctionstyle\correctionname}
        \ifexesheet@exetoc
            \addcontentsline{toc}{section}{\correctionname}
        \fi
        \setcounter{exercise}{0}
    }{% else if
    \ifthenelse{\value{@toclevel} = 2}{%
        \subsection*{\correctionstyle\correctionname}
        \ifexesheet@exetoc
            \addcontentsline{toc}{subsection}{\correctionname}
        \fi
        \setcounter{subpart}{0}
    }{% else if
    \ifthenelse{\value{@toclevel} = 3}{%
        \subsubsection*{\correctionstyle\correctionname}
        \ifexesheet@exetoc
            \addcontentsline{toc}{subsubsection}{\correctionname}
        \fi
    }{% else
    \par\textbf{\correctionstyle\correctionname}\par
    }}}
}

%    \end{macrocode}
% Then we can write the \texttt{answers} environment.
%    \begin{macrocode}
\newenvironment{answers}[1][]{% #1 is the optional level
    \ifthenelse{\boolean{exesheet@answers}}{%
        \ifthenelse{\boolean{exesheet@questions}}{
            \set@toclevel[#1]
            \typeset@correctionname
            \correctionstyle%
            \ifexesheet@multicol
                \renewcommand{\columnseprulecolor}{\color{correctioncolor}}
            \fi
        }{}
    }{\comment}
}{\ifthenelse{\boolean{exesheet@answers}}{}{\endcomment}}

\newenvironment{answers*}{
    \ifthenelse{\boolean{exesheet@answers}}{}{\comment}
}{\ifthenelse{\boolean{exesheet@answers}}{}{\endcomment}}

%    \end{macrocode}
% In the \texttt{answers} environment, when placing |\correctionstyle|
% before |\subsubsection| (case of |\typeset@correctionname|),
% the preceding vertical space may be too wide.
% \end{environment}
%
% \begin{macro}{\question}
%    \begin{macrocode}
\newcommand{\question}[1]{\ifexesheet@questions #1\fi}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\answer}
%    \begin{macrocode}
\newcommand{\answer}[1]{%
    \ifexesheet@answers%
        \ifexesheet@questions \correctionstyle #1\else #1\fi
    \fi
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\answerspace}
% The \texttt{answerspace} macro was a suggestion of Maxime Chupin
% to permit students to write answers on the given paper.
%    \begin{macrocode}
\newcommand\answerspace[1]{
    \ifexesheet@answerspace \par\vspace{#1} \fi}

%    \end{macrocode}
% \end{macro}
%
% \subsection{Marking scheme options processing} \label{MSoptions}
%
% Options \texttt{display}, \texttt{marginpos}, \texttt{marginwidth} 
% and \texttt{noteragged} are processed with the following internal commands.
%
% \medskip
% The \texttt{display} key option sets the value of the two booleans
% |exesheet@pts| and |exesheet@notes|. 
% |exesheet@pts| controls the display of the content of |\pts| and of optional arguments
% of |\note|,
% whereas |exesheet@notes| controls mandatory arguments of |\note|.
%
% \begin{macro}{\exs@process@display}
%    \begin{macrocode}
\newboolean{exesheet@pts}
\newboolean{exesheet@notes}

\def\exs@process@display{
    \ifthenelse{\equal{\exesheet@display}{pts}}{
        \setboolean{exesheet@pts}{true}
        \setboolean{exesheet@notes}{false}
    }{% else if
    \ifthenelse{\equal{\exesheet@display}{notes}}{
        \setboolean{exesheet@pts}{true}
        \setboolean{exesheet@notes}{true}
    }{% else if
    \ifthenelse{\equal{\exesheet@display}{none}}{
        \setboolean{exesheet@pts}{false}
        \setboolean{exesheet@notes}{false}
    }{% else
    \PackageWarning{exesheet}{Value `\exesheet@display'
         is not supported by option `display'}
    }}}
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\exs@process@marginpos}
% The \texttt{marginpos} key option takes value \texttt{left} (the default) or \texttt{right}
% (or \texttt{inner} and \texttt{outer}). In practice \texttt{inner} is equivalent to
% \texttt{left}
% but, in two side mode, \texttt{left} (the default value) or \texttt{right} 
% are converted to \texttt{outer} (the default value for two side mode).
%    \begin{macrocode}
\newboolean{exesheet@leftmargin}

\def\exs@process@marginpos{
    \ifthenelse{\equal{\exesheet@marginpos}{left}}{
        \if@twoside%
            \PackageWarningNoLine{exesheet}{Default `marginpos' option
                \MessageBreak
                for two side documents is `outer'.\MessageBreak
                Use `inner' to change the side}
            \def\exesheet@marginpos{outer}
            \setboolean{exesheet@leftmargin}{false}
            \normalmarginpar
        \else% default
            \setboolean{exesheet@leftmargin}{true}
            \reversemarginpar
        \fi
    }{% else if
    \ifthenelse{\equal{\exesheet@marginpos}{right}}{
        \if@twoside%
            \PackageWarningNoLine{exesheet}{Default `marginpos' option
                \MessageBreak
                for two side documents is `outer'.\MessageBreak
                Use `inner' to change the side}
            \def\exesheet@marginpos{outer}
        \fi
        \setboolean{exesheet@leftmargin}{false}
        \normalmarginpar
    }{% else if
    \ifthenelse{\equal{\exesheet@marginpos}{inner}}{
        \setboolean{exesheet@leftmargin}{true}
        \reversemarginpar
    }{% else if
    \ifthenelse{\equal{\exesheet@marginpos}{outer}}{
        \setboolean{exesheet@leftmargin}{false}
        \normalmarginpar
    }{% else
    \PackageWarningNoLine{exesheet}{Value `\exesheet@marginpos'
         is not supported by option `marginpos'}
    }}}}
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\exs@process@marginwidth}
% The \texttt{marginwidth} option changes the ratio between left and right margins
% depending on what has to be displayed in the margin (only points or full 
% notes)
% \footnote{So that the effect on the margin ratio is correct, this option is processed
% at begin document, after other commands 
% that also could alter page geometry.}.
%
% When \texttt{display=notes}, the additional length \texttt{1\,in} matches 
% the default free space to the left of |\oddsidemargin|.
%
% The macros |\standardmarginwidthfactor| and |\largemarginwidthfactor|
% represent the ratio between total margin width and |\marginparwidth|.
%
%    \begin{macrocode}
\def\standardmarginwidthfactor{0.6}
\def\largemarginwidthfactor{0.8}

\newcommand*{\leftnotemarginwidth}[1]{
    \setlength{\marginparwidth}{\oddsidemargin}
    \addtolength{\marginparwidth}{1in}
    \addtolength{\marginparwidth}{-\marginparsep}
    \setlength{\marginparwidth}{#1\marginparwidth}
}

\newcommand*\rightnotemarginwidth[1]{
    \setlength{\marginparwidth}{\paperwidth}
    \addtolength{\marginparwidth}{-\textwidth}
    \addtolength{\marginparwidth}{-\oddsidemargin}
    \addtolength{\marginparwidth}{-\marginparsep}
    \addtolength{\marginparwidth}{-1in}
    \setlength{\marginparwidth}{#1\marginparwidth} 
}

\def\exesheet@smallmargins{
    \geometry{hmarginratio=1:1}
    \leftnotemarginwidth{\standardmarginwidthfactor} % right gives the same
}
\def\exesheet@standardmargins{
    \ifexesheet@leftmargin
        \geometry{hmarginratio=3:2}
        \leftnotemarginwidth{\standardmarginwidthfactor}
    \else
        \geometry{hmarginratio=2:3}
        \rightnotemarginwidth{\standardmarginwidthfactor}
    \fi
}
\def\exesheet@largemargins{
    \ifexesheet@leftmargin
        \geometry{hmarginratio=3:1}
        \leftnotemarginwidth{\largemarginwidthfactor}
    \else
        \geometry{hmarginratio=1:3}
        \rightnotemarginwidth{\largemarginwidthfactor}
    \fi
}

\def\exs@process@marginwidth{
    \ifthenelse{\equal{\exesheet@marginwidth}{standard}}{
        \ifthenelse{\equal{\exesheet@display}{none}}{
            \if@twoside
                \exesheet@standardmargins
            \else
                \exesheet@smallmargins
            \fi
        }{% else display=pts or notes
            \exesheet@standardmargins
        }
    }{% else if
    \ifthenelse{\equal{\exesheet@marginwidth}{expand}}{
        \ifthenelse{\equal{\exesheet@display}{none}}{
            \if@twoside
                \exesheet@standardmargins
            \else
                \exesheet@smallmargins
            \fi
        }{% else if
        \ifthenelse{\equal{\exesheet@display}{pts}}{
            \exesheet@standardmargins
        }{% else display=notes
            \exesheet@largemargins
        }}
    }{% else if  
        \ifthenelse{\equal{\exesheet@marginwidth}{unset}}{
        % do nothing
    }{% else
    \PackageWarningNoLine{exesheet}{Value `\exesheet@marginwidth'
         is not supported by option `marginwidth'}
    }}}
}

%    \end{macrocode}
% \end{macro}
% For a two side mode document, the package \textsf{geometry} doesn't set the margin 
% paragraph width correctly by default, it's too large. So we made here an explicit setting
% useful in the case of \texttt{marginwidth=unset}. Otherwise, the setting is
% made by the \texttt{marginwidth} key option.
% 
%    \begin{macrocode}
\if@twoside \rightnotemarginwidth{0.5} \fi

%    \end{macrocode}
% \begin{macro}{\exs@process@noteragged}
% The noteragged option takes one of the following values:
% \texttt{left}, \texttt{right}, \texttt{center}, \texttt{justify} or \texttt{twoside}.
%
% |\marginpar| with optional parameter makes the job for a two side document.
% We then use |\noteraggedleft| and |\noteraggedright| instead of |\noteragged|.
% % Commands |\RaggedLeft|, |\RaggedRight|, |\Centering| and |\justifying|
% come from the \textsf{ragged2e} package by Martin Schröder.
% They give better results as standard commands
% |\raggedleft|, |\raggedright| (or |\centering|).
% The default \LaTeX\ setting for marginal notes is justifying.
%    \begin{macrocode}
\newcommand{\noteragged}{}
\newcommand{\noteraggedleft}{}
\newcommand{\noteraggedright}{}

\def\exs@process@noteragged{
    \ifthenelse{\equal{\exesheet@noteragged}{left}}{
        \if@twoside
            \renewcommand{\noteraggedleft}{\RaggedLeft}
            \renewcommand{\noteraggedright}{\RaggedLeft}
        \else
            \renewcommand{\noteragged}{\RaggedLeft}
        \fi
    }{% else if
    \ifthenelse{\equal{\exesheet@noteragged}{right}}{
        \if@twoside
            \renewcommand{\noteraggedleft}{\RaggedRight}
            \renewcommand{\noteraggedright}{\RaggedRight}
        \else
            \renewcommand{\noteragged}{\RaggedRight}
        \fi
    }{% else if
    \ifthenelse{\equal{\exesheet@noteragged}{center}}{
        \if@twoside
            \renewcommand{\noteraggedleft}{\Centering}
            \renewcommand{\noteraggedright}{\Centering}
        \else
            \renewcommand{\noteragged}{\Centering}
        \fi
    }{% else if
    \ifthenelse{\equal{\exesheet@noteragged}{justify}}{
          \renewcommand{\noteraggedleft}{\justifying} % equiv to nothing
          \renewcommand{\noteraggedright}{\justifying}
          \renewcommand{\noteragged}{\justifying}
    % justify is the default LaTeX setting
    }{% else  if
    \ifthenelse{\equal{\exesheet@noteragged}{twoside}}{
        \if@twoside
            \renewcommand{\noteraggedleft}{\RaggedLeft}
            \renewcommand{\noteraggedright}{\RaggedRight}
        \else
            \PackageWarning{exesheet}{Invalid option `noteragged=twoside'
             when the document \MessageBreak is not in two side mode}
        \fi
    }{% else
    \PackageWarning{exesheet}{Value `\exesheet@noteragged'
         is not supported by option `noteragged'}
    }}}}}
}

%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\exs@process@checkpts}
% The scale control option is based on length calculus.
% By default these calculus are local but we need to make them global,
% therefore the two first macros |\gsetlength| and |\gaddtolength|.
% In them we must avoid to produce a too large space at the place
% where |\marginpar| is called, therefore all \% symbols at end of lines.
%
% For each question, points assigned will be added in |\sum@pts|
% and, for each exercise, points are accumulated in |\sum@exe|.
% These lengths are compared to |\exe@total| and |\sheet@total|.
% |\exe@check| is called at the beginning of each exercise 
% (when macro |\points|, |\totalexe| or |\totalpoints| is called)
% to check the previous one,
% and also in the |\exs@process@checkpts| at end of document
% to check the last exercise.
%    \begin{macrocode}
\newlength{\sheet@total}
\newlength{\sum@exe}
\newlength{\exe@total}
\newlength{\sum@pts}
\def\exe@label{none}
\newboolean{scale@valid}
\setboolean{scale@valid}{true}

\gdef\gsetlength#1#2{% to get global length values
    \begingroup
        \setlength\skip@{#2}% local assignment to a scratch register
        \global#1=\skip@%     global assignment to #1
    \endgroup               % \skip@ is restored by end of group
}

\gdef\gaddtolength#1#2{% percent symbol necessary here !
    \begingroup
        \setlength\skip@{#1}%
        \addtolength\skip@{#2}%
        \global#1=\skip@%
    \endgroup
}

\def\exe@check#1{
    \ifthenelse{\lengthtest{\sum@pts = 0pt}\or\equal{\exe@label}{none}}{
    % do not check, no \pts or first exercise begins
    }{
        \ifthenelse{\lengthtest{\exe@total = \sum@pts}}{
            \PackageWarningNoLine{exesheet}{\exe@label:
                scale \the\exe@total\space is valid}
        }{
        \PackageWarningNoLine{exesheet}{\exe@label:
            sum of points is 
            \the\sum@pts\space instead of \the\exe@total}
        \setboolean{scale@valid}{false}
        }
        \gsetlength{\sum@pts}{0pt}
    }
    \def\exe@label{#1} % for the next exercise
}

\def\exs@process@checkpts{
    \ifexesheet@checkpts
        \ifthenelse{\lengthtest{\sheet@total = 0pt}}{
            \PackageWarningNoLine{exesheet}{Option checkpts is true;
                \MessageBreak
                but you didn't use \string\totalsheet\space
                in the preamble. \MessageBreak
                See the documentation for more information}
        }{}
        \gsetlength{\sum@exe}{0pt}
        \gsetlength{\exe@total}{0pt}
        \gsetlength{\sum@pts}{0pt}
        \AtEndDocument{
            \ifthenelse{\equal{\exe@label}{none}}{
                \ifthenelse{\lengthtest{\sheet@total = \sum@pts}}{
                    \PackageWarningNoLine{exesheet}{Sum of points
                        is valid: \the\sheet@total}  
                }{
                    \PackageWarningNoLine{exesheet}{Inconsistent 
                        sum of points: 
                        \the\sum@pts\space instead of \the\sheet@total}
                    \setboolean{scale@valid}{false}
                }
            }{
                \exe@check{end}
                \ifthenelse{\lengthtest{\sheet@total = \sum@exe}}{
                    \PackageWarningNoLine{exesheet}{Sum of points
                        is valid: \the\sheet@total}
                }{
                    \PackageWarningNoLine{exesheet}{Inconsistent
                        sum of points:
                        \the\sum@exe\space instead of \the\sheet@total}
                    \setboolean{scale@valid}{false}
                }
            }
            \ifthenelse{\boolean{scale@valid}}{
                \PackageWarningNoLine{exesheet}{Scale is valid}
            }{
                \PackageWarningNoLine{exesheet}{Scale is NOT valid ! 
                    See above}
            }
        }
    \fi
}

%    \end{macrocode}
% \end{macro}
%
% \subsection{Margin notes commands}
%
% \begin{macro}{\points}
%    \begin{macrocode}
\definecolor{pointscolor}{named}{red}
\newcommand{\pointsstyle}{%
    \small\mdseries\sffamily\color{pointscolor}\fbox}
\newcommand*{\exesheet@points}[1]{\hfill
    \pointsstyle{#1~%
        \ifthenelse{\lengthtest{#1pt < 2pt}}{\pointname}{\pointsname}}
    \ifexesheet@checkpts\gaddtolength{\sum@exe}{#1pt}\fi%
}
\newcommand*{\points}[1]{%
    \ifthenelse{\boolean{exesheet@questions}}{\exesheet@points{#1}}{}}

%    \end{macrocode}
% Percent symbols are necessary to avoid spaces between the
% |\fbox| and its inner text.
% Without |\lengthtest|, the test |#1 < 2| doesn't work with decimal numbers
% but it works with lengths.
% \end{macro}
% \DescribeMacro{\pts}
%    \begin{macrocode}
\definecolor{ptscolor}{named}{red}
\newcommand{\ptsstyle}[1]{%
    \footnotesize\centering\sffamily\color{ptscolor} (#1)}
\newcommand*{\ptsmark}[1]{%
    \ifthenelse{\lengthtest{#1pt < 2pt}}{#1 \ptname}{#1 \ptsname}}
\newcommand*{\pts}[1]{%
    \ifexesheet@pts%
        \mbox{}%
        \marginpar{\hspace{0pt}\ptsstyle{\ptsmark{#1}}}%
        \ifexesheet@checkpts%
            \gaddtolength{\sum@pts}{#1pt}%
        \fi%
    \fi%
    \ignorespaces
}

%    \end{macrocode}
%
% \begin{macro}{\totalexe}
% In the following macros using
% |\marginpar|, percent symbols and |\ignorespaces| are necessary 
% to avoid an enlarged blank space in the text (or the margin)
% where these macros are inserted.
%    \begin{macrocode}
\definecolor{markingcolor}{named}{red}
\newcommand{\markingstyle}[1]{\footnotesize\sffamily% 
    \centering\color{markingcolor}\textbf{#1}}
    % inner arguments allow boxed styles
\newlength{\ptsboxlength}
\setlength{\ptsboxlength}{3.1em}
\cornersize{1}
\newcommand*{\totalexe}[1]{%
    \ifexesheet@pts%
        \mbox{}%
        \marginpar{\hspace{0pt}\markingstyle{\ovalbox{%
            \makebox[\ptsboxlength]{\ptsmark{#1}}}}}%
    \fi%
    \ifexesheet@checkpts%
        \gsetlength{\exe@total}{#1pt}%
        \gaddtolength{\sum@exe}{#1pt}%
    \fi%
    \ignorespaces
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\totalsheet}
%    \begin{macrocode}
\newcommand*{\totalsheet}[1]{
    \gsetlength{\sheet@total}{#1pt}
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\note} 
% Boolean \texttt{exesheet@pts} and \texttt{exesheet@notes} control
% the display of marginal notes. If \texttt{exesheet@pts} is \texttt{false},
% \DescribeMacro{\note*}
% \texttt{exesheet@notes} will be ignored.
% |\noindent| is necessary when using |\justifying| from the \textsf{ragged2e}
% package.
% Inside the |\note@marginpar| macro, double braces around |\markingstyle|
% avoid some unattended style in the mandatory argument of |\note|. 
% A vicious error occur when using |\if| \ldots |\fi| structure inside
% the |\note@marginpar| macro instead of |\ifthenelse| 
% (but only if |@twoside| is \texttt{true}).
%    \begin{macrocode}
\definecolor{notecolor}{rgb}{0.0, 0.4, 0.0} % kind of dark green  
\newcommand{\notestyle}[1]{\footnotesize\sffamily\color{notecolor} #1}
\newcommand{\note@marginpar}[1]{%
    \if@twoside%
        \marginpar[\noteraggedleft #1]{\noteraggedright #1}%
    \else%
        \marginpar{\noteragged #1}%
    \fi%
}
\newcommand{\@note}[2][]{%
    \ifexesheet@pts%
        \mbox{}%
        \note@marginpar{%
            \ifthenelse{\equal{#1}{}}{}{{%
                \noindent\hspace{0pt}\markingstyle{#1}\\}}%
            \ifthenelse{\boolean{exesheet@notes}}{%
                \noindent\hspace{0pt}\notestyle #2%
            }{}%
        }%
    \fi%
    \ifexesheet@checkpts%
        \ifthenelse{\equal{#1}{}}{}{%
            \gaddtolength{\sum@pts}{#1pt}}%
    \fi%
    \ignorespaces
}
\newcommand{\@@note}[1]{%
    \ifexesheet@pts%
        \mbox{}%
        \marginpar{\noindent\hspace{0pt}\markingstyle{#1}}%
    \fi%
    \ifexesheet@checkpts%
        \gaddtolength{\sum@pts}{#1pt}%
    \fi%
    \ignorespaces
}
\newcommand{\note}{\@ifstar{\@@note}{\@note}}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\totalpoints}
%    \begin{macrocode}
\newcommand{\totalpoints}{%
    \ifthenelse{\boolean{exesheet@pts}}{\totalexe}{\points}}

%    \end{macrocode}
% \end{macro}
%
% \subsection{The \texttt{correct} option and other (deprecated) commands}
%
% \begin{macro}{\exs@process@correct}
%    \begin{macrocode}
\def\exs@process@correct{     
    \ifthenelse{\equal{\exesheet@correct}{false}}{
        % do nothing
    }{% else
    \@ifpackageloaded{schooldocs}{
        \ifthenelse{\equal{\exesheet@correct}{true}}{
            \correct
        }{% else
        \ifthenelse{\equal{\exesheet@correct}{conditional}}{
            \ifexesheet@answers \correct \fi
        }{}}
    }{
        \PackageWarningNoLine{exesheet}{Package `schooldocs' must be loaded
            \MessageBreak
            to use the `correct' option}
    }}
}

%    \end{macrocode}
% \end{macro}
%
% The following macros are maintained for now
% only for compatibility reasons.
%    \begin{macrocode}
\newcommand{\questionsonly}{
    \PackageWarning{exesheet}{Command \string\questionsonly\space 
        is deprecated, \MessageBreak
        use `output=questions' as package option instead}
    \renewcommand\exesheet@output{questions}
    \exs@process@output
}
\newcommand{\answersonly}{
    \PackageWarning{exesheet}{Command \string\answersonly\space 
        is deprecated, \MessageBreak
        use `output=answers' as package option instead}
    \renewcommand\exesheet@output{answers}
    \exs@process@output
}
\newcommand{\displaypts}{%
    \PackageWarning{exesheet}{Command \string\displaypts\space 
        is deprecated, \MessageBreak
        use `display=pts' as package option instead}
    \renewcommand\exesheet@display{pts}
    \exs@process@display
}
\newcommand{\displaypoints}{%
    \PackageWarning{exesheet}{Command \string\displaypoints\space 
        is deprecated, \MessageBreak
        use `display=pts' as package option instead}
    \renewcommand\exesheet@display{pts}
    \exs@process@display
}
\newcommand*{\displaynotes}[1][\RaggedLeft]{%
    % \renewcommand{\noteragged}{#1} no effect now!
    \PackageWarning{exesheet}{Command \string\displaynotes\space 
        is deprecated, \MessageBreak
        use `display=notes' as package option instead}
    \renewcommand\exesheet@display{notes}
    \exs@process@display
    \renewcommand{\noteragged}{#1}
}
\newcommand*{\displaynotesright}[1][\RaggedRight]{%
    % \renewcommand{\noteragged}{#1} no effect now!
    \PackageWarning{exesheet}{Command \string\displaynotes\space 
        is deprecated, \MessageBreak
        use `display=notes, margin=right' as package options instead}
    \renewcommand\exesheet@display{notes}
    \exs@process@display
    \renewcommand\exesheet@margin{right}
    \renewcommand{\noteragged}{#1}
}

\PackageInfo{exesheet}{Environment `tablenum' is deprecated \MessageBreak
    and replaced by `tablenum1'. \MessageBreak
    Options `notoc' and `nosetlist' \MessageBreak
    are no longer supported\@gobble} 
    % gobble allow to suppress line number
%</package>
%    \end{macrocode}
%
% \Finale
\endinput
