This question is a following of the two clever and efficient answers linked below to elaborate semi-interactive quizzes/MCQ with ocgx2 (OCG/OCMG).
(1) ocgx2: verify and reset of Multiple Choice Questions with OCGs
The next step I want to deal with is to allow automatically three trials to the user each time he/she click on the check button (see the layout of the result without cosmetics). At the third step, the points are assigned. For the moment being, I am able to on one hand, have the correct/wrong quiz proposals with the OCMD layers, and on the other hand, a set of three symbols related to the trial number (OCG layers). The idea is to mix the two orientations.
After many tests, with nested or not environments, I must admit that I am lost... I certainly don't understand everything about the power of OCG/OCMG. Therefore, is this approach feasible? Intuitively I think so but if yes, how to solve such an issue?
I am also aware of the PDF viewers limitations:
(3) Tikz & OCG: make button cycling through different layers
I do hope that the new (2019) OCMD layers for LaTeX could be a friend...
MWE
\documentclass[10pt]{article}
\usepackage{xparse}
\usepackage{etoolbox}
\usepackage{xcolor}
\usepackage{fontawesome5}
\usepackage[tikz]{ocgx2}
\usepackage{calc}
\newcounter{quizquestion}
\newcounter{mcqproposal}
\newcounter{mcqquiztotal}
\newcounter{trialnumber}
\newlength{\quizcheckboxwidth}
\NewDocumentEnvironment{quizquestion}{ m m }%
{
\stepcounter{quizquestion}%
\let\mcqproposal\mcqproposalMultiple%
}
{
\mcqcheck{#1}{#2}%
\hspace{0.1\linewidth}%
\mcqresetcheck
}
\NewDocumentCommand{\mcqproposalMultiple}{ m }{%
% Syntax − #1 = proposal/statement
\parbox[t]{16pt}{%
\hspace*{2pt}%
\quizMultipleButton{mcqproposalref.\thequizquestion.\themcqproposal}%
}%
\parbox[t]{\linewidth-16pt}{#1}%
}
\NewDocumentCommand{\quizMultipleButton}{m}{%
% Syntax − #1: choice id for answering proposal
% Action on click: toggle myself (choice layer), hide verification layer
\stepcounter{mcqproposal}%
\stepcounter{mcqquiztotal}%
\setlength{\quizcheckboxwidth}{\widthof{\faIcon[regular]{square}}}%
\makebox[\quizcheckboxwidth][c]{%
\actionsocg{#1}{}{check.\thequizquestion}{\faIcon[regular]{square}}%
}%
\begin{ocg}{#1}{#1}{off}% choice layer
\hspace{-\quizcheckboxwidth}%
\makebox[\quizcheckboxwidth][c]{\textcolor{green!60!black}{\faCheckSquare}}%
\hspace{-\quizcheckboxwidth}%
\makebox[\quizcheckboxwidth][c]{\faIcon[regular]{square}}%
\end{ocg}%
}
%%% check button
\NewDocumentCommand{\askreplymcqArgsIdsCheck}{m}{%
mcqproposalref.\thequizquestion.#1%
}
\ExplSyntaxOn
\cs_new_protected:Npn \askreplymcqcheck_process_list:Nn #1 #2
{
% clear the sequence
\seq_clear:N #1
% cycle through the arguments, storing "\mcqArgsIds{<arg>}" in the sequence
\clist_map_inline:nn { #2 }
{
% Here :Nx instead of :Nn ensures that \askreplymcqArgsIds
% is actually evaluated instead of passed as-is
\seq_put_right:Nx #1 { \askreplymcqArgsIdsCheck{##1} }
}
}
\seq_new:N \l_correct_seq
\seq_new:N \l_wrong_seq
\cs_new_protected:Npn \askreplymcq__check:nn #1 #2
{\showocg{check.\thequizquestion}{%
\begin{tikzpicture}
\node[draw] (checkbutton) {\strut Check};%
\end{tikzpicture}%
}
\begin{ocg}{check.\thequizquestion}%
{check.\thequizquestion}{off}% verification layer
\makebox[0pt][l]{%
\begin{ocmd}{\Not{\And{#1,\Not{\Or{#2}}}}}% "wrong" layer (OCMD)
\hspace{0.25em}%
\raisebox{5pt}{\textcolor{red!60!black}{\faTimes}}%Wrong.
\end{ocmd}%
}%
%\makebox[0pt][l]{%
\begin{ocmd}{\And{#1,\Not{\Or{#2}}}}% "correct" layer (OCMD)
\hspace{0.25em}%
\raisebox{5pt}{\textcolor{green!60!black}{\faCheck}}%Correct.
\end{ocmd}%
%}
\end{ocg}%
\makebox[0pt][l]{\actionsocg{trialstep1}{}{trialstep2,trialstep3}{\textcolor{black}{\faCircle}}}%
\begin{ocg}{trialstep1}{trialstep1}{off}% choice layer
\makebox[\widthof{\faCircle}]{\textcolor{red}{\faCircle}}%
\stepcounter{trialnumber}\thetrialnumber
\end{ocg}%
\makebox[0pt][l]{\actionsocg{trialstep2}{trialstep1}{trialstep3}{\textcolor{black}{\faCircle}}}%
\begin{ocg}{trialstep2}{trialstep2}{off}% choice layer
\makebox[\widthof{\faCircle}]{\textcolor{red}{\faCircle}}%
\stepcounter{trialnumber}\thetrialnumber
\end{ocg}%
\makebox[0pt][l]{\actionsocg{trialstep3}{trialstep1,trialstep2}{}{\textcolor{black}{\faCircle}}}%
\begin{ocg}{trialstep3}{trialstep3}{off}% choice layer
\makebox[\widthof{\faCircle}]{\textcolor{red}{\faCircle}}%
\stepcounter{trialnumber}\thetrialnumber
\end{ocg}%
}
\cs_generate_variant:Nn \askreplymcq__check:nn {ff}
\NewDocumentCommand{\mcqcheck}{ m m }{%
% Syntax − #1: list of OCG ids of correct/required answer(s), comma separated
% #2: list of OCG ids of wrong answer(s), comma separated
\askreplymcqcheck_process_list:Nn \l_correct_seq { #1 }% Save OCMD IDs as LaTeX3 seq variable
\askreplymcqcheck_process_list:Nn \l_wrong_seq { #2 }% Save OCMD IDs as LaTeX3 seq variable
\askreplymcq__check:ff { \seq_use:Nn \l_correct_seq {,} } { \seq_use:Nn \l_wrong_seq {,} }
}
\ExplSyntaxOff
%%% reset button
\NewDocumentCommand{\mcqresetcheck}{}{%
\def\ocglistresetcheck{}%
\xdef\ocglistresetcheck{%
\ocglistresetcheck, check.\thequizquestion}%
\foreach \X in {1,...,\value{mcqquiztotal}} {%
\xdef\ocglistresetcheck{\ocglistresetcheck, mcqproposalref.\thequizquestion.\X}%
}%
\hideocg{\ocglistresetcheck}{%
\begin{tikzpicture}
\node[draw] (resetbutton) {\strut Reset};
\end{tikzpicture}%
}%
}
\begin{document}
\begin{quizquestion}{2,4,5}{1,3,6,7,8,9,10,11,12,13}
Which are the colour components of an RGB image?\ Multiple required assertions.\[8pt]
\mcqproposal{Magenta.}\
\mcqproposal{Green.}\
\mcqproposal{Cyan.}\
\mcqproposal{Blue.}\
\mcqproposal{Red.}\
\mcqproposal{Black.}\
\mcqproposal{Yellow.}\
\mcqproposal{Magenta.}\
\mcqproposal{Gray.}\
\mcqproposal{Purple.}\
\mcqproposal{White.}\
\mcqproposal{Pink.}\
\mcqproposal{Maroon.}\[8pt]
\end{quizquestion}
\end{document}


animateto implement a trials indicator such that I am exploiting it here ;-). – AlexG Mar 19 '22 at 21:23