%%
%% This is file `verifiche.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% verifiche.dtx  (with options: `package')
%% This is a generated file.
%% Copyright (C) 2020 by Francesco Raccanello
%% 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}
\ProvidesPackage{verifiche} [2020/07/01 v2.2 .dtx verifiche file]


\RequirePackage{xparse}
\RequirePackage{xkeyval} 
\RequirePackage{amsmath}
\RequirePackage{amssymb}
\RequirePackage{pgffor}
\RequirePackage[shortlabels, inline]{enumitem}
\RequirePackage{siunitx}
\RequirePackage{graphicx}
\RequirePackage{xcolor}
\RequirePackage{tikz}
\RequirePackage{booktabs}
\RequirePackage{fancyhdr}
\RequirePackage[normalem]{ulem}
\RequirePackage{xstring}
%%Forse si può cancellare questo
\usetikzlibrary{calc,shapes.geometric,patterns,positioning,angles,quotes}
\sisetup{
    output-decimal-marker = {,},
    exponent-product = \cdot,
    per-mode=symbol-or-fraction,
    separate-uncertainty
}
\setlength\parindent{0pt}
%%newif
\newif\ifsol
\newif\ifinstitute\institutetrue
\newif\ifinstruction\instructiontrue
\newif\ifduration\durationtrue
\newif\ifasyear\asyeartrue
\newif\ifsolutionscolor\solutionscolorfalse
\newif\ifcandidatename\candidatenametrue
\newif\iftesttype\testtypetrue
\newif\ifprintedheading\printedheadingfalse
\newif\ifexercisesnumbered\exercisesnumberedtrue
\newif\ifshowmarginexercise\showmarginexercisefalse
\newif\ifopenquestionlines\openquestionlinesfalse
\newif\ifopenquestionsquared\openquestionsquaredfalse
%%Package option declaration
\DeclareOptionX{solutions}[]{\soltrue}
\DeclareOptionX{noinstitute}[]{\institutefalse}
\DeclareOptionX{noinstruction}[]{\instructionfalse}
\DeclareOptionX{noduration}[]{\durationfalse}
\DeclareOptionX{noasyear}[]{\asyearfalse}
\DeclareOptionX{nocandidatename}[]{\candidatenamefalse}
\DeclareOptionX{notesttype}[]{\testtypefalse}
\DeclareOptionX{nonumbered}[]{\exercisesnumberedfalse}
\DeclareOptionX{color}[red]{\solutionscolortrue\def\solutionscolor{#1}}
\DeclareOptionX{red}[]{\ExecuteOptionsX{color=red}}
\DeclareOptionX{blue}[]{\ExecuteOptionsX{color=blue}}
\DeclareOptionX*{\PackageWarning{verifiche}{Unknown ‘\CurrentOption’}}
\ProcessOptionsX
%%counters
\newcounter{exercisenumber}
\newcounter{partialpoints}[exercisenumber]
%%macro and environment
%%global variable
\newcommand{\institute}[1]{%
    \gdef\@institute{#1}}
\newcommand{\duration}[2][Tempo della prova:]{%
    \gdef\@durationpreamble{#1}\gdef\@duration{#2}}
\newcommand{\testtype}[1]{%
    \gdef\@testtype{#1}}
\newcommand{\instruction}[1]{%
    \gdef\@instruction{#1}}
\newcommand{\asyear}[2][Anno scolastico]{%
    \gdef\@asyearpreamble{#1}\gdef\@asyear{#2}}
%%fonts and aspects
\newcommand{\institutefont}[1]{%
    \large \sffamily\color{darkgray}#1}
\newcommand{\asyearfont}[1]{%
    \hspace*{\fill} #1\hspace*{\fill}\\[.5em]}
\newcommand{\testtypefont}[1]{%
    \hspace*{\fill}\scshape\huge#1\hspace*{\fill}}
\newcommand{\instructiondelimiter}{%
    \rule{\textwidth}{.5pt}}
\newcommand{\instrunctionfont}[1]{%
    \sffamily#1}
\newcommand{\durationfont}[1]{%
    \hspace*{\fill}\@durationpreamble\space\bfseries #1\hspace*{\fill}}
\newcommand{\eserciziolabel}{%
    Quesito}
\newcommand{\solutionfont}{%
    \footnotesize\ifsolutionscolor\color{\solutionscolor}\fi\itshape}
\newcommand{\diffsymb}{%
    $\bigstar$}
\newcommand{\closedquestionitem}{%
    $\square$}
%%print headings
\newcommand{\printheading}{%
    \ifinstitute\pagestyle{fancy}\fi%
    {\ifinstitute\chead{\institutefont{\@institute}}\fi}%
    {\ifcandidatename\vspace*{.25em}Nome e Cognome \underline{\hspace{6cm}}%
    \hfill Classe \underline{\hspace{1.5cm}} \hfill Data \underline{\hspace{2.5cm}}\\[1em]\fi}%
    {\ifasyear \asyearfont{\@asyearpreamble\space\@asyear}\fi}%
    {\iftesttype\testtypefont{\@testtype}\fi}\\%
    {\ifinstruction\instructiondelimiter\\{\instrunctionfont{\@instruction}}\\%
    \ifduration{\durationfont\@duration\\}\fi\instructiondelimiter\fi}%
}

%%ambiente esercizio
\define@key{esercizio}{label}[Quesito]{%
    \def\tempeserciziolabel{#1}}%
\define@key{esercizio}{diff}[none]{
    \def\diffstar{\hfill\foreach \i in {1,..., #1}{\diffsymb}}%
    \showmarginexercisetrue}%
\define@key{esercizio}{pt}[none]{
    \def\pointes{#1}%
    \def\espoint{\hfill\underline{\hspace{1cm}}/\pointes pt}%
    \showmarginexercisetrue}%
\define@key{esercizio}{partialpt}[none]{%
    \def\sumpartialpt{\underline{\hspace{1cm}}/\ref{ptes@\theexercisenumber} pt}%
    \showmarginexercisetrue}%
\newcommand{\exercisetitle}{%
    \ifdefined\tempeserciziolabel\tempeserciziolabel%
    \else \eserciziolabel\fi%
}
\newsavebox{\box@marginexercise}
\newcommand{\exercisemargin}{%
    \sbox{\box@marginexercise}{\parbox[t]{\marginparwidth}{%
        \ifdefined\diffstar\hfill\diffstar\par\fi% stelle di difficoltà
        \ifdefined\espoint\hfill\espoint\par\fi%[-\baselineskip] %punteggio
        \ifdefined\sumpartialpt\hfill\sumpartialpt\fi} %punteggio parziale automatico
    }%
    \reversemarginpar\marginpar{\usebox{\box@marginexercise}}%
}%
\newcommand{\savepointsaux}{%
    \ifdefined\sumpartialpt%
        \protected@write \@auxout {}{\string\newlabel {ptes@\theexercisenumber}{{\thepartialpoints}{}}}%
    \fi%
    \ifdefined\espoint%
        \protected@write \@auxout {}{\string\newlabel {ptes@\theexercisenumber}{{\pointes}{}}}%
    \fi%
}%

\NewDocumentEnvironment{esercizio}{o +b}{%
    \refstepcounter{exercisenumber}%
    \showmarginexercisefalse%
    \IfValueT{#1}{\setkeys{esercizio}{#1}}%
    \par\addvspace{\baselineskip}%
    {\noindent\bfseries\exercisetitle\ifexercisesnumbered\space\theexercisenumber\fi}%
    \ifshowmarginexercise\exercisemargin\fi%
    \par% newline after label
    \nobreak\noindent\ignorespaces#2%body of the environment
}{%
   \par%
   \ignorespacesafterend%
   \savepointsaux%
}%
\NewDocumentEnvironment{esercizio*}{o +b}{%
    \showmarginexercisefalse%
    \IfValueT{#1}{\setkeys{esercizio}{#1}}%
    \par\addvspace{\baselineskip}{\noindent\bfseries\exercisetitle}%
    \ifshowmarginexercise\exercisemargin\fi%
    \par% newline after label
    \nobreak\noindent\ignorespaces#2% body of the environment
}{%
    \par%
    \ignorespacesafterend
    \savepointsaux%print partial pt sum
}%
\NewDocumentCommand{\partialpt}{m}{%
    \leavevmode\reversemarginpar\marginpar{\hfill(#1 pt)\addtocounter{partialpoints}{#1}}%
}
\NewDocumentEnvironment{soluzione}{+b}{%
    \ifsol%
        \par\addvspace{\baselineskip}%
        {\noindent\bfseries Soluzione}%
        \par\nobreak\noindent\ignorespaces%
        \solutionfont #1%
    \fi%
}{%
    \ifsol%
        \par\ignorespacesafterend
    \fi%
}%
\newcommand{\inlinesol}[1]{%
    \ifsol%
        \bgroup%
            \ifmmode\mathit{\solutionfont#1}%
            \else{\solutionfont#1}%
            \fi%
        \egroup%
    \else\ignorespaces%
    \fi%
}
\newcommand{\completetext}[2][4.5cm]{%
    \ifsol%
        $\overset{\displaystyle\text{\solutionfont#2}}{\underline{\hspace{#1}}}$%
    \else%
        $\overset{\relax}{\underline{\hspace{#1}}}$%
    \fi}%
\newcommand{\truefalse}[1]{%
    \tikz[baseline=-.8ex]{%
        %true part
        \node[draw, rectangle, minimum size=1.5em] {V};%
        \ifsol\IfSubStr{#1}{V}{\node[shift={(1pt,1pt)}]{%
        $\Large\ifsolutionscolor\color{\solutionscolor}\fi\checkmark$}}{};\fi%
        %false part
        \node[xshift=1cm, draw, rectangle, minimum size=1.5em]{F};%
        \ifsol\IfSubStr{#1}{F}{\node[xshift=1cm, shift={(1pt,1pt)}]{%
        $\Large\ifsolutionscolor\color{\solutionscolor}\fi\checkmark$}}{};\fi%
    }%
}
\newcommand{\finderror}[2]{%
    \ifsol%
        $\overset{\text{{\solutionfont#2}}}{\text{\xout{#1}}}$%
    \else%
        #1%
    \fi%
}
\newlist{crocette}{itemize*}{1}%
\setlist[crocette]{label=\closedquestionitem, itemjoin={\hfill}}%
\newcommand{\checked}{%
    \ifsol%
        \closedquestionitem\tikz[remember picture, overlay, baseline=-1ex, xshift=-.7ex]
            {\node{\ifsolutionscolor\color{\solutionscolor}\fi$\checkmark$};}
    \else
        \closedquestionitem
    \fi}
\NewDocumentEnvironment{closedquestion}{+b}{%
    \begin{crocette}#1%
}{%
    \end{crocette}
}

\define@key{openquestion}{width}[\linewidth]{\def\openquestionwidth{#1}}
\define@key{openquestion}{height}[19cm]{\def\openquestionheight{#1}}
\define@key{openquestion}{spacedim}[0.5cm]{\def\spacedim{#1}}
\define@key{openquestion}{linecolor}[gray]{\def\openquestionlinecolor{#1}}
\define@choicekey*+{openquestion}{type}[\val\nr]{lines, squares}[lines]{%
    \ifcase\nr\relax%
        % lines
        \openquestionsquaredfalse\openquestionlinestrue%
    \or%
        % squares
        \openquestionsquaredtrue\openquestionlinesfalse%
    \fi}%
    {\PackageError{verifiche}{Errore nell'opzione openquestion}{Inserire lines o squares}}
\NewDocumentCommand{\openquestion}{o m}{%
    \setkeys{openquestion}{type, width, height, linecolor, spacedim} %init
    \IfValueT{#1}{\setkeys{openquestion}{#1}}%
    \ifopenquestionsquared% if squared open question
        \begin{tikzpicture}%
            \draw[step=\spacedim, \openquestionlinecolor]%
            (0,0) grid (\openquestionwidth,-\openquestionheight);%
            \node[anchor=base west, align=left, text width=\openquestionwidth,%
            inner sep=0cm, font=\solutionfont, execute at begin node=\setlength{\baselineskip}{\spacedim}]%
            at (0, -\spacedim){\ifsol#2\fi};
        \end{tikzpicture}%
    \else% if lined open question
        \begin{tikzpicture}%
            \pgfmathparse{int(\openquestionheight/\spacedim)}%
             \foreach \y in {1, ..., \pgfmathresult}%
             \draw[\openquestionlinecolor] (0, -\y*\spacedim) -- +(\openquestionwidth,0);%
             \node[anchor=base west,align=left,  text width=\openquestionwidth,%
             inner sep=0cm, font=\solutionfont, execute at begin node=\setlength{\baselineskip}{\spacedim}]%
             at (0, -\spacedim){\ifsol#2\fi};%
    \end{tikzpicture}%
    \fi%
}
\NewDocumentCommand{\textandimage}{O{.7\textwidth} O{.3\textwidth} m m}{%
    \begin{minipage}{#1}
       {#3}
    \end{minipage}
    \hfill
    \begin{minipage}{#2}
        {#4}
    \end{minipage}
}
\endinput
%%
%% End of file `verifiche.sty'.
