試験クラス: \printanswers に依存する新しい環境を定義します

試験クラス: \printanswers に依存する新しい環境を定義します

試験クラスの \printanswers オプションに依存する新しい環境を定義するのに問題があります。

\documentclass{exam}
\usepackage{framed}

\printanswers
%\noprintanswers 

\newenvironment{note}{\ifprintanswers\begin{framed}\noindent\textbf{Note:}\par\noindent}{\end{framed}\fi}

\begin{document}
\begin{questions}
\question
question
\begin{solution}
    this is the solution
\end{solution}

\begin{note}
    this is a note
\end{note}

\end{questions}
\end{document}

\printanswers を使用するとすべて正常に見えますが、\noprintanswers を使用するとエラーが発生します。

! Incomplete \iffalse; all text was ignored after line 17.

\noprintanswers を使用するときに、ノート環境を非表示にしたいです。

答え1

環境を抑制する 1 つの方法は、それを{comment}verbatim パッケージで定義された環境と同じにすることです。もう 1 つの方法は、コマンドの本体を に入れて\vbox、 を捨てること\vboxです。これは、試験環境が使用するソリューションです。\vboxアプローチは次のとおりです。

\documentclass{exam}
\usepackage{framed}

\newenvironment{note}{%
    \ifprintanswers
        \begin{framed}\noindent\textbf{Note:}\par\noindent
    \else
        \setbox0\vbox\bgroup
    \fi
}{%
    \ifprintanswers
        \end{framed}%
    \else
        \egroup
    \fi%
}

\printanswers
%\noprintanswers

\begin{document}
\begin{questions}
\question
question
\begin{solution}
    this is the solution
\end{solution}

\begin{note}
    this is a note
\end{note}

\end{questions}
\end{document} 

関連情報