2
1

J'ai besoin d'aide pour adapter le code suivant pour avoir la possibilité de proposer plus qu'une vraie réponse par question, et ce dans un QCM « multiparties » à insérer dans un livre que je suis en train de rédiger.

Le problème avec le code fourni dans le manuel utilisateur xsim est que, après avoir désigné une réponse (par exemple "A", parmi les choix ABCD) comme étant vraie, si une proposition supplémentaire du QCM est choisie (par exemple C) , celle-ci est ignorée une fois une proposition supplémentaire est désignée comme vraie (voir image jointe)

La structure de mon QCM : à la fin de chaque chapitre un QCM d'auto-évaluation est fourni ; les réponses sont collectées suivant la procédure xsim et les réponses de toutes les questions sont fournies en fin du livre.

Le code à adapter:

\documentclass[12pt,a4paper]{article}
\usepackage{xsim}
\usepackage{tasks}
\NewTasksEnvironment[
label = \textbf{\Alph*.},
label-width = 15pt
]{choice}[\choice](4)
\DeclareExerciseEnvironmentTemplate{item}
{\description\item[\GetExerciseName~\GetExerciseProperty{counter}]}
{\enddescription}
\DeclareExerciseEnvironmentTemplate{space}
{\textbf{\GetExerciseProperty{counter}} }
{\quad}
\newcommand*\answer[1]{%
    \XSIMexpandcode{%
            \SetExerciseProperty{solution-body}
            {\noexpand{\Alph{task}}}}%
        #1%
}
\DeclareExerciseCollection{Section1}
\xsimsetup{
    exercise/template = item ,
    solution/template = space ,
    exercise/name = Q. ,
    exercise/the-counter = \arabic{exercise}. ,
    exercise/collect ,
    random/sort = false
}
\begin{document}
    \section{Section 1}
            \collectexercises{Section1}
            Il y a 2 réponses vraies par question, mais c'est toujours la dernière qui est reprise dans la liste des réponses!
        \begin{exercise}
            Lesquels donnent un résultat égale à $-6$?
            \begin{choice}(2)
                \choice \answer $-6 \times 1$
                \choice $-3 \times -2$
                \choice $-6 \times -1$
                \choice \answer $3 \times -2$
            \end{choice}
        % Here the only fourth choice's answer key (the second correct one here "D") is diplayed in answers section
    \end{exercise}
    \begin{exercise}
        Lesquels sont des pays africains?
            \begin{choice}(4)
                \choice \answer Nigeria
                \choice \answer South africa
                \choice Canada
                \choice Germany
            \end{choice}
        % Here the only second choice's answer key (the second correct one here "B") is diplayed in answers section
    \end{exercise}
    \begin{exercise}
        Lesquels sont exacts?
            \begin{choice}(2)
                \choice \answer $-2\times-3=6$
                \choice $-2-3=-6$
                \choice \answer $2+3=5$
                \choice $-2+3=-5$
            \end{choice}
        % Here the only tirth choice's answer key (the second correct one here "C") is diplayed in answers section
    \end{exercise}
            \collectexercisesstop{Section1}
        \subsection{Questions}
            \printrandomexercises[collection=Section1]{5}
        \subsection{Réponses}
            \printsolutions[headings=false]
\end{document}

Posée 10 Fév '23, 22:06

sc-log's gravatar image

sc-log
312
Taux d'acceptation : 0%

Modifiée 14 Fév '23, 15:48

@sc-log : j'ai édité votre question. Il y manquait notamment un mot : j'espère que c'est « à la fin de chaque chapitre » qu'un QCM d'auto-évaluation est fourni. Ce pourrait évidemment être à la fin de chaque page, de chaque section...

(14 Fév '23, 12:45) Pathe ♦♦ Pathe's gravatar image

Merci beaucoup @Pathe, j'ai aussi réduit le code, prière de jeter un coup d'oeil.

(14 Fév '23, 14:21) sc-log sc-log's gravatar image
1

J'ai écourté la première version de mon message en essayant de rendre celui-ci plus clair et concis ; j'ai également fourni un ECM.

(14 Fév '23, 15:49) sc-log sc-log's gravatar image

@touhami et @denis, merci de tout intérêt que vous porterez à ma requête. J'ai confiance en vos compétences en Latex.

(16 Fév '23, 22:08) sc-log sc-log's gravatar image

Voici une solution.

Il faut modifier la définition de la commande \answer pour quelle puisse collecter les différentes réponses.

!TEX none
\newcommand*\answer[1]{%
\xdef\multichoicehook{\ifx\multichoicehook\empty\else\multichoicehook, \fi\noexpand{\Alph{task}}}
\XSIMexpandcode{%
\SetExerciseProperty{solution-body}{\multichoicehook}}%
#1}

Il faut aussi ajouter le réglage suivant pour réinitialiser la commande \multichoicehook:

!TEX none
\xsimsetup{
exercise/template = item ,
solution/template = space ,
exercise/name = Q. ,
exercise/the-counter = \arabic{exercise}. ,
exercise/collect ,
random/sort = false,
exercise/begin-hook ={\let\multichoicehook\empty}
}

ECM.

\documentclass[12pt,a4paper]{article}
\usepackage{xsim}
\usepackage{tasks}
\NewTasksEnvironment[
label = \textbf{\Alph*.},
label-width = 15pt
]{choice}[\choice](4)
\DeclareExerciseEnvironmentTemplate{item}
{\description\item[\GetExerciseName~\GetExerciseProperty{counter}]}
{\enddescription}
\DeclareExerciseEnvironmentTemplate{space}
{\textbf{\GetExerciseProperty{counter}} }
{\quad}
\newcommand*\answer[1]{%
\xdef\multichoicehook{\ifx\multichoicehook\empty\else\multichoicehook, \fi\noexpand{\Alph{task}}}
\XSIMexpandcode{%
\SetExerciseProperty{solution-body}{\multichoicehook}}%
#1}
\DeclareExerciseCollection{Section1}
\xsimsetup{
    exercise/template = item ,
    solution/template = space ,
    exercise/name = Q. ,
    exercise/the-counter = \arabic{exercise}. ,
    exercise/collect ,
    random/sort = false,
    exercise/begin-hook ={\let\multichoicehook\empty}
}
\begin{document}
    \section{Section 1}
            \collectexercises{Section1}
            Il y a 2 réponses vraies par question, mais c'est toujours la dernière qui est reprise dans la liste des réponses!
        \begin{exercise}
            Lesquels donnent un résultat égale à $-6$?
            \begin{choice}(2)
                \choice \answer $-6 \times 1$
                \choice $-3 \times -2$
                \choice $-6 \times -1$
                \choice \answer $3 \times -2$
            \end{choice}
        % Here the only fourth choice's answer key (the second correct one here "D") is diplayed in answers section
    \end{exercise}
    \begin{exercise}
        Lesquels sont des pays africains?
            \begin{choice}(4)
                \choice \answer Nigeria
                \choice \answer South africa
                \choice Canada
                \choice Germany
            \end{choice}
        % Here the only second choice's answer key (the second correct one here "B") is diplayed in answers section
    \end{exercise}
    \begin{exercise}
        Lesquels sont exacts?
            \begin{choice}(2)
                \choice \answer $-2\times-3=6$
                \choice $-2-3=-6$
                \choice \answer $2+3=5$
                \choice $-2+3=-5$
            \end{choice}
        % Here the only tirth choice's answer key (the second correct one here "C") is diplayed in answers section
    \end{exercise}
            \collectexercisesstop{Section1}
        \subsection{Questions}
            \printrandomexercises[collection=Section1]{5}
        \subsection{Réponses}
            \printsolutions[headings=false]
\end{document}
Lien permanent

Publiée 17 Fév '23, 14:48

touhami's gravatar image

touhami
9.7k410
Taux d'acceptation : 51%

Modifiée 17 Fév '23, 14:50

@touhami, merci de tout cœur pour votre réponse précieuse et rapide.

(18 Fév '23, 08:16) sc-log sc-log's gravatar image
Votre réponse
(dés)activer l'aperçu

Suivre cette question

Par courriel :

Une fois que vous serez enregistré, vous pourrez souscrire à n'importe quelle mise à jour ici

Par flux RSS :

Réponses

Réponses et commentaires

Bases de Markdown

  • *italique* ou _italique_
  • **gras** ou __gras__
  • Lien ::[texte](http://url.com/ "Titre ")
  • Image : ?![alt texte](/path/img.jpg "Titre ")
  • Liste numérotée : 1. Foo 2. Bar
  • Pour ajouter un passage à la ligne, ajoutez deux espaces à l'endroit où vous souhaitez que la ligne commence.
  • Les balises HTML de base sont également prises en charge.