%%
%% 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}
[2021/11/15 v1.3 .dtx exesheet file]

\RequirePackage{ifthen}
\newboolean{notoc}
\newboolean{nosetlist}
\DeclareOption{notoc}{\setboolean{notoc}{true}}
\DeclareOption{nosetlist}{\setboolean{nosetlist}{true}}
\ProcessOptions \relax
\RequirePackage{xcolor}
\RequirePackage[shortlabels]{enumitem}
\RequirePackage{tasks}
\RequirePackage{versions}
\RequirePackage{geometry}
\RequirePackage{fancybox}
\RequirePackage{translations}

\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}{Pkte}
\DeclareTranslation{German}{exesheet-pt}{Pkt}

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

\definecolor{pointscolor}{named}{red}
\definecolor{ptscolor}{named}{red}
\definecolor{markingcolor}{named}{red}
\definecolor{notecolor}{rgb}{0.0, 0.4, 0.0} % kind of dark green
\definecolor{correctioncolor}{rgb}{0,0.2,0.6} % kind of dark blue

\newcounter{exercise}

\newcommand{\labelexercise}{\exercisename~\theexercise}
\newcommand{\labelexercisestyle}{}
\newcommand*{\@exercise}[1][]{%
    \refstepcounter{exercise}
    \subsection*{\labelexercisestyle\labelexercise\ #1}
    \ifthenelse{\boolean{notoc}}{}{
        \addcontentsline{toc}{subsection}{\labelexercise}
    }
}
\newcommand*{\@@exercise}[2][]{%
    \subsection*{\labelexercisestyle #2 #1}
    \setcounter{subpart}{0} % resets the parts counter
    \ifthenelse{\boolean{notoc}}{}{
        \addcontentsline{toc}{subsection}{#2}
    }
}
\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\ #1}
    \ifthenelse{\boolean{notoc}}{}{
        \addcontentsline{toc}{subsubsection}{\labelsubpart}
    }
}
\newcommand*{\@@subpart}[2][]{%
    \subsubsection*{\labelsubpartstyle #2 #1}
    \ifthenelse{\boolean{notoc}}{}{
        \addcontentsline{toc}{subsubsection}{#2}
    }
}
\newcommand{\subpart}{\@ifstar{\@@subpart}{\@subpart}}

\newcommand{\annexstyle}{\MakeUppercase}
\newcommand*{\annex}[1][]{%
    \subsection*{\mbox{}\hfill\annexstyle{\annexname} #1\hfill\mbox{}}
    \ifthenelse{\boolean{notoc}}{}{
        \addcontentsline{toc}{subsection}{\annexname}
    }
}

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

\newcommand{\pointsstyle}{%
    \small\mdseries\sffamily\color{pointscolor}\fbox}
\newcommand*{\points}[1]{\hfill
    \pointsstyle{#1~%
        \ifthenelse{\lengthtest{#1 cm < 2cm}}{\pointname}{\pointsname}%
    }
}

\newcommand\standardfrenchlists{%
    \@ifpackagewith{babel}{frenchb}{
        \frenchbsetup{StandardLists=true}}{}
    \@ifpackagewith{babel}{french}{
        \@ifundefined{frenchsetup}{
            \frenchbsetup{StandardLists=true}}{
            \frenchsetup{StandardLists=True}}
    }{}
}
\ifthenelse{\boolean{nosetlist}}{}{
    \AtBeginDocument{% if loaded before babel package
        \standardfrenchlists}
    \standardfrenchlists % necessary when loaded after babel
    \setlist[enumerate]{font=\bfseries}
    \setlist[enumerate,1]{topsep=1.5ex plus 1ex minus 1ex,leftmargin=1.5em}
}

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

\ifthenelse{\boolean{nosetlist}}{
    \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)
}{% by default
    \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)
}
\PackageWarning{exesheet}{Environment tablenum is deprecated and replaced by tablenum1}

\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{questions}
\newboolean{answers}
\setboolean{questions}{true}
\setboolean{answers}{true}
\newcommand{\questionsonly}{
    \setboolean{questions}{true}\setboolean{answers}{false}}
\newcommand{\answersonly}{
    \setboolean{questions}{false}\setboolean{answers}{true}}

\newcounter{exe@ini}
\newcounter{subpart@ini}

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

\newcounter{@toclevel}
\newcommand{\set@toclevel}[1][]{
    \ifthenelse{\equal{#1}{}}{
        \ifthenelse{\value{exercise} > \value{exe@ini}}{
            \setcounter{@toclevel}{1}
        }{\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}}}

\newcommand{\correctionstyle}{\color{correctioncolor}}

\newenvironment{answers}[1][]{% #1 is the optional level
    \ifthenelse{\boolean{answers}}{%
        \ifthenelse{\boolean{questions}}{%
            \set@toclevel[#1]
            \ifthenelse{\value{@toclevel} = 1}{
                \section*{\correctionstyle\correctionname}
                \ifthenelse{\boolean{notoc}}{}{
                    \addcontentsline{toc}{section}{\correctionname}}
                \setcounter{exercise}{0}
            }{\ifthenelse{\value{@toclevel} = 2}{%
                    \subsection*{\correctionstyle\correctionname}
                    \ifthenelse{\boolean{notoc}}{}{
                        \addcontentsline{toc}{subsection}{\correctionname}}
                    \setcounter{subpart}{0}
                }{\ifthenelse{\value{@toclevel} = 3}{%
                        \subsubsection*{\correctionstyle\correctionname}
                        \ifthenelse{\boolean{notoc}}{}{
                            \addcontentsline{toc}{subsubsection}{
                                \correctionname}}
                    }{\par\textbf{\correctionstyle\correctionname}\par
                    }%
                }%
            }%
            \correctionstyle%
        }{}%
    }{\comment}
}{\ifthenelse{\boolean{answers}}{}{\endcomment}}

\newenvironment{answers*}{\ifthenelse{\boolean{answers}}{}{\comment}}%
{\ifthenelse{\boolean{answers}}{}{\endcomment}}

\newcommand{\question}[2]{%
    \ifthenelse{\boolean{questions}}{#1}{}
    \bgroup
    \ifthenelse{\boolean{answers}}{
        \ifthenelse{\boolean{questions}}{
            \ifx#2\empty\else
                \par\correctionstyle\textbf{\correctionname}\par
            \fi
        }{}
        #2}{}
    \egroup
}

\let\@oldpoints\points
\renewcommand*{\points}[1]{%
    \ifthenelse{\boolean{questions}}{\@oldpoints{#1}}{}}

\newboolean{marginpts}
\newcommand*{\pointmark}[1]{%
    \ifthenelse{\lengthtest{#1 cm < 2cm}}{#1 \ptname}{#1 \ptsname}}
\newcommand{\ptsstyle}[1]{%
    \footnotesize\centering\sffamily\color{ptscolor} (#1)}
\newcommand*{\pts}[1]{%
    \ifthenelse{\boolean{marginpts}}{%
        \mbox{}%
        \marginpar{\hspace{0pt}%
            \ptsstyle{\pointmark{#1}}}%
    }{}%
    \ignorespaces
}
\newcommand{\displaypts}{%
    \reversemarginpar
    \geometry{hmarginratio=3:2}
    \setboolean{marginpts}{true}
}

\newlength{\ptsboxlength}
\setlength{\ptsboxlength}{3.1em}
\cornersize{1}
\newcommand*{\totalexe}[1]{%
    \ifthenelse{\boolean{marginpoints}}{%
        \mbox{}%
        \marginpar{\markingstyle{\ovalbox{%
                    \makebox[\ptsboxlength]{\pointmark{#1}}}%
            }}%
    }{}%
    \ignorespaces
}

\newboolean{marginpoints}
\newboolean{marginfullnotes}

\newcommand{\markingstyle}[1]{\hspace{0pt}\footnotesize\sffamily%
    \centering\color{markingcolor}\textbf{#1}}
\newcommand{\noteragged}{\raggedleft}
\newcommand{\notestyle}[1]{\hspace{0pt}\footnotesize\sffamily%
    \noteragged\noindent\color{notecolor} #1}
\newcommand{\@note}[2][]{%
    \ifthenelse{\boolean{marginpoints}}{%
        \mbox{}%
        \marginpar{%
            \ifthenelse{\equal{#1}{}}{}{\markingstyle{#1}\\}%
            \ifthenelse{\boolean{marginfullnotes}}{\notestyle #2}{}%
        }%
    }{}%
    \ignorespaces
}
\newcommand{\@@note}[1]{%
    \ifthenelse{\boolean{marginpoints}}{%
        \mbox{}%
        \marginpar{\markingstyle{#1}}%
    }{}%
    \ignorespaces
}
\newcommand{\note}{\@ifstar{\@@note}{\@note}}

\newcommand{\displaypoints}{%
    \reversemarginpar
    \geometry{hmarginratio=3:2}
    \setboolean{marginpoints}{true}
}

\newcommand*{\displaynotes}[1][\raggedleft]{%
    \reversemarginpar
    \renewcommand{\noteragged}{#1}
    \geometry{hmarginratio=5:1}
    \setlength{\marginparwidth}{\oddsidemargin}
    \addtolength{\marginparwidth}{1in}
    \addtolength{\marginparwidth}{-\marginparsep}
    \setlength{\marginparwidth}{0.8\marginparwidth}
    \setboolean{marginpoints}{true}
    \setboolean{marginfullnotes}{true}
}

\newcommand*{\displaynotesright}[1][\raggedright]{%
    \normalmarginpar
    \renewcommand{\noteragged}{#1}
    \geometry{hmarginratio=1:5}
    \setlength{\marginparwidth}{\paperwidth}
    \addtolength{\marginparwidth}{-\textwidth}
    \addtolength{\marginparwidth}{-\oddsidemargin}
    \addtolength{\marginparwidth}{-\marginparsep}
    \addtolength{\marginparwidth}{-1in}
    \setlength{\marginparwidth}{0.8\marginparwidth}
    \setboolean{marginpoints}{true}
    \setboolean{marginfullnotes}{true}
}
\newcommand{\totalpoints}{%
    \ifthenelse{\boolean{marginpoints}}{\totalexe}{\points}}
\endinput
%%
%% End of file `exesheet.sty'.
