计算 examdesign 中问题类型的数量

计算 examdesign 中问题类型的数量

在之前的问题我问过如何计算考试中的题目总数。现在我很好奇如何计算题目类型的数量 - 例如多项选择题和简答题。

我借鉴了@samcarter 的优秀解决方案,并使用 为多项选择题、简答题和所有问题定义了唯一的计数器etoolbox。但是,它们并没有按计划工作。总共有 5 个问题。总问题计数器 ( thenumquestions) 是正确的,简答题计数器 ( thesa) 也是正确的,但多项选择题计数器 ( \themc) 正在计算所有问题。

问题在于所有问题都由 定义\begin{question},并且我试图在每种问题类型(\begin{multiplechoice}\begin{shortanswer})中分别计算这些实例。

我也尝试借鉴解决方案通过为不同的问题定义不同的环境来实现课堂上的唯一计数exam,但它会引发错误。

我究竟做错了什么?

\documentclass[10pt]{examdesign}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\SectionFont{\large\bfseries\ttfamily}
\ContinuousNumbering
\Fullpages
\NoKey
\NumberOfVersions{1}

\let\namedata\relax

\usepackage{etoolbox}

\newcounter{numquestions}
\setcounter{numquestions}{0}
\AtBeginEnvironment{question}{\addtocounter{numquestions}{1}}

\newcounter{mc}
\setcounter{mc}{0}
\AtBeginEnvironment{multiplechoice}{\AtBeginEnvironment{question}{\addtocounter{mc}{1}}}
\AtEndEnvironment{multiplechoice}{\setcounter{mc}{\value{mc}}}

\newcounter{sa}
\setcounter{sa}{0}
\AtBeginEnvironment{shortanswer}{\AtBeginEnvironment{question}{\addtocounter{sa}{1}}}


\usepackage{totcount}

\newtotcounter{s}
\setcounter{s}{0}
\newenvironment{mcquestion}[1]{
    \stepcounter{s}
    \begin{question} 
    #1 
    \end{question}
   }


\begin{document}

\begin{examtop}
This exam is worth all the marbles. It contains  \themc\ MC questions and \thesa\ short answer questions. There are a total of \thenumquestions\ questions.\\
\end{examtop}

\begin{multiplechoice}[]

\begin{mcquestion}
    Yes?
        \choice[!]{Yes.}
        \choice{No.}
\end{mcquestion}


\begin{question}
  True?
    \choice[!]{True.}
    \choice{False.}
    \choice{Maybe.}
    \choice{Dunno.}
\end{question}

\begin{question}
  False?
    \choice{True.}
    \choice[!]{False.}
    \choice{Maybe.}
    \choice{Dunno.}
\end{question}
\end{multiplechoice}

\begin{shortanswer}[]
\begin{question}
What is love?
\begin{answer}
Baby don't hurt me. 
\end{answer}
\end{question}

\begin{question}
What is the meaning of life?
\begin{answer}
42. 
\end{answer}
\end{question}

\begin{question}
Are you sure?
\begin{answer}
Yes. 
\end{answer}
\end{question}
\end{shortanswer}

\end{document}

答案1

在此处输入图片描述

\documentclass[10pt]{examdesign}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\SectionFont{\large\bfseries\ttfamily}
\ContinuousNumbering
\Fullpages
\NoKey
\NumberOfVersions{1}

\let\namedata\relax

\usepackage{etoolbox}

\newcounter{qcount}
\setcounter{qcount}{0}
\AtBeginEnvironment{question}{\addtocounter{qcount}{1}}

\newcounter{mcount}
\setcounter{mcount}{0}
\AtBeginEnvironment{question}{\ifbool{insidemc}{\addtocounter{mcount}{1}}{}}

\newbool{insidemc}
\makeatletter
\renewenvironment{multiplechoice}[1][]
  {\setbool{insidemc}{true}
  \begin{section}
   \def\@currentsectionname{multiplechoice}
   \exam@definesectiontype{multiplechoice}
   \exam@SetDefaultRearrangeBehavior
   \exam@SetDefaultSectionTitle{\exam@notitle}
   \exam@SetDefaultRecountState{\exam@DefaultNumberingBehavior}
   \setkeys{section}{#1}%
   \get@instructions \relax}
  {\end{section}
  \setbool{insidemc}{false}}
\makeatother  

\newcounter{scount}
\setcounter{scount}{0}
\AtBeginEnvironment{question}{\ifbool{insides}{\addtocounter{scount}{1}}{}}

\newbool{insides}
\makeatletter
\renewenvironment{shortanswer}[1][]
  {\setbool{insides}{true}
  \begin{section}
   \def\@currentsectionname{shortanswer}
   \exam@definesectiontype{shortanswer}
   \exam@SetDefaultRearrangeBehavior
   \exam@SetDefaultSectionTitle{\exam@notitle}
   \exam@SetDefaultRecountState{\exam@DefaultNumberingBehavior}
   \setkeys{section}{#1}%
   \get@instructions \relax}
  {\end{section}
  \setbool{insides}{false}}
\makeatother


\begin{document}

\begin{examtop}
This exam is worth all the marbles. It contains  
\themcount\ 
MC questions and 
\thescount\ 
short answer questions. There are a total of 
\theqcount\ 
questions.\\
\end{examtop}

\begin{multiplechoice}[]

\begin{question}
    Yes?
        \choice[!]{Yes.}
        \choice{No.}
\end{question}


\begin{question}
  True?
    \choice[!]{True.}
    \choice{False.}
    \choice{Maybe.}
    \choice{Dunno.}
\end{question}

\begin{question}
  False?
    \choice{True.}
    \choice[!]{False.}
    \choice{Maybe.}
    \choice{Dunno.}
\end{question}
\end{multiplechoice}

\begin{shortanswer}[]
\begin{question}
What is love?
\begin{answer}
Baby don't hurt me. 
\end{answer}
\end{question}

\begin{question}
What is the meaning of life?
\begin{answer}
42. 
\end{answer}
\end{question}

\begin{question}
Are you sure?
\begin{answer}
Yes. 
\end{answer}
\end{question}
\end{shortanswer}

\end{document}

相关内容