
Estoy creando una tarea para estudiantes que contendrá varios capítulos con teoría, ejercicio y solución. Quiero crear preguntas de opción múltiple utilizando un paquete de ejercicios de látex. Creo que este paquete no admite directamente las preguntas frecuentes. Me encontré con algunas piezas del código que he combinado.
Mi objetivo es crear preguntas frecuentes con una o más de una respuesta correcta, de modo que todas las respuestas, junto con las explicaciones y el análisis, aparezcan al final del capítulo.
Si alguien sugiere otros paquetes/métodos, también estaría bien.
\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}
Respuesta1
No estoy seguro de que esto sea lo que quieres lograr, pero puedes usar tasks
el paquete.
Versión actualizada de la respuesta.
Desde la versión v1.0 del tasks
(04/10/2019) la opción counter-format
está obsoleta, ahora es posible usarla label
como en 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}
Versión antigua de la respuesta.
\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}
En ambos casos, la salida es: