考試類別:不列印問題

考試類別:不列印問題

假設我正在使用考試課程。有一個\printanswers列印解決方案的選項,否則不會列印解決方案。我想抑制問題並只列印解決方案。這可能嗎?

編輯

我添加了一個基本的解決方法,但也許有更好的方法來做到這一點?這是使用修改後的考試類別的演示,發現這裡

% Document
\documentclass[12pt]{exam2}

\usepackage[margin=1.0in]{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath}

\pagestyle{fancy}
\lhead{The author}
\rhead{The assignment}

\setcounter{section}{1}
\unframedsolutions

% Preamble
\printquestions
\printanswers

\begin{document}
\numberwithin{question}{section}

\begin{questions}

\begin{quest}
What is $\int_{0}^{5} x^2 dx$?

\end{quest}

\begin{solution}

This integral can be calculated as

\begin{align}
\int_{0}^{5} x^3 &= \Big[ \frac{x^3}{3} \Big|_{0}^{5} \notag \\
&= \frac{5^{3}}{3}
\end{align}

\end{solution}

\begin{quest} 
The next question would go here

\questp{a}{Part a of the question}
\questsp{i}{Subpart of a}
\questspnob{More information}

\end{quest}

\begin{solution}
The next answer would go here

\begin{parts}
\part Parts works in solution environment
\begin{subparts}
\subpart Here is a subpart
\end{subparts}
\end{parts}

\end{solution}

\end{questions}

\end{document}

問題與解答

% Preamble: 
\printquestions
\printanswers

問題與解答

僅限問題

% Preamble:
\printquestions
%\printanswers

問題

僅提供答案

% Preamble:
%\printquestions
\printanswers

答案

答案1

我對 exam.cls 進行了以下更改。

首先我新增了一個 \printquestions 選項。

\newif\ifprintanswers
\printanswersfalse
\DeclareOption{answers}{\printanswerstrue}
\DeclareOption{noanswers}{\printanswersfalse}

% BEGIN EDIT %
\newif\ifprintquestions
\printquestionsfalse
\DeclareOption{yesquestions}{\printquestionstrue}
\DeclareOption{noquestions}{\printquestionsfalse}
% END EDIT %

然後後來

\def\printanswers{\printanswerstrue}
\def\noprintanswers{\printanswersfalse}

\def\printquestions{\printquestionstrue}

接下來,我修改解決方案環境。如果我不列印問題,那麼我希望解決方案環境充當 \question。

\newenvironment{solution}[1][0pt]{%
  \ifprintquestions % act as a solution
    \@insolutiontrue % cancelled by the end of the environment
    \@addpointsfalse % cancelled by the end of the environment
    \ifprintanswers
      \begingroup
      \Solution@Emphasis
      \begin{TheSolution}%
    \else
      \ifcancelspace
        % Do nothing
      \else
        \par
        \penalty 0
        \vspace*{#1}%
      \fi
      \setbox\z@\vbox\bgroup
    \fi
  \else %act as a question
    \question
  \fi
  }{%
  \ifprintquestions %act as a solution
    \ifprintanswers
      \end{TheSolution}%
      \endgroup
    \else
      \egroup
    \fi
    \fi
  }%

接下來,我新增一個可以隱藏的任務環境。但是,需要使用它來代替 \question。

\newenvironment{quest}[1][0pt]%
  {%
    \ifprintquestions % act as a question
        \question
    \else % don't show the question
        %\par
        %\vspace*{-9mm} %
      \setbox\z@\vbox\bgroup
    \fi
  }{%
    \ifprintquestions
        % don't do anything
    \else % hide the group
      \egroup
    \fi
  }%

一件煩人的事情是逐項列表、部分和子部分在我定義的環境中不起作用(我相信這是由於\question 呼叫初始化了一些我沒有初始化的變數。因此,我創建了一些基本的逐項列表指令使用表格環境。

% PART
\newcommand{\questp}[2]{%
\begin{tabular}{R{0.25cm} p{14.75cm}}
(#1) & #2 \\ 
\end{tabular}

{}
}

\usepackage{array,booktabs,ragged2e}
\newcolumntype{R}[1]{>{\RaggedLeft\arraybackslash}p{#1}}
\newcommand{\questsp}[2]{%
 \hspace*{2em}\begin{tabular}{R{1cm} p{13.15cm}}
(#1) & #2 \\
\end{tabular}

{}
}

% SUBPART
\newcommand{\questssp}[1]{%
\hspace*{8em}\begin{tabular}{p{10.75cm}}
#1 \\ 
\end{tabular}

{}
}

更多的部分命令可以這樣定義。

\newcommand{\questpnob}[1]{%
\begin{tabular}{R{0.25cm} p{13.15cm}}
 & #1 \\
\end{tabular}

{}
}

\newcommand{\questspnob}[1]{%
 \hspace*{2em}\begin{tabular}{R{1cm} p{13.15cm}}
& #1 \\
\end{tabular}

{}
}

相關內容