%%
%% This is file `aleph-moodle.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% aleph-moodle.dtx  (with options: `aleph-moodle')
%% 
%% This is a generated file.
%% LaTeX class for typesetting books
%% 
%% Copyright (C) 2020 by Jonathan Ortiz <jonathan.ortiz.c347@gmail.com>
%% 
%% Para un mejor uso y entendimiento de la actual clase,
%% consultar la documentación.
%% 
\NeedsTeXFormat{LaTeX2e}[2009/09/24]
\ProvidesPackage{aleph-moodle}[2023/12/25 v2.0]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% --- Opciones
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Opciones predeterminadas ninguna
\ProcessOptions\relax
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% --- Paquetes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Son necesarios los siguientes paquetes para utilizar los comandos.
\RequirePackage{iftex}
\ifPDFTeX % FOR LATEX and PDFLATEX
\RequirePackage[draft,subsection]{moodle}
\else % assuming XELATEX or LUALATEX
\RequirePackage[subsection]{moodle}
\fi
\RequirePackage{enumitem}
\RequirePackage{amsmath,amssymb}
\RequirePackage{xcolor}
\RequirePackage{tcolorbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% --- Modificaciones
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Formato retroalimentación
\newtcbox{\retroalimentacion}{bottom=1mm,top=-4mm}
%%  Cambio los estilos de enumeración de opción múltiple
%%  y el formato de la retroalimentación
\def\moodle@multi@latexprocessing{%
  \ifmoodle@allornothing
    \moodle@singletrue
  \fi
  \moodle@countcorrectanswers%
  \ifmoodle@handout\NewList{answerlist}\fi
  \begin{enumerate}[label=\textit{\alph*)}]%%
    \setlength\itemsep{0pt}\setlength\parskip{0pt}%
    \loopthroughitemswithcommand{\moodle@print@multichoice@answer}%
    \ifmoodle@handout
      \ifmoodle@shuffle
        \let\moodle@multi@loop=\ForEachRandomItem
      \else
        \let\moodle@multi@loop=\ForEachFirstItem
      \fi
      \moodle@multi@loop{answerlist}{Answer}{\Answer}%
    \fi
  \end{enumerate}%
  \ifmoodle@handout\else
    \ifx\moodle@generalfeedback\@empty\relax\else%
      \retroalimentacion{\parbox{0.87\linewidth}{\small\paragraph{\small Retroalimentaci\'on:}\moodle@generalfeedback}}%
    \fi
  \fi
}
%% Cambio de formato de la retroalimentación numérica
\ifmoodle@handout
  \let\moodle@numerical@latexprocessing\relax
\else
  \def\moodle@numerical@latexprocessing{%
    \begin{itemize} \setlength\itemsep{0pt}\setlength\parskip{0pt}%
      \loopthroughitemswithcommand{\moodle@print@numerical@answer}%
    \end{itemize}%
    \ifx\moodle@generalfeedback\@empty\relax\else%
      \retroalimentacion{\parbox{0.87\linewidth}{\paragraph{\small Retroalimentaci\'on:}{\small \moodle@generalfeedback}}}%
    \fi
  }
\fi
%%  Cambio de formato de la retroalimentación de respuesta corta
\ifmoodle@handout
  \let\moodle@shortanswer@latexprocessing\relax
\else
  \def\moodle@shortanswer@latexprocessing{%
    \begin{itemize} \setlength\itemsep{0pt}\setlength\parskip{0pt}%
      \loopthroughitemswithcommand{\moodle@print@shortanswer@answer}%
    \end{itemize}%
    \ifx\moodle@generalfeedback\@empty\relax\else%
      \retroalimentacion{\parbox{0.87\linewidth}{\paragraph{\small Retroalimentaci\'on:}{\small \moodle@generalfeedback}}}%
    \fi
  }
\fi
%%  Eliminación del total de puntos
\renewenvironment{quiz}[2][]{%
  \setkeys{moodle}{#1}%
  \gdef\setcategory##1{%
    % At first call (end of \begin{quiz}) enumerate is not started yet
    \ifx\@currenvir\@enumeratename
      % In case no question is defined between two calls of \setcategory
      \def\@noitemerr{}%\@latex@warning{Empty question list}
      \end{enumerate}%
    \fi
    \gdef\moodle@currentcategory{##1}%
    \moodle@write@category@xml{##1}%
    \ifmoodle@section
      \ifmoodle@numbered
        \section{##1}%
      \else
        \section*{##1}%
      \fi
    \else
      \ifmoodle@numbered
        \subsection{##1}%
      \else
        \subsection*{##1}%
      \fi
    \fi
    \begin{enumerate}%
  }%
  \gdef\setsubcategory##1{%
    \def\@noitemerr{}%\@latex@warning{Empty question list}
    \end{enumerate}%
    \moodle@write@category@xml{\moodle@currentcategory/##1}%
    \ifmoodle@section
      \ifmoodle@numbered
        \subsection{##1}%
      \else
        \subsection*{##1}%
      \fi
    \else
      \ifmoodle@numbered
        \subsubsection{##1}%
      \else
        \subsubsection*{##1}%
      \fi
    \fi
    \begin{enumerate}%
  }%
  \setcategory{#2}%
}{%
  \end{enumerate}%
  \let\setcategory\relax
  \let\setsubcategory\relax
}%
%%  Eliminación de las etiquedas en el tipo multiopción
\RenewEnviron{multi}[2][]{%
    \bgroup
      \setkeys{moodle}{#1,questionname={#2}}%
      \global\advance\moodle@totalmarks by \csname moodle@default grade\endcsname pt
      \expandafter\gatheritems\xa{\BODY}%
      \let\moodle@questionheader=\gatheredheader
      %First, the LaTeX processing
      \item \textbf{\moodle@questionname}\par
      \noindent
      \moodle@questionheader
      \edef\moodle@generalfeedback{\expandonce\moodle@feedback}
      \csname moodle@multi@latexprocessing\endcsname
      %Now, writing information to XML
      \@moodle@ifgeneratexml{%
        \xa\questiontext\xa{\moodle@questionheader}% Save the question text.
        \csname writemultiquestion\endcsname
        \bgroup
          \gdef\moodle@answers@xml{}%
          \setkeys{moodle}{feedback={}}%
          \xa\loopthroughitemswithcommand\xa{\csname savemultianswer\endcsname}%
          \passvalueaftergroup{\moodle@answers@xml}%
        \egroup
        \moodle@writeanswers%
        \moodle@writetags%
        \writetomoodle{</question>}%
      }{}%
    \egroup
  }%
%%  Eliminación de las etiquedas en el tipo numérico
\RenewEnviron{numerical}[2][]{%
    \bgroup
      \setkeys{moodle}{#1,questionname={#2}}%
      \global\advance\moodle@totalmarks by \csname moodle@default grade\endcsname pt
      \expandafter\gatheritems\xa{\BODY}%
      \let\moodle@questionheader=\gatheredheader
      %First, the LaTeX processing
      \item \textbf{\moodle@questionname}\par
      \noindent
      \moodle@questionheader
      \edef\moodle@generalfeedback{\expandonce\moodle@feedback}
      \csname moodle@numerical@latexprocessing\endcsname
      %Now, writing information to XML
      \@moodle@ifgeneratexml{%
        \xa\questiontext\xa{\moodle@questionheader}% Save the question text.
        \csname writenumericalquestion\endcsname
        \bgroup
          \gdef\moodle@answers@xml{}%
          \setkeys{moodle}{feedback={}}%
          \xa\loopthroughitemswithcommand\xa{\csname savenumericalanswer\endcsname}%
          \passvalueaftergroup{\moodle@answers@xml}%
        \egroup
        \moodle@writeanswers%
        \moodle@writetags%
        \writetomoodle{</question>}%
      }{}%
    \egroup
  }%
%%  Eliminación de las etiquedas en el tipo respuesta corta
\RenewEnviron{shortanswer}[2][]{%
  \bgroup
    \setkeys{moodle}{#1,questionname={#2}}%
    \global\advance\moodle@totalmarks by \csname moodle@default grade\endcsname pt
    \expandafter\gatheritems\xa{\BODY}%
    \let\moodle@questionheader=\gatheredheader
    %First, the LaTeX processing.
      \item \textbf{\moodle@questionname}\par
      \noindent
      \moodle@questionheader
      \edef\moodle@generalfeedback{\expandonce\moodle@feedback}
      \csname moodle@shortanswer@latexprocessing\endcsname
    %Now, writing information to memory.
    \@moodle@ifgeneratexml{%
      \xa\questiontext\xa{\moodle@questionheader}% Save the question text.
      \csname writeshortanswerquestion\endcsname
      \bgroup
        \gdef\moodle@answers@xml{}%
        \setkeys{moodle}{feedback={}}%
        \xa\loopthroughitemswithcommand\xa{\csname
        saveshortansweranswer\endcsname}%
        \passvalueaftergroup{\moodle@answers@xml}%
      \egroup
        \moodle@writeanswers%
        \moodle@writetags%
        \writetomoodle{</question>}%
    }{}%
  \egroup
}%
%%  Corrección del comando pm
\def\moodle@print@numerical@answer@int@int#1\@rdelim{%
 \gdef\test@i{#1}%
 \trim@spaces@in\test@i
 \ifx\test@i\@star
   \item \test@i
 \else
   \item \moodle@printnum{#1}%
   \ifx\moodle@tolerance\moodle@zero\else
     $\,\pm \,$\moodle@printnum{\expandonce\moodle@tolerance}%
   \fi
 \fi
 \ifx\moodle@fraction\@hundred
   $~\checkmark$%
 \else
   \moodle@checkfraction
   $~(\moodle@fraction\%)$%
 \fi
 \ifx\moodle@feedback\@empty\relax\else
   \moodle@preFeedback \emph{$\rightarrow$ \moodle@feedback}%
 \fi
}%
%%  Y ¡se acabó!
\endinput
%%
%% End of file `aleph-moodle.sty'.
