Multiple-Choice-Frage im Übungspaket

Multiple-Choice-Frage im Übungspaket

Ich erstelle eine Aufgabe für Studenten, die mehrere Kapitel mit Theorie, Übungen und Lösungen enthalten soll. Ich möchte Multiple-Choice-Fragen mithilfe des Übungspakets von Latex erstellen. Ich glaube, dieses Paket unterstützt MCQs nicht direkt. Ich bin auf einige Teile des Codes gestoßen, die ich kombiniert habe.

Mein Ziel besteht darin, MC-Fragen mit einer oder mehreren richtigen Antworten zu erstellen, sodass alle Antworten zusammen mit Erklärungen und Analysen am Ende des Kapitels erscheinen.

Wenn jemand andere Pakete/Methoden vorschlägt, wäre das auch in Ordnung.

\documentclass[a4paper]{amsbook}
\usepackage[margin=1in]{geometry}
\usepackage{mathptmx}
\usepackage[cmintegrals, cmbraces]{newtxmath}
\usepackage{hyperref}% you must load it before the exercise package
\usepackage[answerdelayed]{exercise}
\usepackage{environ}

\newlength{\choiceslen}
\newif\ifshowcorrect
\newcounter{choices}
\newcommand{\choicefinal}[1]{%
\ifnum\value{choices}>0 \hfill\fi\egroup
\hspace{0pt}%
\hbox to\choiceslen
\bgroup
\stepcounter{choices}%
\ifcase#1\relax
(\Alph{choices})%
\else
\ifshowcorrect
\expandafter\bfseries
\fi
{(\Alph{choices})}%
\fi\space
}
\newcommand{\choicetemp}[1]{%
\stepcounter{choices}%
\space(\Alph{choices})\cr
}

\NewEnviron{choices}{%
\setcounter{choices}{0}%
\let\choice\choicetemp
\shorthandchoice% <---------- Add \choice shorthand
\settowidth{\choiceslen}{\vbox{\halign{##\hfil\cr\BODY\crcr}}}
\ifdim\choiceslen>.5\textwidth
\setlength{\choiceslen}{\textwidth}%
\else
\ifdim\choiceslen>.25\textwidth
\setlength{\choiceslen}{.5\textwidth}%
\else
\setlength{\choiceslen}{.25\textwidth}%
\fi
\fi
\let\choice\choicefinal
\shorthandchoice% <---------- Add \choice shorthand
\setcounter{choices}{0}%

\begin{flushleft}
\bgroup\BODY\hfill\egroup
\end{flushleft}
}

\newcommand{\shorthandchoice}{%
\let\oldchoice\choice
\renewcommand{\choice}{\oldchoice{0}}
\def\correctchoice{\oldchoice{1}}
}
\parindent 0pt
\linespread{1.1}

\begin{document}
\begin{Exercise}[label={mylabel}]
What is the value of 2+5? Which fruit do you like?(To see the answer click here: \refAnswer{\ExerciseLabel})
\showcorrecttrue
\begin{choices}
\correctchoice apple
\choice banana
\correctchoice orange
\choice pear
\end{choices}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
7 
\end{Answer}

\begin{ExerciseList}
\Exercise What is the value of $\pi$  \showcorrecttrue
\begin{choices}
\correctchoice apple
\choice banana
\correctchoice orange
\choice pear
\end{choices}
\Answer Approximate value is 22/7.
\Exercise What is the value of $e$
\Answer Approximate value is 2.71...
\end{ExerciseList}
\clearpage
\begin{center}
\textbf{\textit{    Answers.}}
\end{center}
\newpage % I've added a new page only to clearly show the hyperlink. Of course, you don't need it in your document.
\shipoutAnswer
\end{document}

Antwort1

Ich bin nicht sicher, ob dies das ist, was Sie erreichen möchten, aber Sie könnten tasksein Paket verwenden.

Aktualisierte Version der Antwort

Seit Version v1.0 tasks(04.10.2019) ist die Option counter-formatveraltet, jetzt ist eine Verwendung labelwie in möglich enumitem.

\documentclass[a4paper]{amsbook}
\usepackage[margin=1in]{geometry}
\usepackage{mathptmx}
\usepackage[cmintegrals, cmbraces]{newtxmath}
\usepackage{hyperref}% you must load it before the exercise package
\usepackage[answerdelayed, lastexercise]{exercise}
\usepackage{tasks}
\settasks{
    label = {(\Alph*)},
    label-width=1.4em
    }

\begin{document}
\chapter{Exercises}
\begin{Exercise}[label={mylabel}]
What is the value of 2+5? (To see the answer click here: \refAnswer{\ExerciseLabel})
\begin{tasks}(4)
\task 2
\task 5
\task\label{correctchoice}7
\task 3
\end{tasks}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
\ref{correctchoice} 7
\end{Answer}
\begin{Exercise}[label={mysecondlabel}]
Which fruit do you like? (To see the answer click here: \refAnswer{\ExerciseLabel})
\begin{tasks}(4)
\task\label{apple}apple
\task banana
\task\label{orange}orange
\task pear
\end{tasks}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
\ref{apple} apple or \ref{orange} orange 
\end{Answer}
\begin{Exercise}[label={mythirdlabel}]
What is the value of $\pi$? (To see the answer click here: \refAnswer{\ExerciseLabel})
\begin{tasks}(4)
\task 2.15
\task 1.31
\task 4.3
\task\label{correct}3.14
\end{tasks}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
\ref{correct} 3.14
\end{Answer}
\chapter{Answers}
\shipoutAnswer
\end{document}

Alte Version der Antwort

\documentclass[a4paper]{amsbook}
\usepackage[margin=1in]{geometry}
\usepackage{mathptmx}
\usepackage[cmintegrals, cmbraces]{newtxmath}
\usepackage{hyperref}% you must load it before the exercise package
\usepackage[answerdelayed, lastexercise]{exercise}
\usepackage{tasks}
\settasks{
    counter-format = {(tsk[A])},
    label-width=1.4em
    }

\begin{document}
\chapter{Exercises}
\begin{Exercise}[label={mylabel}]
What is the value of 2+5? (To see the answer click here: \refAnswer{\ExerciseLabel})
\begin{tasks}(4)
\task 2
\task 5
\task\label{correctchoice}7
\task 3
\end{tasks}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
\ref{correctchoice} 7
\end{Answer}
\begin{Exercise}[label={mysecondlabel}]
Which fruit do you like? (To see the answer click here: \refAnswer{\ExerciseLabel})
\begin{tasks}(4)
\task\label{apple}apple
\task banana
\task\label{orange}orange
\task pear
\end{tasks}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
\ref{apple} apple or \ref{orange} orange 
\end{Answer}
\begin{Exercise}[label={mythirdlabel}]
What is the value of $\pi$? (To see the answer click here: \refAnswer{\ExerciseLabel})
\begin{tasks}(4)
\task 2.15
\task 1.31
\task 4.3
\task\label{correct}3.14
\end{tasks}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
\ref{correct} 3.14
\end{Answer}
\chapter{Answers}
\shipoutAnswer
\end{document}

In beiden Fällen lautet die Ausgabe:

Bildbeschreibung hier eingeben

Bildbeschreibung hier eingeben

verwandte Informationen