
У меня возникли проблемы с определением новой среды, которая зависит от опции \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}