
我想在(多項選擇)考試頁面的末尾顯示答案鍵。我有一堆問題和答案(總是認為銀行中的第一個答案是正確的選擇),以及一些用於打亂問題及其答案的宏。所有文件均已附上(這裡)。輸出也如下圖所示。問題是我無法在頁面末尾顯示正確答案。
答案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
環境之前調用,您將獲得正確的密鑰: