%%
%% This is file `exesheet.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% exesheet.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% 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.
%% 
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{exesheet}
[2023/01/16 v2.0 .dtx exesheet file]

\@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}
}

\def\exesheetset#1{\setkeys{exesheet}{#1}\exs@process@dynoptions}

\RequirePackage{ifthen}
\RequirePackage{geometry}
\RequirePackage{xcolor}
\RequirePackage[shortlabels]{enumitem}
\RequirePackage{tasks}
\RequirePackage{versions}
\RequirePackage{fancybox}
\RequirePackage{translations}
\RequirePackage{ragged2e}
\ifthenelse{\boolean{@twoside}}{\RequirePackage{mparhack}}{}

\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}}

\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}}

\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}}

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

\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}}

\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}}

\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

  \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

\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)

\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}
}

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

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

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

\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'}
    }}}
}

\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}}

\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}}}

\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
    }}}
}

\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}}

\newcommand{\question}[1]{\ifexesheet@questions #1\fi}

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

\newcommand\answerspace[1]{
    \ifexesheet@answerspace \par\vspace{#1} \fi}

\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'}
    }}}
}

\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'}
    }}}}
}

\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'}
    }}}
}

\if@twoside \rightnotemarginwidth{0.5} \fi

\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'}
    }}}}}
}

\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
}

\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}}{}}

\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
}

\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
}

\newcommand*{\totalsheet}[1]{
    \gsetlength{\sheet@total}{#1pt}
}

\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}}

\newcommand{\totalpoints}{%
    \ifthenelse{\boolean{exesheet@pts}}{\totalexe}{\points}}

\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}
    }}
}

\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
\endinput
%%
%% End of file `exesheet.sty'.
