我无法定义依赖于考试类别的 \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
要抑制环境,一种技术是使其等于{comment}
verbatim 包定义的环境。另一种方法是将命令主体放入 中\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}