![考試課程:定義取決於 \printanswers 的新環境](https://rvso.com/image/370296/%E8%80%83%E8%A9%A6%E8%AA%B2%E7%A8%8B%EF%BC%9A%E5%AE%9A%E7%BE%A9%E5%8F%96%E6%B1%BA%E6%96%BC%20%5Cprintanswers%20%E7%9A%84%E6%96%B0%E7%92%B0%E5%A2%83.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
要抑制環境,一種技巧是使其等於{comment}
逐字包定義的環境。另一種是將命令體放入 a\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}