%% Package `esami' to use with LaTeX 2e
%%  Copyright (C) 2008-2023  G. Messineo e S. Vassallo
%%
%% This is file `esami-xyz.cfg',
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% esami-xyz.cfg,             2023-07-21                %%
%% Copyright (C) 2008-2023 G. Messineo e S. Vassallo    %%
%%                                                      %%
%% This program can be redistributed and/or modified    %%
%% under the terms of the LaTeX Project Public License  %%
%% Distributed from CTAN archives in directory          %%
%% macros/latex/base/lppl.txt; either version 1 of the  %%
%% License, or (at your option) any later version.      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% other packages
\AtEndOfPackage{
\usepackage{amsmath}
%========================================================%
%    Some shortcuts and Italian maths                    %
%========================================================%

\DeclareMathOperator{\sen}{sen}
\DeclareMathOperator{\tg}{tg}
\DeclareMathOperator{\arcsen}{arcsen}
\DeclareMathOperator{\arctg}{arctg}
\providecommand*{\dif}{\mathop{}\!\mathrm{d}}
\providecommand{\dlim}{\displaystyle \lim}
\providecommand{\dsum}{\displaystyle \sum}
\providecommand{\me}{\mathrm{e}}
\providecommand{\D}{\displaystyle}

\newenvironment{sistema}{%%% Taken from somewhere in GUIT forum to write equations systems
\left\lbrace\begin{array}{@{}l@{}}}%
  {\end{array}\right.%
  }

\DeclareRobustCommand{\annu}[2]{_{%%% the annuity command
 \def\arraystretch{0}
 \setlength\arraycolsep{1pt}
\setlength\arrayrulewidth{.2pt}
\begin{array}[b]{c c}
 \setlength\arraycolsep{1.5pt}
 \begin{array}
 [b]{r|}\hline
 \\[\arraycolsep]
 \scriptstyle #1
 \end{array}&\scriptstyle#2%
\end{array}%
}}

\newcommand{\vect}[1]{\boldsymbol{#1}}

%%% We prefer var greek math %%%

\newcommand{\eps}{\varepsilon}
\newcommand{\oldtheta}{\theta} \renewcommand{\theta}{\vartheta}
\newcommand{\oldepsilon}{\epsilon} \renewcommand{\epsilon}{\varepsilon}
\newcommand{\oldrho}{\rho} \renewcommand{\rho}{\varrho}
\newcommand{\oldphi}{\phi} \renewcommand{\phi}{\varphi}

%%%%%%%%%%%%%%%%%%%%%%%%%
}

% +=============================+
% |         THE HEADING         |
% +=============================+

 \@ifpackagewith{esami}{prova}{%
 \def\testa{\relax}}
{%
\def\testa{
{\bfseries\sffamily\small
\begin{center}
\begin{tabular}{|lp{.33\textwidth}|lp{.3\textwidth}|lp{.3\textwidth}|}
\hline
\multicolumn{1}{|p{.33\textwidth}|}{\examname \newline  \Data}&\multicolumn{1}{|p{.3\textwidth}|}{\profname  } &\multicolumn{1}{|p{.3\textwidth}|}{\studsignname}\\[4ex]
\hline
\multicolumn{1}{|p{.33\textwidth}|}{\studlastname:}&\multicolumn{1}{|p{.3\textwidth}|}{\studfirstname:}&\multicolumn{1}{|p{.3\textwidth}|}{\studid:}\\[4ex]
\hline
\end{tabular}\\[3ex]
\end{center}}
 }
 }

% +=============================+
% |         THE FOOTER          |
% +=============================+

\ifes@solutions%%%solutions
\def\ps@esame{\let\@oddhead\@empty\def\@oddfoot{\hfil \textbf{\versionname\
n. \thevers} -- %%
\textbf{\solutionsname} --  %%
 \pagename\ \thepage
\hfil}\let\@evenhead\@empty\let\@evenfoot\@empty}
\else%%% no solutions
    \def\ps@esame{
    \let\@oddhead\@empty\def\@oddfoot%%
    {\hfil  \textbf{\versionname\ n. \thevers\
      -- \pagename\ \thepage}\hfil}\let\@evenhead\@empty\let\@evenfoot\@empty}
\fi

% +=============================+
% |   THE SOLUTION STRING       |
% +=============================+

\def\ps@soltest{\let\@oddhead\@empty\def\@oddfoot{\hfil %\textbf{\versionname\ n. \thevers} -- %%
\textbf{\solutionsname} -- \pagename\ \thepage
\hfil}\let\@evenhead\@empty\let\@evenfoot\@empty}

\ifes@solutions
\newcommand{\stringasol}{\newpage%
\vspace{.8cm}
\pagestyle{soltest}
 \input{\jobname.sol.tex}                                                                                %
}
\else
\newcommand{\stringasol}{\relax}
\fi


% +=============================+
% |   SOME INTRUCTIONS          |
% +=============================+

\def\istruzionii{{
\sffamily \textbf{INSTRUCTIONS}
\begin{itemize}
  \item Write here your instructions
  \item two 
  \item three 
\end{itemize}}}

\def\istruzioniii{\setlength{\fboxsep}{1.5ex}\setlength{\fboxrule}{1.2pt}{\sffamily
\framebox{\parbox{\textwidth}{\textbf{Some other instructions.}}}}\\[3ex]}

 %\AtBeginDocument{
 %\renewcommand\stepverssols{\immediate\write\sols{{\string\large\string\textbf{\es@solutionname\ \versionname\ n. \thevers}}}
%}
 %\renewcommand\closeverssols{
 %\immediate\write\sols{\string\vspace{5ex}}}
% }

%%% THIS CODE IS TO CHECK the total score of exercises


\AtEndOfPackage{
\newdimen\punteggio %% NEW 2016/04/11 to check the total score of exercises
\setlength{\punteggio}{0pt}
\def\@PTs#1{%
\addtolength{\punteggio}{#1 pt} %% NEW 2016/04/11 to check the total score of exercises
\global\punteggio=\punteggio
    \gdef\es@PTs{#1}\ifx\es@PTs\@empty\gdef\es@PTs{1}\fi
    \global\let\esPTs=\es@PTs\global\let\es@PTs=\@empty
    \if\es@star*\else\PTs@Hook\fi
}
\renewcommand{\checkpoints}{%
\ifdim\punteggio=\punti pt %% NEW 2016/04/11 to check the total score of exercises
           \else
\PackageError{esami}{\es@pointerrorshort} {\es@pointerrorlong}
      \fi
 \global\punteggio=0pt%
 }
 }


%%%% %%%%% HERE I GET RID OF THE MINIPAGE IN MULTIPLE CHOICE QUESTIONS
%\AtEndOfPackage{
%\renewcommand{\selectrandomly}[1]{%
%\global\@probN=0\relax
%\firstpasstrue
%\tmp@quest=0
%\input{#1}%%%%%
%\firstpassfalse%%% now prints the question
%\tmp@quest=0
%\input{#1}
%\@ifundefined{base\nome}{\old@random=\number\randomi %%% 2015/01/16
%\setrannum{\rnd@cnta}{1}{\@probN}
%\randomi=\number\old@random
%\expandafter\global\expandafter\edef\csname base\nome \endcsname{\number\rnd@cnta}
%}{}
%\FPeval\restotrentasei{round(\thevers+\thenomefile+1+base\nome-trunc((\thevers+\thenomefile+base\nome)/36:0)*36:0)}
%\ifcase\@probN\or
%\def\j@n{1}%%% just one variant
%\or%%% 2 variants
%\ifthenelse{\isodd{\thevers}}{\def\j@n{1}}{\def\j@n{2}}
%\or%%% 3 variants
%\def\j@n{\ifcase\restotrentasei\or 3\or 2\or 1\or 2\or 1\or 3\or 1\or 3\or 2\or 3\or 1\or 2\or 1\or 2\or 3\or 2\or 3\or 1\or 3\or 2\or 1\or 2\or 1\or 3\or 1\or 3\or 2\or 3\or 1\or 2\or 1\or 2\or 3\or 2\or 3\or 1\fi}%
%\or%%% 4 variants
%\def\j@n{\ifcase\restotrentasei\or 3\or 4\or 1\or 2\or 1\or 2\or 3\or 4\or 3\or 1\or 4\or 2\or 4\or 2\or 3\or 1\or 2\or 3\or 1\or 4\or 1\or 4\or 2\or 3\or 3\or 2\or 1\or 4\or 2\or 3\or 4\or 1\or 4\or 3\or 2\or 1\fi}%
%\or%%% 5 variants
%\def\j@n{\ifcase\restotrentasei\or 5\or 1\or 2\or 3\or 4\or 5\or 2\or 3\or 5\or 1\or 4\or 3\or 1\or 4\or 2\or 5\or 4\or 2\or 3\or 5\or 1\or 5\or 1\or 4\or 2\or 3\or 1\or 3\or 5\or 4\or 2\or 3\or 4\or 5\or 2\or 1\fi}%
%\or%%% 6 variants
%\def\j@n{\ifcase\restotrentasei\or 2\or 5\or 1\or 3\or 4\or 2\or 6\or 1\or 3\or 6\or 5\or 4\or 2\or 3\or 2\or 5\or 4\or 1\or 6\or 1\or 4\or 3\or 2\or 6\or 5\or 4\or 6\or 2\or 5\or 1\or 3\or 6\or 3\or 5\or 1\or 4\fi}%
%\or%%% 7 variants
%\def\j@n{\ifcase\restotrentasei\or 2\or 4\or 1\or 5\or 3\or 6\or 7\or 4\or 1\or 5\or 7\or 6\or 2\or 3\or 7\or 2\or 4\or 6\or 5\or 3\or 1\or 3\or 4\or 7\or 2\or 6\or 1\or 5\or 4\or 5\or 6\or 7\or 3\or 2\or 1\or 5\fi}%
%\or%%% 8 variants
%\def\j@n{\ifcase\restotrentasei\or 2\or 8\or 6\or 7\or 4\or 3\or 1\or 5\or 8\or 5\or 1\or 3\or 7\or 6\or 4\or 2\or 7\or 1\or 8\or 6\or 3\or 2\or 5\or 4\or 1\or 3\or 7\or 5\or 6\or 4\or 2\or 8\or 4\or 3\or 1\or 5\fi}%
%\else
%\FPeval\j@n{round(\thevers*\es@primo+base\nome+1-trunc((\thevers*\es@primo+base\nome)/\number\@probN:0)*\number\@probN:0)}
%\fi
%\def\probchosen{\problabel-q:\romannumeral\j@n}
%\ifes@test
%\csname @probi-\problabel-q:\romannumeral\j@n \endcsname \vspace{5mm}
%\Acapo
%\else
%\csname @probi-\problabel-q:\romannumeral\j@n \endcsname \vspace{5mm}
%\Acapo
%\fi
%    \ifes@fillin
%     \immediate\closeout\parametri
%     \fi
%}
%}

%%%% %%%%% HERE I GET RID OF THE MINIPAGE IN EXERCISES
%\AtEndOfPackage{
%\renewenvironment{problem}[1][]{%%% it's like exercise, but with points
%\es@testfalse
%%\begin{minipage}{\linewidth}  %%% new 2016/02/19
%\renewcommand{\punti}{#1}
%\ifes@solutionsonly\else\examenddef\fi
%\begin{exercise}
%\ifes@prova
%\else
%\ifes@solutions
%\immediate\write\loe{\es@exercisename\space \theex@no:\space \probchosen}
%\fi
%\fi
%}
%{
%\end{exercise}
%%\end{minipage}%%% new 2016/02/19
%\ifes@param
%\immediate\closeout\params
%\fi}
%
%\renewenvironment{problem*}[1][]{\es@testfalse
%%\begin{minipage}{\linewidth}  %%% new 2016/02/19
%\renewcommand{\punti}{#1}
%\ifes@solutionsonly\else\examenddef\fi
%\begin{exercise*}
%\ifes@prova
%\else
%\ifes@solutions
%\immediate\write\loe{\es@exercisename\space \theex@no:\space \probchosen}
%\fi
%\fi
%}
%{
%\end{exercise*}
%%\end{minipage}%%% new 2016/02/19
%\ifes@param
%\immediate\closeout\params
%\fi }
%}
%\makeatletter




%\AtEndOfPackage{
%\newcount\old@rando
%\renewcommand{\shuffle}[3][]{% %%% this command has been adapted from probsoln
%\old@rando=\number\randomi
  %\randomi=\thenomefile
  %\@shfctr=1\relax
  %\whiledo{\@shfctr < 101}%
  %{%
    %\setrannum{\@shfA}{1}{#3}\setrannum{\@shfB}{1}{#3}
    %\ifnum\@shfA=\@shfB
    %\else
      %\edef\@@tmpA{\csname#2\romannumeral\@shfA\endcsname}%
      %\let\@tmpA=\@@tmpA
      %\edef\@@tmpB{\csname#2\romannumeral\@shfB\endcsname}%
      %\let\@tmpB=\@@tmpB
      %\expandafter\xdef\csname#2\romannumeral\@shfA\endcsname{\@tmpB}%
      %\expandafter\xdef\csname#2\romannumeral\@shfB\endcsname{\@tmpA}%
    %\fi
    %\advance\@shfctr by 1\relax
    %\ifthenelse{\equal{#1}{}}{}{
  %\@shfA=0%
  %\loop
  %\advance\@shfA by1
  %\expandafter\xdef\csname#1\romannumeral\@shfA\endcsname{\csname#2\romannumeral\@shfA\endcsname}
  %\ifnum\@shfA<#3 \repeat
%}
  %}%
%\randomi=\number\old@rando
%}

%\newcommand{\shufflees}[3][]{% %%% this command has been adapted from probsoln
%%\old@rando=\number\randomi
%%  \randomi=404
  %\@shfctr=1\relax
  %\whiledo{\@shfctr < 101}%
  %{%
    %\setrannum{\@shfA}{1}{#3}\setrannum{\@shfB}{1}{#3}
    %\ifnum\@shfA=\@shfB
    %\else
      %\edef\@@tmpA{\csname#2\romannumeral\@shfA\endcsname}%
      %\let\@tmpA=\@@tmpA
      %\edef\@@tmpB{\csname#2\romannumeral\@shfB\endcsname}%
      %\let\@tmpB=\@@tmpB
      %\expandafter\xdef\csname#2\romannumeral\@shfA\endcsname{\@tmpB}%
      %\expandafter\xdef\csname#2\romannumeral\@shfB\endcsname{\@tmpA}%
    %\fi
    %\advance\@shfctr by 1\relax
    %\ifthenelse{\equal{#1}{}}{}{
  %\@shfA=0%
  %\loop
  %\advance\@shfA by1
  %\expandafter\xdef\csname#1\romannumeral\@shfA\endcsname{\csname#2\romannumeral\@shfA\endcsname}
  %\ifnum\@shfA<#3 \repeat
%}
  %}%
%%\randomi=\number\old@rando
%}

%\renewcommand{\esercizidb}[1]{
 %\icount=0
%\input{#1.tex}%
%\i@sh=0
%\loop
%\advance\i@sh by1
%\expandafter\edef\csname ftemp\romannumeral\i@sh \endcsname {\romannumeral\i@sh}
%\ifnum\i@sh <\number\icount
%\repeat
%\shufflees{ftemp}{\icount}
%\setcounter{n@par}{1}
%\io=\icount
%\loop
%\ifes@test
%\begin{minipage}{.95\linewidth}
%\fi
%\ifes@shuffleQuestions
%\csname prbl\csname ftemp\romannumeral\io\endcsname\endcsname
%\else
%\csname prbl\romannumeral\io \endcsname
%\fi
%\def\probchosen{\problabel-\probnumber}
%\csname @probi-\problabel-\probnumber \endcsname
%\ifes@test
 %\vspace{5mm}\end{minipage}
 %\Acapo
%\vspace{4mm}
 %\fi
       %\advance\io by-1
    %\ifnum\io > 0 \repeat
 %\par}
 %}
%\makeatother
