获取 mcexam 问题总数

获取 mcexam 问题总数

对于多项选择题考试,我使用麦克萨姆包。似乎没有允许我打印问题总数的命令。有没有办法定义这样的命令?例如:

The total number of questions in this exam is: \numquestions

此命令是为常规exam文档类定义的。我尝试将其添加到我的序言中: \newcommand{\numquestions}{\mc@totalNumberOfQuestions}

但这给了我一个未定义的控制序列。这是一个小例子。由于命令,它不会编译\numquestions。请注意,此示例是 mcexam 附带的 example.tex 文件的精简版本:

\documentclass[a4paper]{article}

\usepackage[output=exam
           ,numberofversions=4
           ,version=1
           ,seed=1
           ,randomizequestions=true
           ,randomizeanswers=true
           ,writeRfile=false
           ]{mcexam}

% Packages used for special things
\usepackage{tikz,framed} 

% Set headers and footers
\usepackage{fancyhdr,lastpage}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt} 
\renewcommand{\footrulewidth}{1pt}
\lfoot{\mctheversion}
\rfoot{Page \thepage\ of \pageref{LastPage}}

% Ensure each question+answers is printed entirely on the same page.
\usepackage{calc}
\renewenvironment{setmcquestion}{\begin{minipage}[t]{\linewidth-\labelwidth}}{\end{minipage}\par}  

\makeatletter
\newcommand{\numquestions}{\mc@totalNumberOfQuestions} %DOES NOT WORK
\makeatother

\begin{document}


\begin{center}
  \bfseries\LARGE Midterm Exam 
\end{center}

\begin{framed}
  \centering\bfseries\Large\MakeUppercase{\mctheversion}
\end{framed}

\mcifoutput{concept,exam}{ 

  \bigskip

  \noindent Name: \dotfill\\[.5\baselineskip]
  \noindent Student Number: \dotfill\\[.5\baselineskip]
  \noindent Program: \dotfill  

  \vspace{2\baselineskip}


  \noindent\textbf{Instructions:}
  \begin{itemize}[nosep]
         \item This exam has \numquestions questions. %THIS THROWS AN UNDEFINED CONTROL SEQUENCE ERROR
  \end{itemize}  
}


\begin{mcquestions}

\question What is the color of the sky?

          \begin{mcanswerslist}[fixlast]
          \answer[correct] blue
          \answer green
          \answer red
          \answer yellow
          \answer none of the above
          \end{mcanswerslist}        

          \begin{mcexplanation}
          If you look up to the sky and there are no clouds, you'll see it is blue.
          \end{mcexplanation}

          \begin{mcnotes}
          This question had a large proportion of good answers last year.
          \end{mcnotes}

\question Which figure is a square?
          \begin{mcanswers}
          \begin{tabular}{@{}cccc}
          \answer{1}{\tikz{\draw (-0.66,0)--(0.66,0)--(0,1)--cycle;}}& 
          \answer{2}{\tikz{\draw (0,0)--(2,0)--(2,1)--(0,1)--cycle;}}& 
          \answer[correct]{3}{\tikz{\draw (0,0)--(1,0)--(1,1)--(0,1)--cycle;}}& 
          \answer{4}{\tikz{\draw (0,0) circle[radius=0.5];}}\\
          \answernum{1}&\answernum{2}&\answernum{3}&\answernum{4}\\
          \end{tabular} 
          \end{mcanswers}


\end{mcquestions}

\end{document}

答案1

这个mcexam包裹是有趣的。顺便说一句,它没有内部用来收集问题总数的功能。我们可以添加一个。

\documentclass[a4paper]{article}

\usepackage[output=exam
           ,numberofversions=4
           ,version=1
           ,seed=1
           ,randomizequestions=true
           ,randomizeanswers=true
           ,writeRfile=false
           ]{mcexam}

% Packages used for special things
\usepackage{tikz,framed} 
\usepackage{fancyhdr,lastpage,totcount,xpatch}
\usepackage{calc}

% Set headers and footers
\pagestyle{fancy}

\fancyhf{}
\renewcommand{\headrulewidth}{0pt} 
\renewcommand{\footrulewidth}{1pt}
\lfoot{\mctheversion}
\rfoot{Page \thepage\ of \pageref{LastPage}}

% Ensure each question+answers is printed entirely on the same page.
\renewenvironment{setmcquestion}
  {\begin{minipage}[t]{\linewidth-\labelwidth}}
  {\end{minipage}\par}

\newtoggle{questionscounted}
\global\togglefalse{questionscounted}
\makeatletter
\newcommand{\patch@mcquestions}{%
  \iftoggle{questionscounted}
    {}
    {%
     \setcounter{numquestions}{\value{mc@counter}}%
     \global\toggletrue{questionscounted}
    }%
}
\newcounter{numquestions}
\regtotcounter{numquestions}
\xpatchcmd{\env@mcquestions@process}
 {\mc@setQuestionAndAnswerNumbers}
 {\mc@setQuestionAndAnswerNumbers\patch@mcquestions}
 {}{}
\makeatother


\begin{document}


\begin{center}
  \bfseries\LARGE Midterm Exam 
\end{center}

\begin{framed}
  \centering\bfseries\Large\MakeUppercase{\mctheversion}
\end{framed}

\mcifoutput{concept,exam}{ 

  \bigskip

  \noindent Name: \dotfill\\[.5\baselineskip]
  \noindent Student Number: \dotfill\\[.5\baselineskip]
  \noindent Program: \dotfill  

  \vspace{2\baselineskip}


  \noindent\textbf{Instructions:}
  \begin{itemize}[nosep]
         \item This exam has \total{numquestions} questions. %THIS THROWS AN UNDEFINED CONTROL SEQUENCE ERROR
  \end{itemize}  
}


\begin{mcquestions}

\question What is the color of the sky?

          \begin{mcanswerslist}[fixlast]
          \answer[correct] blue
          \answer green
          \answer red
          \answer yellow
          \answer none of the above
          \end{mcanswerslist}        

          \begin{mcexplanation}
          If you look up to the sky and there are no clouds, you'll see it is blue.
          \end{mcexplanation}

          \begin{mcnotes}
          This question had a large proportion of good answers last year.
          \end{mcnotes}

\question Which figure is a square?
          \begin{mcanswers}
          \begin{tabular}{@{}cccc}
          \answer{1}{\tikz{\draw (-0.66,0)--(0.66,0)--(0,1)--cycle;}}& 
          \answer{2}{\tikz{\draw (0,0)--(2,0)--(2,1)--(0,1)--cycle;}}& 
          \answer[correct]{3}{\tikz{\draw (0,0)--(1,0)--(1,1)--(0,1)--cycle;}}& 
          \answer{4}{\tikz{\draw (0,0) circle[radius=0.5];}}\\
          \answernum{1}&\answernum{2}&\answernum{3}&\answernum{4}\\
          \end{tabular} 
          \end{mcanswers}

\end{mcquestions}

\end{document}

在此处输入图片描述

另一种解决方案(但我更喜欢另一个)。

\documentclass[a4paper]{article}

\usepackage[output=exam
           ,numberofversions=4
           ,version=1
           ,seed=1
           ,randomizequestions=true
           ,randomizeanswers=true
           ,writeRfile=false
           ]{mcexam}

% Packages used for special things
\usepackage{tikz,framed} 
\usepackage{fancyhdr,lastpage}
\usepackage{calc}

% Set headers and footers
\pagestyle{fancy}

\fancyhf{}
\renewcommand{\headrulewidth}{0pt} 
\renewcommand{\footrulewidth}{1pt}
\lfoot{\mctheversion}
\rfoot{Page \thepage\ of \pageref{LastPage}}

% Ensure each question+answers is printed entirely on the same page.
\renewenvironment{setmcquestion}
  {\begin{minipage}[t]{\linewidth-\labelwidth}}
  {\end{minipage}\par}

\makeatletter
\AtEndDocument{%
  \immediate\write\@auxout{\xdef\string\number@of@questions{\mc@totalNumberOfQuestions}}%
}
\def\numberofquestions{%
  \@ifundefined{number@of@questions}{??}{\number@of@questions}%
}
\makeatother


\begin{document}


\begin{center}
  \bfseries\LARGE Midterm Exam 
\end{center}

\begin{framed}
  \centering\bfseries\Large\MakeUppercase{\mctheversion}
\end{framed}

\mcifoutput{concept,exam}{ 

  \bigskip

  \noindent Name: \dotfill\\[.5\baselineskip]
  \noindent Student Number: \dotfill\\[.5\baselineskip]
  \noindent Program: \dotfill  

  \vspace{2\baselineskip}


  \noindent\textbf{Instructions:}
  \begin{itemize}[nosep]
         \item This exam has \numberofquestions\ questions. %THIS THROWS AN UNDEFINED CONTROL SEQUENCE ERROR
  \end{itemize}  
}


\begin{mcquestions}

\question What is the color of the sky?

          \begin{mcanswerslist}[fixlast]
          \answer[correct] blue
          \answer green
          \answer red
          \answer yellow
          \answer none of the above
          \end{mcanswerslist}        

          \begin{mcexplanation}
          If you look up to the sky and there are no clouds, you'll see it is blue.
          \end{mcexplanation}

          \begin{mcnotes}
          This question had a large proportion of good answers last year.
          \end{mcnotes}

\question Which figure is a square?
          \begin{mcanswers}
          \begin{tabular}{@{}cccc}
          \answer{1}{\tikz{\draw (-0.66,0)--(0.66,0)--(0,1)--cycle;}}& 
          \answer{2}{\tikz{\draw (0,0)--(2,0)--(2,1)--(0,1)--cycle;}}& 
          \answer[correct]{3}{\tikz{\draw (0,0)--(1,0)--(1,1)--(0,1)--cycle;}}& 
          \answer{4}{\tikz{\draw (0,0) circle[radius=0.5];}}\\
          \answernum{1}&\answernum{2}&\answernum{3}&\answernum{4}\\
          \end{tabular} 
          \end{mcanswers}

\end{mcquestions}

\end{document}

相关内容