如何在文档末尾显示多项选择题答案?

如何在文档末尾显示多项选择题答案?

我想在(多项选择题)考试页面的末尾显示答案键。我有一个问题和答案库(库中的第一个答案始终被认为是正确选择),还有一些宏来对问题及其答案进行打乱。所有文件都附在(这里)。输出也显示在下面。问题是我无法在页面末尾显示正确的答案。 示例输出

答案1

有各种各样的软件包可以帮助你制作考试和测验。我对它们不太熟悉,因为我自己制作过。下面是我使用的非常简化的版本:

\documentclass{article}

\makeatletter

\newcounter{ae@prob@cnt}
\let\ae@answer@key\relax

\newcommand\problem[1][a]{%%
  \stepcounter{ae@prob@cnt}%%
  \edef\ae@tmp{\theae@prob@cnt/#1}%%
  \ifx\relax\ae@answer@key
    \edef\ae@answer@key{\ae@tmp}%%
  \else
    \edef\ae@answer@key{\ae@answer@key,\ae@tmp}%%
  \fi
  Problem \theae@prob@cnt\hspace{1em}%%%
  }

\newcommand\presentanswerkey{%%
  \expandafter\ae@present@answers\ae@answer@key,\relax\@nil}

\def\ae@present@answers#1,#2\@nil{%%
  \def\ae@continue{}%%
  \ae@parse@pair#1\@nil
  \ifx\relax#2
  \else
    \def\ae@continue{\ae@present@answers#2\@nil}%%
  \fi
  \ae@continue}

\def\ae@parse@pair#1/#2\@nil{%%
  #1\hspace{0.25cm}#2\par}

\makeatother

\begin{document}

\problem[a] This is a question

\problem[b] This is another question

\problem[d] This is the penultimate question

\problem[c] My favorite question.

\presentanswerkey

\end{document}

更新

以下是上述内容的修改版本:

\makeatletter
\let\ae@answer@key\relax
\newcommand\buildanswerkey[2]{%%
  \typeout{===>#1:#2}%%
  \edef\ae@tmp{#1/#2}%%
  \ifx\relax\ae@answer@key
    \xdef\ae@answer@key{\ae@tmp}%%
  \else
    \xdef\ae@answer@key{\ae@answer@key,\ae@tmp}%%
  \fi}

\newcommand\presentanswerkey{%%
  \typeout{===>\detokenize\expandafter{\ae@answer@key}}%%
  \expandafter\ae@present@answers\ae@answer@key,\relax\@nil}

\def\ae@present@answers#1,#2\@nil{%%
  \def\ae@continue{}%%
  \ae@parse@pair#1\@nil
  \ifx\relax#2
  \else
    \def\ae@continue{\ae@present@answers#2\@nil}%%
  \fi
  \ae@continue}

\def\ae@parse@pair#1/#2\@nil{%%
  #1\hspace{0.25cm}#2\par}

\makeatother

将其保存在名为的文件中buildanswerkey.tex,并将其加载到您的commandsPerm.tex文件中。

在中commandsPerm.tex,我重写了几行如下:

%%-----------------------------------------
\pgfmathrandomitemwithoutreplacement\j{tmp}
\sbox\answera{\ifx\j\correctAnswer * \expandafter\buildanswerkey\expandafter{\thequestion}{a}\fi\ifcase\j\relax\or#1\or#2\or#3\or#4\fi}%
\ifx\j\javab \questionhaspoints{\thequestion = 1} \fi
%%-----------------------------------------
\pgfmathrandomitemwithoutreplacement\j{tmp}
\sbox\answerb{\ifx\j\correctAnswer * \expandafter\buildanswerkey\expandafter{\thequestion}{b}\fi\ifcase\j\relax\or#1\or#2\or#3\or#4\fi}%
\ifx\j\javab \questionhaspoints{\thequestion = 2} \fi
%%-----------------------------------------
\pgfmathrandomitemwithoutreplacement\j{tmp}
\sbox\answerc{\ifx\j\correctAnswer * \expandafter\buildanswerkey\expandafter{\thequestion}{c}\fi\ifcase\j\relax\or#1\or#2\or#3\or#4\fi}%
\ifx\j\javab \questionhaspoints{\thequestion = 3} \fi
%%-----------------------------------------
\pgfmathrandomitemwithoutreplacement\j{tmp}
\sbox\answerd{\ifx\j\correctAnswer * \expandafter\buildanswerkey\expandafter{\thequestion}{d}\fi\ifcase\j\relax\or#1\or#2\or#3\or#4\fi}%
\ifx\j\javab \questionhaspoints{\thequestion = 4} \fi

然后,当您编译文件时,您将获得一个答案键。我没有费心去弄清楚您打算如何创建答案键,但是通过\presentanswerkey在退出mcquestions环境之前调用,您将获得一个正确的键:

在此处输入图片描述

相关内容