Cómo componer subpreguntas y las respuestas correspondientes

Cómo componer subpreguntas y las respuestas correspondientes

Me gustaría componer ejercicios con subpreguntas para que en el código tenga una respuesta inmediatamente después de cada subpregunta, pero en el resultado todas las respuestas estarán al final. También quiero que tanto los ejercicios como las subpreguntas se numeren automáticamente. Sé que existen varios paquetes para ejercicios de composición tipográfica (por ejemplo, 'respuestas', 'ejercicio' y 'probsoln'). También sé que existe un tipo de documento llamado 'examen'.

Mi pregunta es: ¿Qué paquete funcionaría mejor para esto y qué tipo de código produciría el resultado?

Me gustaría escribir algo como lo siguiente:

\begin{ExerciseList}
  \Exercise{}
    Calculate the following:
    \Question{$7+2$}
      \Answer{$9$}
    \Question{$9-9$}
      \Answer{$0$}
    \Question{$5+5+5$}
      \Answer{$15$}
  \Exercise{}
    Solve the following equations:
    \Question{$x+5=7$}
      \Answer{$x=2$}
    \Question{$x-5=9$}
      \Answer{$x=14$}
    \Question{$5x=20$}
      \Answer{$x=4$}
\end{ExerciseList}

Y quiero que el documento final se vea así:

Ejercicio 1
Calcula lo siguiente:
a) 7+2 b) 9-9 c) 5+5+5

Ejercicio 2
Resuelve las siguientes ecuaciones:
a) x+5=7 b) x-5=9 c) 5x=20

Soluciones:

Ejercicio 1
a) 9b) 0c) 15

Ejercicio 2
a) x+5=7 b) x=14 c) x=4

El código que tengo arriba es sólo un ejemplo. Los comandos no tienen que ser exactamente como los he escrito siempre y cuando la estructura sea similar.

Respuesta1

Con el probsolnpaquete, los problemas se pueden definir dentro del documento o en un archivo externo que se puede cargar usando un comando como \loadallproblemso \loadrandomproblems.

A continuación se muestra un ejemplo sencillo con los problemas definidos en el documento:

\documentclass{article}

\usepackage{probsoln}

\begin{defproblem}{prob1}% label
  \begin{onlyproblem}% question
    Calculate the following:%

    \begin{textenum}
    \item $7+2$
    \item $9-9$
    \item $5+5+5$
    \end{textenum}
  \end{onlyproblem}%
  \begin{onlysolution}% solution
    \begin{textenum}
    \item $9$
    \item $0$
    \item $15$
    \end{textenum}
  \end{onlysolution}
\end{defproblem}

\begin{defproblem}{prob2}% label
  \begin{onlyproblem}% question
    Solve the following equations:

    \begin{textenum}
    \item $x+5=7$
    \item $x-5=9$
    \item $5x=20$
    \end{textenum}
  \end{onlyproblem}%
  \begin{onlysolution}% solution
    \begin{textenum}
    \item $x=2$
    \item $x=14$
    \item $x=4$
    \end{textenum}
  \end{onlysolution}
\end{defproblem}

\begin{document}
\renewcommand{\labelenumii}{\theenumii)}

\begin{enumerate}
\foreachproblem{\item\thisproblem}
\end{enumerate}

\section*{Solutions}

\showanswers
\begin{enumerate}
\foreachsolution{\item\thisproblem}
\end{enumerate}

\end{document}

Esto produce

Imagen de documento que muestra los problemas y las soluciones.

El formato se puede cambiar. Por ejemplo, utilizando elenumitempaquete:

\documentclass{article}

\usepackage{probsoln}
\usepackage{enumitem}

\begin{defproblem}{prob1}% label
  \begin{onlyproblem}% question
    Calculate the following:%

    \begin{textenum}
    \item $7+2$
    \item $9-9$
    \item $5+5+5$
    \end{textenum}
  \end{onlyproblem}%
  \begin{onlysolution}% solution
    \begin{textenum}
    \item $9$
    \item $0$
    \item $15$
    \end{textenum}
  \end{onlysolution}
\end{defproblem}

\begin{defproblem}{prob2}% label
  \begin{onlyproblem}% question
    Solve the following equations:

    \begin{textenum}
    \item $x+5=7$
    \item $x-5=9$
    \item $5x=20$
    \end{textenum}
  \end{onlyproblem}%
  \begin{onlysolution}% solution
    \begin{textenum}
    \item $x=2$
    \item $x=14$
    \item $x=4$
    \end{textenum}
  \end{onlysolution}
\end{defproblem}

\newenvironment{ExerciseList}
{\begin{enumerate}[label={\emph{Exercise \arabic*}},%
   ref={\arabic*},wide]
  \renewcommand{\labelenumii}{\theenumii)}%
}
{\end{enumerate}}

\newcommand{\exercise}{\item\mbox{}\par}

\begin{document}

\begin{ExerciseList}
\foreachproblem{\exercise\thisproblem}
\end{ExerciseList}

\section*{Solutions}

\showanswers
\begin{ExerciseList}
\foreachsolution{\exercise\thisproblem}
\end{ExerciseList}

\end{document}

Esto produce:

Imagen del documento resultante

Editar:

Aquí tienes una alternativa donde puedes escribir la respuesta junto a la pregunta en el código:

\documentclass{article}

\usepackage{probsoln}
\usepackage{enumitem}

\newcommand{\QA}[2]{%
  \begin{onlyproblem}#1\end{onlyproblem}%
  \begin{onlysolution}#2\end{onlysolution}}

\begin{defproblem}{prob1}% label
  \begin{onlyproblem}% question
    Calculate the following:%

  \end{onlyproblem}%
  \begin{textenum}
    \item \QA{$7+2$}{$9$}
    \item \QA{$9-9$}{$0$}
    \item \QA{$5+5+5$}{$15$}
  \end{textenum}
\end{defproblem}

\begin{defproblem}{prob2}% label
  \begin{onlyproblem}% question
    Solve the following equations:

  \end{onlyproblem}%
  \begin{textenum}
    \item \QA{$x+5=7$}{$x=2$}
    \item \QA{$x-5=9$}{$x=14$}
    \item \QA{$5x=20$}{$x=4$}
  \end{textenum}
\end{defproblem}

\newenvironment{ExerciseList}
{\begin{enumerate}[label={\emph{Exercise \arabic*}},%
   ref={\arabic*},wide]
  \renewcommand{\labelenumii}{\theenumii)}%
}
{\end{enumerate}}

\newcommand{\exercise}{\item\mbox{}\par}

\begin{document}

\begin{ExerciseList}
\foreachproblem{\exercise\thisproblem}
\end{ExerciseList}

\section*{Solutions}

\showanswers
\begin{ExerciseList}
\foreachsolution{\exercise\thisproblem}
\end{ExerciseList}

\end{document}

El resultado es el mismo que el ejemplo anterior.

Edición 2:

A continuación se muestra un método que define y muestra el problema. La etiqueta se genera automáticamente:

\documentclass{article}

\usepackage{probsoln}
\usepackage{enumitem}

\newcommand{\QA}[2]{%
  \begin{onlyproblem}#1\end{onlyproblem}%
  \begin{onlysolution}#2\end{onlysolution}}

\newenvironment{ExerciseList}
{\begin{enumerate}[label={\emph{Exercise \arabic*}},%
   ref={\arabic*},wide]
  \renewcommand{\labelenumii}{\theenumii)}%
}
{\end{enumerate}}

\newcommand{\exercise}{\item\mbox{}\par}

\newcommand{\Exercise}[2]{\exercise 
 #1\par
 \begin{defproblem}{prob\arabic{enumi}}%
  \begin{textenum}%
  #2%
  \end{textenum}%
 \end{defproblem}%
 \useproblem{prob\arabic{enumi}}%
}

\begin{document}

\begin{ExerciseList}
 \Exercise{Calculate the following:}%
 {%
    \item \QA{$7+2$}{$9$}
    \item \QA{$9-9$}{$0$}
    \item \QA{$5+5+5$}{$15$}
 }%

 \Exercise{Solve the following equations:}
 {%
    \item \QA{$x+5=7$}{$x=2$}
    \item \QA{$x-5=9$}{$x=14$}
    \item \QA{$5x=20$}{$x=4$}
 }
\end{ExerciseList}

\section*{Solutions}

\showanswers
\begin{ExerciseList}
\foreachsolution{\exercise\thisproblem}
\end{ExerciseList}

\end{document}

Respuesta2

Aquí hay una solución usando el answerspaquete. Puedes jugar con el formato de las respuestas.

\documentclass[pdftex,12pt]{article}

\usepackage{amsmath}
\usepackage{answers}

\newcommand{\answerFileName}{anexamanswers}
\Newassociation{sol}{Solution}{\answerFileName}
\Opensolutionfile{\answerFileName}

\newenvironment{Exercise}[1]
{\item #1
\begin{enumerate}
}
{
\end{enumerate}
}

\newcommand{\Question}[1]{%
\item #1
}


\begin{document}
\begin{enumerate}

\begin{Exercise}{Calculate the following:}
    \Question{$7+2$}
     \begin{sol}
         $9$
     \end{sol}
    \Question{$9-9$}
      \begin{sol}
          $0$
      \end{sol}
\end{Exercise}

\begin{Exercise}{Solve the following equations:}
    \Question{$x+5=7$}
      \begin{sol}
        $x=2$
     \end{sol}
    \Question{$x-5=9$}
%      \Answer{$x=14$}
    \Question{$5x=20$}
%      \Answer{$x=4$}
\end{Exercise}

\end{enumerate}

\Closesolutionfile{\answerFileName}
\newpage
Answers to Exercises:

\input{\answerFileName}
\end{document}

ingrese la descripción de la imagen aquí

Respuesta3

Aquí hay una sugerencia para usar los paquetes exsheetsand tasks:

\documentclass{article}
\usepackage{exsheets,tasks}
\SetupExSheets{
  solution/name=Exercise ,
  headings-format=\itshape
}
\begin{document}

\begin{question}
  Calculate the following:
  \begin{tasks}(3)
    \task $7+2$
    \task $9-9$
    \task $5+5+5$
  \end{tasks}
\end{question}
\begin{solution}
  \begin{tasks}(3)
    \task $9$
    \task $0$
    \task $15$
  \end{tasks}
\end{solution}

\begin{question}
  Solve the following equations:
  \begin{tasks}(3)
    \task $x+5=7$
    \task $x-5=9$
    \task $5x=20$
  \end{tasks}
\end{question}
\begin{solution}
  \begin{tasks}(3)
    \task $x=2$
    \task $x=14$
    \task $x=4$
  \end{tasks}
\end{solution}

\section*{Solutions}
\printsolutions

\end{document}

ingrese la descripción de la imagen aquí

información relacionada