![試験クラス: \printanswers に依存する新しい環境を定義します](https://rvso.com/image/370296/%E8%A9%A6%E9%A8%93%E3%82%AF%E3%83%A9%E3%82%B9%3A%20%5Cprintanswers%20%E3%81%AB%E4%BE%9D%E5%AD%98%E3%81%99%E3%82%8B%E6%96%B0%E3%81%97%E3%81%84%E7%92%B0%E5%A2%83%E3%82%92%E5%AE%9A%E7%BE%A9%E3%81%97%E3%81%BE%E3%81%99.png)
試験クラスの \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}